@rdlabo/ionic-angular-kit 22.0.0-6 → 22.0.0-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
@@ -29,6 +29,7 @@ Install `@ionic/storage-angular` when using storage. Other peers are feature-sco
29
29
  | `@rdlabo/ionic-angular-kit/review` | Throttled native in-app review requests |
30
30
  | `@rdlabo/ionic-angular-kit/printer` | DOM-to-PNG, Brother label, and PDF helpers |
31
31
  | `@rdlabo/ionic-angular-kit/auth-firebase` | Firebase dependency wiring and authentication flows |
32
+ | `@rdlabo/ionic-angular-kit/app-update` | Atomic Angular service-worker update transitions |
32
33
  | `@rdlabo/ionic-angular-kit/live-update` | Capawesome Live Update readiness provider |
33
34
 
34
35
  Secondary entry points isolate optional native and SDK dependencies from the core bundle.
@@ -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.
@@ -1,5 +1,21 @@
1
1
  Optional features use secondary entry points so their native plugins and SDKs do not enter applications that do not use them.
2
2
 
3
+ ## Web application updates
4
+
5
+ `provideKitAppUpdate()` from `/app-update` checks for a complete Angular service-worker version before bootstrap. This blocking
6
+ strategy remains the default for applications where preserving all in-progress input is more important than a slow update check.
7
+
8
+ Applications that prefetch every executable application chunk can opt into a non-blocking startup check:
9
+
10
+ ```ts
11
+ provideKitAppUpdate({ strategy: 'background' });
12
+ ```
13
+
14
+ The background strategy reloads only before Angular completes its first render. A later update is left for the next natural page
15
+ load so user input is not discarded. It never calls `activateUpdate()`, which could mix a running shell with lazy chunks from
16
+ another version. An unrecoverable startup generation is retried once with `ngsw-bypass`; the current history state and an
17
+ offline-safe loop guard are retained.
18
+
3
19
  ## Theme and review
4
20
 
5
21
  `provideKitTheme()` and `KitThemeController` persist a user preference, follow `prefers-color-scheme` until overridden, toggle app-provided palette classes, and synchronize the Android status bar.
@@ -1,21 +1,26 @@
1
1
  import { DOCUMENT } from '@angular/common';
2
2
  import * as i0 from '@angular/core';
