@sinequa/atomic-angular 1.0.9 → 1.0.10

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.
@@ -2809,19 +2809,45 @@ function withSavedSearchesFeatures() {
2809
2809
  })));
2810
2810
  }
2811
2811
 
2812
+ /**
2813
+ * Canonical default shape of the user settings state.
2814
+ *
2815
+ * Shared between `initialize()` (overlaid under the fetched settings) and `reset()`
2816
+ * (used as the replacement state) so the two cannot drift apart. Keep in sync with
2817
+ * the `UserSettingsState` type.
2818
+ */
2819
+ const USER_SETTINGS_DEFAULTS = {
2820
+ bookmarks: [],
2821
+ recentSearches: [],
2822
+ savedSearches: [],
2823
+ baskets: [],
2824
+ alerts: [],
2825
+ assistants: {},
2826
+ language: undefined,
2827
+ collapseAssistant: undefined,
2828
+ userTheme: undefined,
2829
+ agents: { isDebugMode: false }
2830
+ };
2812
2831
  function withUserSettingsFeatures() {
2813
2832
  return signalStoreFeature(withState({ language: undefined, collapseAssistant: undefined }), withMethods(store => ({
2814
2833
  /**
2815
2834
  * Initializes the user settings store by fetching the user settings from the backend API
2816
2835
  * and patching the store with the retrieved settings.
2817
2836
  *
2837
+ * The fetched settings are overlaid on top of {@link USER_SETTINGS_DEFAULTS} so that any
2838
+ * key absent from the new user's settings resets to its default instead of retaining the
2839
+ * previous user's in-memory value. This is required because `initialize()` runs both on
2840
+ * first login and on every user override (impersonation): a plain merge would leak the
2841
+ * previous user's data (e.g. `recentSearches`) into the new user's session and backend.
2842
+ *
2818
2843
  * @returns {Promise<void>} A promise that resolves when the initialization is complete.
2819
2844
  */
2820
2845
  async initialize() {
2821
- // Fetch the user settings from the backend API and patch the store with the result
2846
+ // Fetch the user settings from the backend API and overlay them on the defaults,
2847
+ // so missing keys reset rather than keep the previous user's values.
2822
2848
  try {
2823
2849
  const settings = await fetchUserSettings();
2824
- patchState(store, settings);
2850
+ patchState(store, { ...USER_SETTINGS_DEFAULTS, ...settings });
2825
2851
  }
2826
2852
  catch (err) {
2827
2853
  error('Error fetching user settings:', err);
@@ -2839,17 +2865,7 @@ function withUserSettingsFeatures() {
2839
2865
  async reset() {
2840
2866
  // Reset the user settings to the initial state
2841
2867
  await deleteUserSettings();
2842
- patchState(store, {
2843
- bookmarks: [],
2844
- recentSearches: [],
2845
- savedSearches: [],
2846
- baskets: [],
2847
- alerts: [],
2848
- assistants: {},
2849
- language: undefined,
2850
- collapseAssistant: undefined,
2851
- agents: { isDebugMode: false }
2852
- });
2868
+ patchState(store, USER_SETTINGS_DEFAULTS);
2853
2869
  }
2854
2870
  })));
2855
2871
  }