npm package: @precious_atam/oginisearch-client
Description: TypeScript client for the Ogini search engine
Author: Precious Atam
Latest version: 0.0.1

# Ogini TypeScript Client

A TypeScript client library for interacting with the Ogini search engine API.

## Installation

```bash
npm install @ogini/client
```

## Quick Start

```typescript
import { Ogini } from '@ogini/client';

// Create a new client instance
const client = new Ogini({
  baseURL: 'https://api.ogini.com',
  // Optional: Add your API key
  headers: {
    'Authorization': 'Bearer your-api-key'
  }
});

// Create an index
await client.indices.createIndex({
  name: 'products',
  mappings: {
    properties: {
      title: { type: 'text' },
      description: { type: 'text' },
      price: { type: 'float' },
      tags: { type: 'keyword' }
    }
  }
});

// Index a document
await client.documents.indexDocument('products', {
  document: {
    title: 'Nike Air Max',
    description: 'Classic running shoes',
    price: 129.99,
    tags: ['shoes', 'running', 'nike']
  }
});

// Search for documents
const results = await client.search.search('products', {
  query: {
    match: {
      field: 'title',
      value: 'nike'
    }
  }
});
```

## Features

- Full TypeScript support
- Comprehensive API coverage
- Automatic retries and error handling
- Built-in request validation
- Promise-based API

## API Reference

### Client Configuration

```typescript
interface ClientOptions {
  baseURL: string;
  timeout?: number;
  headers?: Record<string, string>;
}
```

### Index Management

```typescript
// Create an index
await client.indices.createIndex({
  name: string;
  mappings: IndexMappings;
});

// Delete an index
await client.indices.deleteIndex(indexName: string);

// Get index info
await client.indices.getIndex(indexName: string);
```

### Document Management

```typescript
// Index a single document
await client.documents.indexDocument(indexName: string, {
  document: any;
});

// Bulk index documents
await client.documents.bulkIndexDocuments(indexName: string, {
  documents: any[];
});

// Delete a document
await client.documents.deleteDocument(indexName: string, documentId: string);
```

### Search

```typescript
// Basic search
await client.search.search(indexName: string, {
  query: {
    match: {
      field: string;
      value: string;
    }
  }
});

// Advanced search with filters and facets
await client.search.search(indexName: string, {
  query: {
    match: {
      field: string;
      value: string;
    }
  },
  filter: {
    range: {
      price: {
        gte: number;
        lte: number;
      }
    }
  },
  facets: string[];
});
```

## Error Handling

The client throws `ClientError` for API errors:

```typescript
try {
  await client.indices.createIndex({ /* ... */ });
} catch (error) {
  if (error instanceof ClientError) {
    console.error(`API Error: ${error.message}`);
    console.error(`Status: ${error.status}`);
    console.error(`Code: ${error.code}`);
  }
}
```

## Contributing

Contributions are welcome! Please read our [contributing guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.