Cronicle client
Light Croncile node client with full TypeScript support
Main features
- Fully typed api client for Cronicle
- No dependencies (you need to install your own
request-promise
library) - Helper methods to build Timing objects for scheduling events
- Type safety extendable for Categories, Plugins and Targets
Install
npm install cronicle-client
--NOTICE--
request-promise
is a peer dependency and must be installed by you (>=1.0.0)
--NOTICE--
If you want to use the timing utils, you must also install moment
Quick example
; ; scheduler.createEvent .then .then .catch;
Extending with custom types example
; ; ; scheduler.createEvent .then .then .catch;
Documentation
Methods
For all api endpoints documentations, please refer to Cronicle api reference
createEvent
When creating an event, there is no unique restriction on the title/id.
While searching for an event using getEvent
, the
api allows you to search by title/id, which is great, but as of now (cronicle v0.89) it will return a single result.
This imposes an issue when you don't enforce a unique title/id since you will get a random result (see #186)
Until this behaviour is fixed, you can tell the createEvent
method to enforce uniqueness and it will fail if an event with the provided title/id already exists.
Note: if id
is provided - it will be used as the unique key, otherwise title
will be used.
Error handling
Croncile
will always return a valid HTTP response (code 200
).
To raise an error, the code
property of the response will be different than 0
.
In such cases, the current method will be rejected with CronicleError
with the proper error message and the
code
property.
Constructor
Options
Parameter Name | Description |
---|---|
masterUrl |
The full url to the master Cronicle server |
apiKey |
The api key to use (make sure it has relevant permissions enabled) |
Typings
The client can enforce the proper usage of categories, targets and plugins (with their required parameters).
This is done using optional generics:
Generics Parameter Name | Description |
---|---|
Categories |
Enum containing the ids of the categories available at you Cronicle server (Defaults to BaseCategories ) |
Targets |
Enum containing the ids of the targets available at you Cronicle server (Defaults to BaseTargets ) |
Plugins |
Interface containing mapping between plugin ids and the interface representing their required event params (Defaults to IBasePlugins ) |
Examples
Example constructor with defaults:
;
Example for setting the categories your server supports:
Example for setting the targets your server supports:
Example for setting the plugins your server supports:
Example constructor with overrides:
;
Timing utils
To support a wide variety of scheduling, the timing object
an be very cumbersome...
To make life easier (at least when you just want to schedule an event for a single future run) you can use the
getFutureTiming
and getFutureUtcTiming
methods:
--NOTICE--
If you want to use the timing utils, you MUST npm install --save moment
Running:
getFutureUtcTimingmoment.utc'2016-05-26T14:50:50.900Z';
Will produce:
Versions
Cronicle client supports Node 6 LTS and higher.
Contributing
All contributions are happily welcomed!
Please make all pull requests to the master
branch from your fork and ensure tests pass locally.