# Changelog

All notable changes to this project will be documented in this file.  
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and follows the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [v2.4.0]

### Added

- **Store-first home sync**: `user.syncHomeWithNodes()` fetches the home tree once and then serves it from the store. Pass `{ force: true }` to fetch again (for example on pull-to-refresh or login). Deleting or leaving a home updates the store in place without a new sync.
- **Shared in-flight requests**: concurrent calls to `getNodeDetails()` or `group.getNodes()` for the same target share a single network request instead of each fetching on their own.
- **One node fetch per home**: nodes fetched for a home are attached to the home and to every room in it, so the rooms no longer need their own requests.
- **Local snapshot**: `initCDF({ snapshot })` keeps a copy of the home tree in app storage and restores it on `restoreSession`, so the first screen paints before the network answers. The snapshot is saved automatically whenever the tree changes, is kept per user, and is cleared on logout and account deletion. Operations on restored entities wait for the first live sync and then run normally. `ESPCDF.isSnapshot` and `groupStore.dataSource` tell the UI whether it is showing restored data.
- **Tree sync state**: `groupStore.treeSynced`, `markTreeSynced()` and `invalidateTree()` expose and control whether the home tree is considered synced.

### Changed

- **Identity-preserving merge**: a sync updates existing group and node instances in place instead of replacing them, so screens do not flash and references held by the UI stay valid across syncs.

### Fixed

- **Group updates**: removing nodes from a group now updates the group's node list, updating metadata now writes it to the group, and adding nodes applies the optimistic update to rooms as well as homes.

## [v2.3.0]

### Added

- **Provisioning Enhancements**:
  - Added an API to reset Wi-Fi credentials on the device.
  - Added an API to retry provisioning after an authentication failure.


## [v2.2.0]

### Added

- **CDF Lifecycle**: new `disposeCDF()` top-level API — the counterpart to `initCDF` — that releases all store entity subscriptions and clears the `ESPCDF` singleton. Call it before re-initializing against a different backend; without it, `initCDF` returns the cached instance and ignores the new config. Safe to call when no instance exists.
- **Stores**: `ESPCDF.dispose()` (static and instance) plus `dispose()` on `nodeStore`, `groupStore`, `userStore`, `scheduleStore`, `automationStore`, and `sceneStore`, each releasing its synchronizer's entity subscriptions so a disposed instance leaves no live listeners behind.
- **User Files**: upload, download, list, get-by-id, and create-upload-request APIs on `ESPCDFUser`.
- **Cmd-Resp**: create, list, get, and cancel APIs on `ESPCDFNode` and `ESPCDFUser`, with a clear error when unsupported by the adaptor.

## [v2.1.1]

### Added

- **Provisioning**: `ESPCDFProvisioningDeviceOperations.provision()` now accepts an optional `options` parameter (`Record<string, any>`) for adaptor-specific provision settings.

### Fixed

- **Transport Registry**: `applyRegisteredTransports` uses `Object.create` instead of object spread so the `ESPCDFNode` prototype (and methods such as `subscribe` / `dispose`) is preserved when merging client-registered transports.
- **User Store**: removed duplicate registered-transport merge in `userStore`; `nodeStore.setNodesList` already applies registered transports internally.

## [v2.1.0]

### Added

- **Matter Fabric & Commissioning**:
  - Group fabric operations on `ESPCDFGroup`: `getFabricDetails`, `convertToMatterFabric`, `issueNodeNoC`, `getNodesWithDetails` — complementing the existing `issueUserNoC` / `startCommissioning` flow.
  - User operation `createFabric` on `ESPCDFUser` to create a new Matter fabric.
  - Public Matter types: `ESPCDFMatterFabricDetails`, `ESPCDFIssueNodeNoCRequest`, `ESPCDFMatterCommissioningRequest`.
  - `ESPCDFNode` exposes `isMatter` and `nodeType` for Matter-aware nodes.
  - Group store synchronizer hooks for fabric conversion and fabric-detail updates.

- **Transport Registry**:
  - `subscriptionStore` persists client-registered transports (`local`, `matter_local`, …) across cloud sync.
  - New `applyRegisteredTransports` utility and `RegisteredTransportsByNodeId` type (exported from the package root) replace the previous local-only merge helper.
  - `groupStore.replaceGroup` action added to swap in the SDK fabric instance after Matter conversion.

### Changed

- **Entities**: constructors now call `Object.assign(this, data)` so adaptor-specific fields flow through without per-entity updates.
- **Group types**: `ESPCDFGroupInterface.fabricDetails` is now `ESPCDFMatterFabricDetails` (previously `Record<string, any>`).
- **User API**: `ESPCDFUser.getGroupsAndFabrics()` and `ESPCDFUser.prepareFabricForMatterCommissioning()` are removed (along with their entries in `ESPCDFUserOperation` / `ESPCDFUserOperationType`). Use the new fabric APIs on `ESPCDFGroup` / `ESPCDFUser` instead.

