@rdlabo/ionic-angular-kit 22.0.0-5 → 22.0.0-7
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/docs/offline-realtime.md +31 -0
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs +26 -8
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit.mjs +36 -6
- package/fesm2022/rdlabo-ionic-angular-kit.mjs.map +1 -1
- package/package.json +1 -1
- package/types/rdlabo-ionic-angular-kit-offline.d.ts +17 -4
- package/types/rdlabo-ionic-angular-kit.d.ts +14 -1
package/docs/offline-realtime.md
CHANGED
|
@@ -69,6 +69,37 @@ not rely on ordering between guards declared in the same `canActivate` array.
|
|
|
69
69
|
Keep `provideOffline()` for existing root installations. Moving a provider is an application design
|
|
70
70
|
choice; adopting the new API is not a required migration.
|
|
71
71
|
|
|
72
|
+
### Defer remote work until authenticated content is visible
|
|
73
|
+
|
|
74
|
+
Route-scoped applications can open only the local substrate on the activation path, then resume
|
|
75
|
+
pull and Outbox transport after their first useful content has rendered. Existing applications keep
|
|
76
|
+
the blocking behavior unless they opt in to both settings below.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const offlineReadyGuard: CanActivateFn = async () => {
|
|
80
|
+
await inject(OfflineRouteInitializerService).initialize({ remote: 'deferred' });
|
|
81
|
+
return true;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
createOfflineAuthBridge({
|
|
85
|
+
exchange,
|
|
86
|
+
currentAuthSubject,
|
|
87
|
+
isUnavailableError,
|
|
88
|
+
resumeMode: 'background',
|
|
89
|
+
beforeRemoteResume: () => authenticatedContentReady.wait(),
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`activate` still installs and lease-checks the remotely verified identity before the guard grants
|
|
94
|
+
access. Only `resumeRemoteSession()` is deferred. Keep `resumeMode: 'blocking'` when the route needs
|
|
95
|
+
the first pull or Outbox replay before it can render safely. A readiness promise should include a
|
|
96
|
+
bounded fallback so a deep link that does not render the primary content cannot suspend transport
|
|
97
|
+
indefinitely. Always call `startRemoteRuntime()` after that same boundary, including when the
|
|
98
|
+
credential exchange falls back to local access. This installs network discovery so an offline start
|
|
99
|
+
can recover immediately when connectivity returns. Start the fallback timer only after local access
|
|
100
|
+
has been granted; starting it in the local initializer can launch the remote runtime while a slow
|
|
101
|
+
credential exchange is still pending.
|
|
102
|
+
|
|
72
103
|
## Realtime connection
|
|
73
104
|
|
|
74
105
|
Subclass `KitRealtimeConnection` to supply connection intent and `{ url, protocols }` targets. The kit owns foreground and network suspension, target-scoped reconnect, exponential backoff, ping/pong detection, self-echo annotation, and `reconnected$` resync signaling.
|
|
@@ -4893,10 +4893,10 @@ class OfflineCoordinatorService {
|
|
|
4893
4893
|
await this.resumeRemoteSession();
|
|
4894
4894
|
}
|
|
4895
4895
|
/** Installs a remotely verified identity without starting pull or outbox replay. */
|
|
4896
|
-
async prepareRemoteSession(userId, scopeIds, authSubject, authLease) {
|
|
4896
|
+
async prepareRemoteSession(userId, scopeIds, authSubject, authLease, options = {}) {
|
|
4897
4897
|
const revision = ++this.#transitionRevision;
|
|
4898
4898
|
const lease = this.#lease(revision, authLease);
|
|
4899
|
-
await this.initialize();
|
|
4899
|
+
await (options.deferRuntime ? this.initializeLocal() : this.initialize());
|
|
4900
4900
|
if (this.#storageUnavailable())
|
|
4901
4901
|
return true;
|
|
4902
4902
|
if (!lease.isCurrent())
|
|
@@ -5022,7 +5022,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
|
|
|
5022
5022
|
*/
|
|
5023
5023
|
function createOfflineAuthBridge(options) {
|
|
5024
5024
|
const offline = options.offline ?? inject(OfflineCoordinatorService);
|
|
5025
|
-
const { exchange, currentAuthSubject, isUnavailableError, isIdentityCurrent, onRemoteResumed, retryDelayMs } = options;
|
|
5025
|
+
const { exchange, currentAuthSubject, isUnavailableError, isIdentityCurrent, beforeRemoteResume, onRemoteResumed, resumeMode, retryDelayMs, } = options;
|
|
5026
5026
|
const defaultAvailability$ = options.availability
|
|
5027
5027
|
? undefined
|
|
5028
5028
|
: toObservable(offline.networkState).pipe(map((state) => state !== 'offline'), distinctUntilChanged());
|
|
@@ -5040,19 +5040,32 @@ function createOfflineAuthBridge(options) {
|
|
|
5040
5040
|
if (!identityStillCurrent(lease, identity))
|
|
5041
5041
|
return false;
|
|
5042
5042
|
return {
|
|
5043
|
+
resumeMode,
|
|
5043
5044
|
activate: async (activateLease) => {
|
|
5044
5045
|
if (!identityStillCurrent(activateLease, identity))
|
|
5045
5046
|
return false;
|
|
5046
5047
|
const identityLease = {
|
|
5047
5048
|
isCurrent: () => identityStillCurrent(activateLease, identity),
|
|
5048
5049
|
};
|
|
5049
|
-
const prepared = await offline.prepareRemoteSession(identity.userId, identity.scopeIds, identity.authSubject, identityLease
|
|
5050
|
+
const prepared = await offline.prepareRemoteSession(identity.userId, identity.scopeIds, identity.authSubject, identityLease, {
|
|
5051
|
+
deferRuntime: resumeMode === 'background',
|
|
5052
|
+
});
|
|
5050
5053
|
return prepared && identityLease.isCurrent();
|
|
5051
5054
|
},
|
|
5052
5055
|
resume: async (resumeLease) => {
|
|
5053
5056
|
const resumeStillCurrent = () => (resumeLease?.isCurrent() ?? true) && currentAuthSubject() === identity.authSubject && (isIdentityCurrent?.(identity) ?? true);
|
|
5054
5057
|
if (!resumeStillCurrent())
|
|
5055
5058
|
return;
|
|
5059
|
+
if (beforeRemoteResume) {
|
|
5060
|
+
await beforeRemoteResume({
|
|
5061
|
+
phase,
|
|
5062
|
+
state,
|
|
5063
|
+
lease: resumeLease ?? lease,
|
|
5064
|
+
identity,
|
|
5065
|
+
});
|
|
5066
|
+
if (!resumeStillCurrent())
|
|
5067
|
+
return;
|
|
5068
|
+
}
|
|
5056
5069
|
await offline.resumeRemoteSession(identity.foregroundScopeIds !== undefined ? { foregroundScopeIds: identity.foregroundScopeIds } : undefined);
|
|
5057
5070
|
if (!resumeStillCurrent())
|
|
5058
5071
|
return;
|
|
@@ -6758,14 +6771,19 @@ class OfflineRouteInitializerService {
|
|
|
6758
6771
|
#errorHandler = inject(ErrorHandler);
|
|
6759
6772
|
#options = inject(OFFLINE_KIT_OPTIONS);
|
|
6760
6773
|
#initialization = null;
|
|
6761
|
-
/** Initialize local storage once,
|
|
6762
|
-
initialize() {
|
|
6763
|
-
return (this.#initialization ??= this.#initialize());
|
|
6774
|
+
/** Initialize local storage once, optionally continuing transport initialization in the background. */
|
|
6775
|
+
initialize(options = {}) {
|
|
6776
|
+
return (this.#initialization ??= this.#initialize(options.remote ?? 'background'));
|
|
6764
6777
|
}
|
|
6765
|
-
|
|
6778
|
+
/** Starts deferred network discovery and synchronization without delaying the caller on transport. */
|
|
6779
|
+
startRemoteRuntime() {
|
|
6766
6780
|
assertSupportedOfflineMode(Capacitor.getPlatform(), this.#options.mode ?? 'synchronized');
|
|
6767
6781
|
return initializeOfflineRuntime(this.#coordinator, this.#errorHandler);
|
|
6768
6782
|
}
|
|
6783
|
+
#initialize(remote) {
|
|
6784
|
+
assertSupportedOfflineMode(Capacitor.getPlatform(), this.#options.mode ?? 'synchronized');
|
|
6785
|
+
return remote === 'deferred' ? this.#coordinator.initializeLocal() : initializeOfflineRuntime(this.#coordinator, this.#errorHandler);
|
|
6786
|
+
}
|
|
6769
6787
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRouteInitializerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
6770
6788
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: OfflineRouteInitializerService }); }
|
|
6771
6789
|
}
|