Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ellipsis-api

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ellipsis-api - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

72

__tests__/test.js

@@ -25,2 +25,4 @@ "use strict";

const api = new EllipsisApi(ellipsis);
const actionsApi = api.actions;
const storageApi = api.storage;

@@ -35,3 +37,3 @@ describe("ActionsApi", () => {

const actionName = "foo";
return api.run({ actionName: actionName, args: args }).then(data => {
return actionsApi.run({ actionName: actionName, args: args }).then(data => {
const form = data.body.form;

@@ -44,3 +46,3 @@ const expectedForm = Object.assign({}, defaultExpectedForm, {

expect(form).toEqual(expectedForm);
expect(data.url).toEqual(api.urlFor("run_action"))
expect(data.url).toEqual(actionsApi.urlFor("run_action"))
});

@@ -54,3 +56,3 @@

const trigger = "foo bar baz";
return api.run({ trigger: trigger }).then(data => {
return actionsApi.run({ trigger: trigger }).then(data => {
const form = data.body.form;

@@ -61,3 +63,3 @@ const expectedForm = Object.assign({}, defaultExpectedForm, {

expect(form).toEqual(expectedForm);
expect(data.url).toEqual(api.urlFor("run_action"))
expect(data.url).toEqual(actionsApi.urlFor("run_action"))
});

@@ -70,3 +72,3 @@

expect.hasAssertions();
api.run({}).catch(err => {
actionsApi.run({}).catch(err => {
expect(err).toEqual(errorMessages.TRIGGER_AND_ACTION_NAME_MISSING);

@@ -80,3 +82,3 @@ });

expect.hasAssertions();
api.run({ actionName: "foo", trigger: "bar" }).catch(err => {
actionsApi.run({ actionName: "foo", trigger: "bar" }).catch(err => {
expect(err).toEqual(errorMessages.BOTH_TRIGGER_AND_ACTION_NAME);

@@ -95,3 +97,3 @@ });

const message = "yo";
return api.say({ message: message }).then(data => {
return actionsApi.say({ message: message }).then(data => {
const form = data.body.form;

@@ -102,3 +104,3 @@ const expectedForm = Object.assign({}, defaultExpectedForm, {

expect(form).toEqual(expectedForm);
expect(data.url).toEqual(api.urlFor("say"))
expect(data.url).toEqual(actionsApi.urlFor("say"))
});

@@ -111,3 +113,3 @@

expect.hasAssertions();
return api.say({ }).catch(err => {
return actionsApi.say({ }).catch(err => {
expect(err).toEqual(errorMessages.MESSAGE_MISSING);

@@ -136,3 +138,3 @@ });

});
return api.schedule(options).then(data => {
return actionsApi.schedule(options).then(data => {
const form = data.body.form;

@@ -145,3 +147,3 @@ const expectedForm = Object.assign({}, defaultExpectedForm, defaultOptions, {

expect(form).toEqual(expectedForm);
expect(data.url).toEqual(api.urlFor("schedule_action"))
expect(data.url).toEqual(actionsApi.urlFor("schedule_action"))
});

@@ -154,3 +156,3 @@

expect.hasAssertions();
return api.schedule(defaultOptions).catch(err => {
return actionsApi.schedule(defaultOptions).catch(err => {
expect(err).toEqual(errorMessages.TRIGGER_AND_ACTION_NAME_MISSING);

@@ -168,3 +170,3 @@ });

});
return api.schedule(options).catch(err => {
return actionsApi.schedule(options).catch(err => {
expect(err).toEqual(errorMessages.BOTH_TRIGGER_AND_ACTION_NAME);

@@ -182,3 +184,3 @@ });

delete options.recurrence;
return api.schedule(options).catch(err => {
return actionsApi.schedule(options).catch(err => {
expect(err).toEqual(errorMessages.RECURRENCE_MISSING);

@@ -200,3 +202,3 @@ });

});
return api.unschedule(options).then(data => {
return actionsApi.unschedule(options).then(data => {
const form = data.body.form;

@@ -207,3 +209,3 @@ const expectedForm = Object.assign({}, defaultExpectedForm, {

expect(form).toEqual(expectedForm);
expect(data.url).toEqual(api.urlFor("unschedule_action"))
expect(data.url).toEqual(actionsApi.urlFor("unschedule_action"))
});

@@ -216,3 +218,3 @@

expect.hasAssertions();
return api.unschedule({}).catch(err => {
return actionsApi.unschedule({}).catch(err => {
expect(err).toEqual(errorMessages.TRIGGER_AND_ACTION_NAME_MISSING);

@@ -230,3 +232,3 @@ });

});
return api.unschedule(options).catch(err => {
return actionsApi.unschedule(options).catch(err => {
expect(err).toEqual(errorMessages.BOTH_TRIGGER_AND_ACTION_NAME);

@@ -240,1 +242,35 @@ });

});
describe("StorageApi", () => {
describe("query", () => {
it("sends an appropriate api request for a query", () => {
expect.hasAssertions();
const query = "{ foo { bar } }";
return storageApi.query({ query: query }).then(data => {
const form = data.body.form;
const expectedForm = {
query: query,
operationName: undefined,
variables: undefined,
token: ellipsis.token
};
expect(form).toEqual(expectedForm);
expect(data.url).toEqual(storageApi.url())
});
});
it("complains if no query", () => {
expect.hasAssertions();
storageApi.query({}).catch(err => {
expect(err).toEqual(errorMessages.GRAPHQL_QUERY_MISSING);
});
});
});
});

@@ -9,3 +9,4 @@ module.exports = {

UNSCHEDULE_ACTION_MISSING: "You need to pass an `action` argument for the thing you want to unschedule",
RECURRENCE_MISSING: "You need to pass a `recurrence` argument to specify when you want to schedule the action to recur, e.g. \"every weekday at 9am\""
RECURRENCE_MISSING: "You need to pass a `recurrence` argument to specify when you want to schedule the action to recur, e.g. \"every weekday at 9am\"",
GRAPHQL_QUERY_MISSING: "You need to pass a `query` argument containing the GraphQL query you want to execute"
};
const request = require('request');
const errorMessages = require('./error-messages');
class Api {
class AbstractApi {

@@ -36,2 +36,16 @@ constructor(ellipsis) {

}
class Api extends AbstractApi {
constructor(ellipsis) {
super(ellipsis);
this.actions = new ActionsApi(ellipsis);
this.storage = new StorageApi(ellipsis);
}
}
class ActionsApi extends AbstractApi {
handleResponse(options, error, response, body) {

@@ -170,2 +184,38 @@ if (error) {

class StorageApi extends AbstractApi {
url() {
return `${this.ellipsis.apiBaseUrl}/api/graphql`;
}
checkOptionsIn(options) {
if (!options.query) {
this.handleError(options, errorMessages.GRAPHQL_QUERY_MISSING);
}
}
query(options) {
return new Promise((resolve, reject) => {
this.checkOptionsIn(options);
const formData = {
query: options.query,
operationName: options.operationName,
variables: options.variables,
token: this.token()
};
request.post({
url: this.url(),
form: formData
}, (error, response, body) => {
if (error) {
reject(error);
} else {
resolve(response, body);
}
});
});
}
}
module.exports = Api;
{
"name": "ellipsis-api",
"version": "0.0.2",
"version": "0.0.3",
"description": "Interact with Ellipsis skills & actions",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc