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

stratumn-agent

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stratumn-agent - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

lib/create.js

36

lib/httpServer.js

@@ -20,6 +20,2 @@ 'use strict';

var _agent = require('./agent');
var _agent2 = _interopRequireDefault(_agent);
var _error = require('./error');

@@ -39,4 +35,3 @@

* Creates an HTTP server for an agent.
* @param {object} transitions - the transition function
* @param {StoreClient} storeClient - the store client
* @param {Agent} agent - the agent instance
* @param {object} [opts] - options

@@ -46,7 +41,6 @@ * @param {object} [opts.cors] - CORS options

*/
function httpServer(transitions, storeClient) {
var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
function httpServer(agent) {
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var app = (0, _express2.default)();
var instance = (0, _agent2.default)(transitions, storeClient);

@@ -66,3 +60,3 @@ app.disable('x-powered-by');

app.get('/', function (req, res, next) {
instance.getInfo(req.params.hash).then(res.json.bind(res)).catch(next);
agent.getInfo(req.params.hash).then(res.json.bind(res)).catch(next);
});

@@ -75,3 +69,3 @@

instance.createMap.apply(instance, _toConsumableArray((0, _parseArgs2.default)(req.body))).then(res.json.bind(res)).catch(next);
agent.createMap.apply(agent, _toConsumableArray((0, _parseArgs2.default)(req.body))).then(res.json.bind(res)).catch(next);
});

@@ -84,15 +78,15 @@

instance.createLink.apply(instance, [req.params.hash, req.params.action].concat(_toConsumableArray((0, _parseArgs2.default)(req.body)))).then(res.json.bind(res)).catch(next);
agent.createLink.apply(agent, [req.params.hash, req.params.action].concat(_toConsumableArray((0, _parseArgs2.default)(req.body)))).then(res.json.bind(res)).catch(next);
});
app.get('/segments/:hash', function (req, res, next) {
instance.getSegment(req.params.hash).then(res.json.bind(res)).catch(next);
agent.getSegment(req.params.hash).then(res.json.bind(res)).catch(next);
});
app.get('/segments', function (req, res, next) {
instance.findSegments(req.query).then(res.json.bind(res)).catch(next);
agent.findSegments(req.query).then(res.json.bind(res)).catch(next);
});
app.get('/maps', function (req, res, next) {
instance.getMapIds(req.query).then(res.json.bind(res)).catch(next);
agent.getMapIds(req.query).then(res.json.bind(res)).catch(next);
});

@@ -106,3 +100,3 @@

instance.createMap.apply(instance, _toConsumableArray((0, _parseArgs2.default)(req.body))).then(res.json.bind(res)).catch(next);
agent.createMap.apply(agent, _toConsumableArray((0, _parseArgs2.default)(req.body))).then(res.json.bind(res)).catch(next);
});

@@ -116,3 +110,3 @@

instance.createLink.apply(instance, [req.params.hash, req.params.action].concat(_toConsumableArray((0, _parseArgs2.default)(req.body)))).then(res.json.bind(res)).catch(next);
agent.createLink.apply(agent, [req.params.hash, req.params.action].concat(_toConsumableArray((0, _parseArgs2.default)(req.body)))).then(res.json.bind(res)).catch(next);
});

@@ -122,3 +116,3 @@

app.get('/links/:hash', function (req, res, next) {
instance.getSegment(req.params.hash).then(res.json.bind(res)).catch(next);
agent.getSegment(req.params.hash).then(res.json.bind(res)).catch(next);
});

@@ -128,3 +122,3 @@

app.get('/links', function (req, res, next) {
instance.findSegments(req.query).then(res.json.bind(res)).catch(next);
agent.findSegments(req.query).then(res.json.bind(res)).catch(next);
});

@@ -138,3 +132,3 @@

instance.findSegments(req.query).then(res.json.bind(res)).catch(next);
agent.findSegments(req.query).then(res.json.bind(res)).catch(next);
});

@@ -154,3 +148,3 @@

instance.findSegments(req.query).then(res.json.bind(res)).catch(next);
agent.findSegments(req.query).then(res.json.bind(res)).catch(next);
});

@@ -157,0 +151,0 @@

'use strict';
var _agent = require('./agent');
var _create = require('./create');
var _agent2 = _interopRequireDefault(_agent);
var _create2 = _interopRequireDefault(_create);

@@ -18,5 +18,5 @@ var _httpServer = require('./httpServer');

