@rdlabo/ionic-angular-kit 0.0.26 → 21.2.0-4

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
@@ -6,7 +6,8 @@ A small ergonomic kit for Ionic Angular applications. It provides:
6
6
  - **KitOverlayController** — a unified presenter for Ionic Modal, Toast, and Alert
7
7
  - **Auth guards** — functional `CanActivateFn` guards for a 4-state auth model
8
8
  - **HTTP interceptor** — a fleet-canonical auth + retry + error-hook interceptor
9
- - **KitAutofillDirective** — an iOS autofill workaround for `ion-input`
9
+ - **KitAuthInputDirective** — sign-in email remember/prefill + iOS autofill workaround for `ion-input`
10
+ - **kitClearStoragePreservingKeys** — `clear()` that restores selected keys (`KIT_LAST_AUTH_EMAIL_KEY`, `KIT_THEME_STORAGE_KEY`, …)
10
11
 
11
12
  ---
12
13
 
@@ -14,8 +15,12 @@ A small ergonomic kit for Ionic Angular applications. It provides:
14
15
 
15
16
  ```bash
16
17
  npm install @rdlabo/ionic-angular-kit
18
+ # prereleases (np: X.Y.Z-N) are on the npm dist-tag `beta`:
19
+ # npm install @rdlabo/ionic-angular-kit@beta
17
20
  ```
18
21
 
22
+ Kit shares the repo `v*` release line with the other libraries (see root README § Release).
23
+
19
24
  ### Peer dependencies
20
25
 
21
26
  | Package | Version |
@@ -395,15 +400,36 @@ await reload.dismiss();
395
400
 
396
401
  ---
397
402
 
398
- ### KitAutofillDirective
403
+ ### KitAuthInputDirective (`kitAuthInput`)
404
+
405
+ Sign-in / sign-up conveniences on `ion-input`:
399
406
 
400
- An iOS workaround for `ion-input` autofill (password managers, iCloud Keychain). Without it, autofilled values are not reflected in the Angular form model on iOS native.
407
+ - `'email'` — remember + prefill the last well-formed address (and forget when the user clears it)
408
+ - `'email-remember'` — remember on change only (no prefill — use on sign-up)
409
+ - `'autofill'` — iOS autofill propagation only (password fields)
401
410
 
402
411
  ```html
403
- <ion-input rdlaboAutofill formControlName="password" type="password" />
412
+ <ion-input type="email" autocomplete="email" kitAuthInput="email" [formField]="form.email" />
413
+ ```
414
+
415
+ ### kitClearStoragePreservingKeys
416
+
417
+ Fleet apps typically `storage.clear()` on sign-out. Pass keys that must survive (e.g. the last sign-in email):
418
+
419
+ ```typescript
420
+ import {
421
+ KIT_LAST_AUTH_EMAIL_KEY,
422
+ KIT_THEME_STORAGE_KEY,
423
+ kitClearStoragePreservingKeys,
424
+ } from '@rdlabo/ionic-angular-kit';
425
+
426
+ await kitSignOut(auth, {
427
+ success: () =>
428
+ kitClearStoragePreservingKeys(this.storage, [KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY]),
429
+ });
404
430
  ```
405
431
 
406
- The directive is a no-op on non-iOS platforms.
432
+ It snapshots the listed keys, clears the store, then writes non-null values back.
407
433
 
408
434
  ---
409
435
 
@@ -19,10 +19,13 @@ const KIT_THEME_CONFIG = new InjectionToken('@rdlabo/ionic-angular-kit:theme');
19
19
  * @returns environment providers to add to the application's provider list
20
20
  * @example
