npm package: @quiqflow-org/quiqflow-multi-tenants-utils
Description: Shared multi-tenant helpers (schema resolution, connection management, middleware) for Quiqflow services.
Latest version: 1.0.5

# quiqflow-multi-tenants-utils

[![npm version](https://badge.fury.io/js/quiqflow-multi-tenants-utils.svg)](https://badge.fury.io/js/quiqflow-multi-tenants-utils)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

Quiqflow multi-tenant management utilities.  
This package provides utility functions and helpers for developing, managing, and operating tenant-aware applications and services within the Quiqflow ecosystem.

---

## Features

- **Tenant isolation:** Utilities for handling multiple tenants with clear separation.
- **Configuration management:** Simplifies the loading and handling of tenant-specific configurations.
- **Helpers for onboarding/provisioning:** Facilitates new tenant setup and management flows.
- **Security and context management:** Assists in establishing secure context for tenant operations.
- **Extensible and framework-agnostic:** Easily integrates with Node.js/TypeScript backends and microservices.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [API Reference](#api-reference)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)

---

## Installation

```bash
npm install quiqflow-multi-tenants-utils
# or
yarn add quiqflow-multi-tenants-utils
```

---

## Usage

Import the package in your TypeScript/Node.js project:

```typescript
import { getTenantContext, TenantConfigLoader } from 'quiqflow-multi-tenants-utils';

// Example: Retrieve tenant context from a request
const tenantId = req.headers['x-tenant-id'];
const tenantContext = getTenantContext(tenantId);
```

Or in JavaScript:

```javascript
const { getTenantContext, TenantConfigLoader } = require('quiqflow-multi-tenants-utils');
```

---

## API Reference

> 📑 **NOTE:** Consult the inline TypeScript documentation or see [API details](#) if available.

### `getTenantContext(tenantId: string): TenantContext`
Retrieves or builds a tenant-specific context object using the provided tenant identifier.

### `TenantConfigLoader`
A utility to load and cache tenant-specific configuration files.

#### Example:

```typescript
const configLoader = new TenantConfigLoader('/path/to/configs');
const tenantConfig = configLoader.loadConfig(tenantId);
```

> Additional helper functions may include:
> - Middleware for Express.js/Koa to inject tenant context
> - Utilities for tenant-aware logging
> - Helper types and guards for safe multi-tenant code

---

## Examples

See the `/examples` directory (if present) or review test files for usage patterns and integration scenarios.

---

## Contributing

Contributions are welcome!  
Please open issues or pull requests for bug fixes, new features, or improvements.

1. Fork the repository.
2. Create a new branch (`git checkout -b feature/my-feature`).
3. Commit your changes (`git commit -am 'Add new feature'`).
4. Push to the branch (`git push origin feature/my-feature`).
5. Create a pull request.

---

## License

This project is licensed under the [MIT License](LICENSE).

---

## About

**quiqflow-multi-tenants-utils** is maintained by the Quiqflow team.

For questions or support, please open an [issue](https://github.com/Quiqflow-2-0/quiqflow-multi-tenants-utils/issues).