module.exports = {
agent: _agent2.default,
create: _create2.default,
httpServer: _httpServer2.default,
storeHttpClient: _storeHttpClient2.default
};
{
"name": "stratumn-agent",
"version": "0.2.3",
"version": "0.3.0",
"description": "",

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

@@ -9,19 +9,23 @@ # Stratumn agent for NodeJS

var express = require('express');
var agent = require('stratumn-agent');
var Agent = require('stratumn-agent');
// Load transition functions.
// Assumes your transition functions are in ./lib/transitions.
var transitions = require('./lib/transitions');
// The server is an Express server.
var app = express();
// Create an HTTP store client to save segments.
// Assumes an HTTP store server is available on env.STRATUMN_STORE_URL or http://store:5000.
var storeHttpClient = agent.storeHttpClient(process.env.STRATUMN_STORE_URL || 'http://store:5000');
var storeHttpClient = Agent.storeHttpClient(process.env.STRATUMN_STORE_URL || 'http://store:5000');
// Create an agent from the transition functions and the store client.
var agent = Agent.create(transitions, storeHttpClient);
// Creates an HTTP server for the agent with CORS enabled.
var agentHttpServer = Agent.httpServer(agent, { cors: {} });
// Create the Express server.
var app = express();
app.disable('x-powered-by');
// Create an agent HTTP server from the transition functions and the store client.
var agentHttpServer = agent.httpServer(transitions, storeHttpClient);
// Mount agent on the root path of the server.

@@ -38,4 +42,4 @@ app.use('/', agentHttpServer);

- `create` creates an agent instance.
- `storeHttpClient` creates an instance to work with stores via HTTP.
- `httpServer` creates an HTTP server for an agent.
- `storeHttpClient` creates an instance to work with stores via HTTP.
- `agent` creates an instance to work directly with an agent without a server.
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import agent from './agent';
import error from './error';

@@ -10,4 +9,3 @@ import parseArgs from './parseArgs';

* Creates an HTTP server for an agent.
* @param {object} transitions - the transition function
* @param {StoreClient} storeClient - the store client
* @param {Agent} agent - the agent instance
* @param {object} [opts] - options

@@ -17,5 +15,4 @@ * @param {object} [opts.cors] - CORS options

*/
export default function httpServer(transitions, storeClient, opts = {}) {
export default function httpServer(agent, opts = {}) {
const app = express();
const instance = agent(transitions, storeClient);

@@ -33,3 +30,3 @@ app.disable('x-powered-by');

app.get('/', (req, res, next) => {
instance
agent
.getInfo(req.params.hash)

@@ -45,3 +42,3 @@ .then(res.json.bind(res))

instance
agent
.createMap(...parseArgs(req.body))

@@ -57,3 +54,3 @@ .then(res.json.bind(res))

instance
agent
.createLink(req.params.hash, req.params.action, ...parseArgs(req.body))

@@ -65,3 +62,3 @@ .then(res.json.bind(res))

app.get('/segments/:hash', (req, res, next) => {
instance
agent
.getSegment(req.params.hash)

@@ -73,3 +70,3 @@ .then(res.json.bind(res))

app.get('/segments', (req, res, next) => {
instance
agent
.findSegments(req.query)

@@ -81,3 +78,3 @@ .then(res.json.bind(res))

app.get('/maps', (req, res, next) => {
instance
agent
.getMapIds(req.query)

@@ -94,3 +91,3 @@ .then(res.json.bind(res))

instance
agent
.createMap(...parseArgs(req.body))

@@ -107,3 +104,3 @@ .then(res.json.bind(res))

instance
agent
.createLink(req.params.hash, req.params.action, ...parseArgs(req.body))

@@ -116,3 +113,3 @@ .then(res.json.bind(res))

app.get('/links/:hash', (req, res, next) => {
instance
agent
.getSegment(req.params.hash)

@@ -125,3 +122,3 @@ .then(res.json.bind(res))

app.get('/links', (req, res, next) => {
instance
agent
.findSegments(req.query)

@@ -138,3 +135,3 @@ .then(res.json.bind(res))

instance
agent
.findSegments(req.query)

@@ -157,3 +154,3 @@ .then(res.json.bind(res))

instance
agent
.findSegments(req.query)

@@ -160,0 +157,0 @@ .then(res.json.bind(res))

@@ -1,2 +0,2 @@

import agent from './agent';
import create from './create';
import httpServer from './httpServer';

@@ -6,5 +6,5 @@ import storeHttpClient from './storeHttpClient';

module.exports = {
agent,
create,
httpServer,
storeHttpClient
};
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