@reciprocityapps/advocate-client
v0.0.1
Published
TypeScript client for the Advocate API
Downloads
16
Readme
@reciprocityapps/advocate-client
TypeScript client library for the Advocate API, automatically generated from OpenAPI specification.
Features
- 🎯 Type-safe - Full TypeScript support with auto-generated types
- 🚀 Zero dependencies - Uses native fetch API
- 📦 Tree-shakeable - Import only what you need
- 🔄 Auto-updated - Regenerated automatically when API changes
- 📝 Complete - Covers all API endpoints from OpenAPI spec
Installation
npm install @reciprocityapps/advocate-client
# or
yarn add @reciprocityapps/advocate-clientUsage
Basic Usage
import { client, getPeople, postOrganizations } from '@reciprocityapps/advocate-client';
// Configure the client (optional, can set baseUrl and headers)
client.setConfig({
baseUrl: 'https://api.yourinstance.com',
headers: {
Authorization: `Bearer ${yourToken}`
}
});
// Make API calls with full type safety
const people = await getPeople({
query: {
skip: 0,
take: 10
}
});
// Create resources
const newOrg = await postOrganizations({
body: {
name: 'My Organization',
// ... other fields with full autocomplete
}
});With Custom Client Instance
import { createClient, createConfig } from '@reciprocityapps/advocate-client';
const myClient = createClient(createConfig({
baseUrl: 'https://api.yourinstance.com',
headers: {
Authorization: `Bearer ${yourToken}`
}
}));
// Use custom client instance
const response = await getPeople({
client: myClient,
query: { take: 10 }
});Error Handling
import { getPeople } from '@reciprocityapps/advocate-client';
try {
const people = await getPeople<true>({
query: { take: 10 },
throwOnError: true
});
console.log(people.data);
} catch (error) {
console.error('API Error:', error);
}Development
This package is automatically generated from the OpenAPI specification located at packages/api/openapi/open-api.json.
Manual Generation
To manually generate the client code:
yarn generateBuilding
yarn buildThis will compile TypeScript to the dist/ directory.
Publishing
This package is automatically published to npm when changes are detected in the OpenAPI specification. The version is automatically bumped based on the type of changes:
- Major: Breaking changes detected
- Minor: New endpoints or features added
- Patch: Bug fixes or non-breaking changes
Generated Code
⚠️ Do not manually edit files in the src/ directory. These files are automatically generated and will be overwritten.
License
UNLICENSED