3
- import { inject, Injectable, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
3
+ import { inject, Injectable, provideAppInitializer, afterNextRender, makeEnvironmentProviders } from '@angular/core';
4
4
  import { SwUpdate } from '@angular/service-worker';
5
+ import { filter, take } from 'rxjs';
5
6
 
6
7
  const UPDATE_CHECK_TIMEOUT_MS = 10_000;
8
+ const UNRECOVERABLE_RELOAD_KEY = 'kit_sw_unrecoverable_reload';
7
9
  /** Checks for a complete Angular service-worker update before users can interact with the application. */
8
10
  class KitAppUpdateService {
9
11
  #document = inject(DOCUMENT);
10
12
  #updates = inject(SwUpdate);
11
13
  #initialization = null;
14
+ #backgroundStarted = false;
15
+ #interactive = false;
16
+ #reloading = false;
12
17
  /** Runs one startup update check and reloads directly into a downloaded version when one is available. */
13
18
  initialize() {
14
19
  this.#initialization ??= this.#initialize();
15
20
  return this.#initialization;
16
21
  }
17
22
  async #initialize() {
18
- if (!this.#updates.isEnabled || !this.#document.defaultView?.navigator.serviceWorker?.controller) {
23
+ if (!this.#canCheckForUpdate()) {
19
24
  return;
20
25
  }
21
26
  const checkForUpdate = async () => withTimeout(this.#updates.checkForUpdate(), UPDATE_CHECK_TIMEOUT_MS);
@@ -26,6 +31,82 @@ class KitAppUpdateService {
26
31
  })
27
32
  .catch((error) => console.error('Angular service-worker update check failed', error));
28
33
  }
34
+ /** Starts an update check that never blocks bootstrap or reloads after the application becomes interactive. */
35
+ startBackground() {
36
+ if (this.#backgroundStarted || !this.#canCheckForUpdate()) {
37
+ return;
38
+ }
39
+ this.#backgroundStarted = true;
40
+ this.#updates.versionUpdates
41
+ .pipe(filter((event) => event.type === 'VERSION_READY'), take(1))
42
+ .subscribe(() => this.#reloadBeforeInteraction());
43
+ this.#updates.unrecoverable.pipe(take(1)).subscribe((event) => {
44
+ console.error('Angular service-worker state is unrecoverable', event.reason);
45
+ this.#recoverBeforeInteraction(event.reason);
46
+ });
47
+ void this.#updates
48
+ .checkForUpdate()
49
+ .then((available) => {
50
+ if (available) {
51
+ this.#reloadBeforeInteraction();
52
+ }
53
+ })
54
+ .catch((error) => console.error('Angular service-worker update check failed', error));
55
+ }
56
+ /** Marks the first rendered application as interactive. Used by the provider's render hook. */
57
+ markInteractive() {
58
+ this.#interactive = true;
59
+ if (!this.#reloading) {
60
+ this.#clearRecoveryBypass();
61
+ }
62
+ }
63
+ #canCheckForUpdate() {
64
+ return this.#updates.isEnabled && Boolean(this.#document.defaultView?.navigator.serviceWorker?.controller);
65
+ }
66
+ #reloadBeforeInteraction() {
67
+ if (this.#interactive || this.#reloading) {
68
+ return;
69
+ }
70
+ this.#reloading = true;
71
+ this.#document.location?.reload();
72
+ }
73
+ #recoverBeforeInteraction(reason) {
74
+ const location = this.#document.location;
75
+ if (this.#interactive || this.#reloading || !location) {
76
+ return;
77
+ }
78
+ const url = new URL(location.href);
79
+ if (url.searchParams.has('sw_reload')) {
80
+ return;
81
+ }
82
+ const storage = this.#document.defaultView?.sessionStorage;
83
+ const remembered = rememberFailure(storage, reason);
84
+ if (remembered === 'same') {
85
+ return;
86
+ }
87
+ url.searchParams.set('ngsw-bypass', 'true');
88
+ url.searchParams.set('sw_reload', '1');
89
+ this.#reloading = true;
90
+ location.replace(url.toString());
91
+ }
92
+ #clearRecoveryBypass() {
93
+ const location = this.#document.location;
94
+ const history = this.#document.defaultView?.history;
95
+ if (!location || !history) {
96
+ return;
97
+ }
98
+ const url = new URL(location.href);
99
+ if (!url.searchParams.has('sw_reload')) {
100
+ return;
101
+ }
102
+ url.searchParams.delete('ngsw-bypass');
103
+ const storage = this.#document.defaultView?.sessionStorage;
104
+ if (readFailure(storage)) {
105
+ url.searchParams.delete('sw_reload');
106
+ clearFailure(storage);
107
+ }
108
+ history.replaceState(history.state, '', url.toString());
109
+ }
29
110
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: KitAppUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
30
111
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: KitAppUpdateService, providedIn: 'root' }); }
31
112
  }
@@ -33,6 +114,47 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
33
114
  type: Injectable,
34
115
  args: [{ providedIn: 'root' }]
35
116
  }] });