21
21
  * ```ts
22
+ * import { KIT_THEME_STORAGE_KEY } from '@rdlabo/ionic-angular-kit';
23
+ * import { provideKitTheme } from '@rdlabo/ionic-angular-kit/theme';
24
+ *
22
25
  * bootstrapApplication(AppComponent, {
23
26
  * providers: [
24
27
  * provideKitTheme({
25
- * storageKey: StorageKeyEnum.theme,
28
+ * storageKey: KIT_THEME_STORAGE_KEY,
26
29
  * darkClasses: ['ion-palette-dark', 'a2ui-dark'],
27
30
  * lightClasses: ['a2ui-light'],
28
31
  * }),
@@ -1 +1 @@
1
- {"version":3,"file":"rdlabo-ionic-angular-kit-theme.mjs","sources":["../../../projects/kit/theme/src/theme-config.ts","../../../projects/kit/theme/src/kit-theme.controller.ts","../../../projects/kit/theme/src/public-api.ts","../../../projects/kit/theme/src/rdlabo-ionic-angular-kit-theme.ts"],"sourcesContent":["import type { EnvironmentProviders } from '@angular/core';\nimport { InjectionToken, makeEnvironmentProviders } from '@angular/core';\n\n/**\n * Theme configuration injected via `provideKitTheme()` and consumed by `KitThemeController`.\n *\n * @remarks\n * All fields are required; the consuming application supplies a complete configuration so every app\n * in the fleet has the same shape. The class lists absorb the per-app CSS drift: the kit toggles\n * `darkClasses` on when dark and `lightClasses` on when light, so an app that only uses Ionic's\n * palette passes `darkClasses: ['ion-palette-dark'], lightClasses: []`, while an app with an extra\n * design-system palette adds its own classes (e.g. `darkClasses: ['ion-palette-dark', 'a2ui-dark']`,\n * `lightClasses: ['a2ui-light']`).\n */\nexport interface KitThemeConfig {\n /** Key under which the chosen theme (`'light'` | `'dark'`) is persisted via `KitStorageService`. */\n readonly storageKey: string;\n /** Classes toggled **on** the document element when the dark theme is active. */\n readonly darkClasses: readonly string[];\n /** Classes toggled **on** the document element when the light theme is active. */\n readonly lightClasses: readonly string[];\n}\n\n/**\n * Injection token carrying the {@link KitThemeConfig} for `KitThemeController`.\n *\n * @remarks\n * Provide it through {@link provideKitTheme} rather than registering it directly.\n */\nexport const KIT_THEME_CONFIG = new InjectionToken<KitThemeConfig>('@rdlabo/ionic-angular-kit:theme');\n\n/**\n * Wire `KitThemeController` into the application.\n *\n * @param config - theme configuration: the storage key and the light/dark class lists\n * @returns environment providers to add to the application's provider list\n * @example\n * ```ts\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideKitTheme({\n * storageKey: StorageKeyEnum.theme,\n * darkClasses: ['ion-palette-dark', 'a2ui-dark'],\n * lightClasses: ['a2ui-light'],\n * }),\n * ],\n * });\n * ```\n */\nexport const provideKitTheme = (config: KitThemeConfig): EnvironmentProviders =>\n makeEnvironmentProviders([{ provide: KIT_THEME_CONFIG, useValue: config }]);\n","import { DOCUMENT, inject, Injectable } from '@angular/core';\nimport { Capacitor } from '@capacitor/core';\nimport { StatusBar, Style } from '@capacitor/status-bar';\nimport { BehaviorSubject } from 'rxjs';\n\nimport { KitStorageService } from '@rdlabo/ionic-angular-kit';\n\nimport { KIT_THEME_CONFIG } from './theme-config';\n\n/** The active theme mode. */\nexport type KitThemeMode = 'light' | 'dark';\n\n/**\n * Light/dark theme controller: persists the user's choice, follows the OS setting until the user\n * overrides it, toggles the configured palette classes, and syncs the native Android status bar.\n *\n * @remarks\n * Consolidates the theme logic that had drifted across the fleet into one behavior. Notably it fixes\n * a latent leak in one variant where the system-theme listener stayed registered after a manual\n * toggle: {@link changeTheme} always detaches the listener via {@link removeEventListener} before\n * applying the forced theme, so a later OS change can no longer silently flip an app the user pinned.\n *\n * - **Persistence** — the chosen mode is stored via {@link KitStorageService} under the configured key.\n * - **Follow OS until overridden** — on boot with nothing stored, it tracks\n * `prefers-color-scheme` (idempotent registration); once the user calls {@link changeTheme} it stops\n * following and honors the explicit choice.\n * - **Class toggling** — toggles {@link KitThemeConfig.darkClasses} on when dark and\n * {@link KitThemeConfig.lightClasses} on when light, absorbing per-app CSS differences via config.\n * - **Native status bar** — on Android native only, mirrors the Ionic behavior of setting the status\n * bar style to match (iOS derives it from the web content, so it is intentionally left untouched).\n *\n * Subscribe to {@link themeSubject} to reflect the current mode in the UI (e.g. a settings toggle).\n *\n * @example\n * ```ts\n * // On boot (app.component):\n * inject(KitThemeController).setDefaultThemeMode();\n *\n * // From a settings toggle:\n * const theme = inject(KitThemeController);\n * theme.themeSubject.subscribe((mode) => this.isDark.set(mode === 'dark'));\n * theme.changeTheme(true);\n * ```\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class KitThemeController {\n readonly #storage = inject(KitStorageService);\n readonly #document = inject(DOCUMENT);\n readonly #config = inject(KIT_THEME_CONFIG);\n\n /**\n * Emits the active theme, seeded with `'light'`.\n *\n * @remarks\n * A `BehaviorSubject`, so a late subscriber immediately receives the current mode; it emits again\n * on every {@link setDefaultThemeMode} / {@link changeTheme} and on OS theme changes while following.\n */\n readonly themeSubject = new BehaviorSubject<KitThemeMode>('light');\n\n #prefersDark?: MediaQueryList;\n #onSystemThemeChange?: (e: MediaQueryListEvent) => void;\n\n /**\n * Apply the persisted theme, or start following the OS setting when nothing is stored yet.\n *\n * @remarks\n * Call once on boot (e.g. from `app.component`).\n *\n * @returns a Promise that resolves once the initial theme has been applied\n */\n async setDefaultThemeMode(): Promise<void> {\n const stored = await this.#storage.get<KitThemeMode>(this.#config.storageKey);\n if (stored) {\n // 保存済みの選択を強制し、OS 追従は解除する。\n this.#unwatchSystemTheme();\n return this.#applyTheme(stored === 'dark');\n }\n\n // 未保存 → OS の設定に追従する。\n this.#watchSystemTheme();\n }\n\n /**\n * Force a theme, persist it, and stop following the OS setting.\n *\n * @param isDark - `true` for the dark theme, `false` for light\n * @returns a Promise that resolves once the theme has been persisted and applied\n */\n async changeTheme(isDark: boolean): Promise<void> {\n this.#unwatchSystemTheme();\n await this.#storage.set(this.#config.storageKey, isDark ? 'dark' : 'light');\n await this.#applyTheme(isDark);\n }\n\n #watchSystemTheme(): void {\n if (this.#prefersDark) {\n // 既に監視中なら二重登録しない(冪等)。\n return;\n }\n this.#prefersDark = window.matchMedia('(prefers-color-scheme: dark)');\n this.#onSystemThemeChange = (e) => void this.#applyTheme(e.matches);\n this.#prefersDark.addEventListener('change', this.#onSystemThemeChange, { passive: true });\n void this.#applyTheme(this.#prefersDark.matches);\n }\n\n #unwatchSystemTheme(): void {\n if (this.#prefersDark && this.#onSystemThemeChange) {\n this.#prefersDark.removeEventListener('change', this.#onSystemThemeChange);\n }\n this.#prefersDark = undefined;\n this.#onSystemThemeChange = undefined;\n }\n\n async #applyTheme(isDark: boolean): Promise<void> {\n if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'android') {\n await StatusBar.setStyle({ style: isDark ? Style.Dark : Style.Light });\n }\n const root = this.#document.documentElement;\n for (const cls of this.#config.darkClasses) {\n root.classList.toggle(cls, isDark);\n }\n for (const cls of this.#config.lightClasses) {\n root.classList.toggle(cls, !isDark);\n }\n this.themeSubject.next(isDark ? 'dark' : 'light');\n }\n}\n","// Theme: light/dark controller with OS-follow and native status-bar sync.\n// Its own entry point so only apps that theme pull in `@capacitor/status-bar`.\nexport * from './theme-config';\nexport * from './k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AAO,CAAC,WAAW,EAAE;YAC1C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;QACpC;QACA,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;YAC3C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;QACrC;AACA,QAAA,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACnD;+GAhFW,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAlB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,kBAAkB,cAFjB,MAAM,EAAA,CAAA,CAAA;;4FAEP,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAH9B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;AC9CD;AACA;;ACDA;;AAEG;;;;"}
1
+ {"version":3,"file":"rdlabo-ionic-angular-kit-theme.mjs","sources":["../../../projects/kit/theme/src/theme-config.ts","../../../projects/kit/theme/src/kit-theme.controller.ts","../../../projects/kit/theme/src/public-api.ts","../../../projects/kit/theme/src/rdlabo-ionic-angular-kit-theme.ts"],"sourcesContent":["import type { EnvironmentProviders } from '@angular/core';\nimport { InjectionToken, makeEnvironmentProviders } from '@angular/core';\n\n/**\n * Theme configuration injected via `provideKitTheme()` and consumed by `KitThemeController`.\n *\n * @remarks\n * All fields are required; the consuming application supplies a complete configuration so every app\n * in the fleet has the same shape. The class lists absorb the per-app CSS drift: the kit toggles\n * `darkClasses` on when dark and `lightClasses` on when light, so an app that only uses Ionic's\n * palette passes `darkClasses: ['ion-palette-dark'], lightClasses: []`, while an app with an extra\n * design-system palette adds its own classes (e.g. `darkClasses: ['ion-palette-dark', 'a2ui-dark']`,\n * `lightClasses: ['a2ui-light']`).\n *\n * Prefer `KIT_THEME_STORAGE_KEY` (from `@rdlabo/ionic-angular-kit`) as `storageKey` so logout\n * clear-preserving lists stay in sync.\n */\nexport interface KitThemeConfig {\n /** Key under which the chosen theme (`'light'` | `'dark'`) is persisted via `KitStorageService`. */\n readonly storageKey: string;\n /** Classes toggled **on** the document element when the dark theme is active. */\n readonly darkClasses: readonly string[];\n /** Classes toggled **on** the document element when the light theme is active. */\n readonly lightClasses: readonly string[];\n}\n\n/**\n * Injection token carrying the {@link KitThemeConfig} for `KitThemeController`.\n *\n * @remarks\n * Provide it through {@link provideKitTheme} rather than registering it directly.\n */\nexport const KIT_THEME_CONFIG = new InjectionToken<KitThemeConfig>('@rdlabo/ionic-angular-kit:theme');\n\n/**\n * Wire `KitThemeController` into the application.\n *\n * @param config - theme configuration: the storage key and the light/dark class lists\n * @returns environment providers to add to the application's provider list\n * @example\n * ```ts\n * import { KIT_THEME_STORAGE_KEY } from '@rdlabo/ionic-angular-kit';\n * import { provideKitTheme } from '@rdlabo/ionic-angular-kit/theme';\n *\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideKitTheme({\n * storageKey: KIT_THEME_STORAGE_KEY,\n * darkClasses: ['ion-palette-dark', 'a2ui-dark'],\n * lightClasses: ['a2ui-light'],\n * }),\n * ],\n * });\n * ```\n */\nexport const provideKitTheme = (config: KitThemeConfig): EnvironmentProviders =>\n makeEnvironmentProviders([{ provide: KIT_THEME_CONFIG, useValue: config }]);\n","import { DOCUMENT, inject, Injectable } from '@angular/core';\nimport { Capacitor } from '@capacitor/core';\nimport { StatusBar, Style } from '@capacitor/status-bar';\nimport { BehaviorSubject } from 'rxjs';\n\nimport { KitStorageService } from '@rdlabo/ionic-angular-kit';\n\nimport { KIT_THEME_CONFIG } from './theme-config';\n\n/** The active theme mode. */\nexport type KitThemeMode = 'light' | 'dark';\n\n/**\n * Light/dark theme controller: persists the user's choice, follows the OS setting until the user\n * overrides it, toggles the configured palette classes, and syncs the native Android status bar.\n *\n * @remarks\n * Consolidates the theme logic that had drifted across the fleet into one behavior. Notably it fixes\n * a latent leak in one variant where the system-theme listener stayed registered after a manual\n * toggle: {@link changeTheme} always detaches the listener via {@link removeEventListener} before\n * applying the forced theme, so a later OS change can no longer silently flip an app the user pinned.\n *\n * - **Persistence** — the chosen mode is stored via {@link KitStorageService} under the configured key.\n * - **Follow OS until overridden** — on boot with nothing stored, it tracks\n * `prefers-color-scheme` (idempotent registration); once the user calls {@link changeTheme} it stops\n * following and honors the explicit choice.\n * - **Class toggling** — toggles {@link KitThemeConfig.darkClasses} on when dark and\n * {@link KitThemeConfig.lightClasses} on when light, absorbing per-app CSS differences via config.\n * - **Native status bar** — on Android native only, mirrors the Ionic behavior of setting the status\n * bar style to match (iOS derives it from the web content, so it is intentionally left untouched).\n *\n * Subscribe to {@link themeSubject} to reflect the current mode in the UI (e.g. a settings toggle).\n *\n * @example\n * ```ts\n * // On boot (app.component):\n * inject(KitThemeController).setDefaultThemeMode();\n *\n * // From a settings toggle:\n * const theme = inject(KitThemeController);\n * theme.themeSubject.subscribe((mode) => this.isDark.set(mode === 'dark'));\n * theme.changeTheme(true);\n * ```\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class KitThemeController {\n readonly #storage = inject(KitStorageService);\n readonly #document = inject(DOCUMENT);\n readonly #config = inject(KIT_THEME_CONFIG);\n\n /**\n * Emits the active theme, seeded with `'light'`.\n *\n * @remarks\n * A `BehaviorSubject`, so a late subscriber immediately receives the current mode; it emits again\n * on every {@link setDefaultThemeMode} / {@link changeTheme} and on OS theme changes while following.\n */\n readonly themeSubject = new BehaviorSubject<KitThemeMode>('light');\n\n #prefersDark?: MediaQueryList;\n #onSystemThemeChange?: (e: MediaQueryListEvent) => void;\n\n /**\n * Apply the persisted theme, or start following the OS setting when nothing is stored yet.\n *\n * @remarks\n * Call once on boot (e.g. from `app.component`).\n *\n * @returns a Promise that resolves once the initial theme has been applied\n */\n async setDefaultThemeMode(): Promise<void> {\n const stored = await this.#storage.get<KitThemeMode>(this.#config.storageKey);\n if (stored) {\n // 保存済みの選択を強制し、OS 追従は解除する。\n this.#unwatchSystemTheme();\n return this.#applyTheme(stored === 'dark');\n }\n\n // 未保存 → OS の設定に追従する。\n this.#watchSystemTheme();\n }\n\n /**\n * Force a theme, persist it, and stop following the OS setting.\n *\n * @param isDark - `true` for the dark theme, `false` for light\n * @returns a Promise that resolves once the theme has been persisted and applied\n */\n async changeTheme(isDark: boolean): Promise<void> {\n this.#unwatchSystemTheme();\n await this.#storage.set(this.#config.storageKey, isDark ? 'dark' : 'light');\n await this.#applyTheme(isDark);\n }\n\n #watchSystemTheme(): void {\n if (this.#prefersDark) {\n // 既に監視中なら二重登録しない(冪等)。\n return;\n }\n this.#prefersDark = window.matchMedia('(prefers-color-scheme: dark)');\n this.#onSystemThemeChange = (e) => void this.#applyTheme(e.matches);\n this.#prefersDark.addEventListener('change', this.#onSystemThemeChange, { passive: true });\n void this.#applyTheme(this.#prefersDark.matches);\n }\n\n #unwatchSystemTheme(): void {\n if (this.#prefersDark && this.#onSystemThemeChange) {\n this.#prefersDark.removeEventListener('change', this.#onSystemThemeChange);\n }\n this.#prefersDark = undefined;\n this.#onSystemThemeChange = undefined;\n }\n\n async #applyTheme(isDark: boolean): Promise<void> {\n if (Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'android') {\n await StatusBar.setStyle({ style: isDark ? Style.Dark : Style.Light });\n }\n const root = this.#document.documentElement;\n for (const cls of this.#config.darkClasses) {\n root.classList.toggle(cls, isDark);\n }\n for (const cls of this.#config.lightClasses) {\n root.classList.toggle(cls, !isDark);\n }\n this.themeSubject.next(isDark ? 'dark' : 'light');\n }\n}\n","// Theme: light/dark controller with OS-follow and native status-bar sync.\n// Its own entry point so only apps that theme pull in `@capacitor/status-bar`.\nexport * from './theme-config';\nexport * from './kit-theme.controller';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AA0BA;;;;;AAKG;MACU,gBAAgB,GAAG,IAAI,cAAc,CAAiB,iCAAiC;AAEpG;;;;;;;;;;;;;;;;;;;;AAoBG;MACU,eAAe,GAAG,CAAC,MAAsB,KACpD,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;;AC5C5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BG;MAIU,kBAAkB,CAAA;AAH/B,IAAA,WAAA,GAAA;AAIW,QAAA,IAAA,CAAA,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC;AACpC,QAAA,IAAA,CAAA,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC5B,QAAA,IAAA,CAAA,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAE3C;;;;;;AAMG;AACM,QAAA,IAAA,CAAA,YAAY,GAAG,IAAI,eAAe,CAAe,OAAO,CAAC;AAqEnE,IAAA;AAhFU,IAAA,QAAQ;AACR,IAAA,SAAS;AACT,IAAA,OAAO;AAWhB,IAAA,YAAY;AACZ,IAAA,oBAAoB;AAEpB;;;;;;;AAOG;AACH,IAAA,MAAM,mBAAmB,GAAA;AACvB,QAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAe,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QAC7E,IAAI,MAAM,EAAE;;YAEV,IAAI,CAAC,mBAAmB,EAAE;YAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,MAAM,CAAC;QAC5C;;QAGA,IAAI,CAAC,iBAAiB,EAAE;IAC1B;AAEA;;;;;AAKG;IACH,MAAM,WAAW,CAAC,MAAe,EAAA;QAC/B,IAAI,CAAC,mBAAmB,EAAE;QA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AK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE;YAC1C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;QACpC;QACA,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;YAC3C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;QACrC;AACA,QAAA,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACnD;+GAhFW,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAlB,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,kBAAkB,cAFjB,MAAM,EAAA,CAAA,CAAA;;4FAEP,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAH9B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;AC9CD;AACA;;ACDA;;AAEG;;;;"}
@@ -157,6 +157,57 @@ const kitRecallEmail = (store) => store.get(KIT_LAST_AUTH_EMAIL_KEY);
157
157
  */
158
158
  const kitForgetEmail = (store) => store.remove(KIT_LAST_AUTH_EMAIL_KEY);
159
159
 
160
+ /**
161
+ * Canonical storage keys persisted via {@link KitStorageService} that fleet apps often need to
162
+ * keep across a sign-out `clear()`.
163
+ *
164
+ * @remarks
165
+ * `KIT_LAST_AUTH_EMAIL_KEY` lives in `kit-auth-email-store` and is exported from the package root.
166
+ * Import both keys from `@rdlabo/ionic-angular-kit` alongside {@link kitClearStoragePreservingKeys}.
167
+ */
168
+ /**
169
+ * Light/dark preference for `provideKitTheme` / `KitThemeController`.
170
+ *
171
+ * @remarks
172
+ * Pass this as `provideKitTheme({ storageKey: KIT_THEME_STORAGE_KEY, … })` and include it in
173
+ * {@link kitClearStoragePreservingKeys} so logout does not reset the user's theme.
174
+ */
175
+ const KIT_THEME_STORAGE_KEY = 'theme';
176
+
177
+ /**
178
+ * Clear a key/value store while restoring selected keys afterward.
179
+ *
180
+ * @remarks
181
+ * Fleet apps often call `storage.clear()` on sign-out to drop session/token state. Values that
182
+ * should survive logout (for example {@link KIT_LAST_AUTH_EMAIL_KEY}) are passed in `keys`.
183
+ * Missing keys are skipped — only non-null values are written back.
184
+ */
185
+ /**
186
+ * Wipe the store, then restore the given keys to their pre-clear values (when present).
187
+ *
188
+ * @param store - the app's storage (e.g. `KitStorageService`)
189
+ * @param keys - keys whose values should survive the clear
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * import { KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY, kitClearStoragePreservingKeys } from '@rdlabo/ionic-angular-kit';
194
+ *
195
+ * await kitSignOut(auth, {
196
+ * success: () =>
197
+ * kitClearStoragePreservingKeys(this.storage, [KIT_LAST_AUTH_EMAIL_KEY, KIT_THEME_STORAGE_KEY]),
198
+ * });
199
+ * ```
200
+ */
201
+ const kitClearStoragePreservingKeys = async (store, keys) => {
202
+ const preserved = await Promise.all(keys.map(async (key) => ({ key, value: await store.get(key) })));
203
+ await store.clear();
204
+ for (const { key, value } of preserved) {
205
+ if (value !== null) {
206
+ await store.set(key, value);
207
+ }
208
+ }
209
+ };
210
+
160
211
  /**
161
212
  * Injection token carrying the {@link KitOverlayConfig} for `KitOverlayController`.
162
213
  *
@@ -651,6 +702,157 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImpo
651
702
  }]
652
703
  }] });
653
704
 
705
+ /**
706
+ * Singleton "maintenance lock" overlay: backdrop-locked, no dismiss buttons, auto-clears via SSE.
707
+ *
708
+ * @remarks
709
+ * Mirrors {@link KitReloadAlertController} as a de-duped stateful controller, but the user cannot
710
+ * cancel or reload out of it — only the server `event: ended` on {@link KitMaintenanceOptions.waitUrl}
711
+ * (or an explicit {@link dismiss}) clears it. Uses Ionic's `AlertController` (not a feature modal)
712
+ * so the kit stays free of page components / i18n; all copy is supplied by the caller.
713
+ *
714
+ * Wire from {@link KitHttpConfig.onMaintenance} when the API returns `503` with
715
+ * `error.error?.code === 'MAINTENANCE'`.
716
+ *
717
+ * @example
718
+ * ```ts
719
+ * provideKitHttp(() => {
720
+ * const maintenance = inject(KitMaintenanceController);
721
+ * return {
722
+ * getAuthHeaders: async () => ({}),
723
+ * onMaintenance: () =>
724
+ * void maintenance.present({
725
+ * header: 'メンテナンス中です',
726
+ * message: 'しばらくお待ちください。終了次第、自動で閉じます。',
727
+ * waitUrl: environment.api + 'public/maintenance/wait',
728
+ * }),
729
+ * };
730
+ * });
731
+ * ```
732
+ */
733
+ class KitMaintenanceController {
734
+ #alertCtrl = inject(AlertController);
735
+ #alert = null;
736
+ #source = null;
737
+ #reconnectTimer = null;
738
+ #reconnectAttempt = 0;
739
+ #waitUrl = null;
740
+ /** When true, EventSource errors must not schedule reconnect (ended / dismiss). */
741
+ #closed = false;
742
+ /**
743
+ * Present the lock overlay and start waiting on the maintenance SSE, unless one is already showing.
744
+ *
745
+ * @param options - overlay copy plus the wait SSE URL
746
+ */
747
+ async present(options) {
748
+ if (this.#alert || document.querySelector('ion-alert.kit-maintenance-alert')) {
749
+ return;
750
+ }
751
+ this.#closed = false;
752
+ this.#waitUrl = options.waitUrl;
753
+ const alert = await this.#alertCtrl.create({
754
+ header: options.header,
755
+ message: options.message,
756
+ backdropDismiss: false,
757
+ // No buttons — dismissal is server-driven via SSE (or an explicit dismiss()).
758
+ buttons: [],
759
+ cssClass: 'kit-maintenance-alert',
760
+ });
761
+ this.#alert = alert;
762
+ void alert.onDidDismiss().then(() => {
763
+ if (this.#alert === alert) {
764
+ this.#alert = null;
765
+ }
766
+ this.#stopWait();
767
+ });
768
+ await alert.present();
769
+ this.#startWait(options.waitUrl);
770
+ }
771
+ /**
772
+ * Dismiss the tracked overlay and tear down the wait SSE.
773
+ *
774
+ * @remarks
775
+ * Normally called when the wait stream emits `ended`. A no-op when nothing is showing.
776
+ */
777
+ async dismiss() {
778
+ this.#stopWait();
779
+ const alert = this.#alert;
780
+ this.#alert = null;
781
+ await alert?.dismiss();
782
+ }
783
+ #startWait(waitUrl) {
784
+ this.#stopSourceOnly();
785
+ if (this.#closed) {
786
+ return;
787
+ }
788
+ const source = new EventSource(waitUrl);
789
+ this.#source = source;
790
+ source.addEventListener('ended', () => {
791
+ void this.dismiss();
792
+ });
793
+ source.addEventListener('ping', () => {
794
+ // Keepalive — resets reconnect backoff so a lively stream does not treat the next pause as failure.
795
+ this.#reconnectAttempt = 0;
796
+ });
797
+ source.onerror = () => {
798
+ // EventSource auto-reconnects, but after a deploy the old isolate may hang; force a clean
799
+ // reconnect with exponential backoff once the browser surfaces an error.
800
+ if (this.#closed || this.#waitUrl !== waitUrl) {
801
+ return;
802
+ }
803
+ this.#stopSourceOnly();
804
+ this.#scheduleReconnect();
805
+ };
806
+ source.onopen = () => {
807
+ this.#reconnectAttempt = 0;
808
+ };
809
+ }
810
+ #scheduleReconnect() {
811
+ if (this.#closed || !this.#waitUrl) {
812
+ return;
813
+ }
814
+ if (this.#reconnectTimer) {
815
+ clearTimeout(this.#reconnectTimer);
816
+ }
817
+ const delay = Math.min(30_000, 500 * 2 ** this.#reconnectAttempt);
818
+ this.#reconnectAttempt += 1;
819
+ const waitUrl = this.#waitUrl;
820
+ this.#reconnectTimer = setTimeout(() => {
821
+ this.#reconnectTimer = null;
822
+ if (!this.#closed && this.#waitUrl === waitUrl) {
823
+ this.#startWait(waitUrl);
824
+ }
825
+ }, delay);
826
+ }
827
+ #stopWait() {
828
+ this.#closed = true;
829
+ this.#waitUrl = null;
830
+ this.#reconnectAttempt = 0;
831
+ if (this.#reconnectTimer) {
832
+ clearTimeout(this.#reconnectTimer);
833
+ this.#reconnectTimer = null;
834
+ }
835
+ this.#stopSourceOnly();
836
+ }
837
+ #stopSourceOnly() {
838
+ const source = this.#source;
839
+ this.#source = null;
840
+ if (source) {
841
+ source.onerror = null;
842
+ source.onopen = null;
843
+ source.close();
844
+ }
845
+ }
846
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitMaintenanceController, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
847
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitMaintenanceController, providedIn: 'root' }); }
848
+ }
849
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: KitMaintenanceController, decorators: [{
850
+ type: Injectable,
851
+ args: [{
852
+ providedIn: 'root',
853
+ }]
854
+ }] });
855
+
654
856
  /**
655
857
  * Present the fleet's canonical "sign-in / token exchange failed" alert.
656
858
  *
@@ -1178,6 +1380,17 @@ const MAX_RETRIES = 2;
1178
1380
  * @internal
1179
1381
  */
