mapexplorer-rails 1.0.0.pre.alpha → 1.0.0.pre.alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mapexplorer/rails/version.rb +1 -1
  3. data/vendor/assets/babel-polyfill/README.md +0 -0
  4. data/vendor/assets/babel-polyfill/bower.json +22 -0
  5. data/vendor/assets/babel-polyfill/browser-polyfill.js +5 -0
  6. data/vendor/assets/d3/LICENSE +27 -0
  7. data/vendor/assets/d3/README.md +45 -0
  8. data/vendor/assets/d3/bower.json +7 -0
  9. data/vendor/assets/d3/d3.js +16383 -0
  10. data/vendor/assets/d3/d3.min.js +8 -0
  11. data/vendor/assets/jsrender/MIT-LICENSE.txt +20 -0
  12. data/vendor/assets/jsrender/bower.json +43 -0
  13. data/vendor/assets/jsrender/index.js +8 -0
  14. data/vendor/assets/jsrender/jsrender-node.js +2298 -0
  15. data/vendor/assets/jsrender/jsrender.js +2350 -0
  16. data/vendor/assets/jsrender/jsrender.min.js +4 -0
  17. data/vendor/assets/jsrender/jsrender.min.js.map +1 -0
  18. data/vendor/assets/jsrender/tmplify/index.js +64 -0
  19. data/vendor/assets/mapexplorer-core/LICENSE +21 -0
  20. data/vendor/assets/mapexplorer-core/README.md +235 -0
  21. data/vendor/assets/mapexplorer-core/assets/stylesheets/map.scss +38 -0
  22. data/vendor/assets/mapexplorer-core/assets/stylesheets/mapexplorer-core.scss +3 -0
  23. data/vendor/assets/mapexplorer-core/assets/stylesheets/merkle-path.scss +10 -0
  24. data/vendor/assets/mapexplorer-core/assets/stylesheets/variables.scss +14 -0
  25. data/vendor/assets/mapexplorer-core/bower.json +32 -0
  26. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js +3872 -0
  27. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js.map +1 -0
  28. data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.min.js +35 -0
  29. data/vendor/assets/mapexplorer-core/karma.conf.js +117 -0
  30. data/vendor/assets/mapexplorer-core/package.json +85 -0
  31. data/vendor/assets/mapexplorer-core/rollup.bower.config.js +41 -0
  32. data/vendor/assets/mapexplorer-core/rollup.es.config.js +16 -0
  33. data/vendor/assets/mapexplorer-core/rollup.umd.config.js +25 -0
  34. data/vendor/assets/stratumn-sdk/LICENSE +21 -0
  35. data/vendor/assets/stratumn-sdk/README.md +267 -0
  36. data/vendor/assets/stratumn-sdk/bower.json +27 -0
  37. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.js +813 -0
  38. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.js.map +1 -0
  39. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.min.js +2 -0
  40. data/vendor/assets/stratumn-sdk/dist/stratumn-sdk.min.js.map +1 -0
  41. data/vendor/assets/stratumn-sdk/examples/browser/index.html +34 -0
  42. data/vendor/assets/stratumn-sdk/package.json +67 -0
  43. data/vendor/assets/stratumn-sdk/rollup.base.config.js +13 -0
  44. data/vendor/assets/stratumn-sdk/rollup.bower.config.js +18 -0
  45. data/vendor/assets/stratumn-sdk/rollup.bower.min.config.js +7 -0
  46. data/vendor/assets/stratumn-sdk/rollup.es.config.js +9 -0
  47. data/vendor/assets/stratumn-sdk/rollup.umd.config.js +10 -0
  48. metadata +46 -1
