# hunto.ai - Node.js SDK Documentation

## Overview

The `hunto-node-sdk` package provides a Node.js SDK for interacting with Hunto's API services. This SDK facilitates various operations including threat detection, incident management, asset monitoring, classification, reporting, authentication, and more.

## Installation

To install the SDK, use npm:

```bash
npm install hunto-node-sdk
```

## Getting Started

First, import the `HuntoClient` class from the package:

```javascript
import { HuntoClient } from "hunto-node-sdk";
```

## Initializing the SDK

Create an instance of the `HuntoClient` class. You can optionally pass a configuration object to customize the base URL, authentication token, and other settings:

```javascript
const client = new HuntoClient({
	BASE: "https://in.hunto.ai/api", // Optional, this is the default
	TOKEN: "your-api-token", // Optional, can be set later
});
```

## Authentication

The SDK supports authentication via token. You can set the token during initialization or later:

```javascript
// Set token during initialization
const client = new HuntoClient({
	TOKEN: "your-api-token",
});

// Or set it later
client.request.config.TOKEN = "your-api-token";
```

## Using SDK Services

Once initialized, you can use various services provided by the SDK:

### Monitor Services
- `client.monitorActivity`: Activity monitoring and audit logs
- `client.monitorAdvisory`: Security advisories and alerts
- `client.monitorAssets`: Asset management and tracking
- `client.monitorClassification`: Detection classification
- `client.monitorControl`: Control and policy management
- `client.monitorDetection`: Threat detection operations
- `client.monitorDiscovery`: Asset discovery
- `client.monitorIncident`: Incident management
- `client.monitorIntegration`: Third-party integrations
- `client.monitorIntel`: Threat intelligence
- `client.monitorNotificationModel`: Notification models
- `client.monitorReportIncident`: Incident reporting
- `client.monitorReports`: Report generation
- `client.monitorScamx`: Scam detection
- `client.monitorSchedule`: Scheduled tasks
- `client.monitorScheduleReport`: Scheduled reports
- `client.monitorScore`: Risk scoring
- `client.monitorStats`: Statistics and analytics
- `client.monitorTags`: Tag management
- `client.monitorTasks`: Task management
- `client.monitorTemplates`: Template management
- `client.monitorViews`: Custom views

### System Services
- `client.sysAuth`: Authentication operations
- `client.sysManage`: System management
- `client.sysPage`: Page management
- `client.sysTwofa`: Two-factor authentication

## Example Usage

Here's an example of how to use the SDK to list detections:

```javascript
import { HuntoClient } from "hunto-node-sdk";

// Initialize the client
const client = new HuntoClient({
	BASE: "https://in.hunto.ai/api",
	TOKEN: "your-api-token",
});

try {
	// List detections
	const detections = await client.monitorDetection.list({
		limit: 10,
		skip: 0,
	});
	console.log("Detections:", detections);

	// Get incident details
	const incident = await client.monitorIncident.get({
		incidentId: "INC-2024-001",
	});
	console.log("Incident:", incident);

	// List assets
	const assets = await client.monitorAssets.list({
		limit: 20,
	});
	console.log("Assets:", assets);
} catch (error) {
	console.error("Error:", error);
}
```

### Authentication Example

```javascript
import { HuntoClient } from "hunto-node-sdk";

const client = new HuntoClient({
	BASE: "https://in.hunto.ai/api",
});

try {
	// Login
	const authResult = await client.sysAuth.login({
		email: "user@example.com",
		password: "your-password",
	});
	
	// Set the token for subsequent requests
	client.request.config.TOKEN = authResult.token;
	
	// Now you can make authenticated requests
	const profile = await client.sysAuth.getProfile();
	console.log("Profile:", profile);
} catch (error) {
	console.error("Authentication error:", error);
}
```

## Advanced Usage

### Working with Detections

```javascript
// Create a detection
const newDetection = await client.monitorDetection.create({
	type: "phishing",
	url: "https://malicious-site.example.com",
	description: "Suspected phishing site",
});

// Update a detection
await client.monitorDetection.update({
	detectionId: "DDT-2024-001",
	classification: "confirmed",
	infringement: ["phishing", "brand_abuse"],
});

// Delete a detection
await client.monitorDetection.delete({
	detectionId: "DDT-2024-001",
});
```

### Working with Incidents

```javascript
// List incidents
const incidents = await client.monitorIncident.list({
	limit: 10,
	skip: 0,
	status: "open",
});

// Create an incident
const incident = await client.monitorIncident.create({
	title: "Security Incident - Phishing Campaign",
	description: "Multiple phishing detections targeting our brand",
	severity: "high",
});

// Update incident status
await client.monitorIncident.update({
	incidentId: "INC-2024-001",
	status: "resolved",
});
```

### Generating Reports

```javascript
// Generate a report
const report = await client.monitorReports.generate({
	type: "monthly",
	startDate: "2024-01-01",
	endDate: "2024-01-31",
	format: "pdf",
});

// List available reports
const reports = await client.monitorReports.list({
	limit: 20,
});

// Download a report
const reportData = await client.monitorReports.download({
	reportId: "RPT-2024-001",
});
```

### Working with Tags

```javascript
// List all tags
const tags = await client.monitorTags.list();

// Create a tag
const newTag = await client.monitorTags.create({
	name: "high-priority",
	color: "#ff0000",
});

// Apply tags to a detection
await client.monitorTags.applyToDetection({
	detectionId: "DDT-2024-001",
	tags: ["high-priority", "urgent"],
});
```

## Error Handling

The SDK uses standard error handling. You should wrap your API calls in try-catch blocks:

```javascript
import { HuntoClient, ApiError } from "hunto-node-sdk";

const client = new HuntoClient({
	BASE: "https://in.hunto.ai/api",
	TOKEN: "your-api-token",
});

try {
	const detections = await client.monitorDetection.list({ limit: 10 });
	console.log(detections);
} catch (error) {
	if (error instanceof ApiError) {
		console.error("API Error:", {
			status: error.status,
			message: error.message,
			body: error.body,
		});
	} else {
		console.error("Unexpected error:", error);
	}
}
```

## TypeScript Support

The SDK is written in TypeScript and includes full type definitions. You can import types for request and response objects:

```typescript
import { 
	HuntoClient, 
	type OpenAPIConfig,
	type request_monitor_views_incident
} from "hunto-node-sdk";

const config: Partial<OpenAPIConfig> = {
	BASE: "https://in.hunto.ai/api",
	TOKEN: "your-api-token",
};

const client = new HuntoClient(config);
```

## Documentation

For detailed API documentation and more examples, refer to the official Hunto SDK documentation.