1180
1382
  const DEFAULT_TIMEOUT_MS = 60_000;
1383
+ /**
1384
+ * True when the error is the fleet maintenance short-circuit (`503` + body `code: 'MAINTENANCE'`).
1385
+ *
1386
+ * @remarks
1387
+ * Matches Angular `HttpErrorResponse` as `error.error?.code === 'MAINTENANCE'` (body top-level
1388
+ * `code`). Must not be retried and must not fall through to {@link KitHttpConfig.onServerBusy}.
1389
+ *
1390
+ * @param error - The failed response.
1391
+ * @returns Whether this is a maintenance response.
1392
+ */
1393
+ const isMaintenanceError = (error) => error.status === 503 && error.error?.code === 'MAINTENANCE';
1181
1394
  /**
1182
1395
  * Parse a `Retry-After` header (delta-seconds or an HTTP-date) into milliseconds, or `null` when it
1183
1396
  * is absent or unparseable.
@@ -1259,6 +1472,9 @@ const dispatchError = (config, req, error) => {
1259
1472
  else if (status === 429) {
1260
1473
  config.onRateLimited?.(retryAfterSeconds);
1261
1474
  }
1475
+ else if (isMaintenanceError(error)) {
1476
+ config.onMaintenance?.();
1477
+ }
1262
1478
  else if ([502, 503, 504].includes(status)) {
1263
1479
  config.onServerBusy?.(status, retryAfterSeconds);
1264
1480
  }
@@ -1283,8 +1499,8 @@ const dispatchError = (config, req, error) => {
1283
1499
  * When the device is offline it stops retrying immediately.
1284
1500
  * 5. On the final error, `offlineFallback` is consulted first; otherwise the error is classified by
1285
1501
  * status (see {@link dispatchError}): `401`→`onUnauthorized`, `403`→`onForbidden`, `0`→
1286
- * `onNetworkError` (when connected), `429`→`onRateLimited`, `502`/`503`/`504`→`onServerBusy`, and
1287
- * `400`/`422`/`500` with a body message→`onServerError`.
1502
+ * `onNetworkError` (when connected), `429`→`onRateLimited`, maintenance `503`→`onMaintenance`,
1503
+ * other `502`/`503`/`504`→`onServerBusy`, and `400`/`422`/`500` with a body message→`onServerError`.
1288
1504
  *
1289
1505
  * @param request - The outgoing request.
1290
1506
  * @param next - The next handler in the interceptor chain.
@@ -1325,7 +1541,8 @@ const kitAuthInterceptor = (request, next) => {
1325
1541
  return throwError(() => error);
1326
1542
  }
1327
1543
  // Only replay idempotent requests, and only on a transient status.
1328
- if (!retryable || !RETRYABLE_STATUSES.includes(error.status)) {
1544
+ // Maintenance 503 is intentional — never retry; go straight to onMaintenance.
1545
+ if (!retryable || !RETRYABLE_STATUSES.includes(error.status) || isMaintenanceError(error)) {
1329
1546
  return throwError(() => error);
1330
1547
  }
1331
1548
  // Short linear backoff (500ms, 1000ms, …) plus jitter to de-correlate a fleet of
@@ -1565,5 +1782,5 @@ const kitCreateDidEnter = (el) => {
1565
1782
  * Generated bundle index. Do not edit.
1566
1783
  */
1567
1784
 
1568
- export { KIT_AUTH_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KitAuthInputDirective, KitLoadingController, KitOverlayController, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, kitAuthInterceptor, kitChangeEventDisabled, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay };
1785
+ export { KIT_AUTH_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KIT_THEME_STORAGE_KEY, KitAuthInputDirective, KitLoadingController, KitMaintenanceController, KitOverlayController, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, isMaintenanceError, kitAuthInterceptor, kitChangeEventDisabled, kitClearStoragePreservingKeys, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay };
1569
1786
  //# sourceMappingURL=rdlabo-ionic-angular-kit.mjs.map