117
+ function rememberFailure(storage, reason) {
118
+ if (!storage) {
119
+ return 'unavailable';
120
+ }
121
+ let existing;
122
+ try {
123
+ existing = storage.getItem(UNRECOVERABLE_RELOAD_KEY);
124
+ }
125
+ catch {
126
+ return 'unavailable';
127
+ }
128
+ if (existing === reason) {
129
+ return 'same';
130
+ }
131
+ try {
132
+ storage.setItem(UNRECOVERABLE_RELOAD_KEY, reason);
133
+ return 'stored';
134
+ }
135
+ catch {
136
+ return 'unavailable';
137
+ }
138
+ }
139
+ function readFailure(storage) {
140
+ if (!storage) {
141
+ return null;
142
+ }
143
+ try {
144
+ return storage.getItem(UNRECOVERABLE_RELOAD_KEY);
145
+ }
146
+ catch {
147
+ return null;
148
+ }
149
+ }
150
+ function clearFailure(storage) {
151
+ try {
152
+ storage?.removeItem(UNRECOVERABLE_RELOAD_KEY);
153
+ }
154
+ catch {
155
+ // A retained value only suppresses the same recovery reason in this tab.
156
+ }
157
+ }
36
158
  /**
37
159
  * Provides a startup check that reloads into the latest complete web application version.
38
160
  *
@@ -41,8 +163,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
41
163
  * than preventing offline startup. API deployments must remain backward compatible while a newly adopted updater is
42
164
  * rolling out because code already running in older application versions cannot gain this behavior retroactively.
43
165
  */
