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 - npm Package Compare versions

Comparing version 0.5.0 to 1.0.0

lib/findSegments.js

248

dist/stratumn-sdk.js

@@ -59,20 +59,15 @@ (function webpackUniversalModuleDefinition(root, factory) {

var _getApplication = __webpack_require__(1);
var _getAgent = __webpack_require__(1);
var _getApplication2 = _interopRequireDefault(_getApplication);
var _getAgent2 = _interopRequireDefault(_getAgent);
var _loadLink = __webpack_require__(11);
var _fromSegment = __webpack_require__(11);
var _loadLink2 = _interopRequireDefault(_loadLink);
var _fromSegment2 = _interopRequireDefault(_fromSegment);
var _config = __webpack_require__(5);
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = {
getApplication: _getApplication2.default,
loadLink: _loadLink2.default,
config: _config2.default
getAgent: _getAgent2.default,
fromSegment: _fromSegment2.default
};

@@ -89,3 +84,3 @@

});
exports.default = getApplication;
exports.default = getAgent;

@@ -96,28 +91,22 @@ var _superagent = __webpack_require__(2);

var _config = __webpack_require__(5);
var _createMap = __webpack_require__(5);
var _config2 = _interopRequireDefault(_config);
var _createMap = __webpack_require__(6);
var _createMap2 = _interopRequireDefault(_createMap);
var _getLink = __webpack_require__(8);
var _getSegment = __webpack_require__(7);
var _getLink2 = _interopRequireDefault(_getLink);
var _getSegment2 = _interopRequireDefault(_getSegment);
var _getMap = __webpack_require__(9);
var _findSegments = __webpack_require__(8);
var _getMap2 = _interopRequireDefault(_getMap);
var _findSegments2 = _interopRequireDefault(_findSegments);
var _getBranches = __webpack_require__(10);
var _getMapIds = __webpack_require__(10);
var _getBranches2 = _interopRequireDefault(_getBranches);
var _getMapIds2 = _interopRequireDefault(_getMapIds);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getApplication(appName, appLocation) {
function getAgent(url) {
return new Promise(function (resolve, reject) {
var url = appLocation || _config2.default.applicationUrl.replace('%s', appName);
return _superagent2.default.get(url).end(function (err, res) {

@@ -129,11 +118,11 @@ if (err) {

var app = res.body;
var agent = res.body;
app.url = url;
app.createMap = _createMap2.default.bind(null, app);
app.getLink = _getLink2.default.bind(null, app);
app.getMap = _getMap2.default.bind(null, app);
app.getBranches = _getBranches2.default.bind(null, app);
agent.url = url;
agent.createMap = _createMap2.default.bind(null, agent);
agent.getSegment = _getSegment2.default.bind(null, agent);
agent.findSegments = _findSegments2.default.bind(null, agent);
agent.getMapIds = _getMapIds2.default.bind(null, agent);
resolve(app);
resolve(agent);
});

@@ -1538,18 +1527,2 @@ });

/* 5 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var config = {
baseUrl: 'https://stratumn.rocks',
applicationUrl: 'https://%s.stratumn.rocks'
};
exports.default = config;
/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {

@@ -1568,13 +1541,9 @@

var _config = __webpack_require__(5);
var _segmentify = __webpack_require__(6);
var _config2 = _interopRequireDefault(_config);
var _segmentify2 = _interopRequireDefault(_segmentify);
var _linkify = __webpack_require__(7);
var _linkify2 = _interopRequireDefault(_linkify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createMap(app) {
function createMap(agent) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {

@@ -1585,3 +1554,3 @@ args[_key - 1] = arguments[_key];

return new Promise(function (resolve, reject) {
var url = _config2.default.applicationUrl.replace('%s', app.name) + '/maps';
var url = agent.url + '/segments';

@@ -1595,3 +1564,3 @@ return _superagent2.default.post(url).send(args).end(function (err, res) {

resolve((0, _linkify2.default)(app, res.body));
resolve((0, _segmentify2.default)(agent, res.body));
});

@@ -1602,3 +1571,3 @@ });

/***/ },
/* 7 */
/* 6 */
/***/ function(module, exports, __webpack_require__) {

@@ -1611,3 +1580,3 @@

});
exports.default = linkify;
exports.default = segmentify;

@@ -1618,10 +1587,6 @@ var _superagent = __webpack_require__(2);

var _config = __webpack_require__(5);
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function linkify(app, obj) {
Object.keys(app.agentInfo.functions).filter(function (key) {
function segmentify(agent, obj) {
Object.keys(agent.agentInfo.functions).filter(function (key) {
return ['init', 'catchAll'].indexOf(key) < 0;

@@ -1636,3 +1601,3 @@ }).forEach(function (key) {

return new Promise(function (resolve, reject) {
var url = _config2.default.applicationUrl.replace('%s', app.name) + '/links/' + obj.meta.linkHash + '/' + key;
var url = agent.url + '/segments/' + obj.meta.linkHash + '/' + key;
/*eslint-enable*/

@@ -1647,3 +1612,3 @@

resolve(linkify(app, res.body));
resolve(segmentify(agent, res.body));
});

@@ -1658,3 +1623,3 @@ });

if (obj.link.meta.prevLinkHash) {
return app.getLink(obj.link.meta.prevLinkHash);
return agent.getSegment(obj.link.meta.prevLinkHash);
}

@@ -1665,14 +1630,2 @@

/*eslint-disable*/
obj.getBranches = function (tags) {
/*eslint-enable*/
return app.getBranches(obj.meta.linkHash, tags);
};
/*eslint-disable*/
obj.load = function () {
/*eslint-enable*/
return app.getLink(obj.meta.linkHash);
};
return obj;

@@ -1682,3 +1635,3 @@ }

/***/ },
/* 8 */
/* 7 */
/***/ function(module, exports, __webpack_require__) {

@@ -1691,3 +1644,3 @@

});
exports.default = getLink;
exports.default = getSegment;

@@ -1698,15 +1651,11 @@ var _superagent = __webpack_require__(2);

var _config = __webpack_require__(5);
var _segmentify = __webpack_require__(6);
var _config2 = _interopRequireDefault(_config);
var _segmentify2 = _interopRequireDefault(_segmentify);
var _linkify = __webpack_require__(7);
var _linkify2 = _interopRequireDefault(_linkify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getLink(app, linkHash) {
function getSegment(agent, linkHash) {
return new Promise(function (resolve, reject) {
var url = _config2.default.applicationUrl.replace('%s', app.name) + '/links/' + linkHash;
var url = agent.url + '/segments/' + linkHash;

@@ -1719,3 +1668,3 @@ return _superagent2.default.get(url).end(function (err, res) {

resolve((0, _linkify2.default)(app, res.body));
resolve((0, _segmentify2.default)(agent, res.body));
});

@@ -1726,3 +1675,3 @@ });

/***/ },
/* 9 */
/* 8 */
/***/ function(module, exports, __webpack_require__) {

@@ -1735,3 +1684,3 @@

});
exports.default = getMap;
exports.default = findSegments;

@@ -1742,24 +1691,18 @@ var _superagent = __webpack_require__(2);

var _config = __webpack_require__(5);
var _segmentify = __webpack_require__(6);
var _config2 = _interopRequireDefault(_config);
var _segmentify2 = _interopRequireDefault(_segmentify);
var _linkify = __webpack_require__(7);
var _makeQueryString = __webpack_require__(9);
var _linkify2 = _interopRequireDefault(_linkify);
var _makeQueryString2 = _interopRequireDefault(_makeQueryString);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getMap(app, mapId) {
var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
function findSegments(agent) {
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
return new Promise(function (resolve, reject) {
var query = '';
var url = agent.url + '/segments' + (0, _makeQueryString2.default)(opts);
if (tags && tags.length) {
query = '?tags=' + tags.join('&tags=');
}
var url = _config2.default.applicationUrl.replace('%s', app.name) + '/maps/' + mapId + query;
return _superagent2.default.get(url).end(function (err, res) {

@@ -1771,4 +1714,4 @@ if (err) {

resolve(res.body.map(function (link) {
return (0, _linkify2.default)(app, link);
resolve(res.body.map(function (obj) {
return (0, _segmentify2.default)(agent, obj);
}));

@@ -1780,2 +1723,31 @@ });

/***/ },
/* 9 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = makeQueryString;
/**
* Makes a query string.
* @param {object} obj - an object of keys
* @returns {string} a query string
*/
function makeQueryString(obj) {
var parts = Object.keys(obj).reduce(function (curr, key) {
var val = Array.isArray(obj[key]) ? obj[key].join(',') : obj[key];
curr.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
return curr;
}, []);
if (parts.length) {
return '?' + parts.join('&');
}
return '';
}
/***/ },
/* 10 */

@@ -1789,3 +1761,3 @@ /***/ function(module, exports, __webpack_require__) {

});
exports.default = getBranches;
exports.default = getMapIds;

@@ -1796,24 +1768,14 @@ var _superagent = __webpack_require__(2);

var _config = __webpack_require__(5);
var _makeQueryString = __webpack_require__(9);
var _config2 = _interopRequireDefault(_config);
var _makeQueryString2 = _interopRequireDefault(_makeQueryString);
var _linkify = __webpack_require__(7);
var _linkify2 = _interopRequireDefault(_linkify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getBranches(app, linkHash) {
var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
function getMapIds(agent) {
var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
return new Promise(function (resolve, reject) {
var query = '';
var url = agent.url + '/maps?' + (0, _makeQueryString2.default)(opts);
if (tags && tags.length) {
query = '?tags=' + tags.join('&tags=');
}
var url = _config2.default.applicationUrl.replace('%s', app.name) + '/branches/' + linkHash + query;
return _superagent2.default.get(url).end(function (err, res) {

@@ -1825,5 +1787,3 @@ if (err) {

resolve(res.body.map(function (link) {
return (0, _linkify2.default)(app, link);
}));
resolve(res.body);
});

@@ -1842,32 +1802,18 @@ });

});
exports.default = loadLink;
exports.default = fromSegment;
var _superagent = __webpack_require__(2);
var _getAgent = __webpack_require__(1);
var _superagent2 = _interopRequireDefault(_superagent);
var _getAgent2 = _interopRequireDefault(_getAgent);
var _linkify = __webpack_require__(7);
var _segmentify = __webpack_require__(6);
var _linkify2 = _interopRequireDefault(_linkify);
var _segmentify2 = _interopRequireDefault(_segmentify);
var _getApplication = __webpack_require__(1);
var _getApplication2 = _interopRequireDefault(_getApplication);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function loadLink(segment) {
return (0, _getApplication2.default)(segment.meta.application, segment.meta.applicationLocation).then(function (app) {
return new Promise(function (resolve, reject) {
var url = segment.meta.linkLocation;
return _superagent2.default.get(url).end(function (err, res) {
if (err) {
reject(err);
return;
}
resolve((0, _linkify2.default)(app, res.body));
});
});
function fromSegment(obj) {
return (0, _getAgent2.default)(obj.meta.agentUrl).then(function (agent) {
var segment = (0, _segmentify2.default)(agent, obj);
return { agent: agent, segment: segment };
});

@@ -1874,0 +1820,0 @@ }

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StratumnSDK=e():t.StratumnSDK=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}var i=r(1),o=n(i),s=r(11),a=n(s),u=r(5),c=n(u);t.exports={getApplication:o["default"],loadLink:a["default"],config:c["default"]}},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){return new Promise(function(r,n){var i=e||u["default"].applicationUrl.replace("%s",t);return s["default"].get(i).end(function(t,e){if(t)return void n(t);var o=e.body;o.url=i,o.createMap=l["default"].bind(null,o),o.getLink=f["default"].bind(null,o),o.getMap=d["default"].bind(null,o),o.getBranches=m["default"].bind(null,o),r(o)})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i;var o=r(2),s=n(o),a=r(5),u=n(a),c=r(6),l=n(c),h=r(8),f=n(h),p=r(9),d=n(p),y=r(10),m=n(y)},function(t,e,r){function n(){}function i(t){var e={}.toString.call(t);switch(e){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function o(t){return t===Object(t)}function s(t){if(!o(t))return t;var e=[];for(var r in t)null!=t[r]&&a(e,r,t[r]);return e.join("&")}function a(t,e,r){return Array.isArray(r)?r.forEach(function(r){a(t,e,r)}):void t.push(encodeURIComponent(e)+"="+encodeURIComponent(r))}function u(t){for(var e,r,n={},i=t.split("&"),o=0,s=i.length;s>o;++o)r=i[o],e=r.split("="),n[decodeURIComponent(e[0])]=decodeURIComponent(e[1]);return n}function c(t){var e,r,n,i,o=t.split(/\r?\n/),s={};o.pop();for(var a=0,u=o.length;u>a;++a)r=o[a],e=r.indexOf(":"),n=r.slice(0,e).toLowerCase(),i=g(r.slice(e+1)),s[n]=i;return s}function l(t){return/[\/+]json\b/.test(t)}function h(t){return t.split(/ *; */).shift()}function f(t){return _(t.split(/ *; */),function(t,e){var r=e.split(/ *= */),n=r.shift(),i=r.shift();return n&&i&&(t[n]=i),t},{})}function p(t,e){e=e||{},this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=c(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function d(t,e){var r=this;b.call(this),this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var t=null,e=null;try{e=new p(r)}catch(n){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=n,t.rawResponse=r.xhr&&r.xhr.responseText?r.xhr.responseText:null,r.callback(t)}if(r.emit("response",e),t)return r.callback(t,e);if(e.status>=200&&e.status<300)return r.callback(t,e);var i=new Error(e.statusText||"Unsuccessful HTTP response");i.original=t,i.response=e,i.status=e.status,r.callback(i,e)})}function y(t,e){return"function"==typeof e?new d("GET",t).end(e):1==arguments.length?new d("GET",t):new d(t,e)}function m(t,e){var r=y("DELETE",t);return e&&r.end(e),r}var v,b=r(3),_=r(4);v="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,y.getXHR=function(){if(!(!v.XMLHttpRequest||v.location&&"file:"==v.location.protocol&&v.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}return!1};var g="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};y.serializeObject=s,y.parseString=u,y.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":s,"application/json":JSON.stringify},y.parse={"application/x-www-form-urlencoded":u,"application/json":JSON.parse},p.prototype.get=function(t){return this.header[t.toLowerCase()]},p.prototype.setHeaderProperties=function(t){var e=this.header["content-type"]||"";this.type=h(e);var r=f(e);for(var n in r)this[n]=r[n]},p.prototype.parseBody=function(t){var e=y.parse[this.type];return e&&t&&(t.length||t instanceof Object)?e(t):null},p.prototype.setStatusProperties=function(t){1223===t&&(t=204);var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.clientError=4==e,this.serverError=5==e,this.error=4==e||5==e?this.toError():!1,this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.notFound=404==t,this.forbidden=403==t},p.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,n="cannot "+e+" "+r+" ("+this.status+")",i=new Error(n);return i.status=this.status,i.method=e,i.url=r,i},y.Response=p,b(d.prototype),d.prototype.use=function(t){return t(this),this},d.prototype.timeout=function(t){return this._timeout=t,this},d.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},d.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},d.prototype.set=function(t,e){if(o(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},d.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},d.prototype.getHeader=function(t){return this._header[t.toLowerCase()]},d.prototype.type=function(t){return this.set("Content-Type",y.types[t]||t),this},d.prototype.parse=function(t){return this._parser=t,this},d.prototype.accept=function(t){return this.set("Accept",y.types[t]||t),this},d.prototype.auth=function(t,e){var r=btoa(t+":"+e);return this.set("Authorization","Basic "+r),this},d.prototype.query=function(t){return"string"!=typeof t&&(t=s(t)),t&&this._query.push(t),this},d.prototype.field=function(t,e){return this._formData||(this._formData=new v.FormData),this._formData.append(t,e),this},d.prototype.attach=function(t,e,r){return this._formData||(this._formData=new v.FormData),this._formData.append(t,e,r||e.name),this},d.prototype.send=function(t){var e=o(t),r=this.getHeader("Content-Type");if(e&&o(this._data))for(var n in t)this._data[n]=t[n];else"string"==typeof t?(r||this.type("form"),r=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==r?this._data=this._data?this._data+"&"+t:t:this._data=(this._data||"")+t):this._data=t;return!e||i(t)?this:(r||this.type("json"),this)},d.prototype.callback=function(t,e){var r=this._callback;this.clearTimeout(),r(t,e)},d.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},d.prototype.timeoutError=function(){var t=this._timeout,e=new Error("timeout of "+t+"ms exceeded");e.timeout=t,this.callback(e)},d.prototype.withCredentials=function(){return this._withCredentials=!0,this},d.prototype.end=function(t){var e=this,r=this.xhr=y.getXHR(),o=this._query.join("&"),s=this._timeout,a=this._formData||this._data;this._callback=t||n,r.onreadystatechange=function(){if(4==r.readyState){var t;try{t=r.status}catch(n){t=0}if(0==t){if(e.timedout)return e.timeoutError();if(e.aborted)return;return e.crossDomainError()}e.emit("end")}};var u=function(t){t.total>0&&(t.percent=t.loaded/t.total*100),t.direction="download",e.emit("progress",t)};this.hasListeners("progress")&&(r.onprogress=u);try{r.upload&&this.hasListeners("progress")&&(r.upload.onprogress=u)}catch(c){}if(s&&!this._timer&&(this._timer=setTimeout(function(){e.timedout=!0,e.abort()},s)),o&&(o=y.serializeObject(o),this.url+=~this.url.indexOf("?")?"&"+o:"?"+o),r.open(this.method,this.url,!0),this._withCredentials&&(r.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof a&&!i(a)){var h=this.getHeader("Content-Type"),f=this._parser||y.serialize[h?h.split(";")[0]:""];!f&&l(h)&&(f=y.serialize["application/json"]),f&&(a=f(a))}for(var p in this.header)null!=this.header[p]&&r.setRequestHeader(p,this.header[p]);return this.emit("request",this),r.send("undefined"!=typeof a?a:null),this},d.prototype.then=function(t,e){return this.end(function(r,n){r?e(r):t(n)})},y.Request=d,y.get=function(t,e,r){var n=y("GET",t);return"function"==typeof e&&(r=e,e=null),e&&n.query(e),r&&n.end(r),n},y.head=function(t,e,r){var n=y("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},y.del=m,y["delete"]=m,y.patch=function(t,e,r){var n=y("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},y.post=function(t,e,r){var n=y("POST",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},y.put=function(t,e,r){var n=y("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},t.exports=y},function(t,e){function r(t){return t?n(t):void 0}function n(t){for(var e in r.prototype)t[e]=r.prototype[e];return t}t.exports=r,r.prototype.on=r.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},r.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=r.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n,i=0;i<r.length;i++)if(n=r[i],n===e||n.fn===e){r.splice(i,1);break}return this},r.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),r=this._callbacks["$"+t];if(r){r=r.slice(0);for(var n=0,i=r.length;i>n;++n)r[n].apply(this,e)}return this},r.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},r.prototype.hasListeners=function(t){return!!this.listeners(t).length}},function(t,e){t.exports=function(t,e,r){for(var n=0,i=t.length,o=3==arguments.length?r:t[n++];i>n;)o=e.call(null,o,t[n],++n,t);return o}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r={baseUrl:"https://stratumn.rocks",applicationUrl:"https://%s.stratumn.rocks"};e["default"]=r},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];return new Promise(function(e,n){var i=u["default"].applicationUrl.replace("%s",t.name)+"/maps";return s["default"].post(i).send(r).end(function(r,i){var o=r||i.body.meta&&i.body.meta.errorMessage;return o?void n(o):void e((0,l["default"])(t,i.body))})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i;var o=r(2),s=n(o),a=r(5),u=n(a),c=r(7),l=n(c)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){return Object.keys(t.agentInfo.functions).filter(function(t){return["init","catchAll"].indexOf(t)<0}).forEach(function(r){e[r]=function(){for(var n=arguments.length,o=Array(n),a=0;n>a;a++)o[a]=arguments[a];return new Promise(function(n,a){var c=u["default"].applicationUrl.replace("%s",t.name)+"/links/"+e.meta.linkHash+"/"+r;return s["default"].post(c).send(o).end(function(e,r){var o=e||r.body.meta&&r.body.meta.errorMessage;return o?void a(o):void n(i(t,r.body))})})}}),e.getPrev=function(){return e.link.meta.prevLinkHash?t.getLink(e.link.meta.prevLinkHash):Promise.resolve(null)},e.getBranches=function(r){return t.getBranches(e.meta.linkHash,r)},e.load=function(){return t.getLink(e.meta.linkHash)},e}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i;var o=r(2),s=n(o),a=r(5),u=n(a)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){return new Promise(function(r,n){var i=u["default"].applicationUrl.replace("%s",t.name)+"/links/"+e;return s["default"].get(i).end(function(e,i){return e?void n(e):void r((0,l["default"])(t,i.body))})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i;var o=r(2),s=n(o),a=r(5),u=n(a),c=r(7),l=n(c)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){var r=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return new Promise(function(n,i){var o="";r&&r.length&&(o="?tags="+r.join("&tags="));var a=u["default"].applicationUrl.replace("%s",t.name)+"/maps/"+e+o;return s["default"].get(a).end(function(e,r){return e?void i(e):void n(r.body.map(function(e){return(0,l["default"])(t,e)}))})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i;var o=r(2),s=n(o),a=r(5),u=n(a),c=r(7),l=n(c)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t,e){var r=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return new Promise(function(n,i){var o="";r&&r.length&&(o="?tags="+r.join("&tags="));var a=u["default"].applicationUrl.replace("%s",t.name)+"/branches/"+e+o;return s["default"].get(a).end(function(e,r){return e?void i(e):void n(r.body.map(function(e){return(0,l["default"])(t,e)}))})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i;var o=r(2),s=n(o),a=r(5),u=n(a),c=r(7),l=n(c)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function i(t){return(0,l["default"])(t.meta.application,t.meta.applicationLocation).then(function(e){return new Promise(function(r,n){var i=t.meta.linkLocation;return s["default"].get(i).end(function(t,i){return t?void n(t):void r((0,u["default"])(e,i.body))})})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i;var o=r(2),s=n(o),a=r(7),u=n(a),c=r(1),l=n(c)}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StratumnSDK=e():t.StratumnSDK=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}var o=r(1),i=n(o),s=r(11),u=n(s);t.exports={getAgent:i["default"],fromSegment:u["default"]}},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){return new Promise(function(e,r){return s["default"].get(t).end(function(n,o){if(n)return void r(n);var i=o.body;i.url=t,i.createMap=a["default"].bind(null,i),i.getSegment=l["default"].bind(null,i),i.findSegments=f["default"].bind(null,i),i.getMapIds=p["default"].bind(null,i),e(i)})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=r(2),s=n(i),u=r(5),a=n(u),c=r(7),l=n(c),h=r(8),f=n(h),d=r(10),p=n(d)},function(t,e,r){function n(){}function o(t){var e={}.toString.call(t);switch(e){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function i(t){return t===Object(t)}function s(t){if(!i(t))return t;var e=[];for(var r in t)null!=t[r]&&u(e,r,t[r]);return e.join("&")}function u(t,e,r){return Array.isArray(r)?r.forEach(function(r){u(t,e,r)}):void t.push(encodeURIComponent(e)+"="+encodeURIComponent(r))}function a(t){for(var e,r,n={},o=t.split("&"),i=0,s=o.length;s>i;++i)r=o[i],e=r.split("="),n[decodeURIComponent(e[0])]=decodeURIComponent(e[1]);return n}function c(t){var e,r,n,o,i=t.split(/\r?\n/),s={};i.pop();for(var u=0,a=i.length;a>u;++u)r=i[u],e=r.indexOf(":"),n=r.slice(0,e).toLowerCase(),o=g(r.slice(e+1)),s[n]=o;return s}function l(t){return/[\/+]json\b/.test(t)}function h(t){return t.split(/ *; */).shift()}function f(t){return b(t.split(/ *; */),function(t,e){var r=e.split(/ *= */),n=r.shift(),o=r.shift();return n&&o&&(t[n]=o),t},{})}function d(t,e){e=e||{},this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||"undefined"==typeof this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText,this.setStatusProperties(this.xhr.status),this.header=this.headers=c(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body="HEAD"!=this.req.method?this.parseBody(this.text?this.text:this.xhr.response):null}function p(t,e){var r=this;_.call(this),this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var t=null,e=null;try{e=new d(r)}catch(n){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=n,t.rawResponse=r.xhr&&r.xhr.responseText?r.xhr.responseText:null,r.callback(t)}if(r.emit("response",e),t)return r.callback(t,e);if(e.status>=200&&e.status<300)return r.callback(t,e);var o=new Error(e.statusText||"Unsuccessful HTTP response");o.original=t,o.response=e,o.status=e.status,r.callback(o,e)})}function y(t,e){return"function"==typeof e?new p("GET",t).end(e):1==arguments.length?new p("GET",t):new p(t,e)}function m(t,e){var r=y("DELETE",t);return e&&r.end(e),r}var v,_=r(3),b=r(4);v="undefined"!=typeof window?window:"undefined"!=typeof self?self:this,y.getXHR=function(){if(!(!v.XMLHttpRequest||v.location&&"file:"==v.location.protocol&&v.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}return!1};var g="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};y.serializeObject=s,y.parseString=a,y.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":s,"application/json":JSON.stringify},y.parse={"application/x-www-form-urlencoded":a,"application/json":JSON.parse},d.prototype.get=function(t){return this.header[t.toLowerCase()]},d.prototype.setHeaderProperties=function(t){var e=this.header["content-type"]||"";this.type=h(e);var r=f(e);for(var n in r)this[n]=r[n]},d.prototype.parseBody=function(t){var e=y.parse[this.type];return e&&t&&(t.length||t instanceof Object)?e(t):null},d.prototype.setStatusProperties=function(t){1223===t&&(t=204);var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.clientError=4==e,this.serverError=5==e,this.error=4==e||5==e?this.toError():!1,this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.notFound=404==t,this.forbidden=403==t},d.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,n="cannot "+e+" "+r+" ("+this.status+")",o=new Error(n);return o.status=this.status,o.method=e,o.url=r,o},y.Response=d,_(p.prototype),p.prototype.use=function(t){return t(this),this},p.prototype.timeout=function(t){return this._timeout=t,this},p.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},p.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},p.prototype.set=function(t,e){if(i(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},p.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},p.prototype.getHeader=function(t){return this._header[t.toLowerCase()]},p.prototype.type=function(t){return this.set("Content-Type",y.types[t]||t),this},p.prototype.parse=function(t){return this._parser=t,this},p.prototype.accept=function(t){return this.set("Accept",y.types[t]||t),this},p.prototype.auth=function(t,e){var r=btoa(t+":"+e);return this.set("Authorization","Basic "+r),this},p.prototype.query=function(t){return"string"!=typeof t&&(t=s(t)),t&&this._query.push(t),this},p.prototype.field=function(t,e){return this._formData||(this._formData=new v.FormData),this._formData.append(t,e),this},p.prototype.attach=function(t,e,r){return this._formData||(this._formData=new v.FormData),this._formData.append(t,e,r||e.name),this},p.prototype.send=function(t){var e=i(t),r=this.getHeader("Content-Type");if(e&&i(this._data))for(var n in t)this._data[n]=t[n];else"string"==typeof t?(r||this.type("form"),r=this.getHeader("Content-Type"),"application/x-www-form-urlencoded"==r?this._data=this._data?this._data+"&"+t:t:this._data=(this._data||"")+t):this._data=t;return!e||o(t)?this:(r||this.type("json"),this)},p.prototype.callback=function(t,e){var r=this._callback;this.clearTimeout(),r(t,e)},p.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},p.prototype.timeoutError=function(){var t=this._timeout,e=new Error("timeout of "+t+"ms exceeded");e.timeout=t,this.callback(e)},p.prototype.withCredentials=function(){return this._withCredentials=!0,this},p.prototype.end=function(t){var e=this,r=this.xhr=y.getXHR(),i=this._query.join("&"),s=this._timeout,u=this._formData||this._data;this._callback=t||n,r.onreadystatechange=function(){if(4==r.readyState){var t;try{t=r.status}catch(n){t=0}if(0==t){if(e.timedout)return e.timeoutError();if(e.aborted)return;return e.crossDomainError()}e.emit("end")}};var a=function(t){t.total>0&&(t.percent=t.loaded/t.total*100),t.direction="download",e.emit("progress",t)};this.hasListeners("progress")&&(r.onprogress=a);try{r.upload&&this.hasListeners("progress")&&(r.upload.onprogress=a)}catch(c){}if(s&&!this._timer&&(this._timer=setTimeout(function(){e.timedout=!0,e.abort()},s)),i&&(i=y.serializeObject(i),this.url+=~this.url.indexOf("?")?"&"+i:"?"+i),r.open(this.method,this.url,!0),this._withCredentials&&(r.withCredentials=!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof u&&!o(u)){var h=this.getHeader("Content-Type"),f=this._parser||y.serialize[h?h.split(";")[0]:""];!f&&l(h)&&(f=y.serialize["application/json"]),f&&(u=f(u))}for(var d in this.header)null!=this.header[d]&&r.setRequestHeader(d,this.header[d]);return this.emit("request",this),r.send("undefined"!=typeof u?u:null),this},p.prototype.then=function(t,e){return this.end(function(r,n){r?e(r):t(n)})},y.Request=p,y.get=function(t,e,r){var n=y("GET",t);return"function"==typeof e&&(r=e,e=null),e&&n.query(e),r&&n.end(r),n},y.head=function(t,e,r){var n=y("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},y.del=m,y["delete"]=m,y.patch=function(t,e,r){var n=y("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},y.post=function(t,e,r){var n=y("POST",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},y.put=function(t,e,r){var n=y("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},t.exports=y},function(t,e){function r(t){return t?n(t):void 0}function n(t){for(var e in r.prototype)t[e]=r.prototype[e];return t}t.exports=r,r.prototype.on=r.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},r.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},r.prototype.off=r.prototype.removeListener=r.prototype.removeAllListeners=r.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var n,o=0;o<r.length;o++)if(n=r[o],n===e||n.fn===e){r.splice(o,1);break}return this},r.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),r=this._callbacks["$"+t];if(r){r=r.slice(0);for(var n=0,o=r.length;o>n;++n)r[n].apply(this,e)}return this},r.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},r.prototype.hasListeners=function(t){return!!this.listeners(t).length}},function(t,e){t.exports=function(t,e,r){for(var n=0,o=t.length,i=3==arguments.length?r:t[n++];o>n;)i=e.call(null,i,t[n],++n,t);return i}},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){for(var e=arguments.length,r=Array(e>1?e-1:0),n=1;e>n;n++)r[n-1]=arguments[n];return new Promise(function(e,n){var o=t.url+"/segments";return s["default"].post(o).send(r).end(function(r,o){var i=r||o.body.meta&&o.body.meta.errorMessage;return i?void n(i):void e((0,a["default"])(t,o.body))})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=r(2),s=n(i),u=r(6),a=n(u)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){return Object.keys(t.agentInfo.functions).filter(function(t){return["init","catchAll"].indexOf(t)<0}).forEach(function(r){e[r]=function(){for(var n=arguments.length,i=Array(n),u=0;n>u;u++)i[u]=arguments[u];return new Promise(function(n,u){var a=t.url+"/segments/"+e.meta.linkHash+"/"+r;return s["default"].post(a).send(i).end(function(e,r){var i=e||r.body.meta&&r.body.meta.errorMessage;return i?void u(i):void n(o(t,r.body))})})}}),e.getPrev=function(){return e.link.meta.prevLinkHash?t.getSegment(e.link.meta.prevLinkHash):Promise.resolve(null)},e}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=r(2),s=n(i)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){return new Promise(function(r,n){var o=t.url+"/segments/"+e;return s["default"].get(o).end(function(e,o){return e?void n(e):void r((0,a["default"])(t,o.body))})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=r(2),s=n(i),u=r(6),a=n(u)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return new Promise(function(r,n){var o=t.url+"/segments"+(0,l["default"])(e);return s["default"].get(o).end(function(e,o){return e?void n(e):void r(o.body.map(function(e){return(0,a["default"])(t,e)}))})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=r(2),s=n(i),u=r(6),a=n(u),c=r(9),l=n(c)},function(t,e){"use strict";function r(t){var e=Object.keys(t).reduce(function(e,r){var n=Array.isArray(t[r])?t[r].join(","):t[r];return e.push(encodeURIComponent(r)+"="+encodeURIComponent(n)),e},[]);return e.length?"?"+e.join("&"):""}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return new Promise(function(r,n){var o=t.url+"/maps?"+(0,a["default"])(e);return s["default"].get(o).end(function(t,e){return t?void n(t):void r(e.body)})})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=r(2),s=n(i),u=r(9),a=n(u)},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t){return(0,s["default"])(t.meta.agentUrl).then(function(e){var r=(0,a["default"])(e,t);return{agent:e,segment:r}})}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=o;var i=r(1),s=n(i),u=r(6),a=n(u)}])});

@@ -12,13 +12,9 @@ 'use strict';

var _config = require('./config');
var _segmentify = require('./segmentify');
var _config2 = _interopRequireDefault(_config);
var _segmentify2 = _interopRequireDefault(_segmentify);
var _linkify = require('./linkify');
var _linkify2 = _interopRequireDefault(_linkify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createMap(app) {
function createMap(agent) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {

@@ -29,3 +25,3 @@ args[_key - 1] = arguments[_key];

return new Promise(function (resolve, reject) {
var url = _config2.default.applicationUrl.replace('%s', app.name) + '/maps';
var url = agent.url + '/segments';

@@ -39,5 +35,5 @@ return _superagent2.default.post(url).send(args).end(function (err, res) {

resolve((0, _linkify2.default)(app, res.body));
resolve((0, _segmentify2.default)(agent, res.body));
});
});
}
'use strict';
var _getApplication = require('./getApplication');
var _getAgent = require('./getAgent');
var _getApplication2 = _interopRequireDefault(_getApplication);
var _getAgent2 = _interopRequireDefault(_getAgent);
var _loadLink = require('./loadLink');
var _fromSegment = require('./fromSegment');
var _loadLink2 = _interopRequireDefault(_loadLink);
var _fromSegment2 = _interopRequireDefault(_fromSegment);
var _config = require('./config');
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = {
getApplication: _getApplication2.default,
loadLink: _loadLink2.default,
config: _config2.default
getAgent: _getAgent2.default,
fromSegment: _fromSegment2.default
};
{
"name": "stratumn-sdk",
"version": "0.5.0",
"version": "1.0.0",
"description": "Stratumn SDK for Javascript",
"main": "lib/index.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --recursive --require babel-polyfill --require should 2> /dev/null",
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive --require should --require should 2> /dev/null",
"test": "mocha --compilers js:babel-core/register --recursive --require babel-polyfill --require should",
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive --require should --require should",
"lint": "eslint src test",

@@ -10,0 +10,0 @@ "check": "npm run lint && npm run test",

@@ -29,15 +29,15 @@ # Stratumn SDK for Javascript

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

@@ -51,11 +51,11 @@ .catch(function(err) {

### StratumnSDK#getApplication(appName)
### StratumnSDK#getAgent(url)
Returns a promise that resolves with an application.
Returns a promise that resolves with an agent client.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
console.log(app.id);
.getAgent('http://localhost:3000')
.then(function(agent) {
console.log(agent);
})

@@ -67,14 +67,12 @@ .catch(function(err) {

### Application#createMap(...args)
### StratumnSDK#fromSegment(rawSegment)
Returns a promise that resolves with a new map.
Returns a promise that resolves with the agent and segment from a given raw object.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.createMap('A new map');
})
.fromSegment(someRawSegment)
.then(function(res) {
console.log(res);
console.log(res.agent);
console.log(res.segment);
})

@@ -86,14 +84,14 @@ .catch(function(err) {

### Application#getLink(hash)
### Agent#createMap(...args)
Returns a promise that resolves with an existing link.
Returns a promise that resolves with a the first segment of a map.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.getLink('aee5427');
.getAgent('http://localhost:3000')
.then(function(agent) {
return agent.createMap('A new map');
})
.then(function(res) {
console.log(res);
.then(function(segment) {
console.log(segment);
})

@@ -105,15 +103,14 @@ .catch(function(err) {

### Application#getMap(mapId, tags)
### Agent#getSegment(linkHash)
Returns a promise that resolves with the meta data of the links in a map,
optionally filters by tags.
Returns a promise that resolves with an existing segment.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.getMap('56ef33', ['tag1', 'tag2']);
.getAgent('http://localhost:3000')
.then(function(agent) {
return agent.getSegment('aee5427');
})
.then(function(res) {
console.log(res);
.then(function(segment) {
console.log(segment);
})

@@ -125,15 +122,22 @@ .catch(function(err) {

### Application#getBranches(linkHash, tags)
### Agent#findSegments(opts)
Returns a promise that resolves with the meta data of the links whose previous hashes
are the given hash, optionally filters by tags.
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)
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.getBranches('abcdef', ['tag1', 'tag2']);
.getAgent('http://localhost:3000')
.then(function(agent) {
return agent.findSegments({ tags: ['tag1', 'tag2'], offset: 20, limit: 10 });
})
.then(function(res) {
console.log(res);
.then(function(segments) {
console.log(segments);
})

@@ -145,40 +149,20 @@ .catch(function(err) {

### Link#getPrev()
### Agent#getMapIds(opts)
Returns a promise that resolves with the previous link of a link.
Returns a promise that resolves with existing map IDs.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.getLink('aee5427');
})
.then(function(res) {
return res.getPrev();
})
.then(function(res) {
console.log(res);
})
.catch(function(err) {
// Handle errors
});
```
Available options are:
### Link#load()
- `offset`: offset of first returned map ID
- `limit`: limit number of returned map ID
Returns a promise that resolves with the full link.
Can be useful when you only have the meta data of links.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.getBranches('aee5427');
.getAgent('http://localhost:3000')
.then(function(agent) {
return agent.findSegments({ offset: 20, limit: 10 });
})
.then(function(res) {
return Promise.all(res.map(function(link) { return link.load(); }));
.then(function(mapIDs) {
console.log(mapIDs);
})
.then(function(res) {
console.log(res);
})
.catch(function(err) {

@@ -189,18 +173,17 @@ // Handle errors

### Link#getBranches(tags)
### Segment#getPrev()
Returns a promise that resolves with the meta data of the links whose previous hashes
are the hash of the link, optionally filters by tags.
Returns a promise that resolves with the previous segment.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.getLink('aee5427');
.getAgent('http://localhost:3000')
.then(function(agent) {
return agent.getSegment('aee5427');
})
.then(function(res) {
return res.getBranches(['tag1']);
.then(function(segment) {
return segment.getPrev();
})
.then(function(res) {
console.log(res);
.then(function(segment) {
console.log(segment);
})

@@ -212,17 +195,17 @@ .catch(function(err) {

### Link#:transitionFunction(...args)
### Segment#:transitionFunction(...args)
Executes a transition function and returns a promise that resolves with a new link.
Executes a transition function and returns a promise that resolves with a new segment.
```javascript
StratumnSDK
.getApplication('quickstart')
.then(function(app) {
return app.getLink('aee5427');
.getAgent('http://localhost:3000')
.then(function(agent) {
return agent.getSegment('aee5427');
})
.then(function(res) {
return res.addMessage('Hello, World!');
.then(function(segment) {
return segment.addMessage('Hello, World!');
})
.then(function(res) {
console.log(res);
.then(function(segment) {
console.log(segment);
})

@@ -229,0 +212,0 @@ .catch(function(err) {

import request from 'superagent';
import config from './config';
import linkify from './linkify';
import segmentify from './segmentify';
export default function createMap(app, ...args) {
export default function createMap(agent, ...args) {
return new Promise((resolve, reject) => {
const url = `${config.applicationUrl.replace('%s', app.name)}/maps`;
const url = `${agent.url}/segments`;

@@ -19,5 +18,5 @@ return request

resolve(linkify(app, res.body));
resolve(segmentify(agent, res.body));
});
});
}

@@ -1,9 +0,7 @@

import getApplication from './getApplication';
import loadLink from './loadLink';
import config from './config';
import getAgent from './getAgent';
import fromSegment from './fromSegment';
module.exports = {
getApplication,
loadLink,
config
getAgent,
fromSegment
};

Sorry, the diff of this file is not supported yet

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