### Removed

- `mergeLocalTransportFromNodeMap` — superseded by the registered-transport registry in `subscriptionStore` and the new `applyRegisteredTransports` utility.

## [v2.0.1]

### Fixed

- **Types**:
  - Added missing public types for group `accessType` and on-network provisioning.
  - Exposed `addOnNetworkDevice`, `checkOnNetworkProvisioning`, callbacks, and progress messages.

## [v2.0.0]

> Major CDF revamp with a unified, SDK-agnostic architecture. No longer pinned to a specific SDK — bring your own adapter via the registry.

### Breaking Changes

- CDF must be initialized by registering an SDK adapter through `src/registry.ts`; direct coupling to `@espressif/rainmaker-base-sdk` is removed.
- Store sync methods have moved off `nodeStore`, `groupStore`, `userStore`, `sceneStore`, `scheduleStore`, and `automationStore` onto their `*Synchronizer` counterparts under `src/store/sync/`.
- Entity and store type imports have moved to `src/types/entities/*` and `src/types/store/*`.
- Errors are now thrown as typed classes from `src/errors` (`base`, `config`, `registry`).

### Added

- **Entities** (`src/entities`): classes for `Node`, `Group`, `User`, `Device`, `Scene`, `Schedule`, `Automation`, `Service`, and params — the app-facing contract across adapters.
- **SDK Registry** (`src/registry.ts`): register, resolve, and switch SDK adapters at runtime.
- **Service Event Handling** (`src/services`): centralizes how external node events translate into entity/store mutations.
- **Centralized Errors** (`src/errors`): base, config, and registry error classes with consistent construction.

### Changed

- **Stores**: split into store + synchronizer pairs under `src/store/sync/`. Stores own state; synchronizers own data sync.
- **Types**: reorganized into `src/types/entities/*` and `src/types/store/*`.

## [v1.2.1]

### Fixed

- `syncScenes` now syncs the scenes store only for the given nodes.
- Corrected pagination reference across stores.

## [v1.2.0]

> Supports SDK [`v2.0.4`](https://www.npmjs.com/package/@espressif/rainmaker-base-sdk/v/2.0.4)

### Added

- **Schedule Management**:
  - Introduced `scheduleStore` for centralized schedule handling
  - Implemented `Schedule` class with CRUD operations and sync capabilities
  - Added multi-node schedule reconciliation and validation
  - Support for time-based, day-based, and recurring schedules

- **Automation Management**:
  - Introduced `automationStore` for managing smart automations
  - Added support for weather, daylight, and location-based triggers
  - Implemented comprehensive automation APIs:
    - Weather and daylight-based automation creation
    - Geolocation management for context-aware automations
    - Multi-node automation handling and synchronization
  - Added automation update capabilities:
    - Event and action modifications
    - Retrigger control and enabled status management

## [v1.1.1]

> Supports SDK [`v2.0.1`](https://www.npmjs.com/package/@espressif/rainmaker-base-sdk/v/2.0.1)

### Fixed

- **Transport Updates**:
  - Corrected node lookup in subscription store transport listener.

- **Node Updates**:
  - Replaced deepmerge with explicit handlers for devices, params, and config updates.

- **Store Refresh**
  - Added clearing of node and group stores on first-page sync to avoid stale or duplicate entries.

## [v1.1.0]

### Added

- **Scene Management**:
  - Introduced `scenesStore` in `/store` for centralized scene handling.
  - Implemented `Scene` object in `impls/Scene` with comprehensive functionality:
    - Scene creation and modification
    - Scene removal
    - Scene activation
  - Added intelligent scene consolidation for multi-node scenes.

### Fixed

- **Group Management**:
  - Enhanced subgroup deletion logic in group store:
    - Added interceptor to properly remove subgroup references
    - Improved data consistency across parent groups

## [v1.0.1] - 2025-04-23

### Changed

- **Version Upgrade**:
  - Bumped `@espressif/rainmaker-base-sdk` from v1.0.0 to v1.0.1.

- **Code Updates**:
  - Improved imports to ensure compatibility with the updated SDK.

## [v1.0.0] - 2025-01-28

### Added

- **Reactive State Management**:
  - Introduced predefined MobX-based stores for seamless state synchronization:
    - `GroupStore`
    - `NodeStore`
    - `UserStore`
    - `SubscriptionStore`

- **Backend Integration**:
  - Automated API sync via `@espressif/rainmaker-base-sdk` for real-time updates.

- **Effortless Initialization**:
  - Minimal setup required for SDK and CDF integration.

- **Unified Data Flow**:
  - Centralized, reactive layer for managing RainMaker backend services.

- **Modular and Scalable**:
  - Supports both simple and complex applications with extensibility.

This release establishes a solid foundation for scalable **ESP RainMaker** app development.
