# Changelog

All notable changes to @wardnmesh/sdk-node will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.0] - 2026-01-17

### 🚨 Breaking Changes

**Action-Based Architecture**: Replaces boolean `allowed` field with granular action types.

- **`ScanResult.allowed` → `ScanResult.action`**
  - Type: `boolean` → `ThreatAction` (`'block'` | `'confirm'` | `'warn'` | `'log'` | `'allow'`)
  - Provides fine-grained control over threat response
  - Enables user confirmation for high-risk operations

### Added

- **Confirmation Support** (`action: 'confirm'`)
  - New `confirmationDetails` field in `ScanResult`
  - Pre-formatted confirmation messages with context
  - Configurable timeout and default action
  - Designed for user approval dialogs in CLI/UI

- **Action Priority System**
  - `determineAction()` method with priority: `block` > `confirm` > `warn` > `log` > `allow`
  - Defensive fail-closed design: defaults to `'block'` on invalid actions
  - Comprehensive validation with fallback safety

- **Enhanced Violation Metadata**
  - Added `recommendedAction: ThreatAction` field to `Violation`
  - Added `scope: string` field for categorization
  - Richer context for decision-making

### Changed

- **Core API**: `scan()` now returns `action` instead of `allowed`
- **Middleware**: Callbacks now receive full `ScanResult` instead of just `violations`
- **Error Handling**: Invalid `recommendedAction` values trigger warnings and fail-closed

### Fixed

- **Defensive Design**: Prevents security bypass from missing/invalid `recommendedAction`
- **Type Safety**: All violation fields properly validated before action determination

### Migration

See [MIGRATION_v0.4.0.md](MIGRATION_v0.4.0.md) for detailed upgrade guide.

**Quick Migration**:
```typescript
// Before (v0.2.3)
if (!result.allowed) { throw new Error('Blocked'); }

// After (v0.4.0)
if (result.action === 'block') { throw new Error('Blocked'); }
```

### Testing

- ✅ 17 tests passing (4 test suites)
- ✅ All action types validated
- ✅ Confirmation flow tested
- ✅ Fail-closed behavior verified

---

## [0.2.3] - 2026-01-16

### Fixed

- Improved severity-to-action mapping in integrations
- Enhanced error handling with better null checks

### Documentation

- Updated examples with current API patterns
- Clarified rule configuration options

---

## [0.2.0] - 2026-01-15

### Added

- **Semantic Analysis**: ML-based threat detection using local models
- **State Tracking**: Session-aware detection for multi-turn attacks
- **Pattern Detectors**: Regex-based threat pattern matching
- **Sequence Detectors**: Multi-step attack pattern recognition

### Changed

- Unified detector API for all detection types
- Improved telemetry with detailed metrics

### Performance

- <20ms latency for most scans
- Local-first processing (no external API calls)
- Lazy loading for ML models

---

## [0.1.0] - 2026-01-10

### Added

- Initial release of WardnMesh SDK for Node.js
- Core `Wardn` class with singleton pattern
- Basic threat detection for:
  - PII (Personal Identifiable Information)
  - Prompt injection patterns
  - API key leakage
- Express middleware support
- Next.js middleware support
- Vercel AI SDK integration
- Local rule management

### Features

- Rule-based scanning engine
- Configurable severity levels
- Telemetry and reporting
- Extensible detector system
- TypeScript support with full type definitions

---

## Version Compatibility

| SDK Version | MCP Server | Node.js | Status |
|-------------|------------|---------|--------|
| 0.4.0 | 0.2.3+ | 18+ | ✅ Current |
| 0.2.3 | 0.2.0+ | 18+ | ⚠️ Legacy |
| 0.2.0 | 0.2.0+ | 18+ | ⚠️ Legacy |
| 0.1.0 | 0.1.0+ | 18+ | ❌ Deprecated |

---

## Links

- [NPM Package](https://www.npmjs.com/package/@wardnmesh/sdk-node)
- [GitHub Repository](https://github.com/PCIRCLE-AI/wardnmesh)
- [Documentation](https://wardnmesh.ai/docs/sdk)
- [Migration Guides](MIGRATION_v0.4.0.md)
