Skip to content

PruvoNet/cronicle-client

Repository files navigation

Npm Version Build Status Coverage Status Codacy Badge Known Vulnerabilities dependencies Status devDependencies Status

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 objects helpers, you must also install moment

Quick example

import { CronicleClient, NumberedBoolean, BaseCategories, BaseTargets, getUtcTiming, 
 HttpPluginMethods, } from 'cronicle-client';

const scheduler = new CronicleClient({
  masterUrl: 'http://localhost:3012',
  apiKey: '<your api key>',
});

scheduler.createEvent({
        plugin: 'urlplug',
        title: 'test event1',
        enabled: NumberedBoolean.TRUE,
        category: BaseCategories.GENERAL,
        target: BaseTargets.GENERAL,
        timing: getUtcTiming('2016-05-26T14:50:50.900Z'),
        timezone: 'Etc/UTC',
        params: {
          method: HttpPluginMethods.POST,
          timeout: '60',
          headers:  'Content-Type: application/json',
          data: JSON.stringify({ a: 1 }),
          url: 'https://requestbin.com',
        },
      })
      .then((data) => {
        console.log(`Created event with id: ${data.id}`);
        return scheduler.runEvent({ id: data.id });
      })
      .then((data) => {
        console.log(`Started event with job id: ${data.ids[0]}`);
      });

Extending with custom types example

import { CronicleClient, IHttpPluginData, IShellPluginData, ITestPluginData, NumberedBoolean,
    getUtcTiming } from 'cronicle-client';

export interface ICustomPluginData {
  duration: string;
  action: string;
}

export interface Plugins {
  // Default plugins
  urlplug: IHttpPluginData;
  shellplug: IShellPluginData;
  testplug: ITestPluginData;
  // Custom plugins
  mycustomplug: ICustomPluginData;
}

export enum Categories {
  // Default category
  GENERAL = 'general',
  // Custom categories...
  TEST_CATEGORY = 'cjw6g085901', 
  TEST_CATEGORY2 = 'cjw6l8mnb02',
}

export enum Targets {
    // Default targets...
    ALL = 'allgrp',
    MAIN = 'maingrp',
    // Custom targets...
    AWS = 'awsgrp',
    GCP = 'gcpgrp',
}

const scheduler = new CronicleClient<Categories, Targets, Plugins>({
  masterUrl: 'http://localhost:3012',
  apiKey: '<your api key>',
});

scheduler.createEvent({
        plugin: 'mycustomplug',
        title: 'test event1',
        enabled: NumberedBoolean.TRUE,
        category: Categories.TEST_CATEGORY2,
        target: Targets.AWS,
        timing: getUtcTiming('2016-05-26T14:50:50.900Z'),
        timezone: 'Etc/UTC',
        params: {
          duration: '60',
          action: JSON.stringify({ a: 1 }),
        },
      })
      .then((data) => {
        console.log(`Created event with id: ${data.id}`);
        return scheduler.runEvent({ id: data.id });
      })
      .then((data) => {
        console.log(`Started event with job id: ${data.ids[0]}`);
      });

Documentation

TBD

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.