@@ -0,0 +1,813 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (factory((global.StratumnSDK = global.StratumnSDK || {})));
5
+ }(this, (function (exports) { 'use strict';
6
+
7
+ function deprecated(oldFunc, newFunc) {
8
+ if (!newFunc) {
9
+ console.warn("WARNING: " + oldFunc + " is deprecated.");
10
+ } else {
11
+ console.warn("WARNING: " + oldFunc + " is deprecated. Please use " + newFunc + " instead.");
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Makes a query string.
17
+ * @param {object} obj - an object of keys
18
+ * @returns {string} a query string
19
+ */
20
+ function makeQueryString(obj) {
21
+ var parts = Object.keys(obj).reduce(function (curr, key) {
22
+ var val = Array.isArray(obj[key]) ? obj[key].join('+') : obj[key];
23
+ curr.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
24
+ return curr;
25
+ }, []);
26
+
27
+ if (parts.length) {
28
+ return '?' + parts.join('&');
29
+ }
30
+
31
+ return '';
32
+ }
33
+
34
+ function interopDefault(ex) {
35
+ return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
36
+ }
37
+
38
+ function createCommonjsModule(fn, module) {
39
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
40
+ }
41
+
42
+ var jsonrequest = createCommonjsModule(function (module) {
43
+ 'use strict';
44
+
45
+ module.exports = {
46
+ processRequest: function(req) {
47
+ var
48
+ contentType = req.header('Content-Type'),
49
+ hasJsonContentType = contentType &&
50
+ contentType.indexOf('application/json') !== -1;
51
+
52
+ if (contentType != null && !hasJsonContentType) {
53
+ return;
54
+ }
55
+
56
+ if (req.body) {
57
+ if (!contentType) {
58
+ req.header('Content-Type', 'application/json');
59
+ }
60
+
61
+ req.body = JSON.stringify(req.body);
62
+ }
63
+ }
64
+ };
65
+ });
66
+
67
+ var jsonrequest$1 = interopDefault(jsonrequest);
68
+ var processRequest$1 = jsonrequest.processRequest;
69
+
70
+ var require$$1 = Object.freeze({
71
+ default: jsonrequest$1,
72
+ processRequest: processRequest$1
73
+ });
74
+
75
+ var jsonresponse = createCommonjsModule(function (module) {
76
+ 'use strict';
77
+
78
+ module.exports = {
79
+ processRequest: function(req) {
80
+ var accept = req.header('Accept');
81
+ if (accept == null) {
82
+ req.header('Accept', 'application/json');
83
+ }
84
+ },
85
+ processResponse: function(res) {
86
+ // Check to see if the contentype is "something/json" or
87
+ // "something/somethingelse+json"
88
+ if (res.contentType && /^.*\/(?:.*\+)?json(;|$)/i.test(res.contentType)) {
89
+ var raw = typeof res.body === 'string' ? res.body : res.text;
90
+ if (raw) {
91
+ res.body = JSON.parse(raw);
92
+ }
93
+ }
94
+ }
95
+ };
96
+ });
97
+
98
+ var jsonresponse$1 = interopDefault(jsonresponse);
99
+ var processRequest$2 = jsonresponse.processRequest;
100
+ var processResponse$1 = jsonresponse.processResponse;
101
+
102
+ var require$$0 = Object.freeze({
103
+ default: jsonresponse$1,
104
+ processRequest: processRequest$2,
105
+ processResponse: processResponse$1
106
+ });
107
+
108
+ var json = createCommonjsModule(function (module) {
109
+ 'use strict';
110
+
111
+ var jsonrequest = interopDefault(require$$1),
112
+ jsonresponse = interopDefault(require$$0);
113
+
114
+ module.exports = {
115
+ processRequest: function(req) {
116
+ jsonrequest.processRequest.call(this, req);
117
+ jsonresponse.processRequest.call(this, req);
118
+ },
119
+ processResponse: function(res) {
120
+ jsonresponse.processResponse.call(this, res);
121
+ }
122
+ };
123
+ });
124
+
125
+ var json$1 = interopDefault(json);
126
+
127
+ var cleanurl = createCommonjsModule(function (module) {
128
+ 'use strict';
129
+
130
+ module.exports = {
131
+ processRequest: function(req) {
132
+ req.url = req.url.replace(/[^%]+/g, function(s) {
133
+ return encodeURI(s);
134
+ });
135
+ }
136
+ };
137
+ });
138
+
139
+ var cleanurl$1 = interopDefault(cleanurl);
140
+ var processRequest$3 = cleanurl.processRequest;
141
+
142
+ var require$$7 = Object.freeze({
143
+ default: cleanurl$1,
144
+ processRequest: processRequest$3
145
+ });
146
+
147
+ var xhrBrowser = createCommonjsModule(function (module) {
148
+ module.exports = window.XMLHttpRequest;
149
+ });
150
+
151
+ var xhrBrowser$1 = interopDefault(xhrBrowser);
152
+
153
+
154
+ var require$$6 = Object.freeze({
155
+ default: xhrBrowser$1
156
+ });
157
+
158
+ var delay = createCommonjsModule(function (module) {
159
+ 'use strict';
160
+
161
+ // Wrap a function in a `setTimeout` call. This is used to guarantee async
162
+ // behavior, which can avoid unexpected errors.
163
+
164
+ module.exports = function(fn) {
165
+ return function() {
166
+ var
167
+ args = Array.prototype.slice.call(arguments, 0),
168
+ newFunc = function() {
169
+ return fn.apply(null, args);
170
+ };
171
+ setTimeout(newFunc, 0);
172
+ };
173
+ };
174
+ });
175
+
176
+ var delay$1 = interopDefault(delay);
177
+
178
+
179
+ var require$$5 = Object.freeze({
180
+ default: delay$1
181
+ });
182
+
183
+ var request$1 = createCommonjsModule(function (module) {
184
+ 'use strict';
185
+
186
+ function Request(optsOrUrl) {
187
+ var opts = typeof optsOrUrl === 'string' ? {url: optsOrUrl} : optsOrUrl || {};
188
+ this.method = opts.method ? opts.method.toUpperCase() : 'GET';
189
+ this.url = opts.url;
190
+ this.headers = opts.headers || {};
191
+ this.body = opts.body;
192
+ this.timeout = opts.timeout || 0;
193
+ this.errorOn404 = opts.errorOn404 != null ? opts.errorOn404 : true;
194
+ this.onload = opts.onload;
195
+ this.onerror = opts.onerror;
196
+ }
197
+
198
+ Request.prototype.abort = function() {
199
+ if (this.aborted) return;
200
+ this.aborted = true;
201
+ this.xhr.abort();
202
+ return this;
203
+ };
204
+
205
+ Request.prototype.header = function(name, value) {
206
+ var k;
207
+ for (k in this.headers) {
208
+ if (this.headers.hasOwnProperty(k)) {
209
+ if (name.toLowerCase() === k.toLowerCase()) {
210
+ if (arguments.length === 1) {
211
+ return this.headers[k];
212
+ }
213
+
214
+ delete this.headers[k];
215
+ break;
216
+ }
217
+ }
218
+ }
219
+ if (value != null) {
220
+ this.headers[name] = value;
221
+ return value;
222
+ }
223
+ };
224
+
225
+
226
+ module.exports = Request;
227
+ });
228
+
229
+ var request$2 = interopDefault(request$1);
230
+
231
+
232
+ var require$$1$1 = Object.freeze({
233
+ default: request$2
234
+ });
235
+
236
+ var index$1 = createCommonjsModule(function (module) {
237
+ module.exports = extend
238
+
239
+ function extend() {
240
+ var target = {}
241
+
242
+ for (var i = 0; i < arguments.length; i++) {
243
+ var source = arguments[i]
244
+
245
+ for (var key in source) {
246
+ if (source.hasOwnProperty(key)) {
247
+ target[key] = source[key]
248
+ }
249
+ }
250
+ }
251
+
252
+ return target
253
+ }
254
+ });
255
+
256
+ var index$2 = interopDefault(index$1);
257
+
258
+
259
+ var require$$0$2 = Object.freeze({
260
+ default: index$2
261
+ });
262
+
263
+ var extractResponseProps = createCommonjsModule(function (module) {
264
+ 'use strict';
265
+
266
+ var extend = interopDefault(require$$0$2);
267
+
268
+ module.exports = function(req) {
269
+ var xhr = req.xhr;
270
+ var props = {request: req, xhr: xhr};
271
+
272
+ // Try to create the response from the request. If the request was aborted,
273
+ // accesssing properties of the XHR may throw an error, so we wrap in a
274
+ // try/catch.
275
+ try {
276
+ var lines, i, m, headers = {};
277
+ if (xhr.getAllResponseHeaders) {
278
+ lines = xhr.getAllResponseHeaders().split('\n');
279
+ for (i = 0; i < lines.length; i++) {
280
+ if ((m = lines[i].match(/\s*([^\s]+):\s+([^\s]+)/))) {
281
+ headers[m[1]] = m[2];
282
+ }
283
+ }
284
+ }
285
+
286
+ props = extend(props, {
287
+ status: xhr.status,
288
+ contentType: xhr.contentType || (xhr.getResponseHeader && xhr.getResponseHeader('Content-Type')),
289
+ headers: headers,
290
+ text: xhr.responseText,
291
+ body: xhr.response || xhr.responseText
292
+ });
293
+ } catch (err) {}
294
+
295
+ return props;
296
+ };
297
+ });
298
+
299
+ var extractResponseProps$1 = interopDefault(extractResponseProps);
300
+
301
+
302
+ var require$$0$1 = Object.freeze({
303
+ default: extractResponseProps$1
304
+ });
305
+
306
+ var response = createCommonjsModule(function (module) {
307
+ 'use strict';
308
+
309
+ var Request = interopDefault(require$$1$1);
310
+ var extractResponseProps = interopDefault(require$$0$1);
311
+
312
+ function Response(props) {
313
+ this.request = props.request;
314
+ this.xhr = props.xhr;
315
+ this.headers = props.headers || {};
316
+ this.status = props.status || 0;
317
+ this.text = props.text;
318
+ this.body = props.body;
319
+ this.contentType = props.contentType;
320
+ this.isHttpError = props.status >= 400;
321
+ }
322
+
323
+ Response.prototype.header = Request.prototype.header;
324
+
325
+ Response.fromRequest = function(req) {
326
+ return new Response(extractResponseProps(req));
327
+ };
328
+
329
+
330
+ module.exports = Response;
331
+ });
332
+
333
+ var response$1 = interopDefault(response);
334
+
335
+
336
+ var require$$2 = Object.freeze({
337
+ default: response$1
338
+ });
339
+
340
+ var error = createCommonjsModule(function (module) {
341
+ 'use strict';
342
+
343
+ var Response = interopDefault(require$$2);
344
+ var extractResponseProps = interopDefault(require$$0$1);
345
+ var extend = interopDefault(require$$0$2);
346
+
347
+ function RequestError(message, props) {
348
+ var err = new Error(message);
349
+ err.name = 'RequestError';
350
+ this.name = err.name;
351
+ this.message = err.message;
352
+ if (err.stack) {
353
+ this.stack = err.stack;
354
+ }
355
+
356
+ this.toString = function() {
357
+ return this.message;
358
+ };
359
+
360
+ for (var k in props) {
361
+ if (props.hasOwnProperty(k)) {
362
+ this[k] = props[k];
363
+ }
364
+ }
365
+ }
366
+
367
+ RequestError.prototype = extend(Error.prototype);
368
+ RequestError.prototype.constructor = RequestError;
369
+
370
+ RequestError.create = function(message, req, props) {
371
+ var err = new RequestError(message, props);
372
+ Response.call(err, extractResponseProps(req));
373
+ return err;
374
+ };
375
+
376
+ module.exports = RequestError;
377
+ });
378
+
379
+ var error$1 = interopDefault(error);
380
+
381
+
382
+ var require$$4 = Object.freeze({
383
+ default: error$1
384
+ });
385
+
386
+ var once = createCommonjsModule(function (module) {
387
+ 'use strict';
388
+
389
+ // A "once" utility.
390
+ module.exports = function(fn) {
391
+ var result, called = false;
392
+ return function() {
393
+ if (!called) {
394
+ called = true;
395
+ result = fn.apply(this, arguments);
396
+ }
397
+ return result;
398
+ };
399
+ };
400
+ });
401
+
402
+ var once$1 = interopDefault(once);
403
+
404
+
405
+ var require$$0$3 = Object.freeze({
406
+ default: once$1
407
+ });
408
+
409
+ var index = createCommonjsModule(function (module) {
410
+ 'use strict';
411
+
412
+ var
413
+ cleanURL = interopDefault(require$$7),
414
+ XHR = interopDefault(require$$6),
415
+ delay = interopDefault(require$$5),
416
+ RequestError = interopDefault(require$$4),
417
+ Response = interopDefault(require$$2),
418
+ Request = interopDefault(require$$1$1),
419
+ extend = interopDefault(require$$0$2),
420
+ once = interopDefault(require$$0$3);
421
+
422
+ var i,
423
+ createError = RequestError.create;
424
+
425
+ function factory(defaults, plugins) {
426
+ defaults = defaults || {};
427
+ plugins = plugins || [];
428
+
429
+ function http(req, cb) {
430
+ var xhr, plugin, done, k, timeoutId, supportsLoadAndErrorEvents;
431
+
432
+ req = new Request(extend(defaults, req));
433
+
434
+ for (i = 0; i < plugins.length; i++) {
435
+ plugin = plugins[i];
436
+ if (plugin.processRequest) {
437
+ plugin.processRequest(req);
438
+ }
439
+ }
440
+
441
+ // Give the plugins a chance to create the XHR object
442
+ for (i = 0; i < plugins.length; i++) {
443
+ plugin = plugins[i];
444
+ if (plugin.createXHR) {
445
+ xhr = plugin.createXHR(req);
446
+ break; // First come, first serve
447
+ }
448
+ }
449
+ xhr = xhr || new XHR();
450
+
451
+ req.xhr = xhr;
452
+
453
+ // Use a single completion callback. This can be called with or without
454
+ // an error. If no error is passed, the request will be examined to see
455
+ // if it was successful.
456
+ done = once(delay(function(rawError) {
457
+ clearTimeout(timeoutId);
458
+ xhr.onload = xhr.onerror = xhr.onabort = xhr.onreadystatechange = xhr.ontimeout = xhr.onprogress = null;
459
+
460
+ var err = getError(req, rawError);
461
+
462
+ var res = err || Response.fromRequest(req);
463
+ for (i = 0; i < plugins.length; i++) {
464
+ plugin = plugins[i];
465
+ if (plugin.processResponse) {
466
+ plugin.processResponse(res);
467
+ }
468
+ }
469
+
470
+ // Invoke callbacks
471
+ if (err && req.onerror) req.onerror(err);
472
+ if (!err && req.onload) req.onload(res);
473
+ if (cb) cb(err, err ? undefined : res);
474
+
475
+ }));
476
+
477
+ supportsLoadAndErrorEvents = ('onload' in xhr) && ('onerror' in xhr);
478
+ xhr.onload = function() { done(); };
479
+ xhr.onerror = done;
480
+ xhr.onabort = function() { done(); };
481
+
482
+ // We'd rather use `onload`, `onerror`, and `onabort` since they're the
483
+ // only way to reliably detect successes and failures but, if they
484
+ // aren't available, we fall back to using `onreadystatechange`.
485
+ xhr.onreadystatechange = function() {
486
+ if (xhr.readyState !== 4) return;
487
+
488
+ if (req.aborted) return done();
489
+
490
+ if (!supportsLoadAndErrorEvents) {
491
+ // Assume a status of 0 is an error. This could be a false
492
+ // positive, but there's no way to tell when using
493
+ // `onreadystatechange` ):
494
+ // See matthewwithanm/react-inlinesvg#10.
495
+
496
+ // Some browsers don't like you reading XHR properties when the
497
+ // XHR has been aborted. In case we've gotten here as a result
498
+ // of that (either our calling `about()` in the timeout handler
499
+ // or the user calling it directly even though they shouldn't),
500
+ // be careful about accessing it.
501
+ var status;
502
+ try {
503
+ status = xhr.status;
504
+ } catch (err) {}
505
+ var err = status === 0 ? new Error('Internal XHR Error') : null;
506
+ return done(err);
507
+ }
508
+ };
509
+
510
+ // IE sometimes fails if you don't specify every handler.
511
+ // See http://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
512
+ xhr.ontimeout = function() { /* noop */ };
513
+ xhr.onprogress = function() { /* noop */ };
514
+
515
+ xhr.open(req.method, req.url);
516
+
517
+ if (req.timeout) {
518
+ // If we use the normal XHR timeout mechanism (`xhr.timeout` and
519
+ // `xhr.ontimeout`), `onreadystatechange` will be triggered before
520
+ // `ontimeout`. There's no way to recognize that it was triggered by
521
+ // a timeout, and we'd be unable to dispatch the right error.
522
+ timeoutId = setTimeout(function() {
523
+ req.timedOut = true;
524
+ done();
525
+ try {
526
+ xhr.abort();
527
+ } catch (err) {}
528
+ }, req.timeout);
529
+ }
530
+
531
+ for (k in req.headers) {
532
+ if (req.headers.hasOwnProperty(k)) {
533
+ xhr.setRequestHeader(k, req.headers[k]);
534
+ }
535
+ }
536
+
537
+ xhr.send(req.body);
538
+
539
+ return req;
540
+ }
541
+
542
+ var method,
543
+ methods = ['get', 'post', 'put', 'head', 'patch', 'delete'],
544
+ verb = function(method) {
545
+ return function(req, cb) {
546
+ req = new Request(req);
547
+ req.method = method;
548
+ return http(req, cb);
549
+ };
550
+ };
551
+ for (i = 0; i < methods.length; i++) {
552
+ method = methods[i];
553
+ http[method] = verb(method);
554
+ }
555
+
556
+ http.plugins = function() {
557
+ return plugins;
558
+ };
559
+
560
+ http.defaults = function(newValues) {
561
+ if (newValues) {
562
+ return factory(extend(defaults, newValues), plugins);
563
+ }
564
+ return defaults;
565
+ };
566
+
567
+ http.use = function() {
568
+ var newPlugins = Array.prototype.slice.call(arguments, 0);
569
+ return factory(defaults, plugins.concat(newPlugins));
570
+ };
571
+
572
+ http.bare = function() {
573
+ return factory();
574
+ };
575
+
576
+ http.Request = Request;
577
+ http.Response = Response;
578
+ http.RequestError = RequestError;
579
+
580
+ return http;
581
+ }
582
+
583
+ module.exports = factory({}, [cleanURL]);
584
+
585
+ /**
586
+ * Analyze the request to see if it represents an error. If so, return it! An
587
+ * original error object can be passed as a hint.
588
+ */
589
+ function getError(req, err) {
590
+ if (req.aborted) return createError('Request aborted', req, {name: 'Abort'});
591
+
592
+ if (req.timedOut) return createError('Request timeout', req, {name: 'Timeout'});
593
+
594
+ var xhr = req.xhr;
595
+ var type = Math.floor(xhr.status / 100);
596
+
597
+ var kind;
598
+ switch (type) {
599
+ case 0:
600
+ case 2:
601
+ // These don't represent errors unless the function was passed an
602
+ // error object explicitly.
603
+ if (!err) return;
604
+ return createError(err.message, req);
605
+ case 4:
606
+ // Sometimes 4XX statuses aren't errors.
607
+ if (xhr.status === 404 && !req.errorOn404) return;
608
+ kind = 'Client';
609
+ break;
610
+ case 5:
611
+ kind = 'Server';
612
+ break;
613
+ default:
614
+ kind = 'HTTP';
615
+ }
616
+ var msg = kind + ' Error: ' +
617
+ 'The server returned a status of ' + xhr.status +
618
+ ' for the request "' +
619
+ req.method.toUpperCase() + ' ' + req.url + '"';
620
+ return createError(msg, req);
621
+ }
622
+ });
623
+
624
+ var httpplease = interopDefault(index);
625
+
626
+ var request = httpplease.use(json$1);
627
+
628
+ function send(method, url, args) {
629
+ return new Promise(function (resolve, reject) {
630
+ request({ method: method, url: url, body: args }, function (err, res) {
631
+ if (err) {
632
+ var error = err && err.body && err.body.meta && err.body.meta.errorMessage ? new Error(err.body.meta.errorMessage) : err;
633
+ error.status = err.status;
634
+ reject(error);
635
+ } else {
636
+ resolve(res);
637
+ }
638
+ });
639
+ });
640
+ }
641
+
642
+ function get(url) {
643
+ return send('GET', url);
644
+ }
645
+
646
+ function post(url, args) {
647
+ return send('POST', url, args);
648
+ }
649
+
650
+ function findSegments(agent) {
651
+ var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
652
+
653
+ return get(agent.url + '/segments' + makeQueryString(opts)).then(function (res) {
654
+ return res.body.map(function (obj) {
655
+ return segmentify(agent, obj);
656
+ });
657
+ });
658
+ }
659
+
660
+ function getBranches(agent, prevLinkHash) {
661
+ var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
662
+
663
+ deprecated('Agent#getBranches(agent, prevLinkHash, tags = [])', 'Agent#findSegments(agent, filter)');
664
+
665
+ return findSegments(agent, { prevLinkHash: prevLinkHash, tags: tags });
666
+ }
667
+
668
+ function segmentify(agent, obj) {
669
+ Object.keys(agent.agentInfo.actions).filter(function (key) {
670
+ return ['init'].indexOf(key) < 0;
671
+ }).forEach(function (key) {
672
+ /*eslint-disable*/
673
+ obj[key] = function () {
674
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
675
+ args[_key] = arguments[_key];
676
+ }
677
+
678
+ return post(agent.url + '/segments/' + obj.meta.linkHash + '/' + key, args).then(function (res) {
679
+ return segmentify(agent, res.body);
680
+ });
681
+ };
682
+ });
683
+
684
+ /*eslint-disable*/
685
+ obj.getPrev = function () {
686
+ /*eslint-enable*/
687
+ if (obj.link.meta.prevLinkHash) {
688
+ return agent.getSegment(obj.link.meta.prevLinkHash);
689
+ }
690
+
691
+ return Promise.resolve(null);
692
+ };
693
+
694
+ // Deprecated.
695
+ /*eslint-disable*/
696
+ obj.load = function () {
697
+ /*eslint-enable*/
698
+ deprecated('segment#load()');
699
+ return Promise.resolve(segmentify(agent, {
700
+ link: JSON.parse(JSON.stringify(obj.link)),
701
+ meta: JSON.parse(JSON.stringify(obj.meta))
702
+ }));
703
+ };
704
+
705
+ // Deprecated.
706
+ /*eslint-disable*/
707
+ obj.getBranches = function () {
708
+ for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
709
+ args[_key2] = arguments[_key2];
710
+ }
711
+
712
+ /*eslint-enable*/
713
+ return getBranches.apply(undefined, [agent, obj.meta.linkHash].concat(args));
714
+ };
715
+
716
+ return obj;
717
+ }
718
+
719
+ function createMap(agent) {
720
+ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
721
+ args[_key - 1] = arguments[_key];
722
+ }
723
+
724
+ return post(agent.url + '/segments', args).then(function (res) {
725
+ return segmentify(agent, res.body);
726
+ });
727
+ }
728
+
729
+ function getSegment(agent, linkHash) {
730
+ return get(agent.url + '/segments/' + linkHash).then(function (res) {
731
+ return segmentify(agent, res.body);
732
+ });
733
+ }
734
+
735
+ function getMapIds(agent) {
736
+ var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
737
+
738
+ return get(agent.url + '/maps' + makeQueryString(opts)).then(function (res) {
739
+ return res.body;
740
+ });
741
+ }
742
+
743
+ function getLink(agent, hash) {
744
+ deprecated('Agent#getLink(agent, hash)', 'Agent#getSegment(agent, hash)');
745
+
746
+ return getSegment(agent, hash);
747
+ }
748
+
749
+ function getMap(agent, mapId) {
750
+ var tags = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
751
+
752
+ deprecated('getMap(agent, mapId, tags = [])', 'findSegments(agent, filter)');
753
+
754
+ return findSegments(agent, { mapId: mapId, tags: tags });
755
+ }
756
+
757
+ // Deprecated.
758
+ function getAgent(url) {
759
+ return get(url).then(function (res) {
760
+ var agent = res.body;
761
+
762
+ agent.url = url;
763
+ agent.createMap = createMap.bind(null, agent);
764
+ agent.getSegment = getSegment.bind(null, agent);
765
+ agent.findSegments = findSegments.bind(null, agent);
766
+ agent.getMapIds = getMapIds.bind(null, agent);
767
+
768
+ // Deprecated.
769
+ agent.getBranches = getBranches.bind(null, agent);
770
+ agent.getLink = getLink.bind(null, agent);
771
+ agent.getMap = getMap.bind(null, agent);
772
+
773
+ return agent;
774
+ });
775
+ }
776
+
777
+ function fromSegment(obj) {
778
+ return getAgent(obj.meta.agentUrl || obj.meta.applicationLocation).then(function (agent) {
779
+ var segment = segmentify(agent, obj);
780
+ return { agent: agent, segment: segment };
781
+ });
782
+ }
783
+
784
+ // Deprecated.
785
+ var config = {
786
+ applicationUrl: 'https://%s.stratumn.rocks'
787
+ };
788
+
789
+ function getApplication(name, url) {
790
+ deprecated('getApplication(name, url)', 'getAgent(url)');
791
+
792
+ return getAgent(url || config.applicationUrl.replace('%s', name));
793
+ }
794
+
795
+ function loadLink(obj) {
796
+ deprecated('loadLink(obj)', 'fromSegment(obj)');
797
+
798
+ return fromSegment(obj).then(function (_ref) {
799
+ var segment = _ref.segment;
800
+ return segment;
801
+ });
802
+ }
803
+
804
+ exports.getAgent = getAgent;
805
+ exports.fromSegment = fromSegment;
806
+ exports.getApplication = getApplication;
807
+ exports.loadLink = loadLink;
808
+ exports.config = config;
809
+
810
+ Object.defineProperty(exports, '__esModule', { value: true });
811
+
812
+ })));
813
+ //# sourceMappingURL=stratumn-sdk.js.map