wt-api-client
v0.1.0
Published
Library for convenient calling of the standard WebSoft API
Maintainers
Readme
wt-api-client
TypeScript client for WebSoft WebTutor endpoints:
extjs_json_collection_data.html(collections)lpapi.html(catalog metadata and remote actions)
Installation
npm install wt-api-clientQuick Start
import { WTApiClient } from 'wt-api-client';
const client = new WTApiClient({
baseUrl: 'https://your-domain.com',
requestInit: {
headers: {
Authorization: 'Bearer <token>'
}
}
});
const users = await client.evalCollectionByCode('users_list', {
limit: 20,
start: 0,
parameters: { active: '1' },
sortBy: 'fullname',
direction: 'asc'
});
console.log(users.results);Public API
Class: WTApiClient
new WTApiClient(options?: WTApiClientOptions)Options:
baseUrl?: stringrequestInit?: SafeRequestInit
Methods:
evalCollectionByCode<T>(collectionCode, options?)evalCollectionById<T>(collectionId, options?)evalAction<T>(remoteActionId, params)fetchCollections(catalogName?)fetchCollection(objectId?)fetchActions(catalogName?)fetchAction(objectId?)fetchObjectFields(catalogName?)
Standalone functions
Also exported from package root:
evalCollectionevalActionfetchCollectionsfetchCollectionfetchActionsfetchObjectFieldslpapicreateParametersStringWTApiError
Key types
CollectionRequestParamsCollectionResponse<T>EvalActionParamsWTApiClientOptionsLpapi*response/request types
Collection Request Example
import { evalCollection } from 'wt-api-client';
const response = await evalCollection<{ id: string; name: string }>(
'https://your-domain.com',
{
collectionCode: 'users_list',
parameters: {
department: 'IT',
active: '1'
},
userId: '123',
limit: 100,
start: 0,
sortBy: 'name',
direction: 'asc'
}
);
console.log(response.total, response.results);Remote Action Example
import { evalAction } from 'wt-api-client';
const result = await evalAction(
'5709302381483599564',
'https://your-domain.com',
{
command: 'run',
form_fields: {
object_id: '123'
},
wvars: [
{ name: 'user_id', value: 456 }
],
page_url: '/view_doc.html?mode=...'
}
);
console.log(result);Publishing
Release checklist:
- Update version in
package.json. - Run
npm ci. - Run
npm run test:unit. - Optional: run
npm run test:integrationin environment with available WebTutor API. - Run
npm run build. - Run
npm run check:packageand verify tarball content includesdist/*. - Publish with
npm publish.
prepack and prepublishOnly automatically rebuild dist before packaging/publishing.
License
MIT
