mapexplorer-rails 1.0.0.pre.alpha.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/LICENSE +202 -0
- data/README.md +1 -1
- data/app/assets/javascripts/mapexplorer-rails.js +16 -0
- data/app/assets/stylesheets/mapexplorer-rails.scss +16 -0
- data/app/helpers/mapexplorer_helper.rb +14 -0
- data/config/routes.rb +14 -0
- data/lib/mapexplorer/rails.rb +14 -0
- data/lib/mapexplorer/rails/engine.rb +14 -0
- data/lib/mapexplorer/rails/version.rb +15 -1
- data/lib/tasks/mapexplorer/rails_tasks.rake +14 -0
- data/vendor/assets/mapexplorer-core/LICENSE +202 -21
- data/vendor/assets/mapexplorer-core/LICENSE_HEADER +15 -0
- data/vendor/assets/mapexplorer-core/bower.json +1 -1
- data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js +1552 -330
- data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.js.map +1 -1
- data/vendor/assets/mapexplorer-core/karma.conf.js +4 -2
- data/vendor/assets/mapexplorer-core/package-lock.json +3486 -0
- data/vendor/assets/mapexplorer-core/package.json +8 -8
- data/vendor/assets/mapexplorer-core/update-license-headers.sh +20 -0
- data/vendor/assets/stratumn-agent-client/LICENSE +202 -0
- data/vendor/assets/stratumn-agent-client/LICENSE_HEADER +15 -0
- data/vendor/assets/stratumn-agent-client/README.md +268 -0
- data/vendor/assets/stratumn-agent-client/bower.json +27 -0
- data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.js +1449 -0
- data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.js.map +1 -0
- data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.min.js +2 -0
- data/vendor/assets/stratumn-agent-client/dist/stratumn-agent-client.min.js.map +1 -0
- data/vendor/assets/stratumn-agent-client/examples/browser/index.html +34 -0
- data/vendor/assets/stratumn-agent-client/package.json +69 -0
- data/vendor/assets/stratumn-agent-client/rollup.base.config.js +13 -0
- data/vendor/assets/stratumn-agent-client/rollup.bower.config.js +18 -0
- data/vendor/assets/stratumn-agent-client/rollup.bower.min.config.js +7 -0
- data/vendor/assets/stratumn-agent-client/rollup.es.config.js +9 -0
- data/vendor/assets/stratumn-agent-client/rollup.umd.config.js +10 -0
- data/vendor/assets/stratumn-agent-client/update-license-headers.sh +20 -0
- metadata +25 -7
- data/MIT-LICENSE +0 -20
- data/vendor/assets/mapexplorer-core/dist/mapexplorer-core.min.js +0 -35
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"name": "stratumn-agent-client",
|
3
|
+
"description": "Stratumn Indigo agent client library",
|
4
|
+
"main": "dist/stratumn-agent-client.js",
|
5
|
+
"authors": [
|
6
|
+
"Stratumn Team"
|
7
|
+
],
|
8
|
+
"license": "Apache-2.0",
|
9
|
+
"keywords": [
|
10
|
+
"stratumn",
|
11
|
+
"lib",
|
12
|
+
"blockchain",
|
13
|
+
"client"
|
14
|
+
],
|
15
|
+
"homepage": "https://github.com/stratumn/agent-client-js",
|
16
|
+
"ignore": [
|
17
|
+
"**/.*",
|
18
|
+
"node_modules",
|
19
|
+
"bower_components",
|
20
|
+
"test",
|
21
|
+
"tests",
|
22
|
+
"src"
|
23
|
+
],
|
24
|
+
"dependencies": {
|
25
|
+
"babel-polyfill": "babel/babel/tree/master/packages/babel-polyfill#^0.0.1"
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,1449 @@
|
|
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.StratumnAgentClient = global.StratumnAgentClient || {})));
|
5
|
+
}(this, (function (exports) { 'use strict';
|
6
|
+
|
7
|
+
/*
|
8
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
9
|
+
|
10
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
+
you may not use this file except in compliance with the License.
|
12
|
+
You may obtain a copy of the License at
|
13
|
+
|
14
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
15
|
+
|
16
|
+
Unless required by applicable law or agreed to in writing, software
|
17
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
See the License for the specific language governing permissions and
|
20
|
+
limitations under the License.
|
21
|
+
*/
|
22
|
+
|
23
|
+
function deprecated(oldFunc, newFunc) {
|
24
|
+
if (!newFunc) {
|
25
|
+
console.warn("WARNING: " + oldFunc + " is deprecated.");
|
26
|
+
} else {
|
27
|
+
console.warn("WARNING: " + oldFunc + " is deprecated. Please use " + newFunc + " instead.");
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
/*
|
32
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
33
|
+
|
34
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
35
|
+
you may not use this file except in compliance with the License.
|
36
|
+
You may obtain a copy of the License at
|
37
|
+
|
38
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
39
|
+
|
40
|
+
Unless required by applicable law or agreed to in writing, software
|
41
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
42
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
43
|
+
See the License for the specific language governing permissions and
|
44
|
+
limitations under the License.
|
45
|
+
*/
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Makes a query string.
|
49
|
+
* @param {object} obj - an object of keys
|
50
|
+
* @returns {string} a query string
|
51
|
+
*/
|
52
|
+
function makeQueryString(obj) {
|
53
|
+
var parts = Object.keys(obj).reduce(function (curr, key) {
|
54
|
+
var val = Array.isArray(obj[key]) ? obj[key].join('+') : obj[key];
|
55
|
+
curr.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
|
56
|
+
return curr;
|
57
|
+
}, []);
|
58
|
+
|
59
|
+
if (parts.length) {
|
60
|
+
return '?' + parts.join('&');
|
61
|
+
}
|
62
|
+
|
63
|
+
return '';
|
64
|
+
}
|
65
|
+
|
66
|
+
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}
|
67
|
+
|
68
|
+
function interopDefault(ex) {
|
69
|
+
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
|
70
|
+
}
|
71
|
+
|
72
|
+
function createCommonjsModule(fn, module) {
|
73
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
74
|
+
}
|
75
|
+
|
76
|
+
var setImmediate$1 = createCommonjsModule(function (module) {
|
77
|
+
(function (global, undefined) {
|
78
|
+
"use strict";
|
79
|
+
|
80
|
+
if (global.setImmediate) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
|
84
|
+
var nextHandle = 1; // Spec says greater than zero
|
85
|
+
var tasksByHandle = {};
|
86
|
+
var currentlyRunningATask = false;
|
87
|
+
var doc = global.document;
|
88
|
+
var registerImmediate;
|
89
|
+
|
90
|
+
function setImmediate(callback) {
|
91
|
+
// Callback can either be a function or a string
|
92
|
+
if (typeof callback !== "function") {
|
93
|
+
callback = new Function("" + callback);
|
94
|
+
}
|
95
|
+
// Copy function arguments
|
96
|
+
var args = new Array(arguments.length - 1);
|
97
|
+
for (var i = 0; i < args.length; i++) {
|
98
|
+
args[i] = arguments[i + 1];
|
99
|
+
}
|
100
|
+
// Store and register the task
|
101
|
+
var task = { callback: callback, args: args };
|
102
|
+
tasksByHandle[nextHandle] = task;
|
103
|
+
registerImmediate(nextHandle);
|
104
|
+
return nextHandle++;
|
105
|
+
}
|
106
|
+
|
107
|
+
function clearImmediate(handle) {
|
108
|
+
delete tasksByHandle[handle];
|
109
|
+
}
|
110
|
+
|
111
|
+
function run(task) {
|
112
|
+
var callback = task.callback;
|
113
|
+
var args = task.args;
|
114
|
+
switch (args.length) {
|
115
|
+
case 0:
|
116
|
+
callback();
|
117
|
+
break;
|
118
|
+
case 1:
|
119
|
+
callback(args[0]);
|
120
|
+
break;
|
121
|
+
case 2:
|
122
|
+
callback(args[0], args[1]);
|
123
|
+
break;
|
124
|
+
case 3:
|
125
|
+
callback(args[0], args[1], args[2]);
|
126
|
+
break;
|
127
|
+
default:
|
128
|
+
callback.apply(undefined, args);
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
function runIfPresent(handle) {
|
134
|
+
// From the spec: "Wait until any invocations of this algorithm started before this one have completed."
|
135
|
+
// So if we're currently running a task, we'll need to delay this invocation.
|
136
|
+
if (currentlyRunningATask) {
|
137
|
+
// Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a
|
138
|
+
// "too much recursion" error.
|
139
|
+
setTimeout(runIfPresent, 0, handle);
|
140
|
+
} else {
|
141
|
+
var task = tasksByHandle[handle];
|
142
|
+
if (task) {
|
143
|
+
currentlyRunningATask = true;
|
144
|
+
try {
|
145
|
+
run(task);
|
146
|
+
} finally {
|
147
|
+
clearImmediate(handle);
|
148
|
+
currentlyRunningATask = false;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
function installNextTickImplementation() {
|
155
|
+
registerImmediate = function(handle) {
|
156
|
+
process.nextTick(function () { runIfPresent(handle); });
|
157
|
+
};
|
158
|
+
}
|
159
|
+
|
160
|
+
function canUsePostMessage() {
|
161
|
+
// The test against `importScripts` prevents this implementation from being installed inside a web worker,
|
162
|
+
// where `global.postMessage` means something completely different and can't be used for this purpose.
|
163
|
+
if (global.postMessage && !global.importScripts) {
|
164
|
+
var postMessageIsAsynchronous = true;
|
165
|
+
var oldOnMessage = global.onmessage;
|
166
|
+
global.onmessage = function() {
|
167
|
+
postMessageIsAsynchronous = false;
|
168
|
+
};
|
169
|
+
global.postMessage("", "*");
|
170
|
+
global.onmessage = oldOnMessage;
|
171
|
+
return postMessageIsAsynchronous;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
function installPostMessageImplementation() {
|
176
|
+
// Installs an event handler on `global` for the `message` event: see
|
177
|
+
// * https://developer.mozilla.org/en/DOM/window.postMessage
|
178
|
+
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
|
179
|
+
|
180
|
+
var messagePrefix = "setImmediate$" + Math.random() + "$";
|
181
|
+
var onGlobalMessage = function(event) {
|
182
|
+
if (event.source === global &&
|
183
|
+
typeof event.data === "string" &&
|
184
|
+
event.data.indexOf(messagePrefix) === 0) {
|
185
|
+
runIfPresent(+event.data.slice(messagePrefix.length));
|
186
|
+
}
|
187
|
+
};
|
188
|
+
|
189
|
+
if (global.addEventListener) {
|
190
|
+
global.addEventListener("message", onGlobalMessage, false);
|
191
|
+
} else {
|
192
|
+
global.attachEvent("onmessage", onGlobalMessage);
|
193
|
+
}
|
194
|
+
|
195
|
+
registerImmediate = function(handle) {
|
196
|
+
global.postMessage(messagePrefix + handle, "*");
|
197
|
+
};
|
198
|
+
}
|
199
|
+
|
200
|
+
function installMessageChannelImplementation() {
|
201
|
+
var channel = new MessageChannel();
|
202
|
+
channel.port1.onmessage = function(event) {
|
203
|
+
var handle = event.data;
|
204
|
+
runIfPresent(handle);
|
205
|
+
};
|
206
|
+
|
207
|
+
registerImmediate = function(handle) {
|
208
|
+
channel.port2.postMessage(handle);
|
209
|
+
};
|
210
|
+
}
|
211
|
+
|
212
|
+
function installReadyStateChangeImplementation() {
|
213
|
+
var html = doc.documentElement;
|
214
|
+
registerImmediate = function(handle) {
|
215
|
+
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
|
216
|
+
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
|
217
|
+
var script = doc.createElement("script");
|
218
|
+
script.onreadystatechange = function () {
|
219
|
+
runIfPresent(handle);
|
220
|
+
script.onreadystatechange = null;
|
221
|
+
html.removeChild(script);
|
222
|
+
script = null;
|
223
|
+
};
|
224
|
+
html.appendChild(script);
|
225
|
+
};
|
226
|
+
}
|
227
|
+
|
228
|
+
function installSetTimeoutImplementation() {
|
229
|
+
registerImmediate = function(handle) {
|
230
|
+
setTimeout(runIfPresent, 0, handle);
|
231
|
+
};
|
232
|
+
}
|
233
|
+
|
234
|
+
// If supported, we should attach to the prototype of global, since that is where setTimeout et al. live.
|
235
|
+
var attachTo = Object.getPrototypeOf && Object.getPrototypeOf(global);
|
236
|
+
attachTo = attachTo && attachTo.setTimeout ? attachTo : global;
|
237
|
+
|
238
|
+
// Don't get fooled by e.g. browserify environments.
|
239
|
+
if ({}.toString.call(global.process) === "[object process]") {
|
240
|
+
// For Node.js before 0.9
|
241
|
+
installNextTickImplementation();
|
242
|
+
|
243
|
+
} else if (canUsePostMessage()) {
|
244
|
+
// For non-IE10 modern browsers
|
245
|
+
installPostMessageImplementation();
|
246
|
+
|
247
|
+
} else if (global.MessageChannel) {
|
248
|
+
// For web workers, where supported
|
249
|
+
installMessageChannelImplementation();
|
250
|
+
|
251
|
+
} else if (doc && "onreadystatechange" in doc.createElement("script")) {
|
252
|
+
// For IE 6–8
|
253
|
+
installReadyStateChangeImplementation();
|
254
|
+
|
255
|
+
} else {
|
256
|
+
// For older browsers
|
257
|
+
installSetTimeoutImplementation();
|
258
|
+
}
|
259
|
+
|
260
|
+
attachTo.setImmediate = setImmediate;
|
261
|
+
attachTo.clearImmediate = clearImmediate;
|
262
|
+
}(typeof self === "undefined" ? typeof commonjsGlobal === "undefined" ? commonjsGlobal : commonjsGlobal : self));
|
263
|
+
});
|
264
|
+
|
265
|
+
interopDefault(setImmediate$1);
|
266
|
+
|
267
|
+
/*
|
268
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
269
|
+
|
270
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
271
|
+
you may not use this file except in compliance with the License.
|
272
|
+
You may obtain a copy of the License at
|
273
|
+
|
274
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
275
|
+
|
276
|
+
Unless required by applicable law or agreed to in writing, software
|
277
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
278
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
279
|
+
See the License for the specific language governing permissions and
|
280
|
+
limitations under the License.
|
281
|
+
*/
|
282
|
+
|
283
|
+
/**
|
284
|
+
* Calls a function that returns a Promise until a condition is reached
|
285
|
+
* @param {function} condition - while condition is true body will keep being called
|
286
|
+
* @param {function} body - a function that is repeatedly called while condition is true
|
287
|
+
* @returns {Promise} a Promise that resolves when the condition is no longer true
|
288
|
+
*/
|
289
|
+
function promiseWhile(condition, body) {
|
290
|
+
return new Promise(function (resolve, reject) {
|
291
|
+
function loop() {
|
292
|
+
body().then(function () {
|
293
|
+
// When the result of calling `condition` is no longer true, we are
|
294
|
+
// done.
|
295
|
+
if (!condition()) {
|
296
|
+
resolve();
|
297
|
+
} else {
|
298
|
+
loop();
|
299
|
+
}
|
300
|
+
}).catch(reject);
|
301
|
+
}
|
302
|
+
|
303
|
+
// Start running the loop in the next tick so that this function is
|
304
|
+
// completely async. It would be unexpected if `body` was called
|
305
|
+
// synchronously the first time.
|
306
|
+
setImmediate(loop);
|
307
|
+
});
|
308
|
+
}
|
309
|
+
|
310
|
+
var jsonrequest = createCommonjsModule(function (module) {
|
311
|
+
'use strict';
|
312
|
+
|
313
|
+
module.exports = {
|
314
|
+
processRequest: function(req) {
|
315
|
+
var
|
316
|
+
contentType = req.header('Content-Type'),
|
317
|
+
hasJsonContentType = contentType &&
|
318
|
+
contentType.indexOf('application/json') !== -1;
|
319
|
+
|
320
|
+
if (contentType != null && !hasJsonContentType) {
|
321
|
+
return;
|
322
|
+
}
|
323
|
+
|
324
|
+
if (req.body) {
|
325
|
+
if (!contentType) {
|
326
|
+
req.header('Content-Type', 'application/json');
|
327
|
+
}
|
328
|
+
|
329
|
+
req.body = JSON.stringify(req.body);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
};
|
333
|
+
});
|
334
|
+
|
335
|
+
var jsonrequest$1 = interopDefault(jsonrequest);
|
336
|
+
var processRequest$1 = jsonrequest.processRequest;
|
337
|
+
|
338
|
+
var require$$1 = Object.freeze({
|
339
|
+
default: jsonrequest$1,
|
340
|
+
processRequest: processRequest$1
|
341
|
+
});
|
342
|
+
|
343
|
+
var jsonresponse = createCommonjsModule(function (module) {
|
344
|
+
'use strict';
|
345
|
+
|
346
|
+
module.exports = {
|
347
|
+
processRequest: function(req) {
|
348
|
+
var accept = req.header('Accept');
|
349
|
+
if (accept == null) {
|
350
|
+
req.header('Accept', 'application/json');
|
351
|
+
}
|
352
|
+
},
|
353
|
+
processResponse: function(res) {
|
354
|
+
// Check to see if the contentype is "something/json" or
|
355
|
+
// "something/somethingelse+json"
|
356
|
+
if (res.contentType && /^.*\/(?:.*\+)?json(;|$)/i.test(res.contentType)) {
|
357
|
+
var raw = typeof res.body === 'string' ? res.body : res.text;
|
358
|
+
if (raw) {
|
359
|
+
res.body = JSON.parse(raw);
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
};
|
364
|
+
});
|
365
|
+
|
366
|
+
var jsonresponse$1 = interopDefault(jsonresponse);
|
367
|
+
var processRequest$2 = jsonresponse.processRequest;
|
368
|
+
var processResponse$1 = jsonresponse.processResponse;
|
369
|
+
|
370
|
+
var require$$0 = Object.freeze({
|
371
|
+
default: jsonresponse$1,
|
372
|
+
processRequest: processRequest$2,
|
373
|
+
processResponse: processResponse$1
|
374
|
+
});
|
375
|
+
|
376
|
+
var json = createCommonjsModule(function (module) {
|
377
|
+
'use strict';
|
378
|
+
|
379
|
+
var jsonrequest = interopDefault(require$$1),
|
380
|
+
jsonresponse = interopDefault(require$$0);
|
381
|
+
|
382
|
+
module.exports = {
|
383
|
+
processRequest: function(req) {
|
384
|
+
jsonrequest.processRequest.call(this, req);
|
385
|
+
jsonresponse.processRequest.call(this, req);
|
386
|
+
},
|
387
|
+
processResponse: function(res) {
|
388
|
+
jsonresponse.processResponse.call(this, res);
|
389
|
+
}
|
390
|
+
};
|
391
|
+
});
|
392
|
+
|
393
|
+
var json$1 = interopDefault(json);
|
394
|
+
|
395
|
+
var cleanurl = createCommonjsModule(function (module) {
|
396
|
+
'use strict';
|
397
|
+
|
398
|
+
module.exports = {
|
399
|
+
processRequest: function(req) {
|
400
|
+
req.url = req.url.replace(/[^%]+/g, function(s) {
|
401
|
+
return encodeURI(s);
|
402
|
+
});
|
403
|
+
}
|
404
|
+
};
|
405
|
+
});
|
406
|
+
|
407
|
+
var cleanurl$1 = interopDefault(cleanurl);
|
408
|
+
var processRequest$3 = cleanurl.processRequest;
|
409
|
+
|
410
|
+
var require$$7 = Object.freeze({
|
411
|
+
default: cleanurl$1,
|
412
|
+
processRequest: processRequest$3
|
413
|
+
});
|
414
|
+
|
415
|
+
var xhrBrowser = createCommonjsModule(function (module) {
|
416
|
+
module.exports = window.XMLHttpRequest;
|
417
|
+
});
|
418
|
+
|
419
|
+
var xhrBrowser$1 = interopDefault(xhrBrowser);
|
420
|
+
|
421
|
+
|
422
|
+
var require$$6 = Object.freeze({
|
423
|
+
default: xhrBrowser$1
|
424
|
+
});
|
425
|
+
|
426
|
+
var delay = createCommonjsModule(function (module) {
|
427
|
+
'use strict';
|
428
|
+
|
429
|
+
// Wrap a function in a `setTimeout` call. This is used to guarantee async
|
430
|
+
// behavior, which can avoid unexpected errors.
|
431
|
+
|
432
|
+
module.exports = function(fn) {
|
433
|
+
return function() {
|
434
|
+
var
|
435
|
+
args = Array.prototype.slice.call(arguments, 0),
|
436
|
+
newFunc = function() {
|
437
|
+
return fn.apply(null, args);
|
438
|
+
};
|
439
|
+
setTimeout(newFunc, 0);
|
440
|
+
};
|
441
|
+
};
|
442
|
+
});
|
443
|
+
|
444
|
+
var delay$1 = interopDefault(delay);
|
445
|
+
|
446
|
+
|
447
|
+
var require$$5 = Object.freeze({
|
448
|
+
default: delay$1
|
449
|
+
});
|
450
|
+
|
451
|
+
var request$1 = createCommonjsModule(function (module) {
|
452
|
+
'use strict';
|
453
|
+
|
454
|
+
function Request(optsOrUrl) {
|
455
|
+
var opts = typeof optsOrUrl === 'string' ? {url: optsOrUrl} : optsOrUrl || {};
|
456
|
+
this.method = opts.method ? opts.method.toUpperCase() : 'GET';
|
457
|
+
this.url = opts.url;
|
458
|
+
this.headers = opts.headers || {};
|
459
|
+
this.body = opts.body;
|
460
|
+
this.timeout = opts.timeout || 0;
|
461
|
+
this.errorOn404 = opts.errorOn404 != null ? opts.errorOn404 : true;
|
462
|
+
this.onload = opts.onload;
|
463
|
+
this.onerror = opts.onerror;
|
464
|
+
}
|
465
|
+
|
466
|
+
Request.prototype.abort = function() {
|
467
|
+
if (this.aborted) return;
|
468
|
+
this.aborted = true;
|
469
|
+
this.xhr.abort();
|
470
|
+
return this;
|
471
|
+
};
|
472
|
+
|
473
|
+
Request.prototype.header = function(name, value) {
|
474
|
+
var k;
|
475
|
+
for (k in this.headers) {
|
476
|
+
if (this.headers.hasOwnProperty(k)) {
|
477
|
+
if (name.toLowerCase() === k.toLowerCase()) {
|
478
|
+
if (arguments.length === 1) {
|
479
|
+
return this.headers[k];
|
480
|
+
}
|
481
|
+
|
482
|
+
delete this.headers[k];
|
483
|
+
break;
|
484
|
+
}
|
485
|
+
}
|
486
|
+
}
|
487
|
+
if (value != null) {
|
488
|
+
this.headers[name] = value;
|
489
|
+
return value;
|
490
|
+
}
|
491
|
+
};
|
492
|
+
|
493
|
+
|
494
|
+
module.exports = Request;
|
495
|
+
});
|
496
|
+
|
497
|
+
var request$2 = interopDefault(request$1);
|
498
|
+
|
499
|
+
|
500
|
+
var require$$1$1 = Object.freeze({
|
501
|
+
default: request$2
|
502
|
+
});
|
503
|
+
|
504
|
+
var index$1 = createCommonjsModule(function (module) {
|
505
|
+
module.exports = extend
|
506
|
+
|
507
|
+
function extend() {
|
508
|
+
var target = {}
|
509
|
+
|
510
|
+
for (var i = 0; i < arguments.length; i++) {
|
511
|
+
var source = arguments[i]
|
512
|
+
|
513
|
+
for (var key in source) {
|
514
|
+
if (source.hasOwnProperty(key)) {
|
515
|
+
target[key] = source[key]
|
516
|
+
}
|
517
|
+
}
|
518
|
+
}
|
519
|
+
|
520
|
+
return target
|
521
|
+
}
|
522
|
+
});
|
523
|
+
|
524
|
+
var index$2 = interopDefault(index$1);
|
525
|
+
|
526
|
+
|
527
|
+
var require$$0$2 = Object.freeze({
|
528
|
+
default: index$2
|
529
|
+
});
|
530
|
+
|
531
|
+
var extractResponseProps = createCommonjsModule(function (module) {
|
532
|
+
'use strict';
|
533
|
+
|
534
|
+
var extend = interopDefault(require$$0$2);
|
535
|
+
|
536
|
+
module.exports = function(req) {
|
537
|
+
var xhr = req.xhr;
|
538
|
+
var props = {request: req, xhr: xhr};
|
539
|
+
|
540
|
+
// Try to create the response from the request. If the request was aborted,
|
541
|
+
// accesssing properties of the XHR may throw an error, so we wrap in a
|
542
|
+
// try/catch.
|
543
|
+
try {
|
544
|
+
var lines, i, m, headers = {};
|
545
|
+
if (xhr.getAllResponseHeaders) {
|
546
|
+
lines = xhr.getAllResponseHeaders().split('\n');
|
547
|
+
for (i = 0; i < lines.length; i++) {
|
548
|
+
if ((m = lines[i].match(/\s*([^\s]+):\s+([^\s]+)/))) {
|
549
|
+
headers[m[1]] = m[2];
|
550
|
+
}
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
props = extend(props, {
|
555
|
+
status: xhr.status,
|
556
|
+
contentType: xhr.contentType || (xhr.getResponseHeader && xhr.getResponseHeader('Content-Type')),
|
557
|
+
headers: headers,
|
558
|
+
text: xhr.responseText,
|
559
|
+
body: xhr.response || xhr.responseText
|
560
|
+
});
|
561
|
+
} catch (err) {}
|
562
|
+
|
563
|
+
return props;
|
564
|
+
};
|
565
|
+
});
|
566
|
+
|
567
|
+
var extractResponseProps$1 = interopDefault(extractResponseProps);
|
568
|
+
|
569
|
+
|
570
|
+
var require$$0$1 = Object.freeze({
|
571
|
+
default: extractResponseProps$1
|
572
|
+
});
|
573
|
+
|
574
|
+
var response = createCommonjsModule(function (module) {
|
575
|
+
'use strict';
|
576
|
+
|
577
|
+
var Request = interopDefault(require$$1$1);
|
578
|
+
var extractResponseProps = interopDefault(require$$0$1);
|
579
|
+
|
580
|
+
function Response(props) {
|
581
|
+
this.request = props.request;
|
582
|
+
this.xhr = props.xhr;
|
583
|
+
this.headers = props.headers || {};
|
584
|
+
this.status = props.status || 0;
|
585
|
+
this.text = props.text;
|
586
|
+
this.body = props.body;
|
587
|
+
this.contentType = props.contentType;
|
588
|
+
this.isHttpError = props.status >= 400;
|
589
|
+
}
|
590
|
+
|
591
|
+
Response.prototype.header = Request.prototype.header;
|
592
|
+
|
593
|
+
Response.fromRequest = function(req) {
|
594
|
+
return new Response(extractResponseProps(req));
|
595
|
+
};
|
596
|
+
|
597
|
+
|
598
|
+
module.exports = Response;
|
599
|
+
});
|
600
|
+
|
601
|
+
var response$1 = interopDefault(response);
|
602
|
+
|
603
|
+
|
604
|
+
var require$$2 = Object.freeze({
|
605
|
+
default: response$1
|
606
|
+
});
|
607
|
+
|
608
|
+
var error = createCommonjsModule(function (module) {
|
609
|
+
'use strict';
|
610
|
+
|
611
|
+
var Response = interopDefault(require$$2);
|
612
|
+
var extractResponseProps = interopDefault(require$$0$1);
|
613
|
+
var extend = interopDefault(require$$0$2);
|
614
|
+
|
615
|
+
function RequestError(message, props) {
|
616
|
+
var err = new Error(message);
|
617
|
+
err.name = 'RequestError';
|
618
|
+
this.name = err.name;
|
619
|
+
this.message = err.message;
|
620
|
+
if (err.stack) {
|
621
|
+
this.stack = err.stack;
|
622
|
+
}
|
623
|
+
|
624
|
+
this.toString = function() {
|
625
|
+
return this.message;
|
626
|
+
};
|
627
|
+
|
628
|
+
for (var k in props) {
|
629
|
+
if (props.hasOwnProperty(k)) {
|
630
|
+
this[k] = props[k];
|
631
|
+
}
|
632
|
+
}
|
633
|
+
}
|
634
|
+
|
635
|
+
RequestError.prototype = extend(Error.prototype);
|
636
|
+
RequestError.prototype.constructor = RequestError;
|
637
|
+
|
638
|
+
RequestError.create = function(message, req, props) {
|
639
|
+
var err = new RequestError(message, props);
|
640
|
+
Response.call(err, extractResponseProps(req));
|
641
|
+
return err;
|
642
|
+
};
|
643
|
+
|
644
|
+
module.exports = RequestError;
|
645
|
+
});
|
646
|
+
|
647
|
+
var error$1 = interopDefault(error);
|
648
|
+
|
649
|
+
|
650
|
+
var require$$4 = Object.freeze({
|
651
|
+
default: error$1
|
652
|
+
});
|
653
|
+
|
654
|
+
var once = createCommonjsModule(function (module) {
|
655
|
+
'use strict';
|
656
|
+
|
657
|
+
// A "once" utility.
|
658
|
+
module.exports = function(fn) {
|
659
|
+
var result, called = false;
|
660
|
+
return function() {
|
661
|
+
if (!called) {
|
662
|
+
called = true;
|
663
|
+
result = fn.apply(this, arguments);
|
664
|
+
}
|
665
|
+
return result;
|
666
|
+
};
|
667
|
+
};
|
668
|
+
});
|
669
|
+
|
670
|
+
var once$1 = interopDefault(once);
|
671
|
+
|
672
|
+
|
673
|
+
var require$$0$3 = Object.freeze({
|
674
|
+
default: once$1
|
675
|
+
});
|
676
|
+
|
677
|
+
var index = createCommonjsModule(function (module) {
|
678
|
+
'use strict';
|
679
|
+
|
680
|
+
var
|
681
|
+
cleanURL = interopDefault(require$$7),
|
682
|
+
XHR = interopDefault(require$$6),
|
683
|
+
delay = interopDefault(require$$5),
|
684
|
+
RequestError = interopDefault(require$$4),
|
685
|
+
Response = interopDefault(require$$2),
|
686
|
+
Request = interopDefault(require$$1$1),
|
687
|
+
extend = interopDefault(require$$0$2),
|
688
|
+
once = interopDefault(require$$0$3);
|
689
|
+
|
690
|
+
var i,
|
691
|
+
createError = RequestError.create;
|
692
|
+
|
693
|
+
function factory(defaults, plugins) {
|
694
|
+
defaults = defaults || {};
|
695
|
+
plugins = plugins || [];
|
696
|
+
|
697
|
+
function http(req, cb) {
|
698
|
+
var xhr, plugin, done, k, timeoutId, supportsLoadAndErrorEvents;
|
699
|
+
|
700
|
+
req = new Request(extend(defaults, req));
|
701
|
+
|
702
|
+
for (i = 0; i < plugins.length; i++) {
|
703
|
+
plugin = plugins[i];
|
704
|
+
if (plugin.processRequest) {
|
705
|
+
plugin.processRequest(req);
|
706
|
+
}
|
707
|
+
}
|
708
|
+
|
709
|
+
// Give the plugins a chance to create the XHR object
|
710
|
+
for (i = 0; i < plugins.length; i++) {
|
711
|
+
plugin = plugins[i];
|
712
|
+
if (plugin.createXHR) {
|
713
|
+
xhr = plugin.createXHR(req);
|
714
|
+
break; // First come, first serve
|
715
|
+
}
|
716
|
+
}
|
717
|
+
xhr = xhr || new XHR();
|
718
|
+
|
719
|
+
req.xhr = xhr;
|
720
|
+
|
721
|
+
// Use a single completion callback. This can be called with or without
|
722
|
+
// an error. If no error is passed, the request will be examined to see
|
723
|
+
// if it was successful.
|
724
|
+
done = once(delay(function(rawError) {
|
725
|
+
clearTimeout(timeoutId);
|
726
|
+
xhr.onload = xhr.onerror = xhr.onabort = xhr.onreadystatechange = xhr.ontimeout = xhr.onprogress = null;
|
727
|
+
|
728
|
+
var err = getError(req, rawError);
|
729
|
+
|
730
|
+
var res = err || Response.fromRequest(req);
|
731
|
+
for (i = 0; i < plugins.length; i++) {
|
732
|
+
plugin = plugins[i];
|
733
|
+
if (plugin.processResponse) {
|
734
|
+
plugin.processResponse(res);
|
735
|
+
}
|
736
|
+
}
|
737
|
+
|
738
|
+
// Invoke callbacks
|
739
|
+
if (err && req.onerror) req.onerror(err);
|
740
|
+
if (!err && req.onload) req.onload(res);
|
741
|
+
if (cb) cb(err, err ? undefined : res);
|
742
|
+
|
743
|
+
}));
|
744
|
+
|
745
|
+
supportsLoadAndErrorEvents = ('onload' in xhr) && ('onerror' in xhr);
|
746
|
+
xhr.onload = function() { done(); };
|
747
|
+
xhr.onerror = done;
|
748
|
+
xhr.onabort = function() { done(); };
|
749
|
+
|
750
|
+
// We'd rather use `onload`, `onerror`, and `onabort` since they're the
|
751
|
+
// only way to reliably detect successes and failures but, if they
|
752
|
+
// aren't available, we fall back to using `onreadystatechange`.
|
753
|
+
xhr.onreadystatechange = function() {
|
754
|
+
if (xhr.readyState !== 4) return;
|
755
|
+
|
756
|
+
if (req.aborted) return done();
|
757
|
+
|
758
|
+
if (!supportsLoadAndErrorEvents) {
|
759
|
+
// Assume a status of 0 is an error. This could be a false
|
760
|
+
// positive, but there's no way to tell when using
|
761
|
+
// `onreadystatechange` ):
|
762
|
+
// See matthewwithanm/react-inlinesvg#10.
|
763
|
+
|
764
|
+
// Some browsers don't like you reading XHR properties when the
|
765
|
+
// XHR has been aborted. In case we've gotten here as a result
|
766
|
+
// of that (either our calling `about()` in the timeout handler
|
767
|
+
// or the user calling it directly even though they shouldn't),
|
768
|
+
// be careful about accessing it.
|
769
|
+
var status;
|
770
|
+
try {
|
771
|
+
status = xhr.status;
|
772
|
+
} catch (err) {}
|
773
|
+
var err = status === 0 ? new Error('Internal XHR Error') : null;
|
774
|
+
return done(err);
|
775
|
+
}
|
776
|
+
};
|
777
|
+
|
778
|
+
// IE sometimes fails if you don't specify every handler.
|
779
|
+
// 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
|
780
|
+
xhr.ontimeout = function() { /* noop */ };
|
781
|
+
xhr.onprogress = function() { /* noop */ };
|
782
|
+
|
783
|
+
xhr.open(req.method, req.url);
|
784
|
+
|
785
|
+
if (req.timeout) {
|
786
|
+
// If we use the normal XHR timeout mechanism (`xhr.timeout` and
|
787
|
+
// `xhr.ontimeout`), `onreadystatechange` will be triggered before
|
788
|
+
// `ontimeout`. There's no way to recognize that it was triggered by
|
789
|
+
// a timeout, and we'd be unable to dispatch the right error.
|
790
|
+
timeoutId = setTimeout(function() {
|
791
|
+
req.timedOut = true;
|
792
|
+
done();
|
793
|
+
try {
|
794
|
+
xhr.abort();
|
795
|
+
} catch (err) {}
|
796
|
+
}, req.timeout);
|
797
|
+
}
|
798
|
+
|
799
|
+
for (k in req.headers) {
|
800
|
+
if (req.headers.hasOwnProperty(k)) {
|
801
|
+
xhr.setRequestHeader(k, req.headers[k]);
|
802
|
+
}
|
803
|
+
}
|
804
|
+
|
805
|
+
xhr.send(req.body);
|
806
|
+
|
807
|
+
return req;
|
808
|
+
}
|
809
|
+
|
810
|
+
var method,
|
811
|
+
methods = ['get', 'post', 'put', 'head', 'patch', 'delete'],
|
812
|
+
verb = function(method) {
|
813
|
+
return function(req, cb) {
|
814
|
+
req = new Request(req);
|
815
|
+
req.method = method;
|
816
|
+
return http(req, cb);
|
817
|
+
};
|
818
|
+
};
|
819
|
+
for (i = 0; i < methods.length; i++) {
|
820
|
+
method = methods[i];
|
821
|
+
http[method] = verb(method);
|
822
|
+
}
|
823
|
+
|
824
|
+
http.plugins = function() {
|
825
|
+
return plugins;
|
826
|
+
};
|
827
|
+
|
828
|
+
http.defaults = function(newValues) {
|
829
|
+
if (newValues) {
|
830
|
+
return factory(extend(defaults, newValues), plugins);
|
831
|
+
}
|
832
|
+
return defaults;
|
833
|
+
};
|
834
|
+
|
835
|
+
http.use = function() {
|
836
|
+
var newPlugins = Array.prototype.slice.call(arguments, 0);
|
837
|
+
return factory(defaults, plugins.concat(newPlugins));
|
838
|
+
};
|
839
|
+
|
840
|
+
http.bare = function() {
|
841
|
+
return factory();
|
842
|
+
};
|
843
|
+
|
844
|
+
http.Request = Request;
|
845
|
+
http.Response = Response;
|
846
|
+
http.RequestError = RequestError;
|
847
|
+
|
848
|
+
return http;
|
849
|
+
}
|
850
|
+
|
851
|
+
module.exports = factory({}, [cleanURL]);
|
852
|
+
|
853
|
+
/**
|
854
|
+
* Analyze the request to see if it represents an error. If so, return it! An
|
855
|
+
* original error object can be passed as a hint.
|
856
|
+
*/
|
857
|
+
function getError(req, err) {
|
858
|
+
if (req.aborted) return createError('Request aborted', req, {name: 'Abort'});
|
859
|
+
|
860
|
+
if (req.timedOut) return createError('Request timeout', req, {name: 'Timeout'});
|
861
|
+
|
862
|
+
var xhr = req.xhr;
|
863
|
+
var type = Math.floor(xhr.status / 100);
|
864
|
+
|
865
|
+
var kind;
|
866
|
+
switch (type) {
|
867
|
+
case 0:
|
868
|
+
case 2:
|
869
|
+
// These don't represent errors unless the function was passed an
|
870
|
+
// error object explicitly.
|
871
|
+
if (!err) return;
|
872
|
+
return createError(err.message, req);
|
873
|
+
case 4:
|
874
|
+
// Sometimes 4XX statuses aren't errors.
|
875
|
+
if (xhr.status === 404 && !req.errorOn404) return;
|
876
|
+
kind = 'Client';
|
877
|
+
break;
|
878
|
+
case 5:
|
879
|
+
kind = 'Server';
|
880
|
+
break;
|
881
|
+
default:
|
882
|
+
kind = 'HTTP';
|
883
|
+
}
|
884
|
+
var msg = kind + ' Error: ' +
|
885
|
+
'The server returned a status of ' + xhr.status +
|
886
|
+
' for the request "' +
|
887
|
+
req.method.toUpperCase() + ' ' + req.url + '"';
|
888
|
+
return createError(msg, req);
|
889
|
+
}
|
890
|
+
});
|
891
|
+
|
892
|
+
var httpplease = interopDefault(index);
|
893
|
+
|
894
|
+
/*
|
895
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
896
|
+
|
897
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
898
|
+
you may not use this file except in compliance with the License.
|
899
|
+
You may obtain a copy of the License at
|
900
|
+
|
901
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
902
|
+
|
903
|
+
Unless required by applicable law or agreed to in writing, software
|
904
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
905
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
906
|
+
See the License for the specific language governing permissions and
|
907
|
+
limitations under the License.
|
908
|
+
*/
|
909
|
+
|
910
|
+
var request = httpplease.use(json$1);
|
911
|
+
|
912
|
+
function send(method, url, args) {
|
913
|
+
return new Promise(function (resolve, reject) {
|
914
|
+
request({ method: method, url: url, body: args }, function (err, res) {
|
915
|
+
if (err) {
|
916
|
+
var error = err && err.body && err.body.meta && err.body.meta.errorMessage ? new Error(err.body.meta.errorMessage) : err;
|
917
|
+
error.status = err.status;
|
918
|
+
reject(error);
|
919
|
+
} else {
|
920
|
+
resolve(res);
|
921
|
+
}
|
922
|
+
});
|
923
|
+
});
|
924
|
+
}
|
925
|
+
|
926
|
+
function get(url) {
|
927
|
+
return send('GET', url);
|
928
|
+
}
|
929
|
+
|
930
|
+
function post(url, args) {
|
931
|
+
return send('POST', url, args);
|
932
|
+
}
|
933
|
+
|
934
|
+
var asyncGenerator = function () {
|
935
|
+
function AwaitValue(value) {
|
936
|
+
this.value = value;
|
937
|
+
}
|
938
|
+
|
939
|
+
function AsyncGenerator(gen) {
|
940
|
+
var front, back;
|
941
|
+
|
942
|
+
function send(key, arg) {
|
943
|
+
return new Promise(function (resolve, reject) {
|
944
|
+
var request = {
|
945
|
+
key: key,
|
946
|
+
arg: arg,
|
947
|
+
resolve: resolve,
|
948
|
+
reject: reject,
|
949
|
+
next: null
|
950
|
+
};
|
951
|
+
|
952
|
+
if (back) {
|
953
|
+
back = back.next = request;
|
954
|
+
} else {
|
955
|
+
front = back = request;
|
956
|
+
resume(key, arg);
|
957
|
+
}
|
958
|
+
});
|
959
|
+
}
|
960
|
+
|
961
|
+
function resume(key, arg) {
|
962
|
+
try {
|
963
|
+
var result = gen[key](arg);
|
964
|
+
var value = result.value;
|
965
|
+
|
966
|
+
if (value instanceof AwaitValue) {
|
967
|
+
Promise.resolve(value.value).then(function (arg) {
|
968
|
+
resume("next", arg);
|
969
|
+
}, function (arg) {
|
970
|
+
resume("throw", arg);
|
971
|
+
});
|
972
|
+
} else {
|
973
|
+
settle(result.done ? "return" : "normal", result.value);
|
974
|
+
}
|
975
|
+
} catch (err) {
|
976
|
+
settle("throw", err);
|
977
|
+
}
|
978
|
+
}
|
979
|
+
|
980
|
+
function settle(type, value) {
|
981
|
+
switch (type) {
|
982
|
+
case "return":
|
983
|
+
front.resolve({
|
984
|
+
value: value,
|
985
|
+
done: true
|
986
|
+
});
|
987
|
+
break;
|
988
|
+
|
989
|
+
case "throw":
|
990
|
+
front.reject(value);
|
991
|
+
break;
|
992
|
+
|
993
|
+
default:
|
994
|
+
front.resolve({
|
995
|
+
value: value,
|
996
|
+
done: false
|
997
|
+
});
|
998
|
+
break;
|
999
|
+
}
|
1000
|
+
|
1001
|
+
front = front.next;
|
1002
|
+
|
1003
|
+
if (front) {
|
1004
|
+
resume(front.key, front.arg);
|
1005
|
+
} else {
|
1006
|
+
back = null;
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
this._invoke = send;
|
1011
|
+
|
1012
|
+
if (typeof gen.return !== "function") {
|
1013
|
+
this.return = undefined;
|
1014
|
+
}
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
if (typeof Symbol === "function" && Symbol.asyncIterator) {
|
1018
|
+
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
|
1019
|
+
return this;
|
1020
|
+
};
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
AsyncGenerator.prototype.next = function (arg) {
|
1024
|
+
return this._invoke("next", arg);
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
AsyncGenerator.prototype.throw = function (arg) {
|
1028
|
+
return this._invoke("throw", arg);
|
1029
|
+
};
|
1030
|
+
|
1031
|
+
AsyncGenerator.prototype.return = function (arg) {
|
1032
|
+
return this._invoke("return", arg);
|
1033
|
+
};
|
1034
|
+
|
1035
|
+
return {
|
1036
|
+
wrap: function (fn) {
|
1037
|
+
return function () {
|
1038
|
+
return new AsyncGenerator(fn.apply(this, arguments));
|
1039
|
+
};
|
1040
|
+
},
|
1041
|
+
await: function (value) {
|
1042
|
+
return new AwaitValue(value);
|
1043
|
+
}
|
1044
|
+
};
|
1045
|
+
}();
|
1046
|
+
|
1047
|
+
var toConsumableArray = function (arr) {
|
1048
|
+
if (Array.isArray(arr)) {
|
1049
|
+
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
1050
|
+
|
1051
|
+
return arr2;
|
1052
|
+
} else {
|
1053
|
+
return Array.from(arr);
|
1054
|
+
}
|
1055
|
+
};
|
1056
|
+
|
1057
|
+
/*
|
1058
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1059
|
+
|
1060
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1061
|
+
you may not use this file except in compliance with the License.
|
1062
|
+
You may obtain a copy of the License at
|
1063
|
+
|
1064
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1065
|
+
|
1066
|
+
Unless required by applicable law or agreed to in writing, software
|
1067
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1068
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1069
|
+
See the License for the specific language governing permissions and
|
1070
|
+
limitations under the License.
|
1071
|
+
*/
|
1072
|
+
|
1073
|
+
var DEFAULT_BATCH_SIZE = 20;
|
1074
|
+
|
1075
|
+
function findSegments(agent) {
|
1076
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1077
|
+
|
1078
|
+
var options = Object.assign({}, opts);
|
1079
|
+
if (opts.limit === -1) {
|
1080
|
+
options.limit = options.batchSize || DEFAULT_BATCH_SIZE;
|
1081
|
+
delete options.batchSize;
|
1082
|
+
options.offset = 0;
|
1083
|
+
var segments = [];
|
1084
|
+
|
1085
|
+
return promiseWhile(function () {
|
1086
|
+
return segments.length === options.limit;
|
1087
|
+
}, function () {
|
1088
|
+
return findSegments(agent, options).then(function (newSegments) {
|
1089
|
+
segments.push.apply(segments, toConsumableArray(newSegments));
|
1090
|
+
options.offset += options.limit;
|
1091
|
+
});
|
1092
|
+
}).then(function () {
|
1093
|
+
return segments;
|
1094
|
+
});
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
return get(agent.url + '/segments' + makeQueryString(opts)).then(function (res) {
|
1098
|
+
return res.body.map(function (obj) {
|
1099
|
+
return segmentify(agent, obj);
|
1100
|
+
});
|
1101
|
+
});
|
1102
|
+
}
|
1103
|
+
|
1104
|
+
/*
|
1105
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1106
|
+
|
1107
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1108
|
+
you may not use this file except in compliance with the License.
|
1109
|
+
You may obtain a copy of the License at
|
1110
|
+
|
1111
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1112
|
+
|
1113
|
+
Unless required by applicable law or agreed to in writing, software
|
1114
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1115
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1116
|
+
See the License for the specific language governing permissions and
|
1117
|
+
limitations under the License.
|
1118
|
+
*/
|
1119
|
+
|
1120
|
+
function getBranches(agent, prevLinkHash) {
|
1121
|
+
var tags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
1122
|
+
|
1123
|
+
deprecated('Agent#getBranches(agent, prevLinkHash, tags = [])', 'Agent#findSegments(agent, filter)');
|
1124
|
+
|
1125
|
+
return findSegments(agent, { prevLinkHash: prevLinkHash, tags: tags });
|
1126
|
+
}
|
1127
|
+
|
1128
|
+
/*
|
1129
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1130
|
+
|
1131
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1132
|
+
you may not use this file except in compliance with the License.
|
1133
|
+
You may obtain a copy of the License at
|
1134
|
+
|
1135
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1136
|
+
|
1137
|
+
Unless required by applicable law or agreed to in writing, software
|
1138
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1140
|
+
See the License for the specific language governing permissions and
|
1141
|
+
limitations under the License.
|
1142
|
+
*/
|
1143
|
+
|
1144
|
+
function segmentify(agent, obj) {
|
1145
|
+
Object.keys(agent.agentInfo.actions).filter(function (key) {
|
1146
|
+
return ['init'].indexOf(key) < 0;
|
1147
|
+
}).forEach(function (key) {
|
1148
|
+
/*eslint-disable*/
|
1149
|
+
obj[key] = function () {
|
1150
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
1151
|
+
args[_key] = arguments[_key];
|
1152
|
+
}
|
1153
|
+
|
1154
|
+
return post(agent.url + '/segments/' + obj.meta.linkHash + '/' + key, args).then(function (res) {
|
1155
|
+
return segmentify(agent, res.body);
|
1156
|
+
});
|
1157
|
+
};
|
1158
|
+
});
|
1159
|
+
|
1160
|
+
/*eslint-disable*/
|
1161
|
+
obj.getPrev = function () {
|
1162
|
+
/*eslint-enable*/
|
1163
|
+
if (obj.link.meta.prevLinkHash) {
|
1164
|
+
return agent.getSegment(obj.link.meta.prevLinkHash);
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
return Promise.resolve(null);
|
1168
|
+
};
|
1169
|
+
|
1170
|
+
// Deprecated.
|
1171
|
+
/*eslint-disable*/
|
1172
|
+
obj.load = function () {
|
1173
|
+
/*eslint-enable*/
|
1174
|
+
deprecated('segment#load()');
|
1175
|
+
return Promise.resolve(segmentify(agent, {
|
1176
|
+
link: JSON.parse(JSON.stringify(obj.link)),
|
1177
|
+
meta: JSON.parse(JSON.stringify(obj.meta))
|
1178
|
+
}));
|
1179
|
+
};
|
1180
|
+
|
1181
|
+
// Deprecated.
|
1182
|
+
/*eslint-disable*/
|
1183
|
+
obj.getBranches = function () {
|
1184
|
+
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
1185
|
+
args[_key2] = arguments[_key2];
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
/*eslint-enable*/
|
1189
|
+
return getBranches.apply(undefined, [agent, obj.meta.linkHash].concat(args));
|
1190
|
+
};
|
1191
|
+
|
1192
|
+
return obj;
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
/*
|
1196
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1197
|
+
|
1198
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1199
|
+
you may not use this file except in compliance with the License.
|
1200
|
+
You may obtain a copy of the License at
|
1201
|
+
|
1202
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1203
|
+
|
1204
|
+
Unless required by applicable law or agreed to in writing, software
|
1205
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1206
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1207
|
+
See the License for the specific language governing permissions and
|
1208
|
+
limitations under the License.
|
1209
|
+
*/
|
1210
|
+
|
1211
|
+
function createMap(agent) {
|
1212
|
+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
1213
|
+
args[_key - 1] = arguments[_key];
|
1214
|
+
}
|
1215
|
+
|
1216
|
+
return post(agent.url + '/segments', args).then(function (res) {
|
1217
|
+
return segmentify(agent, res.body);
|
1218
|
+
});
|
1219
|
+
}
|
1220
|
+
|
1221
|
+
/*
|
1222
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1223
|
+
|
1224
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1225
|
+
you may not use this file except in compliance with the License.
|
1226
|
+
You may obtain a copy of the License at
|
1227
|
+
|
1228
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1229
|
+
|
1230
|
+
Unless required by applicable law or agreed to in writing, software
|
1231
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1232
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1233
|
+
See the License for the specific language governing permissions and
|
1234
|
+
limitations under the License.
|
1235
|
+
*/
|
1236
|
+
|
1237
|
+
function getSegment(agent, linkHash) {
|
1238
|
+
return get(agent.url + '/segments/' + linkHash).then(function (res) {
|
1239
|
+
return segmentify(agent, res.body);
|
1240
|
+
});
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
/*
|
1244
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1245
|
+
|
1246
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1247
|
+
you may not use this file except in compliance with the License.
|
1248
|
+
You may obtain a copy of the License at
|
1249
|
+
|
1250
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1251
|
+
|
1252
|
+
Unless required by applicable law or agreed to in writing, software
|
1253
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1254
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1255
|
+
See the License for the specific language governing permissions and
|
1256
|
+
limitations under the License.
|
1257
|
+
*/
|
1258
|
+
|
1259
|
+
function getMapIds(agent) {
|
1260
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1261
|
+
|
1262
|
+
return get(agent.url + '/maps' + makeQueryString(opts)).then(function (res) {
|
1263
|
+
return res.body;
|
1264
|
+
});
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
/*
|
1268
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1269
|
+
|
1270
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1271
|
+
you may not use this file except in compliance with the License.
|
1272
|
+
You may obtain a copy of the License at
|
1273
|
+
|
1274
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1275
|
+
|
1276
|
+
Unless required by applicable law or agreed to in writing, software
|
1277
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1278
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1279
|
+
See the License for the specific language governing permissions and
|
1280
|
+
limitations under the License.
|
1281
|
+
*/
|
1282
|
+
|
1283
|
+
function getLink(agent, hash) {
|
1284
|
+
deprecated('Agent#getLink(agent, hash)', 'Agent#getSegment(agent, hash)');
|
1285
|
+
|
1286
|
+
return getSegment(agent, hash);
|
1287
|
+
}
|
1288
|
+
|
1289
|
+
/*
|
1290
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1291
|
+
|
1292
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1293
|
+
you may not use this file except in compliance with the License.
|
1294
|
+
You may obtain a copy of the License at
|
1295
|
+
|
1296
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1297
|
+
|
1298
|
+
Unless required by applicable law or agreed to in writing, software
|
1299
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1300
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1301
|
+
See the License for the specific language governing permissions and
|
1302
|
+
limitations under the License.
|
1303
|
+
*/
|
1304
|
+
|
1305
|
+
function getMap(agent, mapId) {
|
1306
|
+
var tags = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
1307
|
+
|
1308
|
+
deprecated('getMap(agent, mapId, tags = [])', 'findSegments(agent, filter)');
|
1309
|
+
|
1310
|
+
return findSegments(agent, { mapId: mapId, tags: tags });
|
1311
|
+
}
|
1312
|
+
|
1313
|
+
/*
|
1314
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1315
|
+
|
1316
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1317
|
+
you may not use this file except in compliance with the License.
|
1318
|
+
You may obtain a copy of the License at
|
1319
|
+
|
1320
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1321
|
+
|
1322
|
+
Unless required by applicable law or agreed to in writing, software
|
1323
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1324
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1325
|
+
See the License for the specific language governing permissions and
|
1326
|
+
limitations under the License.
|
1327
|
+
*/
|
1328
|
+
|
1329
|
+
// Deprecated.
|
1330
|
+
function getAgent(url) {
|
1331
|
+
return get(url).then(function (res) {
|
1332
|
+
var agent = res.body;
|
1333
|
+
|
1334
|
+
agent.url = url;
|
1335
|
+
agent.createMap = createMap.bind(null, agent);
|
1336
|
+
agent.getSegment = getSegment.bind(null, agent);
|
1337
|
+
agent.findSegments = findSegments.bind(null, agent);
|
1338
|
+
agent.getMapIds = getMapIds.bind(null, agent);
|
1339
|
+
|
1340
|
+
// Deprecated.
|
1341
|
+
agent.getBranches = getBranches.bind(null, agent);
|
1342
|
+
agent.getLink = getLink.bind(null, agent);
|
1343
|
+
agent.getMap = getMap.bind(null, agent);
|
1344
|
+
|
1345
|
+
return agent;
|
1346
|
+
});
|
1347
|
+
}
|
1348
|
+
|
1349
|
+
/*
|
1350
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1351
|
+
|
1352
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1353
|
+
you may not use this file except in compliance with the License.
|
1354
|
+
You may obtain a copy of the License at
|
1355
|
+
|
1356
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1357
|
+
|
1358
|
+
Unless required by applicable law or agreed to in writing, software
|
1359
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1360
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1361
|
+
See the License for the specific language governing permissions and
|
1362
|
+
limitations under the License.
|
1363
|
+
*/
|
1364
|
+
|
1365
|
+
function fromSegment(obj) {
|
1366
|
+
return getAgent(obj.meta.agentUrl || obj.meta.applicationLocation).then(function (agent) {
|
1367
|
+
var segment = segmentify(agent, obj);
|
1368
|
+
return { agent: agent, segment: segment };
|
1369
|
+
});
|
1370
|
+
}
|
1371
|
+
|
1372
|
+
/*
|
1373
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1374
|
+
|
1375
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1376
|
+
you may not use this file except in compliance with the License.
|
1377
|
+
You may obtain a copy of the License at
|
1378
|
+
|
1379
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1380
|
+
|
1381
|
+
Unless required by applicable law or agreed to in writing, software
|
1382
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1383
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1384
|
+
See the License for the specific language governing permissions and
|
1385
|
+
limitations under the License.
|
1386
|
+
*/
|
1387
|
+
|
1388
|
+
// Deprecated.
|
1389
|
+
var config = {
|
1390
|
+
applicationUrl: 'https://%s.stratumn.rocks'
|
1391
|
+
};
|
1392
|
+
|
1393
|
+
/*
|
1394
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1395
|
+
|
1396
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1397
|
+
you may not use this file except in compliance with the License.
|
1398
|
+
You may obtain a copy of the License at
|
1399
|
+
|
1400
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1401
|
+
|
1402
|
+
Unless required by applicable law or agreed to in writing, software
|
1403
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1404
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1405
|
+
See the License for the specific language governing permissions and
|
1406
|
+
limitations under the License.
|
1407
|
+
*/
|
1408
|
+
|
1409
|
+
function getApplication(name, url) {
|
1410
|
+
deprecated('getApplication(name, url)', 'getAgent(url)');
|
1411
|
+
|
1412
|
+
return getAgent(url || config.applicationUrl.replace('%s', name));
|
1413
|
+
}
|
1414
|
+
|
1415
|
+
/*
|
1416
|
+
Copyright 2017 Stratumn SAS. All rights reserved.
|
1417
|
+
|
1418
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
1419
|
+
you may not use this file except in compliance with the License.
|
1420
|
+
You may obtain a copy of the License at
|
1421
|
+
|
1422
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
1423
|
+
|
1424
|
+
Unless required by applicable law or agreed to in writing, software
|
1425
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
1426
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
1427
|
+
See the License for the specific language governing permissions and
|
1428
|
+
limitations under the License.
|
1429
|
+
*/
|
1430
|
+
|
1431
|
+
function loadLink(obj) {
|
1432
|
+
deprecated('loadLink(obj)', 'fromSegment(obj)');
|
1433
|
+
|
1434
|
+
return fromSegment(obj).then(function (_ref) {
|
1435
|
+
var segment = _ref.segment;
|
1436
|
+
return segment;
|
1437
|
+
});
|
1438
|
+
}
|
1439
|
+
|
1440
|
+
exports.getAgent = getAgent;
|
1441
|
+
exports.fromSegment = fromSegment;
|
1442
|
+
exports.getApplication = getApplication;
|
1443
|
+
exports.loadLink = loadLink;
|
1444
|
+
exports.config = config;
|
1445
|
+
|
1446
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
1447
|
+
|
1448
|
+
})));
|
1449
|
+
//# sourceMappingURL=stratumn-agent-client.js.map
|