@infoxchange/iss4
v1.0.3
Published
ISS v4 REST API client for Node.js
Downloads
210
Readme
ISS v4 REST API Node.js Client
This package provides a Node.js client for interacting with the ISS v4 REST API. This client has been transpiled from the python client https://github.com/InfoxchangeTS/iss-v4-rest-python-client
Installation
npm install iss-v4-rest-nodejs-clientUsage
Basic Usage
import { ISSV4APIClient } from 'iss-v4-rest-nodejs-client';
// Initialize the client with JWT authentication
const client = new ISSV4APIClient(
'https://api.example.com/api/',
{},
'client_id',
'client_secret'
);
// Or with Basic token authentication
import { BasicTokenSession } from 'iss-v4-rest-nodejs-client';
const client = new ISSV4APIClient(
'https://api.example.com/api/',
{ session: BasicTokenSession },
'your_token'
);
// Directory search provides a simple yet powerfull parameter based method for a simpler search experience
async function simpleSearch() {
try {
const results = await client.directorySearch({
name: 'health services',
lga: 'city of yarra',
fields: '*'
});
console.log(results);
} catch (error) {
console.error('Search failed:', error);
}
}
// Advanced search is provided via the search endpoint and takes Appsearch based filters and boosts
async function advancedSearch() {
try {
const results = await client.search(
'search term',
{ filter_key: 'filter_value' }
);
console.log(results);
} catch (error) {
console.error('Search failed:', error);
}
}
// Entity operations example
async function createOrganisation() {
try {
const response = await client.createOrganisation({
name: 'Test Organisation',
// Other fields...
});
console.log('Organisation created:', response.data);
} catch (error) {
console.error('Failed to create organisation:', error);
}
}Authentication
The client supports two authentication methods:
- JWT authentication (default)
- Basic token authentication
JWT Authentication
const client = new ISSV4APIClient(
'https://api.example.com/api/',
{},
'client_id',
'client_secret'
);Basic Token Authentication
import { BasicTokenSession } from 'iss-v4-rest-nodejs-client';
const client = new ISSV4APIClient(
'https://api.example.com/api/',
{ session: BasicTokenSession },
'your_token'
);Query Parameters
When working with list operations, you can provide query parameters to filter and paginate results:
// Get organisations with pagination
const organisations = await client.organisations(undefined, { limit: '50', offset: '10' });
// Get services with a search term and filters
const services = await client.services(
{ name: 'Health' }, // search term
{ active: 'true' } // query parameters
);The client automatically handles various parameter formats, including:
- String values (e.g.,
{ limit: '50' }) - Array values (e.g.,
{ limit: ['50'] }) - Mixed values (e.g.,
{ limit: '50', tags: ['tag1', 'tag2'] })
Note: For array parameters, the client uses the first value in the array when making API requests.
API Reference
The client provides methods for interacting with all the endpoints of the ISS v4 API.
Search Operations
search(term, filters, boosts, serialiser, options)- Search ISS v4directorySearch(queryParams)- Directory search with GET parameterssearchExplain(term, filters, boosts, serialiser, options)- Explain search querysearchElasticsearch(query, params, analyticsQuery, analyticsTags)- Submit an Elasticsearch querymultiSearch(queries)- Perform a multi-searchquerySuggestion(query, options)- Get search suggestions
Organisation Operations
organisations(searchTerm, params)- Get a list of organisationsorganisationExists(entityId)- Check if an organisation existsfetchOrganisation(entityId)- Fetch an organisationcreateOrganisation(data)- Create an organisationupdateOrganisation(entityId, data)- Update an organisationdeleteOrganisation(entityId)- Delete an organisationcreateOrUpdateOrganisation(entityId, data)- Create or update an organisation
Site Operations
sites(searchTerm, params)- Get a list of sitessiteExists(entityId)- Check if a site existsfetchSite(entityId)- Fetch a sitecreateSite(data)- Create a siteupdateSite(entityId, data)- Update a sitedeleteSite(entityId)- Delete a sitecreateOrUpdateSite(entityId, data)- Create or update a site
Service Operations
services(searchTerm, params)- Get a list of servicesserviceExists(entityId)- Check if a service existsfetchService(entityId)- Fetch a servicecreateService(data)- Create a serviceupdateService(entityId, data)- Update a servicedeleteService(entityId)- Delete a servicecreateOrUpdateService(entityId, data)- Create or update a servicefetchServiceType(entityId)- Fetch a service typelistServiceTypes(params)- List service types
Event Operations
listEvents(queryParams)- List eventseventExists(entityId)- Check if an event existsfetchEvent(entityId)- Fetch an eventcreateEvent(data)- Create an eventupdateEvent(entityId, data)- Update an eventdeleteEvent(entityId)- Delete an eventcreateOrUpdateEvent(entityId, data)- Create or update an event
Other Operations
listAgeGroups(queryParams)- List age groupsfetchAgeGroup(entityId)- Fetch an age grouplistDatasets(queryParams)- List datasetsfetchDataset(entityId)- Fetch a datasetlistCrisisKeywords(queryParams)- List crisis keywordslistRelatedCrisisKeywords(terms)- List related crisis keywordsfetchCrisisKeyword(entityId)- Fetch a crisis keywordcreateCrisisKeyword(data)- Create a crisis keyworddeleteCrisisKeyword(entityId)- Delete a crisis keywordlistLanguages(queryParams)- List languagesfetchLanguage(entityId)- Fetch a languageanalyticsQueries(options)- Fetch query analyticsfetchByExternalId(externalId, organisation)- Fetch by external IDsuggest(suggestionType, start)- Get suggestions
Development
Setup
# Install dependencies
yarn install
# Build
yarn run build
# Run tests
yarn testTesting
The package includes a comprehensive test suite:
# Run all tests
yarn test
# Run with coverage
yarn test -- --coverage