{"version":3,"file":null,"sources":["../src/deprecated.js","../src/makeQueryString.js","../src/promiseWhile.js","../src/request.js","../src/findSegments.js","../src/getBranches.js","../src/segmentify.js","../src/createMap.js","../src/getSegment.js","../src/getMapIds.js","../src/getLink.js","../src/getMap.js","../src/getAgent.js","../src/fromSegment.js","../src/getApplication.js","../src/loadLink.js","../node_modules/setimmediate/setImmediate.js","../node_modules/httpplease/plugins/jsonrequest.js","../node_modules/httpplease/plugins/jsonresponse.js","../node_modules/httpplease/plugins/json.js","../node_modules/httpplease/plugins/cleanurl.js","../node_modules/httpplease/lib/xhr-browser.js","../node_modules/httpplease/lib/utils/delay.js","../node_modules/httpplease/lib/request.js","../node_modules/xtend/index.js","../node_modules/httpplease/lib/utils/extractResponseProps.js","../node_modules/httpplease/lib/response.js","../node_modules/httpplease/lib/error.js","../node_modules/httpplease/lib/utils/once.js","../node_modules/httpplease/lib/index.js","../src/config.js"],"sourcesContent":["/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nexport default function deprecated(oldFunc, newFunc) {\n if (!newFunc) {\n console.warn(`WARNING: ${oldFunc} is deprecated.`);\n } else {\n console.warn(`WARNING: ${oldFunc} is deprecated. Please use ${newFunc} instead.`);\n }\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\n/**\n * Makes a query string.\n * @param {object} obj - an object of keys\n * @returns {string} a query string\n */\nexport default function makeQueryString(obj) {\n const parts = Object.keys(obj).reduce((curr, key) => {\n const val = Array.isArray(obj[key]) ? obj[key].join('+') : obj[key];\n curr.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`);\n return curr;\n }, []);\n\n if (parts.length) {\n return `?${parts.join('&')}`;\n }\n\n return '';\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport 'setimmediate';\n\n/**\n * Calls a function that returns a Promise until a condition is reached\n * @param {function} condition - while condition is true body will keep being called\n * @param {function} body - a function that is repeatedly called while condition is true\n * @returns {Promise} a Promise that resolves when the condition is no longer true\n */\nexport default function promiseWhile(condition, body) {\n return new Promise((resolve, reject) => {\n function loop() {\n body()\n .then(() => {\n // When the result of calling `condition` is no longer true, we are\n // done.\n if (!condition()) {\n resolve();\n } else {\n loop();\n }\n })\n .catch(reject);\n }\n\n // Start running the loop in the next tick so that this function is\n // completely async. It would be unexpected if `body` was called\n // synchronously the first time.\n setImmediate(loop);\n });\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport json from 'httpplease/plugins/json';\nimport httpplease from 'httpplease';\n\nconst request = httpplease.use(json);\n\nfunction send(method, url, args) {\n return new Promise((resolve, reject) => {\n request({ method, url, body: args }, (err, res) => {\n if (err) {\n const error = (err && err.body && err.body.meta && err.body.meta.errorMessage)\n ? new Error(err.body.meta.errorMessage)\n : err;\n error.status = err.status;\n reject(error);\n } else {\n resolve(res);\n }\n });\n });\n}\n\nexport function get(url) {\n return send('GET', url);\n}\n\nexport function post(url, args) {\n return send('POST', url, args);\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport segmentify from './segmentify';\nimport makeQueryString from './makeQueryString';\nimport promiseWhile from './promiseWhile';\nimport { get } from './request';\n\nconst DEFAULT_BATCH_SIZE = 20;\n\nexport default function findSegments(agent, opts = {}) {\n const options = Object.assign({}, opts);\n if (opts.limit === -1) {\n options.limit = options.batchSize || DEFAULT_BATCH_SIZE;\n delete options.batchSize;\n options.offset = 0;\n const segments = [];\n\n return promiseWhile(\n () => segments.length === options.limit,\n () => findSegments(agent, options)\n .then(newSegments => {\n segments.push(...newSegments);\n options.offset += options.limit;\n })\n ).then(() => segments);\n }\n\n return get(`${agent.url}/segments${makeQueryString(opts)}`)\n .then(res => res.body.map(obj => segmentify(agent, obj)));\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport findSegments from './findSegments';\nimport deprecated from './deprecated';\n\nexport default function getBranches(agent, prevLinkHash, tags = []) {\n deprecated(\n 'Agent#getBranches(agent, prevLinkHash, tags = [])',\n 'Agent#findSegments(agent, filter)'\n );\n\n return findSegments(agent, { prevLinkHash, tags });\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport deprecated from './deprecated';\nimport getBranches from './getBranches';\nimport { post } from './request';\n\nexport default function segmentify(agent, obj) {\n Object\n .keys(agent.agentInfo.actions)\n .filter(key => ['init'].indexOf(key) < 0)\n .forEach(key => {\n /*eslint-disable*/\n obj[key] = (...args) =>\n post(`${agent.url}/segments/${obj.meta.linkHash}/${key}`, args)\n .then(res => segmentify(agent, res.body))\n });\n\n /*eslint-disable*/\n obj.getPrev = () => {\n /*eslint-enable*/\n if (obj.link.meta.prevLinkHash) {\n return agent.getSegment(obj.link.meta.prevLinkHash);\n }\n\n return Promise.resolve(null);\n };\n\n // Deprecated.\n /*eslint-disable*/\n obj.load = () => {\n /*eslint-enable*/\n deprecated('segment#load()');\n return Promise.resolve(segmentify(agent, {\n link: JSON.parse(JSON.stringify(obj.link)),\n meta: JSON.parse(JSON.stringify(obj.meta))\n }));\n };\n\n // Deprecated.\n /*eslint-disable*/\n obj.getBranches = (...args) => {\n /*eslint-enable*/\n return getBranches(agent, obj.meta.linkHash, ...args);\n };\n\n return obj;\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport segmentify from './segmentify';\nimport { post } from './request';\n\nexport default function createMap(agent, ...args) {\n return post(`${agent.url}/segments`, args)\n .then(res => segmentify(agent, res.body));\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport segmentify from './segmentify';\nimport { get } from './request';\n\nexport default function getSegment(agent, linkHash) {\n return get(`${agent.url}/segments/${linkHash}`)\n .then(res => segmentify(agent, res.body));\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport makeQueryString from './makeQueryString';\nimport { get } from './request';\n\nexport default function getMapIds(agent, opts = {}) {\n return get(`${agent.url}/maps${makeQueryString(opts)}`)\n .then(res => res.body);\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport getSegment from './getSegment';\nimport deprecated from './deprecated';\n\nexport default function getLink(agent, hash) {\n deprecated('Agent#getLink(agent, hash)', 'Agent#getSegment(agent, hash)');\n\n return getSegment(agent, hash);\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport findSegments from './findSegments';\nimport deprecated from './deprecated';\n\nexport default function getMap(agent, mapId, tags = []) {\n deprecated('getMap(agent, mapId, tags = [])', 'findSegments(agent, filter)');\n\n return findSegments(agent, { mapId, tags });\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport createMap from './createMap';\nimport getSegment from './getSegment';\nimport findSegments from './findSegments';\nimport getMapIds from './getMapIds';\nimport { get } from './request';\n\n// Deprecated.\nimport getBranches from './getBranches';\nimport getLink from './getLink';\nimport getMap from './getMap';\n\nexport default function getAgent(url) {\n return get(url)\n .then(res => {\n const agent = res.body;\n\n agent.url = url;\n agent.createMap = createMap.bind(null, agent);\n agent.getSegment = getSegment.bind(null, agent);\n agent.findSegments = findSegments.bind(null, agent);\n agent.getMapIds = getMapIds.bind(null, agent);\n\n // Deprecated.\n agent.getBranches = getBranches.bind(null, agent);\n agent.getLink = getLink.bind(null, agent);\n agent.getMap = getMap.bind(null, agent);\n\n return agent;\n });\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport getAgent from './getAgent';\nimport segmentify from './segmentify';\n\nexport default function fromSegment(obj) {\n return getAgent(obj.meta.agentUrl || obj.meta.applicationLocation)\n .then(agent => {\n const segment = segmentify(agent, obj);\n return { agent, segment };\n });\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport getAgent from './getAgent';\nimport deprecated from './deprecated';\nimport config from './config';\n\nexport default function getApplication(name, url) {\n deprecated('getApplication(name, url)', 'getAgent(url)');\n\n return getAgent(url || config.applicationUrl.replace('%s', name));\n}\n","/*\n Copyright 2017 Stratumn SAS. All rights reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nimport fromSegment from './fromSegment';\nimport deprecated from './deprecated';\n\nexport default function loadLink(obj) {\n deprecated('loadLink(obj)', 'fromSegment(obj)');\n\n return fromSegment(obj)\n .then(({ segment }) => segment);\n}\n","(function (global, undefined) {\n \"use strict\";\n\n if (global.setImmediate) {\n return;\n }\n\n var nextHandle = 1; // Spec says greater than zero\n var tasksByHandle = {};\n var currentlyRunningATask = false;\n var doc = global.document;\n var registerImmediate;\n\n function setImmediate(callback) {\n // Callback can either be a function or a string\n if (typeof callback !== \"function\") {\n callback = new Function(\"\" + callback);\n }\n // Copy function arguments\n var args = new Array(arguments.length - 1);\n for (var i = 0; i < args.length; i++) {\n args[i] = arguments[i + 1];\n }\n // Store and register the task\n var task = { callback: callback, args: args };\n tasksByHandle[nextHandle] = task;\n registerImmediate(nextHandle);\n return nextHandle++;\n }\n\n function clearImmediate(handle) {\n delete tasksByHandle[handle];\n }\n\n function run(task) {\n var callback = task.callback;\n var args = task.args;\n switch (args.length) {\n case 0:\n callback();\n break;\n case 1:\n callback(args[0]);\n break;\n case 2:\n callback(args[0], args[1]);\n break;\n case 3:\n callback(args[0], args[1], args[2]);\n break;\n default:\n callback.apply(undefined, args);\n break;\n }\n }\n\n function runIfPresent(handle) {\n // From the spec: \"Wait until any invocations of this algorithm started before this one have completed.\"\n // So if we're currently running a task, we'll need to delay this invocation.\n if (currentlyRunningATask) {\n // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a\n // \"too much recursion\" error.\n setTimeout(runIfPresent, 0, handle);\n } else {\n var task = tasksByHandle[handle];\n if (task) {\n currentlyRunningATask = true;\n try {\n run(task);\n } finally {\n clearImmediate(handle);\n currentlyRunningATask = false;\n }\n }\n }\n }\n\n function installNextTickImplementation() {\n registerImmediate = function(handle) {\n process.nextTick(function () { runIfPresent(handle); });\n };\n }\n\n function canUsePostMessage() {\n // The test against `importScripts` prevents this implementation from being installed inside a web worker,\n // where `global.postMessage` means something completely different and can't be used for this purpose.\n if (global.postMessage && !global.importScripts) {\n var postMessageIsAsynchronous = true;\n var oldOnMessage = global.onmessage;\n global.onmessage = function() {\n postMessageIsAsynchronous = false;\n };\n global.postMessage(\"\", \"*\");\n global.onmessage = oldOnMessage;\n return postMessageIsAsynchronous;\n }\n }\n\n function installPostMessageImplementation() {\n // Installs an event handler on `global` for the `message` event: see\n // * https://developer.mozilla.org/en/DOM/window.postMessage\n // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages\n\n var messagePrefix = \"setImmediate$\" + Math.random() + \"$\";\n var onGlobalMessage = function(event) {\n if (event.source === global &&\n typeof event.data === \"string\" &&\n event.data.indexOf(messagePrefix) === 0) {\n runIfPresent(+event.data.slice(messagePrefix.length));\n }\n };\n\n if (global.addEventListener) {\n global.addEventListener(\"message\", onGlobalMessage, false);\n } else {\n global.attachEvent(\"onmessage\", onGlobalMessage);\n }\n\n registerImmediate = function(handle) {\n global.postMessage(messagePrefix + handle, \"*\");\n };\n }\n\n function installMessageChannelImplementation() {\n var channel = new MessageChannel();\n channel.port1.onmessage = function(event) {\n var handle = event.data;\n runIfPresent(handle);\n };\n\n registerImmediate = function(handle) {\n channel.port2.postMessage(handle);\n };\n }\n\n function installReadyStateChangeImplementation() {\n var html = doc.documentElement;\n registerImmediate = function(handle) {\n // Create a