whozwho-client
v1.2.8
Published
TypeScript client library for WhozWho service
Readme
🌟 WhozWho Client
A client for WhozWho services with seamless integration and error handling.
Getting Started • Features • Installation • Usage • API • Contributing
📦 Installation
npm install whozwho-client
# or
yarn add whozwho-client🚀 Getting Started
WhozWho Client provides a seamless interface to interact with WhozWho services. Built with TypeScript for type safety and modern JavaScript features for developer productivity.
import { Whozwho } from 'whozwho-client';
const client = new Whozwho({
whozwho: {
serverUrl: 'https://your-whozwho-service.com',
myUrl: 'https://your-service.com',
category: 'your-category',
id: 1 // Numeric ID for your service instance
}
});
// Check if user is principal
const isPrincipal = await client.isPrincipal();
console.log('Is Principal:', isPrincipal);✨ Features
- 🔒 Type-Safe: Full TypeScript support with comprehensive type definitions
- 🚦 Smart Error Handling: Robust error management and logging
- 🔄 Health Checks: Automated service health monitoring
- 🎯 Advice Management: Easy handling of service advices
- 🔌 Mock Mode: Built-in mock mode for testing
- 📝 Extensive Logging: Detailed logging for debugging
📚 Documentation
Memory Bank
This project uses a Memory Bank for comprehensive documentation and context retention. The Memory Bank is located in the
.memory-bank directory and contains the following files:
memory-bank-rules.md: Rules to follow and to consider in all contextsprojectbrief.md: Overview of the project, core requirements, and goalsproductContext.md: Why the project exists, problems it solves, and how it workssystemPatterns.md: System architecture, key technical decisions, and design patternstechContext.md: Technologies used, development setup, and technical constraintsactiveContext.md: Current work focus, recent changes, and next stepsprogress.md: What works, what's left to build, and known issues
=> !! These files should always be considered as a context and kept up-to-date !!
💡 Usage
Basic Configuration
import { Whozwho } from 'whozwho-client';
const client = new Whozwho({
whozwho: {
serverUrl: 'https://api.whozwho.com',
myUrl: 'https://my-service.com',
category: 'my-service',
id: 1, // Numeric ID for service instance
weight: 1,
alivePeriodInSec: 60,
disabled: false
},
deploy: {
version: '1.1.2'
}
});Managing Advices
// Get all advices
const advices = await client.getAdvices();
// Post new advice
const newAdvice = await client.postAdvice(AdviceType.UPDATE);
// Mark advice as ongoing
await client.mentionThatAdviceIsOnGoing(advice);Principal Role Verification
const isPrincipal = await client.isPrincipal();
if (isPrincipal) {
console.log('This instance is the principal!');
}📚 API
Whozwho
Main client class for interacting with WhozWho services.
Methods
getAdvices(): Fetch all available advicespostAdvice(type: AdviceType): Create a new advicementionThatAdviceIsOnGoing(advice: Advice): Update advice statusisPrincipal(): Check if current instance is principalgetPrincipalAddress(category: string): Get the address of the principal actor for a specific categorygetAllAddresses(category: string): Get addresses of all actors in a specific category
Advice
Data model for WhozWho advices.
interface Advice {
id: string;
type: AdviceType;
}AdviceType
Enum for different types of advice:
enum AdviceType {
UPDATE = 'you need an update'
}AdviceStatus
Enum for tracking the status of advice:
enum AdviceStatus {
TODO = 'toDo',
ONGOING = 'onGoing',
DONE = 'done'
}Question
Enum for different types of questions that can be asked to the WhozWho service:
enum Question {
PRINCIPAL = 'have I the principal role for my category ?',
ADDRESS_ALL = 'what is all actors (from a category) addresses ?',
ADDRESS_PRINCIPAL = 'what is principal actor (from a category) address ?'
}Answer
Enum for standard answers from the WhozWho service:
enum Answer {
YES = 'yes',
NO = 'no'
}🔧 Configuration
| Option | Type | Description | Default Value | |------------------|---------|---------------------------------------|-------------------------| | serverUrl | string | WhozWho service URL | 'http://localhost:3003' | | myUrl | string | URL of this service instance | 'http://localhost:3000' | | category | string | Service category | 'default' | | id | number | Service identifier (must be a number) | 1 | | weight | number | Instance weight | 1 | | alivePeriodInSec | number | Health check interval | 60 | | disabled | boolean | Enable mock mode | false |
🤝 Contributing
We welcome contributions! Follow these steps:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
Release process
Before any git push, consider to align documentation: readme, changelog, badge version, memory bank...
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with TypeScript
- Powered by Axios
- Tested with Jest
Made with ❤️ by mlefree
