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

stratumn-sdk

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stratumn-sdk

Stratumn SDK for Javascript

  • 1.0.1-alpha
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Stratumn SDK for Javascript

Installation

Browser

<!-- Polyfill for browser compatibility -->
<script src="https://libs.stratumn.com/babel-polyfill.min.js"></script>
<!-- Actual Stratumn SDK -->
<script src="https://libs.stratumn.com/stratumn-sdk.min.js"></script>

If you want a specific version, include https://libs.stratumn.com/stratumn-sdk-{version}.min.js instead (for instance https://libs.stratumn.com/stratumn-sdk-0.4.1.min.js).

Node.js

$ npm install stratumn-sdk
var StratumnSDK = require('stratumn-sdk');

Quickstart

StratumnSDK.getAgent('http://localhost:3000')
  .then(function(agent) {
    console.log(agent);
    // Create a new map, you can pass arguments to init
    return agent.createMap('My conversation');
  })
  .then(function(segment) {
    // You can call a transition function like a regular function
    return segment.addMessage('Hello, World');
  })
  .then(function(segment) {
    console.log(segment.link);
    console.log(segment.meta);
  })
  .catch(function(err) {
    // Handle errors
  });

Reference

StratumnSDK#getAgent(url)

Returns a promise that resolves with an agent client.

StratumnSDK
  .getAgent('http://localhost:3000')
  .then(function(agent) {
    console.log(agent);
  })
  .catch(function(err) {
    // Handle errors
  });

StratumnSDK#fromSegment(rawSegment)

Returns a promise that resolves with the agent and segment from a given raw object.

StratumnSDK
  .fromSegment(someRawSegment)
  .then(function(res) {
    console.log(res.agent);
    console.log(res.segment);
  })
  .catch(function(err) {
    // Handle errors
  });

Agent#createMap(...args)

Returns a promise that resolves with a the first segment of a map.

StratumnSDK
  .getAgent('http://localhost:3000')
  .then(function(agent) {
    return agent.createMap('A new map');
  })
  .then(function(segment) {
    console.log(segment);
  })
  .catch(function(err) {
    // Handle errors
  });

Agent#getSegment(linkHash)

Returns a promise that resolves with an existing segment.

StratumnSDK
  .getAgent('http://localhost:3000')
  .then(function(agent) {
    return agent.getSegment('aee5427');
  })
  .then(function(segment) {
    console.log(segment);
  })
  .catch(function(err) {
    // Handle errors
  });

Agent#findSegments(opts)

Returns a promise that resolves with existing segments.

Available options are:

  • offset: offset of first returned segments
  • limit: limit number of returned segments
  • mapId: return segments with specified map ID
  • prevLinkHash: return segments with specified previous link hash
  • tags: return segments that contains all the tags (array)
StratumnSDK
  .getAgent('http://localhost:3000')
  .then(function(agent) {
    return agent.findSegments({ tags: ['tag1', 'tag2'], offset: 20, limit: 10 });
  })
  .then(function(segments) {
    console.log(segments);
  })
  .catch(function(err) {
    // Handle errors
  });

Agent#getMapIds(opts)

Returns a promise that resolves with existing map IDs.

Available options are:

  • offset: offset of first returned map ID
  • limit: limit number of returned map ID
StratumnSDK
  .getAgent('http://localhost:3000')
  .then(function(agent) {
    return agent.findSegments({ offset: 20, limit: 10 });
  })
  .then(function(mapIDs) {
    console.log(mapIDs);
  })
  .catch(function(err) {
    // Handle errors
  });

Segment#getPrev()

Returns a promise that resolves with the previous segment.

StratumnSDK
  .getAgent('http://localhost:3000')
  .then(function(agent) {
    return agent.getSegment('aee5427');
  })
  .then(function(segment) {
    return segment.getPrev();
  })
  .then(function(segment) {
    console.log(segment);
  })
  .catch(function(err) {
    // Handle errors
  });

Segment#:transitionFunction(...args)

Executes a transition function and returns a promise that resolves with a new segment.

StratumnSDK
  .getAgent('http://localhost:3000')
  .then(function(agent) {
    return agent.getSegment('aee5427');
  })
  .then(function(segment) {
    return segment.addMessage('Hello, World!');
  })
  .then(function(segment) {
    console.log(segment);
  })
  .catch(function(err) {
    // Handle errors
  });

Development

Install dependencies:

$ npm install

Build:

$ npm run build:all

Test:

$ npm test

Test coverage:

$ npm run test:cov
$ open coverage/lcov-report/index.html

Lint:

$ npm run lint

Lint and test:

$ npm run check

Bump version:

$ npm version major|minor|patch

Publish:

$ npm publish

Keywords

FAQs

Package last updated on 23 Jul 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc