@serverless/fdk
Advanced tools
Comparing version 0.4.0 to 0.5.0
# Development | ||
IMPORTANT: While the library is supposed to work with Node 6 you will need to Node 8 or higher to run the tests. | ||
## Setup | ||
``` | ||
@@ -7,2 +11,4 @@ npm install | ||
## Running the tests | ||
```js | ||
@@ -12,2 +18,14 @@ npm run test | ||
Running them in watch mode | ||
```js | ||
npm run test -- --watch | ||
``` | ||
## Running the browser tests | ||
```js | ||
npm run test:browser | ||
``` | ||
# Design Decision | ||
@@ -14,0 +32,0 @@ |
@@ -1,1 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.fdk={})}(this,function(t){"use strict";function e(t,e){return e={exports:{}},t(e,e.exports),e.exports}function r(t){return decodeURIComponent(t.replace(/\+/g," "))}function n(t){var e,r={},n=void 0===(t=t||s.location||{})?"undefined":a(t);if("blob:"===t.protocol)r=new u(unescape(t.pathname),{});else if("string"===n){r=new u(t,{});for(e in j)delete r[e]}else if("object"===n){for(e in t)e in j||(r[e]=t[e]);void 0===r.slashes&&(r.slashes=v.test(t.href))}return r}function o(t){var e=w.exec(t);return{protocol:e[1]?e[1].toLowerCase():"",slashes:!!e[2],rest:e[3]}}function i(t,e){for(var r=(e||"/").split("/").slice(0,-1).concat(t.split("/")),n=r.length,o=r[n-1],i=!1,u=0;n--;)"."===r[n]?r.splice(n,1):".."===r[n]?(r.splice(n,1),u++):u&&(0===n&&(i=!0),r.splice(n,1),u--);return i&&r.unshift(""),"."!==o&&".."!==o||r.push(""),r.join("/")}function u(t,e,r){if(!(this instanceof u))return new u(t,e,r);var s,c,f,h,l,p,d=g.slice(),b=void 0===e?"undefined":a(e),w=this,v=0;for("object"!==b&&"string"!==b&&(r=e,e=null),r&&"function"!=typeof r&&(r=m.parse),e=n(e),s=!(c=o(t||"")).protocol&&!c.slashes,w.slashes=c.slashes||s&&e.slashes,w.protocol=c.protocol||e.protocol||"",t=c.rest,c.slashes||(d[2]=[/(.*)/,"pathname"]);v<d.length;v++)f=(h=d[v])[0],p=h[1],f!==f?w[p]=t:"string"==typeof f?~(l=t.indexOf(f))&&("number"==typeof h[2]?(w[p]=t.slice(0,l),t=t.slice(l+h[2])):(w[p]=t.slice(l),t=t.slice(0,l))):(l=f.exec(t))&&(w[p]=l[1],t=t.slice(0,l.index)),w[p]=w[p]||(s&&h[3]?e[p]||"":""),h[4]&&(w[p]=w[p].toLowerCase());r&&(w.query=r(w.query)),s&&e.slashes&&"/"!==w.pathname.charAt(0)&&(""!==w.pathname||""!==e.pathname)&&(w.pathname=i(w.pathname,e.pathname)),y(w.port,w.protocol)||(w.host=w.hostname,w.port=""),w.username=w.password="",w.auth&&(h=w.auth.split(":"),w.username=h[0]||"",w.password=h[1]||""),w.origin=w.protocol&&w.host&&"file:"!==w.protocol?w.protocol+"//"+w.host:"null",w.href=w.toString()}var s="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c=function(t){return null!=t&&"object"===(void 0===t?"undefined":a(t))&&!0===t["@@functional/placeholder"]},f=function(t){return function e(r){return 0===arguments.length||c(r)?e:t.apply(this,arguments)}},h=f(function(t){return null==t}),l=function(t){return function e(r,n){switch(arguments.length){case 0:return e;case 1:return c(r)?e:f(function(e){return t(r,e)});default:return c(r)&&c(n)?e:c(r)?f(function(e){return t(e,n)}):c(n)?f(function(e){return t(r,e)}):t(r,n)}}},p=function(t){return"[object String]"===Object.prototype.toString.call(t)},d=l(function(t,e){var r=t<0?e.length+t:t;return p(e)?e.charAt(r):e[r]})(-1),y=function(t,e){if(e=e.split(":")[0],!(t=+t))return!1;switch(e){case"http":case"ws":return 80!==t;case"https":case"wss":return 443!==t;case"ftp":return 21!==t;case"gopher":return 70!==t;case"file":return!1}return 0!==t},b=Object.prototype.hasOwnProperty,m={stringify:function(t,e){var r=[];"string"!=typeof(e=e||"")&&(e="?");for(var n in t)b.call(t,n)&&r.push(encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return r.length?e+r.join("&"):""},parse:function(t){for(var e,n=/([^=?&]+)=?([^&]*)/g,o={};e=n.exec(t);o[r(e[1])]=r(e[2]));return o}},w=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,v=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,g=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],j={hash:1,query:1};u.prototype={set:function(t,e,r){var n=this;switch(t){case"query":"string"==typeof e&&e.length&&(e=(r||m.parse)(e)),n[t]=e;break;case"port":n[t]=e,y(e,n.protocol)?e&&(n.host=n.hostname+":"+e):(n.host=n.hostname,n[t]="");break;case"hostname":n[t]=e,n.port&&(e+=":"+n.port),n.host=e;break;case"host":n[t]=e,/:\d+$/.test(e)?(e=e.split(":"),n.port=e.pop(),n.hostname=e.join(":")):(n.hostname=e,n.port="");break;case"protocol":n.protocol=e.toLowerCase(),n.slashes=!r;break;case"pathname":n.pathname=e.length&&"/"!==e.charAt(0)?"/"+e:e;break;default:n[t]=e}for(var o=0;o<g.length;o++){var i=g[o];i[4]&&(n[i[1]]=n[i[1]].toLowerCase())}return n.origin=n.protocol&&n.host&&"file:"!==n.protocol?n.protocol+"//"+n.host:"null",n.href=n.toString(),n},toString:function(t){t&&"function"==typeof t||(t=m.stringify);var e,r=this,n=r.protocol;n&&":"!==n.charAt(n.length-1)&&(n+=":");var o=n+(r.slashes?"//":"");return r.username&&(o+=r.username,r.password&&(o+=":"+r.password),o+="@"),o+=r.host+r.pathname,(e="object"===a(r.query)?t(r.query):r.query)&&(o+="?"!==e.charAt(0)?"?"+e:e),r.hash&&(o+=r.hash),o}},u.extractProtocol=o,u.location=n,u.qs=m;var E=u,x=e(function(t){t.exports={generateConfigureUrl:function(t){var e=new E(t),r=e.auth?e.auth+"@":"";return e.protocol+"//"+r+e.hostname+":4001/"},joinUrlWithPath:function(t,e){var r="/"===d(t),n="/"===e[0];return r&&n?""+t+e.substring(1):r||n?""+t+e:t+"/"+e}}}),A=e(function(t){t.exports=function(t,e){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/functions"),{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then(function(t){if(200!==t.status)throw new Error("Failed to add the function.");return t.json()})}}),P=function(t,e){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/functions/"+e.functionId),{method:"DELETE"}).then(function(t){if(204!==t.status)throw new Error("Failed to remove the function.")})},T=e(function(t){t.exports=function(t){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/functions")).then(function(t){if(200!==t.status)throw new Error("Failed to fetch the functions.");return t.json()})}}),O=e(function(t){t.exports=function(t,e){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/subscriptions"),{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then(function(t){if(200!==t.status)throw new Error("Failed to add the subscription.");return t.json()})}}),U=function(t,e){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/subscriptions/"+e.subscriptionId),{method:"DELETE"}).then(function(t){if(204!==t.status)throw new Error("Failed to remove the subscription.")})},S=e(function(t){t.exports=function(t){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/subscriptions")).then(function(t){if(200!==t.status)throw new Error("Failed to fetch the functions.");return t.json()})}}),_=function(t,e){switch(t){case 0:return function(){return e.apply(this,arguments)};case 1:return function(t){return e.apply(this,arguments)};case 2:return function(t,r){return e.apply(this,arguments)};case 3:return function(t,r,n){return e.apply(this,arguments)};case 4:return function(t,r,n,o){return e.apply(this,arguments)};case 5:return function(t,r,n,o,i){return e.apply(this,arguments)};case 6:return function(t,r,n,o,i,u){return e.apply(this,arguments)};case 7:return function(t,r,n,o,i,u,s){return e.apply(this,arguments)};case 8:return function(t,r,n,o,i,u,s,a){return e.apply(this,arguments)};case 9:return function(t,r,n,o,i,u,s,a,c){return e.apply(this,arguments)};case 10:return function(t,r,n,o,i,u,s,a,c,f){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}},B=function(t,e){return function(){return e.call(this,t.apply(this,arguments))}},F=function(t){return function e(r,n,o){switch(arguments.length){case 0:return e;case 1:return c(r)?e:l(function(e,n){return t(r,e,n)});case 2:return c(r)&&c(n)?e:c(r)?l(function(e,r){return t(e,n,r)}):c(n)?l(function(e,n){return t(r,e,n)}):f(function(e){return t(r,n,e)});default:return c(r)&&c(n)&&c(o)?e:c(r)&&c(n)?l(function(e,r){return t(e,r,o)}):c(r)&&c(o)?l(function(e,r){return t(e,n,r)}):c(n)&&c(o)?l(function(e,n){return t(r,e,n)}):c(r)?f(function(e){return t(e,n,o)}):c(n)?f(function(e){return t(r,e,o)}):c(o)?f(function(e){return t(r,n,e)}):t(r,n,o)}}},I=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)},C=f(function(t){return!!I(t)||!!t&&("object"===(void 0===t?"undefined":a(t))&&(!p(t)&&(1===t.nodeType?!!t.length:0===t.length||t.length>0&&(t.hasOwnProperty(0)&&t.hasOwnProperty(t.length-1)))))}),R=function(){function t(t){this.f=t}return t.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},t.prototype["@@transducer/result"]=function(t){return t},t.prototype["@@transducer/step"]=function(t,e){return this.f(t,e)},function(e){return new t(e)}}(),D=l(function(t,e){return _(t.length,function(){return t.apply(e,arguments)})}),k=function(){function t(t,e,r){for(var n=0,o=r.length;n<o;){if((e=t["@@transducer/step"](e,r[n]))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}n+=1}return t["@@transducer/result"](e)}function e(t,e,r){for(var n=r.next();!n.done;){if((e=t["@@transducer/step"](e,n.value))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}n=r.next()}return t["@@transducer/result"](e)}function r(t,e,r,n){return t["@@transducer/result"](r[n](D(t["@@transducer/step"],t),e))}var n="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";return function(o,i,u){if("function"==typeof o&&(o=R(o)),C(u))return t(o,i,u);if("function"==typeof u["fantasy-land/reduce"])return r(o,i,u,"fantasy-land/reduce");if(null!=u[n])return e(o,i,u[n]());if("function"==typeof u.next)return e(o,i,u);if("function"==typeof u.reduce)return r(o,i,u,"reduce");throw new TypeError("reduce: list must be array or iterable")}}(),q=F(k),L=function(t,e){return function(){var r=arguments.length;if(0===r)return e();var n=arguments[r-1];return I(n)||"function"!=typeof n[t]?e.apply(this,arguments):n[t].apply(n,Array.prototype.slice.call(arguments,0,r-1))}},N=F(L("slice",function(t,e,r){return Array.prototype.slice.call(r,t,e)})),G=f(L("tail",N(1,1/0))),W=function(){if(0===arguments.length)throw new Error("pipe requires at least one argument");return _(arguments[0].length,q(B,arguments[0],G(arguments)))},H=function(t,e){return Object.prototype.hasOwnProperty.call(e,t)},z=F(function(t,e,r){return null!=r&&H(e,r)?r[e]:t}),J=function(t){return"function"==typeof t["@@transducer/step"]},X=function(t,e){for(var r=0,n=e.length,o=Array(n);r<n;)o[r]=t(e[r]),r+=1;return o},$={init:function(){return this.xf["@@transducer/init"]()},result:function(t){return this.xf["@@transducer/result"](t)}},M=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=$.init,t.prototype["@@transducer/result"]=$.result,t.prototype["@@transducer/step"]=function(t,e){return this.xf["@@transducer/step"](t,this.f(e))},l(function(e,r){return new t(e,r)})}(),V=function t(e,r,n){return function(){for(var o=[],i=0,u=e,s=0;s<r.length||i<arguments.length;){var a;s<r.length&&(!c(r[s])||i>=arguments.length)?a=r[s]:(a=arguments[i],i+=1),o[s]=a,c(a)||(u-=1),s+=1}return u<=0?n.apply(this,o):_(u,t(e,o,n))}},Z=l(function(t,e){return 1===t?f(e):_(t,V(t,[],e))}),K=function(){var t=Object.prototype.toString;return"[object Arguments]"===t.call(arguments)?function(e){return"[object Arguments]"===t.call(e)}:function(t){return H("callee",t)}}(),Q=function(){var t=!{toString:null}.propertyIsEnumerable("toString"),e=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],r=function(){return arguments.propertyIsEnumerable("length")}(),n=function(t,e){for(var r=0;r<t.length;){if(t[r]===e)return!0;r+=1}return!1};return f("function"!=typeof Object.keys||r?function(o){if(Object(o)!==o)return[];var i,u,s=[],a=r&&K(o);for(i in o)!H(i,o)||a&&"length"===i||(s[s.length]=i);if(t)for(u=e.length-1;u>=0;)H(i=e[u],o)&&!n(s,i)&&(s[s.length]=i),u-=1;return s}:function(t){return Object(t)!==t?[]:Object.keys(t)})}(),Y=l(function(t,e,r){return function(){if(0===arguments.length)return r();var n=Array.prototype.slice.call(arguments,0),o=n.pop();if(!I(o)){for(var i=0;i<t.length;){if("function"==typeof o[t[i]])return o[t[i]].apply(o,n);i+=1}if(J(o))return e.apply(null,n)(o)}return r.apply(this,arguments)}}(["fantasy-land/map","map"],M,function(t,e){switch(Object.prototype.toString.call(e)){case"[object Function]":return Z(e.length,function(){return t.call(this,e.apply(this,arguments))});case"[object Object]":return k(function(r,n){return r[n]=t(e[n]),r},{},Q(e));default:return X(t,e)}})),tt=e(function(t){t.exports=function(t,e){var r=W(z([],"functions"),Y(function(e){return A(t,e)})),n=W(z([],"subscriptions"),Y(function(e){return O(t,e)}));return Promise.all(r(e)).then(function(t){return Promise.all(n(e)).then(function(e){return{functions:t,subscriptions:e}}).catch(function(t){throw new Error("Failed to initate at least one subscription.\n",t)})}).catch(function(t){throw new Error("Failed to register at least one function.\n",t)})}}),et=function(t){return Promise.all([T(t),S(t)]).then(function(e){return Promise.all(e[1].subscriptions.map(function(e){return U(t,{subscriptionId:e.subscriptionId})})).then(function(){return Promise.all(e[0].functions.map(function(e){return P(t,{functionId:e.functionId})})).then(function(){}).catch(function(t){throw new Error("Failed to remove certain functions.\n",t)})}).catch(function(t){throw new Error("Failed to remove certain subscriptions and functions.\n",t)})})},rt=e(function(t){t.exports=function(t,e){var r=e.dataType?e.data:JSON.stringify(e.data);return t.fetch(""+t.apiUrl,{method:"POST",body:r,headers:{"Content-Type":e.dataType||"application/json",Event:e.event}}).then(function(t){if(202!==t.status)throw new Error("Failed to emit the event "+e.event);return t})}}),nt=e(function(t){t.exports=function(t,e){var r=e.dataType?e.data:JSON.stringify(e.data);return t.fetch(""+t.apiUrl,{method:"POST",body:r,headers:{"Content-Type":e.dataType||"application/json",Event:"invoke","Function-ID":e.functionId}})}});!function(t){function e(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function r(t){return"string"!=typeof t&&(t=String(t)),t}function n(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return m.iterable&&(e[Symbol.iterator]=function(){return e}),e}function o(t){this.map={},t instanceof o?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function i(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function u(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function s(t){var e=new FileReader,r=u(e);return e.readAsArrayBuffer(t),r}function a(t){var e=new FileReader,r=u(e);return e.readAsText(t),r}function c(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}function f(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function h(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(m.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(m.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(m.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(m.arrayBuffer&&m.blob&&v(t))this._bodyArrayBuffer=f(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!m.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!g(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=f(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):m.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},m.blob&&(this.blob=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?i(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(s)}),this.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return a(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(c(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},m.formData&&(this.formData=function(){return this.text().then(d)}),this.json=function(){return this.text().then(JSON.parse)},this}function l(t){var e=t.toUpperCase();return j.indexOf(e)>-1?e:t}function p(t,e){var r=(e=e||{}).body;if(t instanceof p){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new o(t.headers)),this.method=t.method,this.mode=t.mode,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new o(e.headers)),this.method=l(e.method||this.method||"GET"),this.mode=e.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function d(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}}),e}function y(t){var e=new o;return t.split(/\r?\n/).forEach(function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}}),e}function b(t,e){e||(e={}),this.type="default",this.status="status"in e?e.status:200,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new o(e.headers),this.url=e.url||"",this._initBody(t)}if(!t.fetch){var m={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(m.arrayBuffer)var w=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],v=function(t){return t&&DataView.prototype.isPrototypeOf(t)},g=ArrayBuffer.isView||function(t){return t&&w.indexOf(Object.prototype.toString.call(t))>-1};o.prototype.append=function(t,n){t=e(t),n=r(n);var o=this.map[t];this.map[t]=o?o+","+n:n},o.prototype.delete=function(t){delete this.map[e(t)]},o.prototype.get=function(t){return t=e(t),this.has(t)?this.map[t]:null},o.prototype.has=function(t){return this.map.hasOwnProperty(e(t))},o.prototype.set=function(t,n){this.map[e(t)]=r(n)},o.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},o.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),n(t)},o.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),n(t)},o.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),n(t)},m.iterable&&(o.prototype[Symbol.iterator]=o.prototype.entries);var j=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},h.call(p.prototype),h.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new o(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var E=[301,302,303,307,308];b.redirect=function(t,e){if(-1===E.indexOf(e))throw new RangeError("Invalid status code");return new b(null,{status:e,headers:{location:t}})},t.Headers=o,t.Request=p,t.Response=b,t.fetch=function(t,e){return new Promise(function(r,n){var o=new p(t,e),i=new XMLHttpRequest;i.onload=function(){var t={status:i.status,statusText:i.statusText,headers:y(i.getAllResponseHeaders()||"")};t.url="responseURL"in i?i.responseURL:t.headers.get("X-Request-URL");var e="response"in i?i.response:i.responseText;r(new b(e,t))},i.onerror=function(){n(new TypeError("Network request failed"))},i.ontimeout=function(){n(new TypeError("Network request failed"))},i.open(o.method,o.url,!0),"include"===o.credentials&&(i.withCredentials=!0),"responseType"in i&&m.blob&&(i.responseType="blob"),o.headers.forEach(function(t,e){i.setRequestHeader(e,t)}),i.send(void 0===o._bodyInit?null:o._bodyInit)})},t.fetch.polyfill=!0}}("undefined"!=typeof self?self:void 0);var ot=self.fetch.bind(self),it=e(function(t){t.exports={eventGateway:function(t){if(h(t)||"object"!==(void 0===t?"undefined":a(t))||h(t.url)||"string"!=typeof t.url)throw new Error("Please provide an object with the property 'url' to eventGateway");var e={apiUrl:t.url,configurationUrl:t.configurationUrl||x.generateConfigureUrl(t.url),fetch:t.fetch||ot};return{emit:function(t){return rt(e,t)},invoke:function(t){return nt(e,t)},configure:function(t){return tt(e,t)},resetConfiguration:function(t){return et(e)},registerFunction:function(t){return A(e,t)},deleteFunction:function(t){return P(e,t)},listFunctions:function(t){return T(e,t)},subscribe:function(t){return O(e,t)},unsubscribe:function(t){return U(e,t)},listSubscriptions:function(t){return S(e,t)}}}}}),ut=it.eventGateway;t.default=it,t.eventGateway=ut,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(t.fdk={})}(this,function(t){"use strict";function r(t,r){return r={exports:{}},t(r,r.exports),r.exports}function e(t){return decodeURIComponent(t.replace(/\+/g," "))}function n(t){var r,e={},n=void 0===(t=t||s.location||{})?"undefined":a(t);if("blob:"===t.protocol)e=new u(unescape(t.pathname),{});else if("string"===n){e=new u(t,{});for(r in E)delete e[r]}else if("object"===n){for(r in t)r in E||(e[r]=t[r]);void 0===e.slashes&&(e.slashes=v.test(t.href))}return e}function o(t){var r=m.exec(t);return{protocol:r[1]?r[1].toLowerCase():"",slashes:!!r[2],rest:r[3]}}function i(t,r){for(var e=(r||"/").split("/").slice(0,-1).concat(t.split("/")),n=e.length,o=e[n-1],i=!1,u=0;n--;)"."===e[n]?e.splice(n,1):".."===e[n]?(e.splice(n,1),u++):u&&(0===n&&(i=!0),e.splice(n,1),u--);return i&&e.unshift(""),"."!==o&&".."!==o||e.push(""),e.join("/")}function u(t,r,e){if(!(this instanceof u))return new u(t,r,e);var s,c,f,h,l,p,d=g.slice(),b=void 0===r?"undefined":a(r),m=this,v=0;for("object"!==b&&"string"!==b&&(e=r,r=null),e&&"function"!=typeof e&&(e=w.parse),r=n(r),s=!(c=o(t||"")).protocol&&!c.slashes,m.slashes=c.slashes||s&&r.slashes,m.protocol=c.protocol||r.protocol||"",t=c.rest,c.slashes||(d[2]=[/(.*)/,"pathname"]);v<d.length;v++)f=(h=d[v])[0],p=h[1],f!==f?m[p]=t:"string"==typeof f?~(l=t.indexOf(f))&&("number"==typeof h[2]?(m[p]=t.slice(0,l),t=t.slice(l+h[2])):(m[p]=t.slice(l),t=t.slice(0,l))):(l=f.exec(t))&&(m[p]=l[1],t=t.slice(0,l.index)),m[p]=m[p]||(s&&h[3]?r[p]||"":""),h[4]&&(m[p]=m[p].toLowerCase());e&&(m.query=e(m.query)),s&&r.slashes&&"/"!==m.pathname.charAt(0)&&(""!==m.pathname||""!==r.pathname)&&(m.pathname=i(m.pathname,r.pathname)),y(m.port,m.protocol)||(m.host=m.hostname,m.port=""),m.username=m.password="",m.auth&&(h=m.auth.split(":"),m.username=h[0]||"",m.password=h[1]||""),m.origin=m.protocol&&m.host&&"file:"!==m.protocol?m.protocol+"//"+m.host:"null",m.href=m.toString()}var s="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c=function(t){return null!=t&&"object"===(void 0===t?"undefined":a(t))&&!0===t["@@functional/placeholder"]},f=function(t){return function r(e){return 0===arguments.length||c(e)?r:t.apply(this,arguments)}},h=f(function(t){return null==t}),l=function(t){return function r(e,n){switch(arguments.length){case 0:return r;case 1:return c(e)?r:f(function(r){return t(e,r)});default:return c(e)&&c(n)?r:c(e)?f(function(r){return t(r,n)}):c(n)?f(function(r){return t(e,r)}):t(e,n)}}},p=function(t){return"[object String]"===Object.prototype.toString.call(t)},d=l(function(t,r){var e=t<0?r.length+t:t;return p(r)?r.charAt(e):r[e]})(-1),y=function(t,r){if(r=r.split(":")[0],!(t=+t))return!1;switch(r){case"http":case"ws":return 80!==t;case"https":case"wss":return 443!==t;case"ftp":return 21!==t;case"gopher":return 70!==t;case"file":return!1}return 0!==t},b=Object.prototype.hasOwnProperty,w={stringify:function(t,r){var e=[];"string"!=typeof(r=r||"")&&(r="?");for(var n in t)b.call(t,n)&&e.push(encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e.length?r+e.join("&"):""},parse:function(t){for(var r,n=/([^=?&]+)=?([^&]*)/g,o={};r=n.exec(t);o[e(r[1])]=e(r[2]));return o}},m=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,v=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,g=[["#","hash"],["?","query"],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],E={hash:1,query:1};u.prototype={set:function(t,r,e){var n=this;switch(t){case"query":"string"==typeof r&&r.length&&(r=(e||w.parse)(r)),n[t]=r;break;case"port":n[t]=r,y(r,n.protocol)?r&&(n.host=n.hostname+":"+r):(n.host=n.hostname,n[t]="");break;case"hostname":n[t]=r,n.port&&(r+=":"+n.port),n.host=r;break;case"host":n[t]=r,/:\d+$/.test(r)?(r=r.split(":"),n.port=r.pop(),n.hostname=r.join(":")):(n.hostname=r,n.port="");break;case"protocol":n.protocol=r.toLowerCase(),n.slashes=!e;break;case"pathname":n.pathname=r.length&&"/"!==r.charAt(0)?"/"+r:r;break;default:n[t]=r}for(var o=0;o<g.length;o++){var i=g[o];i[4]&&(n[i[1]]=n[i[1]].toLowerCase())}return n.origin=n.protocol&&n.host&&"file:"!==n.protocol?n.protocol+"//"+n.host:"null",n.href=n.toString(),n},toString:function(t){t&&"function"==typeof t||(t=w.stringify);var r,e=this,n=e.protocol;n&&":"!==n.charAt(n.length-1)&&(n+=":");var o=n+(e.slashes?"//":"");return e.username&&(o+=e.username,e.password&&(o+=":"+e.password),o+="@"),o+=e.host+e.pathname,(r="object"===a(e.query)?t(e.query):e.query)&&(o+="?"!==r.charAt(0)?"?"+r:r),e.hash&&(o+=e.hash),o}},u.extractProtocol=o,u.location=n,u.qs=w;var j=u,x=r(function(t){t.exports={generateConfigureUrl:function(t){var r=new j(t),e=r.auth?r.auth+"@":"";return r.protocol+"//"+e+r.hostname+":4001/"},joinUrlWithPath:function(t,r){var e="/"===d(t),n="/"===r[0];return e&&n?""+t+r.substring(1):e||n?""+t+r:t+"/"+r}}}),A=r(function(t){t.exports=function(t,r){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/functions"),{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}}).then(function(t){if(200!==t.status){var e=null,n=r.functionId;return t.json().then(function(t){throw e=t.error,new Error("Internal rethrow of "+t)}).catch(function(){throw e?new Error("Failed to register the function "+n+" due the error: "+e):new Error("Failed to register the function "+n+" and couldn't parse error body.")})}return t.json()})}}),P=r(function(t){t.exports=function(t,r){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/functions/"+r.functionId),{method:"DELETE"}).then(function(t){if(204!==t.status){var e=null;return t.json().then(function(t){throw e=t.error,new Error("Internal rethrow of "+t)}).catch(function(){throw e?new Error("Failed to delete the function "+r.functionId+" due the error: "+e):new Error("Failed to delete the function "+r.functionId+" and couldn't parse error body.")})}})}}),T=r(function(t){t.exports=function(t){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/functions")).then(function(t){if(200!==t.status){var r=null;return t.json().then(function(t){throw r=t.error,new Error("Internal rethrow of "+t)}).catch(function(){throw r?new Error("Failed to fetch the function list due the error: "+r):new Error("Failed to fetch the function list and couldn't parse error body.")})}return t.json()})}}),O=r(function(t){t.exports=function(t,r){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/subscriptions"),{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}}).then(function(t){if(200!==t.status){var e=null,n="Failed to subscribe the event "+r.event+" to the function "+r.functionId;return t.json().then(function(t){throw e=t.error,new Error("Internal rethrow of "+t)}).catch(function(){throw e?new Error(n+" due the error: "+e):new Error(n+" and couldn't parse error body.")})}return t.json()})}}),U=r(function(t){t.exports=function(t,r){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/subscriptions/"+r.subscriptionId),{method:"DELETE"}).then(function(t){if(204!==t.status){var e=null,n="Failed to unsubscribe the subscription "+r.subscriptionId;return t.json().then(function(t){throw e=t.error,new Error("Internal rethrow of "+t)}).catch(function(){throw e?new Error(n+" due the error: "+e):new Error(n+" and couldn't parse error body.")})}})}}),I=r(function(t){t.exports=function(t){return t.fetch(x.joinUrlWithPath(t.configurationUrl,"/v1/subscriptions")).then(function(t){if(200!==t.status){var r=null;return t.json().then(function(t){throw r=t.error,new Error("Internal rethrow of "+t)}).catch(function(){throw r?new Error("Failed to fetch the subscriptions list due the error: "+r):new Error("Failed to fetch the subscriptions list and couldn't parse error body.")})}return t.json()})}}),S=function(t,r){switch(t){case 0:return function(){return r.apply(this,arguments)};case 1:return function(t){return r.apply(this,arguments)};case 2:return function(t,e){return r.apply(this,arguments)};case 3:return function(t,e,n){return r.apply(this,arguments)};case 4:return function(t,e,n,o){return r.apply(this,arguments)};case 5:return function(t,e,n,o,i){return r.apply(this,arguments)};case 6:return function(t,e,n,o,i,u){return r.apply(this,arguments)};case 7:return function(t,e,n,o,i,u,s){return r.apply(this,arguments)};case 8:return function(t,e,n,o,i,u,s,a){return r.apply(this,arguments)};case 9:return function(t,e,n,o,i,u,s,a,c){return r.apply(this,arguments)};case 10:return function(t,e,n,o,i,u,s,a,c,f){return r.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}},_=function(t,r){return function(){return r.call(this,t.apply(this,arguments))}},F=function(t){return function r(e,n,o){switch(arguments.length){case 0:return r;case 1:return c(e)?r:l(function(r,n){return t(e,r,n)});case 2:return c(e)&&c(n)?r:c(e)?l(function(r,e){return t(r,n,e)}):c(n)?l(function(r,n){return t(e,r,n)}):f(function(r){return t(e,n,r)});default:return c(e)&&c(n)&&c(o)?r:c(e)&&c(n)?l(function(r,e){return t(r,e,o)}):c(e)&&c(o)?l(function(r,e){return t(r,n,e)}):c(n)&&c(o)?l(function(r,n){return t(e,r,n)}):c(e)?f(function(r){return t(r,n,o)}):c(n)?f(function(r){return t(e,r,o)}):c(o)?f(function(r){return t(e,n,r)}):t(e,n,o)}}},B=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)},C=f(function(t){return!!B(t)||!!t&&("object"===(void 0===t?"undefined":a(t))&&(!p(t)&&(1===t.nodeType?!!t.length:0===t.length||t.length>0&&(t.hasOwnProperty(0)&&t.hasOwnProperty(t.length-1)))))}),R=function(){function t(t){this.f=t}return t.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},t.prototype["@@transducer/result"]=function(t){return t},t.prototype["@@transducer/step"]=function(t,r){return this.f(t,r)},function(r){return new t(r)}}(),D=l(function(t,r){return S(t.length,function(){return t.apply(r,arguments)})}),k=function(){function t(t,r,e){for(var n=0,o=e.length;n<o;){if((r=t["@@transducer/step"](r,e[n]))&&r["@@transducer/reduced"]){r=r["@@transducer/value"];break}n+=1}return t["@@transducer/result"](r)}function r(t,r,e){for(var n=e.next();!n.done;){if((r=t["@@transducer/step"](r,n.value))&&r["@@transducer/reduced"]){r=r["@@transducer/value"];break}n=e.next()}return t["@@transducer/result"](r)}function e(t,r,e,n){return t["@@transducer/result"](e[n](D(t["@@transducer/step"],t),r))}var n="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";return function(o,i,u){if("function"==typeof o&&(o=R(o)),C(u))return t(o,i,u);if("function"==typeof u["fantasy-land/reduce"])return e(o,i,u,"fantasy-land/reduce");if(null!=u[n])return r(o,i,u[n]());if("function"==typeof u.next)return r(o,i,u);if("function"==typeof u.reduce)return e(o,i,u,"reduce");throw new TypeError("reduce: list must be array or iterable")}}(),q=F(k),L=function(t,r){return function(){var e=arguments.length;if(0===e)return r();var n=arguments[e-1];return B(n)||"function"!=typeof n[t]?r.apply(this,arguments):n[t].apply(n,Array.prototype.slice.call(arguments,0,e-1))}},N=F(L("slice",function(t,r,e){return Array.prototype.slice.call(e,t,r)})),G=f(L("tail",N(1,1/0))),W=function(){if(0===arguments.length)throw new Error("pipe requires at least one argument");return S(arguments[0].length,q(_,arguments[0],G(arguments)))},H=function(t,r){return Object.prototype.hasOwnProperty.call(r,t)},z=F(function(t,r,e){return null!=e&&H(r,e)?e[r]:t}),J=function(t){return"function"==typeof t["@@transducer/step"]},X=function(t,r){for(var e=0,n=r.length,o=Array(n);e<n;)o[e]=t(r[e]),e+=1;return o},$={init:function(){return this.xf["@@transducer/init"]()},result:function(t){return this.xf["@@transducer/result"](t)}},M=function(){function t(t,r){this.xf=r,this.f=t}return t.prototype["@@transducer/init"]=$.init,t.prototype["@@transducer/result"]=$.result,t.prototype["@@transducer/step"]=function(t,r){return this.xf["@@transducer/step"](t,this.f(r))},l(function(r,e){return new t(r,e)})}(),V=function t(r,e,n){return function(){for(var o=[],i=0,u=r,s=0;s<e.length||i<arguments.length;){var a;s<e.length&&(!c(e[s])||i>=arguments.length)?a=e[s]:(a=arguments[i],i+=1),o[s]=a,c(a)||(u-=1),s+=1}return u<=0?n.apply(this,o):S(u,t(r,o,n))}},Z=l(function(t,r){return 1===t?f(r):S(t,V(t,[],r))}),K=function(){var t=Object.prototype.toString;return"[object Arguments]"===t.call(arguments)?function(r){return"[object Arguments]"===t.call(r)}:function(t){return H("callee",t)}}(),Q=function(){var t=!{toString:null}.propertyIsEnumerable("toString"),r=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],e=function(){return arguments.propertyIsEnumerable("length")}(),n=function(t,r){for(var e=0;e<t.length;){if(t[e]===r)return!0;e+=1}return!1};return f("function"!=typeof Object.keys||e?function(o){if(Object(o)!==o)return[];var i,u,s=[],a=e&&K(o);for(i in o)!H(i,o)||a&&"length"===i||(s[s.length]=i);if(t)for(u=r.length-1;u>=0;)H(i=r[u],o)&&!n(s,i)&&(s[s.length]=i),u-=1;return s}:function(t){return Object(t)!==t?[]:Object.keys(t)})}(),Y=l(function(t,r,e){return function(){if(0===arguments.length)return e();var n=Array.prototype.slice.call(arguments,0),o=n.pop();if(!B(o)){for(var i=0;i<t.length;){if("function"==typeof o[t[i]])return o[t[i]].apply(o,n);i+=1}if(J(o))return r.apply(null,n)(o)}return e.apply(this,arguments)}}(["fantasy-land/map","map"],M,function(t,r){switch(Object.prototype.toString.call(r)){case"[object Function]":return Z(r.length,function(){return t.call(this,r.apply(this,arguments))});case"[object Object]":return k(function(e,n){return e[n]=t(r[n]),e},{},Q(r));default:return X(t,r)}})),tt=r(function(t){t.exports=function(t,r){var e=W(z([],"functions"),Y(function(r){return A(t,r)})),n=W(z([],"subscriptions"),Y(function(r){return O(t,r)}));return Promise.all(e(r)).then(function(t){return Promise.all(n(r)).then(function(r){return{functions:t,subscriptions:r}}).catch(function(t){throw new Error("Failed to configure the Event Gateway. "+t.message)})}).catch(function(t){throw new Error("Failed to configure the Event Gateway. "+t.message)})}}),rt=function(t){return Promise.all([T(t),I(t)]).then(function(r){return Promise.all(r[1].subscriptions.map(function(r){return U(t,{subscriptionId:r.subscriptionId})})).then(function(){return Promise.all(r[0].functions.map(function(r){return P(t,{functionId:r.functionId})})).then(function(){}).catch(function(t){throw new Error("Failed to reset the Event Gateway configuration. "+t.message)})}).catch(function(t){throw new Error("Failed to reset the Event Gateway configuration. "+t.message)})})},et=r(function(t){t.exports=function(t,r){var e=r.dataType?r.data:JSON.stringify(r.data);return t.fetch(""+t.apiUrl,{method:"POST",body:e,headers:{"Content-Type":r.dataType||"application/json",Event:r.event}}).then(function(t){if(202!==t.status)throw new Error("Failed to emit the event "+r.event);return t})}}),nt=r(function(t){t.exports=function(t,r){var e=r.dataType?r.data:JSON.stringify(r.data);return t.fetch(""+t.apiUrl,{method:"POST",body:e,headers:{"Content-Type":r.dataType||"application/json",Event:"invoke","Function-ID":r.functionId}}).then(function(t){if(200!==t.status){var e=null;return t.text().then(function(t){throw e=t,new Error("Internal rethrow of "+t)}).catch(function(){throw e?new Error("Failed to invoke function "+r.functionId+" due the error: "+e):new Error("Failed to invoke function "+r.functionId+" and couldn't parse error body.")})}return t})}});!function(t){function r(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function e(t){return"string"!=typeof t&&(t=String(t)),t}function n(t){var r={next:function(){var r=t.shift();return{done:void 0===r,value:r}}};return w.iterable&&(r[Symbol.iterator]=function(){return r}),r}function o(t){this.map={},t instanceof o?t.forEach(function(t,r){this.append(r,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(r){this.append(r,t[r])},this)}function i(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function u(t){return new Promise(function(r,e){t.onload=function(){r(t.result)},t.onerror=function(){e(t.error)}})}function s(t){var r=new FileReader,e=u(r);return r.readAsArrayBuffer(t),e}function a(t){var r=new FileReader,e=u(r);return r.readAsText(t),e}function c(t){for(var r=new Uint8Array(t),e=new Array(r.length),n=0;n<r.length;n++)e[n]=String.fromCharCode(r[n]);return e.join("")}function f(t){if(t.slice)return t.slice(0);var r=new Uint8Array(t.byteLength);return r.set(new Uint8Array(t)),r.buffer}function h(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(w.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(w.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(w.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(w.arrayBuffer&&w.blob&&v(t))this._bodyArrayBuffer=f(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!w.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!g(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=f(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):w.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},w.blob&&(this.blob=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?i(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(s)}),this.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return a(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(c(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},w.formData&&(this.formData=function(){return this.text().then(d)}),this.json=function(){return this.text().then(JSON.parse)},this}function l(t){var r=t.toUpperCase();return E.indexOf(r)>-1?r:t}function p(t,r){var e=(r=r||{}).body;if(t instanceof p){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,r.headers||(this.headers=new o(t.headers)),this.method=t.method,this.mode=t.mode,e||null==t._bodyInit||(e=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=r.credentials||this.credentials||"omit",!r.headers&&this.headers||(this.headers=new o(r.headers)),this.method=l(r.method||this.method||"GET"),this.mode=r.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&e)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(e)}function d(t){var r=new FormData;return t.trim().split("&").forEach(function(t){if(t){var e=t.split("="),n=e.shift().replace(/\+/g," "),o=e.join("=").replace(/\+/g," ");r.append(decodeURIComponent(n),decodeURIComponent(o))}}),r}function y(t){var r=new o;return t.split(/\r?\n/).forEach(function(t){var e=t.split(":"),n=e.shift().trim();if(n){var o=e.join(":").trim();r.append(n,o)}}),r}function b(t,r){r||(r={}),this.type="default",this.status="status"in r?r.status:200,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in r?r.statusText:"OK",this.headers=new o(r.headers),this.url=r.url||"",this._initBody(t)}if(!t.fetch){var w={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(w.arrayBuffer)var m=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],v=function(t){return t&&DataView.prototype.isPrototypeOf(t)},g=ArrayBuffer.isView||function(t){return t&&m.indexOf(Object.prototype.toString.call(t))>-1};o.prototype.append=function(t,n){t=r(t),n=e(n);var o=this.map[t];this.map[t]=o?o+","+n:n},o.prototype.delete=function(t){delete this.map[r(t)]},o.prototype.get=function(t){return t=r(t),this.has(t)?this.map[t]:null},o.prototype.has=function(t){return this.map.hasOwnProperty(r(t))},o.prototype.set=function(t,n){this.map[r(t)]=e(n)},o.prototype.forEach=function(t,r){for(var e in this.map)this.map.hasOwnProperty(e)&&t.call(r,this.map[e],e,this)},o.prototype.keys=function(){var t=[];return this.forEach(function(r,e){t.push(e)}),n(t)},o.prototype.values=function(){var t=[];return this.forEach(function(r){t.push(r)}),n(t)},o.prototype.entries=function(){var t=[];return this.forEach(function(r,e){t.push([e,r])}),n(t)},w.iterable&&(o.prototype[Symbol.iterator]=o.prototype.entries);var E=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},h.call(p.prototype),h.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new o(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var j=[301,302,303,307,308];b.redirect=function(t,r){if(-1===j.indexOf(r))throw new RangeError("Invalid status code");return new b(null,{status:r,headers:{location:t}})},t.Headers=o,t.Request=p,t.Response=b,t.fetch=function(t,r){return new Promise(function(e,n){var o=new p(t,r),i=new XMLHttpRequest;i.onload=function(){var t={status:i.status,statusText:i.statusText,headers:y(i.getAllResponseHeaders()||"")};t.url="responseURL"in i?i.responseURL:t.headers.get("X-Request-URL");var r="response"in i?i.response:i.responseText;e(new b(r,t))},i.onerror=function(){n(new TypeError("Network request failed"))},i.ontimeout=function(){n(new TypeError("Network request failed"))},i.open(o.method,o.url,!0),"include"===o.credentials&&(i.withCredentials=!0),"responseType"in i&&w.blob&&(i.responseType="blob"),o.headers.forEach(function(t,r){i.setRequestHeader(r,t)}),i.send(void 0===o._bodyInit?null:o._bodyInit)})},t.fetch.polyfill=!0}}("undefined"!=typeof self?self:void 0);var ot=self.fetch.bind(self),it=r(function(t){t.exports={eventGateway:function(t){if(h(t)||"object"!==(void 0===t?"undefined":a(t))||h(t.url)||"string"!=typeof t.url)throw new Error("Please provide an object with the property 'url' to eventGateway");var r={apiUrl:t.url,configurationUrl:t.configurationUrl||x.generateConfigureUrl(t.url),fetch:t.fetch||ot};return{emit:function(t){return et(r,t)},invoke:function(t){return nt(r,t)},configure:function(t){return tt(r,t)},resetConfiguration:function(t){return rt(r)},registerFunction:function(t){return A(r,t)},deleteFunction:function(t){return P(r,t)},listFunctions:function(t){return T(r,t)},subscribe:function(t){return O(r,t)},unsubscribe:function(t){return U(r,t)},listSubscriptions:function(t){return I(r,t)}}}}}),ut=it.eventGateway;t.default=it,t.eventGateway=ut,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=fdk.min.js.map |
@@ -29,8 +29,8 @@ const registerFunction = require('./registerFunction') | ||
.catch(subscriptionError => { | ||
throw new Error('Failed to initate at least one subscription.\n', subscriptionError) | ||
throw new Error(`Failed to configure the Event Gateway. ${subscriptionError.message}`) | ||
}) | ||
) | ||
.catch(functionError => { | ||
throw new Error('Failed to register at least one function.\n', functionError) | ||
throw new Error(`Failed to configure the Event Gateway. ${functionError.message}`) | ||
}) | ||
} |
@@ -13,5 +13,22 @@ const urlUtils = require('./urlUtils') | ||
if (response.status !== 204) { | ||
// TODO improve throwed errors | ||
throw new Error('Failed to remove the function.') | ||
let errorMessage = null | ||
return response | ||
.json() | ||
.then(error => { | ||
errorMessage = error.error | ||
throw new Error(`Internal rethrow of ${error}`) | ||
}) | ||
.catch(() => { | ||
if (errorMessage) { | ||
throw new Error( | ||
`Failed to delete the function ${params.functionId} due the error: ${errorMessage}` | ||
) | ||
} else { | ||
throw new Error( | ||
`Failed to delete the function ${params.functionId} and couldn't parse error body.` | ||
) | ||
} | ||
}) | ||
} | ||
return undefined | ||
}) |
module.exports = (config, params) => { | ||
const data = params.dataType ? params.data : JSON.stringify(params.data) | ||
return config.fetch(`${config.apiUrl}`, { | ||
method: 'POST', | ||
body: data, | ||
headers: { | ||
'Content-Type': params.dataType || 'application/json', | ||
Event: 'invoke', | ||
'Function-ID': params.functionId, | ||
}, | ||
}) | ||
return config | ||
.fetch(`${config.apiUrl}`, { | ||
method: 'POST', | ||
body: data, | ||
headers: { | ||
'Content-Type': params.dataType || 'application/json', | ||
Event: 'invoke', | ||
'Function-ID': params.functionId, | ||
}, | ||
}) | ||
.then(response => { | ||
if (response.status !== 200) { | ||
let errorMessage = null | ||
return response | ||
.text() | ||
.then(errMsg => { | ||
errorMessage = errMsg | ||
throw new Error(`Internal rethrow of ${errMsg}`) | ||
}) | ||
.catch(() => { | ||
if (errorMessage) { | ||
throw new Error( | ||
`Failed to invoke function ${params.functionId} due the error: ${errorMessage}` | ||
) | ||
} else { | ||
throw new Error( | ||
`Failed to invoke function ${params.functionId} and couldn't parse error body.` | ||
) | ||
} | ||
}) | ||
} | ||
return response | ||
}) | ||
} |
@@ -8,6 +8,18 @@ const urlUtils = require('./urlUtils') | ||
if (response.status !== 200) { | ||
// TODO improve throwed errors | ||
throw new Error('Failed to fetch the functions.') | ||
let errorMessage = null | ||
return response | ||
.json() | ||
.then(error => { | ||
errorMessage = error.error | ||
throw new Error(`Internal rethrow of ${error}`) | ||
}) | ||
.catch(() => { | ||
if (errorMessage) { | ||
throw new Error(`Failed to fetch the function list due the error: ${errorMessage}`) | ||
} else { | ||
throw new Error("Failed to fetch the function list and couldn't parse error body.") | ||
} | ||
}) | ||
} | ||
return response.json() | ||
}) |
@@ -8,6 +8,22 @@ const urlUtils = require('./urlUtils') | ||
if (response.status !== 200) { | ||
// TODO improve throwed errors | ||
throw new Error('Failed to fetch the functions.') | ||
let errorMessage = null | ||
return response | ||
.json() | ||
.then(error => { | ||
errorMessage = error.error | ||
throw new Error(`Internal rethrow of ${error}`) | ||
}) | ||
.catch(() => { | ||
if (errorMessage) { | ||
throw new Error( | ||
`Failed to fetch the subscriptions list due the error: ${errorMessage}` | ||
) | ||
} else { | ||
throw new Error( | ||
"Failed to fetch the subscriptions list and couldn't parse error body." | ||
) | ||
} | ||
}) | ||
} | ||
return response.json() | ||
}) |
@@ -12,6 +12,23 @@ const urlUtils = require('./urlUtils') | ||
if (response.status !== 200) { | ||
// TODO improve throwed errors | ||
throw new Error('Failed to add the function.') | ||
let errorMessage = null | ||
const funcId = params.functionId | ||
return response | ||
.json() | ||
.then(error => { | ||
errorMessage = error.error | ||
throw new Error(`Internal rethrow of ${error}`) | ||
}) | ||
.catch(() => { | ||
if (errorMessage) { | ||
throw new Error( | ||
`Failed to register the function ${funcId} due the error: ${errorMessage}` | ||
) | ||
} else { | ||
throw new Error( | ||
`Failed to register the function ${funcId} and couldn't parse error body.` | ||
) | ||
} | ||
}) | ||
} | ||
return response.json() | ||
}) |
@@ -28,3 +28,3 @@ const listFunctions = require('./listFunctions') | ||
.catch(funcError => { | ||
throw new Error('Failed to remove certain functions.\n', funcError) | ||
throw new Error(`Failed to reset the Event Gateway configuration. ${funcError.message}`) | ||
}) | ||
@@ -34,6 +34,5 @@ ) | ||
throw new Error( | ||
'Failed to remove certain subscriptions and functions.\n', | ||
subscriptionError | ||
`Failed to reset the Event Gateway configuration. ${subscriptionError.message}` | ||
) | ||
}) | ||
) |
@@ -12,6 +12,20 @@ const urlUtils = require('./urlUtils') | ||
if (response.status !== 200) { | ||
// TODO improve throwed errors | ||
throw new Error('Failed to add the subscription.') | ||
let errorMessage = null | ||
const tmpMsg = `Failed to subscribe the event ${params.event}` | ||
const errorStart = `${tmpMsg} to the function ${params.functionId}` | ||
return response | ||
.json() | ||
.then(error => { | ||
errorMessage = error.error | ||
throw new Error(`Internal rethrow of ${error}`) | ||
}) | ||
.catch(() => { | ||
if (errorMessage) { | ||
throw new Error(`${errorStart} due the error: ${errorMessage}`) | ||
} else { | ||
throw new Error(`${errorStart} and couldn't parse error body.`) | ||
} | ||
}) | ||
} | ||
return response.json() | ||
}) |
@@ -16,5 +16,19 @@ const urlUtils = require('./urlUtils') | ||
if (response.status !== 204) { | ||
// TODO improve throwed errors | ||
throw new Error('Failed to remove the subscription.') | ||
let errorMessage = null | ||
const errorStart = `Failed to unsubscribe the subscription ${params.subscriptionId}` | ||
return response | ||
.json() | ||
.then(error => { | ||
errorMessage = error.error | ||
throw new Error(`Internal rethrow of ${error}`) | ||
}) | ||
.catch(() => { | ||
if (errorMessage) { | ||
throw new Error(`${errorStart} due the error: ${errorMessage}`) | ||
} else { | ||
throw new Error(`${errorStart} and couldn't parse error body.`) | ||
} | ||
}) | ||
} | ||
return undefined | ||
}) |
{ | ||
"name": "@serverless/fdk", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"license": "MIT", | ||
@@ -10,2 +10,3 @@ "repository": "https://github.com/serverless/fdk", | ||
"test": "jest --maxWorkers=1", | ||
"test:browser": "npm run build && jest --config=tests-browser/jest.config.json --maxWorkers=1", | ||
"test:watch": "jest --watch --maxWorkers=1", | ||
@@ -27,2 +28,3 @@ "build": "rollup -c" | ||
"jest": "^20.0.4", | ||
"puppeteer": "^0.9.0", | ||
"rimraf": "^2.6.1", | ||
@@ -34,2 +36,3 @@ "rollup": "^0.45.2", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
"rollup-plugin-uglify": "^2.0.1", | ||
@@ -36,0 +39,0 @@ "rollup-plugin-visualizer": "^0.3.1", |
@@ -8,2 +8,3 @@ /* eslint-disable import/no-extraneous-dependencies, node/no-unpublished-require */ | ||
const visualizer = require('rollup-plugin-visualizer') | ||
const sourcemaps = require('rollup-plugin-sourcemaps') | ||
@@ -33,2 +34,3 @@ // eslint-disable-next-line no-console | ||
visualizer(), | ||
sourcemaps(), | ||
] | ||
@@ -40,4 +42,5 @@ | ||
exports: 'named', | ||
sourceMap: true, | ||
targets, | ||
plugins, | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
214049
27
575
0
18