44
- function provideKitAppUpdate() {
45
- return makeEnvironmentProviders([provideAppInitializer(() => inject(KitAppUpdateService).initialize())]);
166
+ function provideKitAppUpdate(options = {}) {
167
+ const initializer = options.strategy === 'background'
168
+ ? provideAppInitializer(() => {
169
+ const updates = inject(KitAppUpdateService);
170
+ updates.startBackground();
171
+ afterNextRender(() => updates.markInteractive());
172
+ })
173
+ : provideAppInitializer(() => inject(KitAppUpdateService).initialize());
174
+ return makeEnvironmentProviders([initializer]);
46
175
  }
47
176
  function withTimeout(promise, timeoutMs) {
48
177
  return new Promise((resolve, reject) => {
@@ -1 +1 @@
1
- {"version":3,"file":"rdlabo-ionic-angular-kit-app-update.mjs","sources":["../../../projects/kit/app-update/src/lib/kit-app-update.provider.ts","../../../projects/kit/app-update/src/public-api.ts","../../../projects/kit/app-update/src/rdlabo-ionic-angular-kit-app-update.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport type { EnvironmentProviders } from '@angular/core';\nimport { Injectable, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\nimport { SwUpdate } from '@angular/service-worker';\n\nconst UPDATE_CHECK_TIMEOUT_MS = 10_000;\n\n/** Checks for a complete Angular service-worker update before users can interact with the application. */\n@Injectable({ providedIn: 'root' })\nexport class KitAppUpdateService {\n readonly #document = inject(DOCUMENT);\n readonly #updates = inject(SwUpdate);\n #initialization: Promise<void> | null = null;\n\n /** Runs one startup update check and reloads directly into a downloaded version when one is available. */\n initialize(): Promise<void> {\n this.#initialization ??= this.#initialize();\n return this.#initialization;\n }\n\n async #initialize(): Promise<void> {\n if (!this.#updates.isEnabled || !this.#document.defaultView?.navigator.serviceWorker?.controller) {\n return;\n }\n const checkForUpdate = async (): Promise<boolean | undefined> => withTimeout(this.#updates.checkForUpdate(), UPDATE_CHECK_TIMEOUT_MS);\n await checkForUpdate()\n .then((available) => {\n if (available) this.#document.location?.reload();\n })\n .catch((error: unknown) => console.error('Angular service-worker update check failed', error));\n }\n}\n\n/**\n * Provides a startup check that reloads into the latest complete web application version.\n *\n * @remarks\n * The check finishes before application bootstrap so a delayed update cannot discard user input. It times out rather\n * than preventing offline startup. API deployments must remain backward compatible while a newly adopted updater is\n * rolling out because code already running in older application versions cannot gain this behavior retroactively.\n */\nexport function provideKitAppUpdate(): EnvironmentProviders {\n return makeEnvironmentProviders([provideAppInitializer(() => inject(KitAppUpdateService).initialize())]);\n}\n\nfunction withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T | undefined> {\n return new Promise((resolve, reject) => {\n const timeout = window.setTimeout(() => resolve(undefined), timeoutMs);\n void promise.then(\n (value) => {\n window.clearTimeout(timeout);\n resolve(value);\n },\n (error: unknown) => {\n window.clearTimeout(timeout);\n reject(error instanceof Error ? error : new Error(String(error)));\n },\n );\n });\n}\n","/** Automatic startup updates for Angular service-worker web applications. */\nexport * from './lib/kit-app-update.provider';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAKA,MAAM,uBAAuB,GAAG,MAAM;AAEtC;MAEa,mBAAmB,CAAA;AACrB,IAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC5B,IAAA,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACpC,eAAe,GAAyB,IAAI;;IAG5C,UAAU,GAAA;AACR,QAAA,IAAI,CAAC,eAAe,KAAK,IAAI,CAAC,WAAW,EAAE;QAC3C,OAAO,IAAI,CAAC,eAAe;IAC7B;AAEA,IAAA,MAAM,WAAW,GAAA;QACf,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC,aAAa,EAAE,UAAU,EAAE;YAChG;QACF;AACA,QAAA,MAAM,cAAc,GAAG,YAA0C,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,uBAAuB,CAAC;AACrI,QAAA,MAAM,cAAc;AACjB,aAAA,IAAI,CAAC,CAAC,SAAS,KAAI;AAClB,YAAA,IAAI,SAAS;AAAE,gBAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE;AAClD,QAAA,CAAC;AACA,aAAA,KAAK,CAAC,CAAC,KAAc,KAAK,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;IAClG;8GArBW,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAnB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA,CAAA;;2FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;AAyBlC;;;;;;;AAOG;SACa,mBAAmB,GAAA;AACjC,IAAA,OAAO,wBAAwB,CAAC,CAAC,qBAAqB,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;AAC1G;AAEA,SAAS,WAAW,CAAI,OAAmB,EAAE,SAAiB,EAAA;IAC5D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACrC,QAAA,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;AACtE,QAAA,KAAK,OAAO,CAAC,IAAI,CACf,CAAC,KAAK,KAAI;AACR,YAAA,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC;AAChB,QAAA,CAAC,EACD,CAAC,KAAc,KAAI;AACjB,YAAA,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC;YAC5B,MAAM,CAAC,KAAK,YAAY,KAAK,GAAG,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,QAAA,CAAC,CACF;AACH,IAAA,CAAC,CAAC;AACJ;;AC3DA;;ACAA;;AAEG;;;;"}
1
+ {"version":3,"file":"rdlabo-ionic-angular-kit-app-update.mjs","sources":["../../../projects/kit/app-update/src/lib/kit-app-update.provider.ts","../../../projects/kit/app-update/src/public-api.ts","../../../projects/kit/app-update/src/rdlabo-ionic-angular-kit-app-update.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport type { EnvironmentProviders } from '@angular/core';\nimport { Injectable, afterNextRender, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\nimport { SwUpdate } from '@angular/service-worker';\nimport type { UnrecoverableStateEvent, VersionEvent } from '@angular/service-worker';\nimport { filter, take } from 'rxjs';\n\nconst UPDATE_CHECK_TIMEOUT_MS = 10_000;\nconst UNRECOVERABLE_RELOAD_KEY = 'kit_sw_unrecoverable_reload';\n\n/** Configuration for Angular service-worker application updates. */\nexport interface KitAppUpdateOptions {\n /** `blocking` preserves startup safety; `background` never delays bootstrap and reloads only before interaction. */\n strategy?: 'blocking' | 'background';\n}\n\n/** Checks for a complete Angular service-worker update before users can interact with the application. */\n@Injectable({ providedIn: 'root' })\nexport class KitAppUpdateService {\n readonly #document = inject(DOCUMENT);\n readonly #updates = inject(SwUpdate);\n #initialization: Promise<void> | null = null;\n #backgroundStarted = false;\n #interactive = false;\n #reloading = false;\n\n /** Runs one startup update check and reloads directly into a downloaded version when one is available. */\n initialize(): Promise<void> {\n this.#initialization ??= this.#initialize();\n return this.#initialization;\n }\n\n async #initialize(): Promise<void> {\n if (!this.#canCheckForUpdate()) {\n return;\n }\n const checkForUpdate = async (): Promise<boolean | undefined> => withTimeout(this.#updates.checkForUpdate(), UPDATE_CHECK_TIMEOUT_MS);\n await checkForUpdate()\n .then((available) => {\n if (available) this.#document.location?.reload();\n })\n .catch((error: unknown) => console.error('Angular service-worker update check failed', error));\n }\n\n /** Starts an update check that never blocks bootstrap or reloads after the application becomes interactive. */\n startBackground(): void {\n if (this.#backgroundStarted || !this.#canCheckForUpdate()) {\n return;\n }\n this.#backgroundStarted = true;\n this.#updates.versionUpdates\n .pipe(\n filter((event: VersionEvent) => event.type === 'VERSION_READY'),\n take(1),\n )\n .subscribe(() => this.#reloadBeforeInteraction());\n this.#updates.unrecoverable.pipe(take(1)).subscribe((event: UnrecoverableStateEvent) => {\n console.error('Angular service-worker state is unrecoverable', event.reason);\n this.#recoverBeforeInteraction(event.reason);\n });\n void this.#updates\n .checkForUpdate()\n .then((available) => {\n if (available) {\n this.#reloadBeforeInteraction();\n }\n })\n .catch((error: unknown) => console.error('Angular service-worker update check failed', error));\n }\n\n /** Marks the first rendered application as interactive. Used by the provider's render hook. */\n markInteractive(): void {\n this.#interactive = true;\n if (!this.#reloading) {\n this.#clearRecoveryBypass();\n }\n }\n\n #canCheckForUpdate(): boolean {\n return this.#updates.isEnabled && Boolean(this.#document.defaultView?.navigator.serviceWorker?.controller);\n }\n\n #reloadBeforeInteraction(): void {\n if (this.#interactive || this.#reloading) {\n return;\n }\n this.#reloading = true;\n this.#document.location?.reload();\n }\n\n #recoverBeforeInteraction(reason: string): void {\n const location = this.#document.location;\n if (this.#interactive || this.#reloading || !location) {\n return;\n }\n const url = new URL(location.href);\n if (url.searchParams.has('sw_reload')) {\n return;\n }\n const storage = this.#document.defaultView?.sessionStorage;\n const remembered = rememberFailure(storage, reason);\n if (remembered === 'same') {\n return;\n }\n url.searchParams.set('ngsw-bypass', 'true');\n url.searchParams.set('sw_reload', '1');\n this.#reloading = true;\n location.replace(url.toString());\n }\n\n #clearRecoveryBypass(): void {\n const location = this.#document.location;\n const history = this.#document.defaultView?.history;\n if (!location || !history) {\n return;\n }\n const url = new URL(location.href);\n if (!url.searchParams.has('sw_reload')) {\n return;\n }\n url.searchParams.delete('ngsw-bypass');\n const storage = this.#document.defaultView?.sessionStorage;\n if (readFailure(storage)) {\n url.searchParams.delete('sw_reload');\n clearFailure(storage);\n }\n history.replaceState(history.state, '', url.toString());\n }\n}\n\nfunction rememberFailure(storage: Storage | undefined, reason: string): 'stored' | 'same' | 'unavailable' {\n if (!storage) {\n return 'unavailable';\n }\n let existing: string | null;\n try {\n existing = storage.getItem(UNRECOVERABLE_RELOAD_KEY);\n } catch {\n return 'unavailable';\n }\n if (existing === reason) {\n return 'same';\n }\n try {\n storage.setItem(UNRECOVERABLE_RELOAD_KEY, reason);\n return 'stored';\n } catch {\n return 'unavailable';\n }\n}\n\nfunction readFailure(storage: Storage | undefined): string | null {\n if (!storage) {\n return null;\n }\n try {\n return storage.getItem(UNRECOVERABLE_RELOAD_KEY);\n } catch {\n return null;\n }\n}\n\nfunction clearFailure(storage: Storage | undefined): void {\n try {\n storage?.removeItem(UNRECOVERABLE_RELOAD_KEY);\n } catch {\n // A retained value only suppresses the same recovery reason in this tab.\n }\n}\n\n/**\n * Provides a startup check that reloads into the latest complete web application version.\n *\n * @remarks\n * The check finishes before application bootstrap so a delayed update cannot discard user input. It times out rather\n * than preventing offline startup. API deployments must remain backward compatible while a newly adopted updater is\n * rolling out because code already running in older application versions cannot gain this behavior retroactively.\n */\nexport function provideKitAppUpdate(options: KitAppUpdateOptions = {}): EnvironmentProviders {\n const initializer =\n options.strategy === 'background'\n ? provideAppInitializer(() => {\n const updates = inject(KitAppUpdateService);\n updates.startBackground();\n afterNextRender(() => updates.markInteractive());\n })\n : provideAppInitializer(() => inject(KitAppUpdateService).initialize());\n return makeEnvironmentProviders([initializer]);\n}\n\nfunction withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T | undefined> {\n return new Promise((resolve, reject) => {\n const timeout = window.setTimeout(() => resolve(undefined), timeoutMs);\n void promise.then(\n (value) => {\n window.clearTimeout(timeout);\n resolve(value);\n },\n (error: unknown) => {\n window.clearTimeout(timeout);\n reject(error instanceof Error ? error : new Error(String(error)));\n },\n );\n });\n}\n","/** Automatic startup updates for Angular service-worker web applications. */\nexport * from './lib/kit-app-update.provider';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAOA,MAAM,uBAAuB,GAAG,MAAM;AACtC,MAAM,wBAAwB,GAAG,6BAA6B;AAQ9D;MAEa,mBAAmB,CAAA;AACrB,IAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC5B,IAAA,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACpC,eAAe,GAAyB,IAAI;IAC5C,kBAAkB,GAAG,KAAK;IAC1B,YAAY,GAAG,KAAK;IACpB,UAAU,GAAG,KAAK;;IAGlB,UAAU,GAAA;AACR,QAA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,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC;YAC3C,OAAO,CAAC,eAAe,EAAE;YACzB,eAAe,CAAC,MAAM,OAAO,CAAC,eAAe,EAAE,CAAC;AAClD,QAAA,CAAC;AACH,UAAE,qBAAqB,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC,UAAU,EAAE,CAAC;AAC3E,IAAA,OAAO,wBAAwB,CAAC,CAAC,WAAW,CAAC,CAAC;AAChD;AAEA,SAAS,WAAW,CAAI,OAAmB,EAAE,SAAiB,EAAA;IAC5D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACrC,QAAA,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;AACtE,QAAA,KAAK,OAAO,CAAC,IAAI,CACf,CAAC,KAAK,KAAI;AACR,YAAA,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC;AAChB,QAAA,CAAC,EACD,CAAC,KAAc,KAAI;AACjB,YAAA,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC;YAC5B,MAAM,CAAC,KAAK,YAAY,KAAK,GAAG,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,QAAA,CAAC,CACF;AACH,IAAA,CAAC,CAAC;AACJ;;AC5MA;;ACAA;;AAEG;;;;"}
@@ -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, then continue transport initialization in the background. */
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
- #initialize() {
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
  }