Socket
Socket
Sign inDemoInstall

schedulerapi-js

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    schedulerapi-js

A Javascript / Typescript SDK for the www.schedulerapi.com service.


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Javascript / Node SDK written in Typescript for the SchedulerAPI Service

A lightweight library and rapid way to add the www.schedulerapi.com service into your Javascript / Typescript / Node projects.

Installation

The recommended way to install the SchedulerAPI SDK is through npm or Yarn.

npm:

npm install schedulerapi-js

yarn:

yarn add schedulerapi-js

Prerequisites

You will need an API key from the www.schedulerapi.com service.

Additional things to think about (if using SQS)

If you want to schedule SQS events you will want to create a user in your AWS account and provide that user ONLY access to publish messages into the SQS queue. Make sure you ONLY provide that access for that user. An example policy might be this:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "sqs:SendMessage",
            "Resource": "arn:aws:sqs:region:accountID:queueName"
        }
    ]
}

Usage

Scheduling an SQS Event

To schedule an event you need to call the scheduleSqs function with the information you want to schedule.

const s = new Scheduler({ key: SCHEDULER_API_KEY });
const results = await s.scheduleSqs({
    when: new Date('2020-08-24 20:13:00'),
    url: YOUR_SQS_QUEUE_URL,
    body: 'THE_BODY_OF_YOUR_SQS_MESSAGE'
});
console.log(results);

output:

{
    "id": "cLzxqmLKAEc2Tf2YzKRZW",
    "when": "2020-08-24 20:13:00",
    "now": "2020-08-24 20:11:35",
    "user": "CkM2xwzjvxjGhWeiMFWy9s"
}

Scheduling a Webhook Event

To schedule an event you need to call the scheduleWebhook function with the information you want to schedule.

const s = new Scheduler({ key: SCHEDULER_API_KEY });
const results = await s.scheduleWebhook({
    when: new Date('2020-08-24 20:13:00'),
    url: YOUR_URL,
    method: 'get', // or 'post' or 'GET' or 'POST'
    body: 'REQUEST_BODY' // typically used for POST
});
console.log(results);

output:

{
    "id": "FiGGCz8BMieyuRXPVtKLFT",
    "when": "2020-08-24 20:13:00",
    "now": "2020-08-24 20:11:35",
    "user": "CkM2xwzjvxjGhWeiMFWy9s"
}

Updating an SQS Event

To update a previously scheduled event you need to call the updateSqs function with the id of the event you want to change. When you update an event you need to re-send all of the information along with the event. If you do not have it you can obtain it from a call to getStatus.

const s = new Scheduler({ key: SCHEDULER_API_KEY });
const results = await s.updateSqs({
    id: 'cLzxqmLKAEc2Tf2YzKRZW',
<<<<<<< HEAD
    when: new Date('2020-08-24 20:13:00'),
=======
    when: new Date('2020-08-24 22:13:00'),
>>>>>>> 4bf3364b2dba18d04ebf80f566d0b3475c8b0af9
    url: YOUR_SQS_QUEUE_URL,
    body: 'THE_BODY_OF_YOUR_SQS_MESSAGE'
});
console.log(results);

output:

{
    "id": "cLzxqmLKAEc2Tf2YzKRZW",
    "when": "2020-08-24 22:13:00",
    "now": "2020-08-24 20:11:35",
    "user": "CkM2xwzjvxjGhWeiMFWy9s"
}

Updating an Webhook Event

To update a previously scheduled event you need to call the updateWebhook function with the id of the event you want to change. When you update an event you need to re-send all of the information along with the event. If you do not have it you can obtain it from a call to getStatus.

const s = new Scheduler({ key: SCHEDULER_API_KEY });
const results = await s.updateWebhook({
    id: 'FiGGCz8BMieyuRXPVtKLFT',
    when: new Date('2020-08-24 20:13:00'),
    url: YOUR_URL,
    method: 'get', // or 'post' or 'GET' or 'POST'
    body: 'REQUEST_BODY' // typically used for POST
});
console.log(results);

output:

{
    "id": "FiGGCz8BMieyuRXPVtKLFT",
    "when": "2020-08-24 22:13:00",
    "now": "2020-08-24 20:11:35",
    "user": "CkM2xwzjvxjGhWeiMFWy9s"
}

Tests

Tests are executed via Jest.

npm run test

Keywords

FAQs

Last updated on 10 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc