New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cloudapi-gql

Package Overview
Dependencies
Maintainers
5
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloudapi-gql - npm Package Compare versions

Comparing version 7.1.4 to 7.2.0

48

lib/formatters.js

@@ -14,9 +14,9 @@ 'use strict';

NIC: {
network: ({ network }, args, request) => {
return Handlers.network(request.plugins.cloudapi.fetch, { id: network });
network: function ({ network }, args, request) {
return Handlers.network(this.fetch, { id: network });
}
},
User: {
keys: (root, args, request) => {
return Handlers.keys(request.plugins.cloudapi.fetch, args);
keys: function (root, args, request) {
return Handlers.keys(this.fetch, args);
}

@@ -29,4 +29,4 @@ },

image: (root, args, request) => {
return Handlers.image(request.plugins.cloudapi.fetch, { id: root.image, brand: root.brand });
image: function (root, args, request) {
return Handlers.image(this.fetch, { id: root.image, brand: root.brand });
},

@@ -37,17 +37,17 @@

tags: (root, { name }, request) => {
tags: function (root, { name }, request) {
const { id: machine } = root;
return Handlers.tags(request.plugins.cloudapi.fetch, { machine, name });
return Handlers.tags(this.fetch, { machine, name });
},
metadata: (root, { name }, request) => {
metadata: function (root, { name }, request) {
const { id: machine } = root;
return Handlers.metadata(request.plugins.cloudapi.fetch, { machine, name });
return Handlers.metadata(this.fetch, { machine, name });
},
networks: async (root, args, request) => {
networks: async function (root, args, request) {
const networks = [];
for (const id of root.networks) {
const network = await Handlers.network(request.plugins.cloudapi.fetch, { id });
const network = await Handlers.network(this.fetch, { id });
networks.push(network);

@@ -60,20 +60,20 @@ }

// eslint-disable-next-line camelcase
package: (root, args, request) => {
return Handlers.package(request.plugins.cloudapi.fetch, { name: root.package });
package: function (root, args, request) {
return Handlers.package(this.fetch, { name: root.package });
},
snapshots: (root, { name }, request) => {
snapshots: function (root, { name }, request) {
const { id: machine } = root;
return Handlers.snapshots(request.plugins.cloudapi.fetch, { machine, name });
return Handlers.snapshots(this.fetch, { machine, name });
},
// eslint-disable-next-line camelcase
firewall_rules: (root, { id }, request) => {
firewall_rules: function (root, { id }, request) {
const { id: machine } = root;
return Handlers.firewall_rules(request.plugins.cloudapi.fetch, { machine, id });
return Handlers.firewall_rules(this.fetch, { machine, id });
},
actions: (root, args, request) => {
actions: function (root, args, request) {
const { id: machine } = root;
return Handlers.actions(request.plugins.cloudapi.fetch, { machine });
return Handlers.actions(this.fetch, { machine });
}

@@ -100,4 +100,4 @@ },

FirewallRule: {
machines: ({ id }, args, request) => {
return request.plugins.cloudapi.fetch(`/fwrules/${id}/machines`);
machines: function ({ id }, args, request) {
return this.fetch(`/fwrules/${id}/machines`);
},

@@ -152,3 +152,3 @@ rule_str: ({ rule }) => { return rule; },

Network: {
machines: async ({ id, fabric }, args, request) => {
machines: async function ({ id, fabric }, args, request) {
if (!fabric) {

@@ -158,3 +158,3 @@ return [];

const machines = await request.plugins.cloudapi.fetch('/machines');
const machines = await this.fetch('/machines');

@@ -161,0 +161,0 @@ return ForceArray(machines).filter(({ networks }) => {

@@ -9,3 +9,3 @@ 'use strict';

const Package = require('../package.json');
const CloudApi = require('./cloudapi');
const CloudApi = require('webconsole-cloudapi-client');
const Formatters = require('./formatters');

@@ -17,2 +17,24 @@ const Routes = require('./routes');

const setupCloudApi = ({ keyId, key, apiBaseUrl }) => {
return ({ auth, log }) => {
return new CloudApi({
token: auth.credentials && auth.credentials.token,
url: apiBaseUrl,
keyId,
key,
log
});
};
};
const preResolve = (cloudapi) => {
return (root, args, request) => {
if (request.route.settings.auth === false) {
return;
}
return cloudapi({ auth: request.auth, log: request.log.bind(request) });
};
};
const postAuth = (cloudapi) => {
return (request, h) => {

@@ -23,9 +45,3 @@ if (request.route.settings.auth === false) {

request.plugins.cloudapi = new CloudApi({
token: request.auth && request.auth.credentials && request.auth.credentials.token,
url: apiBaseUrl,
keyId,
key,
log: request.log.bind(request)
});
request.plugins.cloudapi = cloudapi({ auth: request.auth, log: request.log.bind(request) });

@@ -50,7 +66,11 @@ return h.continue;

const key = Fs.readFileSync(options.keyPath);
options.dcName = options.dcName || Url.parse(options.apiBaseUrl).host.split('.')[0];
const cloudapi = setupCloudApi({ key, ...options });
const schema = Graphi.makeExecutableSchema({
schema: Schema.toString(),
resolvers: Formatters
resolvers: Formatters,
preResolve: preResolve(cloudapi)
});

@@ -70,4 +90,3 @@

const key = Fs.readFileSync(options.keyPath);
server.ext('onPostAuth', setupCloudApi({ key, ...options }));
server.ext({ type: 'onPostAuth', method: postAuth(cloudapi), options: { sandbox: 'plugin' } });
};

@@ -74,0 +93,0 @@

{
"name": "cloudapi-gql",
"version": "7.1.4",
"version": "7.2.0",
"license": "MPL-2.0",

@@ -15,15 +15,16 @@ "repository": "github:joyent/cloudapi-gql",

"pretest": "npm run lint",
"test": "lab -t 76 --coverage-path lib -a code"
"test": "lab -t 79 --coverage-path lib -a code"
},
"dependencies": {
"apr-map": "3.x.x",
"boom": "7.x.x",
"bounce": "1.x.x",
"apr-map": "3.0.x",
"boom": "7.2.x",
"bounce": "1.2.x",
"webconsole-cloudapi-client": "1.0.x",
"force-array": "3.1.x",
"fwrule": "2.x.x",
"graphi": "5.x.x",
"fwrule": "2.0.x",
"graphi": "5.6.x",
"hasha": "3.0.x",
"lodash.uniq": "4.5.x",
"sentiment": "4.2.x",
"wreck": "14.x.x"
"wreck": "14.0.x"
},

@@ -30,0 +31,0 @@ "devDependencies": {

# cloudapi-gql
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0) [![Build Status](https://secure.travis-ci.org/joyent/cloudapi-gql.svg)](http://travis-ci.org/joyent/cloudapi-gql)
[![Build Status](https://secure.travis-ci.org/joyent/cloudapi-gql.svg)](http://travis-ci.org/joyent/cloudapi-gql)
hapi plugin that exposes [CloudApi](https://apidocs.joyent.com/cloudapi/) through

@@ -9,0 +7,0 @@ [GraphQL](http://graphql.org).

@@ -9,3 +9,3 @@ 'use strict';

const StandIn = require('stand-in');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -17,2 +17,3 @@

describe('cloudapi', () => {
const keyId = 'ba:co:n1';
const key = Fs.readFileSync(Path.join(__dirname, 'test.key'));

@@ -24,3 +25,3 @@ const log = () => {};

process.env.NODE_ENV = 'production';
expect(() => { return new CloudApi({ key, log }); }).to.throw(AssertionError);
expect(() => { return new CloudApi({ keyId, key, log }); }).to.throw(AssertionError);
process.env.NODE_ENV = env;

@@ -32,3 +33,3 @@ });

process.env.NODE_ENV = 'development';
expect(() => { return new CloudApi({ key, log }); }).to.not.throw();
expect(() => { return new CloudApi({ keyId, key, log }); }).to.not.throw();
process.env.NODE_ENV = env;

@@ -40,3 +41,3 @@ });

process.env.NODE_ENV = 'test';
expect(() => { return new CloudApi({ key, log }); }).to.not.throw();
expect(() => { return new CloudApi({ keyId, key, log }); }).to.not.throw();
process.env.NODE_ENV = env;

@@ -46,8 +47,8 @@ });

it('won\'t throw when there is a token', () => {
expect(() => { return new CloudApi({ key, log, token: 'blah' }); }).to.not.throw();
expect(() => { return new CloudApi({ keyId, key, log, token: 'blah' }); }).to.not.throw();
});
describe('fetch', () => {
it('caches GET responses', async () => {
const cloudapi = new CloudApi({ key, log, token: 'blah' });
it('returns GET responses', async () => {
const cloudapi = new CloudApi({ keyId, key, log, token: 'blah' });
StandIn.replaceOnce(cloudapi._wreck, 'get', (stand) => {

@@ -62,7 +63,6 @@ return {

const results1 = await cloudapi.fetch('/test');
const results2 = await cloudapi.fetch('/test');
expect(results1.foo).to.equal(results2.foo);
const results = await cloudapi.fetch('/test');
expect(results).to.equal({foo: 'bar'});
});
});
});

@@ -10,3 +10,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -29,2 +29,5 @@

apiBaseUrl: 'http://localhost'
},
routes: {
prefix: '/test'
}

@@ -47,3 +50,3 @@ };

const res = await server.inject({
url: `/graphql?${query}`
url: `/test/graphql?${query}`
});

@@ -50,0 +53,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

@@ -9,3 +9,3 @@ 'use strict';

const CloudApiGql = require('../lib/');
const CloudApi = require('../lib/cloudapi');
const CloudApi = require('webconsole-cloudapi-client');

@@ -12,0 +12,0 @@

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