appbase-js
Advanced tools
Comparing version 4.1.2 to 4.1.3
@@ -328,2 +328,4 @@ 'use strict'; | ||
return resolve(response); | ||
}).catch(function (e) { | ||
return reject(e); | ||
}); | ||
@@ -330,0 +332,0 @@ }).catch(function (e) { |
@@ -324,2 +324,4 @@ import URL from 'url-parser-lite'; | ||
return resolve(response); | ||
}).catch(function (e) { | ||
return reject(e); | ||
}); | ||
@@ -326,0 +328,0 @@ }).catch(function (e) { |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Appbase=t()}(this,function(){"use strict";var e=function(e){var t=RegExp("^(([^:/?#]*)?://)?(((.*)?@)?([^/?#]*)?)([^?#]*)(\\?([^#]*))?(#(.*))?"),r=e.match(t);return{protocol:r[2],auth:r[5],host:r[6],path:r[7],query:r[9],hash:r[11]}},t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function r(){for(var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r="",n=0,o=0,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.charAt(0|o)||(i="=",o%1);r+=i.charAt(63&n>>8-o%1*8)){if((e=t.charCodeAt(o+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');n=n<<8|e}return r}function n(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e&&"[object Array]"===Object.prototype.toString.call(e)){for(var r=0;r<e.length;r+=1){var n=e[r];if(!n)return new Error("query object can not have an empty value");if(!n.id)return new Error("'id' field must be present in query object");if((n.type&&"search"!==n.type||t)&&!n.dataField)return new Error("'dataField' field must be present in query object");if(n.dataField&&"[object Array]"!==Object.prototype.toString.call(n.dataField))return new Error("'dataField' field must be an array")}return!0}return new Error("invalid query value, 'query' value must be an array")}function o(e,r){var n=[],o={object:null,string:""};Object.keys(r).forEach(function(i){var s=r[i];t(e[i])===s&&e[i]!==o[s]||n.push(i)});for(var i="",s=0;s<n.length;s+=1)i+=n[s]+", ";return!(n.length>0)||new Error("fields missing: "+i)}function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e||0!==Object.keys(e).length||e.constructor!==Object?JSON.parse(JSON.stringify(e)):null}function s(t){var r=e(t.url||""),n=r.auth,o=void 0===n?null:n,i=r.host,s=void 0===i?"":i,a=r.path,u=void 0===a?"":a,f=r.protocol,c=void 0===f?"":f,p=s+u;if("string"!=typeof p||""===p)throw new Error("URL not present in options.");if("string"!=typeof t.app||""===t.app)throw new Error("App name is not present in options.");if("string"!=typeof c||""===c)throw new Error("Protocol is not present in url. URL should be of the form https://scalr.api.appbase.io");"/"===p.slice(-1)&&(p=p.slice(0,-1));var d=o||null;if("string"==typeof t.credentials&&""!==t.credentials?d=t.credentials:"string"==typeof t.username&&""!==t.username&&"string"==typeof t.password&&""!==t.password&&(d=t.username+":"+t.password),function(e){return t="scalr.api.appbase.io",-1!==e.indexOf(t);var t}(p)&&null===d)throw new Error("Authentication information is not present. Did you add credentials?");this.url=p,this.protocol=c,this.app=t.app,this.credentials=d,this.headers={}}var a="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(e,t){return e(t={exports:{}},t.exports),t.exports}function f(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var c=function(e,t,r,n){t=t||"&",r=r||"=";var o={};if("string"!=typeof e||0===e.length)return o;var i=/\+/g;e=e.split(t);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var a=e.length;s>0&&a>s&&(a=s);for(var u=0;u<a;++u){var c,p,d,y,h=e[u].replace(i,"%20"),l=h.indexOf(r);l>=0?(c=h.substr(0,l),p=h.substr(l+1)):(c=h,p=""),d=decodeURIComponent(c),y=decodeURIComponent(p),f(o,d)?Array.isArray(o[d])?o[d].push(y):o[d]=[o[d],y]:o[d]=y}return o},p=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},d=function(e,t,r,n){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(n){var o=encodeURIComponent(p(n))+r;return Array.isArray(e[n])?e[n].map(function(e){return o+encodeURIComponent(p(e))}).join(t):o+encodeURIComponent(p(e[n]))}).join(t):n?encodeURIComponent(p(n))+r+encodeURIComponent(p(e)):""},y=u(function(e,t){t.decode=t.parse=c,t.encode=t.stringify=d}),h=(y.decode,y.parse,y.encode,y.stringify,u(function(e){var t=function(e){function t(){this.fetch=!1}return t.prototype=e,new t}("undefined"!=typeof self?self:a);(function(e){!function(e){if(!e.fetch){var t={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(t.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=function(e){return e&&DataView.prototype.isPrototypeOf(e)},o=ArrayBuffer.isView||function(e){return e&&r.indexOf(Object.prototype.toString.call(e))>-1};c.prototype.append=function(e,t){e=a(e),t=u(t);var r=this.map[e];this.map[e]=r?r+","+t:t},c.prototype.delete=function(e){delete this.map[a(e)]},c.prototype.get=function(e){return e=a(e),this.has(e)?this.map[e]:null},c.prototype.has=function(e){return this.map.hasOwnProperty(a(e))},c.prototype.set=function(e,t){this.map[a(e)]=u(t)},c.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},c.prototype.keys=function(){var e=[];return this.forEach(function(t,r){e.push(r)}),f(e)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),f(e)},c.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),f(e)},t.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var i=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},l.call(b.prototype),l.call(v.prototype),v.prototype.clone=function(){return new v(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},v.error=function(){var e=new v(null,{status:0,statusText:""});return e.type="error",e};var s=[301,302,303,307,308];v.redirect=function(e,t){if(-1===s.indexOf(t))throw new RangeError("Invalid status code");return new v(null,{status:t,headers:{location:e}})},e.Headers=c,e.Request=b,e.Response=v,e.fetch=function(e,r){return new Promise(function(n,o){var i=new b(e,r),s=new XMLHttpRequest;s.onload=function(){var e,t,r={status:s.status,statusText:s.statusText,headers:(e=s.getAllResponseHeaders()||"",t=new c,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var r=e.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();t.append(n,o)}}),t)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var o="response"in s?s.response:s.responseText;n(new v(o,r))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.open(i.method,i.url,!0),"include"===i.credentials?s.withCredentials=!0:"omit"===i.credentials&&(s.withCredentials=!1),"responseType"in s&&t.blob&&(s.responseType="blob"),i.headers.forEach(function(e,t){s.setRequestHeader(t,e)}),s.send(void 0===i._bodyInit?null:i._bodyInit)})},e.fetch.polyfill=!0}function a(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function u(e){return"string"!=typeof e&&(e=String(e)),e}function f(e){var r={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return t.iterable&&(r[Symbol.iterator]=function(){return r}),r}function c(e){this.map={},e instanceof c?e.forEach(function(e,t){this.append(t,e)},this):Array.isArray(e)?e.forEach(function(e){this.append(e[0],e[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function d(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function y(e){var t=new FileReader,r=d(t);return t.readAsArrayBuffer(e),r}function h(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function l(){return this.bodyUsed=!1,this._initBody=function(e){if(this._bodyInit=e,e)if("string"==typeof e)this._bodyText=e;else if(t.blob&&Blob.prototype.isPrototypeOf(e))this._bodyBlob=e;else if(t.formData&&FormData.prototype.isPrototypeOf(e))this._bodyFormData=e;else if(t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e))this._bodyText=e.toString();else if(t.arrayBuffer&&t.blob&&n(e))this._bodyArrayBuffer=h(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!t.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(e)&&!o(e))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=h(e)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},t.blob&&(this.blob=function(){var e=p(this);if(e)return e;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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var e,t,r,n=p(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=d(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},t.formData&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}function b(e,t){var r,n,o=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new c(e.headers)),this.method=e.method,this.mode=e.mode,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"omit",!t.headers&&this.headers||(this.headers=new c(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),i.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function m(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}}),t}function v(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new c(t.headers),this.url=t.url||"",this._initBody(e)}}(void 0!==e?e:this)}).call(t,void 0);var r=t.fetch;r.Response=t.Response,r.Request=t.Request,r.Headers=t.Headers;e.exports&&(e.exports=r,e.exports.default=r)}));function l(e){var t=this;return new Promise(function(n,o){var s=i(e);try{var a=s.method,u=s.path,f=s.params,c=s.body,p=s.isRSAPI,d=s.isSuggestionsAPI?".suggestions":t.app,l=c,b=u.endsWith("msearch")||u.endsWith("bulk")?"application/x-ndjson":"application/json",m=Object.assign({},{Accept:"application/json","Content-Type":b},t.headers),v=Date.now();t.credentials&&(m.Authorization="Basic "+r(t.credentials));var g={method:a,headers:m};if(Array.isArray(l)){var w="";l.forEach(function(e){w+=JSON.stringify(e),w+="\n"}),l=w}else l=JSON.stringify(l)||{};0!==Object.keys(l).length&&(g.body=l);var j={},O="";f&&(O="?"+y.stringify(f));var x=t.protocol+"://"+t.url+"/"+d+"/"+u+O;return function(e){if(t.transformRequest&&"function"==typeof t.transformRequest){var r=t.transformRequest(e);return r instanceof Promise?r:Promise.resolve(r)}return Promise.resolve(e)}(Object.assign({},{url:x},g)).then(function(e){var t=Object.assign({},e),r=t.url;return delete t.url,h(r||x,t).then(function(e){return e.status>=500?o(e):(j=e.headers,e.json().then(function(t){if(e.status>=400)return o(e);if(t&&t.error)return o(t);if(p&&t&&"[object Object]"===Object.prototype.toString.call(t)&&c&&c.query&&c.query instanceof Array){var r=0,i=c.query.filter(function(e){return e.execute||void 0===e.execute}).length;if(t&&Object.keys(t).forEach(function(e){t[e]&&Object.prototype.hasOwnProperty.call(t[e],"error")&&(r+=1)}),r>0&&i===r)return o(t)}if(t&&t.responses instanceof Array&&t.responses.length===t.responses.filter(function(e){return Object.prototype.hasOwnProperty.call(e,"error")}).length)return o(t);var s=Object.assign({},t,{_timestamp:v,_headers:j});return n(s)}))}).catch(function(e){return o(e)})}).catch(function(e){return o(e)})}catch(e){return o(e)}})}var b="undefined"!=typeof window?window.WebSocket:require("ws");function m(e,n,o,s){var a=this;try{var u=i(e),f=u.method,c=u.path,p=u.params,d=e.body;d&&"object"===(void 0===d?"undefined":t(d))||(d={});return this.wsClosed=function(){s&&s()},this.stop=function(){a.ws.onmessage=void 0,a.ws.onclose=void 0,a.ws.onerror=void 0,a.wsClosed();var e=JSON.parse(JSON.stringify(a.request));e.unsubscribe=!0,!0!==a.unsubscribed&&a.send(e),a.unsubscribed=!0},this.reconnect=function(){return a.stop(),m(e,n,o,s)},this.processError=function(e){o?o(e):console.warn(e)},this.processMessage=function(e){var t=JSON.parse(JSON.stringify(e));if(t.id||!t.message)return t.id===a.id?t.message?(delete t.id,void(o&&o(t))):(t.query_id&&(a.query_id=t.query_id),t.channel&&(a.channel=t.channel),void(t.body&&""!==t.body&&n&&n(t.body))):void(!t.id&&t.channel&&t.channel===a.channel&&n&&n(t.event));o&&o(t)},a.ws=new b("wss://"+a.url+"/"+a.app),a.id="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),a.request={id:a.id,path:a.app+"/"+c+"?"+y.stringify(p),method:f,body:d},a.credentials&&(a.request.authorization="Basic "+r(a.credentials)),a.result={},a.closeHandler=function(){a.wsClosed()},a.errorHandler=function(e){a.processError.apply(a,[e])},a.messageHandler=function(e){var t=JSON.parse(e.data);t.body&&t.body.status>=400?a.processError.apply(a,[t]):a.processMessage.apply(a,[t])},a.send=function(e){!function e(t,r){setTimeout(function(){1===t.readyState?null!=r&&r():e(t,r)},5)}(a.ws,function(){try{a.ws.send(JSON.stringify(e))}catch(e){console.warn(e)}})},a.ws.onmessage=a.messageHandler,a.ws.onerror=a.errorHandler,a.ws.onclose=a.closeHandler,a.send(a.request),a.result.stop=a.stop,a.result.reconnect=a.reconnect,a.result}catch(e){return o?o(e):console.warn(e),null}}function v(e){var t=i(e),r=o(t,{type:"string",body:"object"});if(!0!==r)throw r;var n=t.type,s=t.id,a=t.body;delete t.type,delete t.body,delete t.id;var u=void 0;return u=s?n+"/"+encodeURIComponent(s):n,this.performFetchRequest({method:"POST",path:u,params:t,body:a})}function g(e){var t=i(e),r=o(t,{type:"string",id:"string"});if(!0!==r)throw r;var n=t.type,s=t.id;delete t.type,delete t.id;var a=n+"/"+encodeURIComponent(s);return this.performFetchRequest({method:"GET",path:a,params:t})}function w(e){var t=i(e),r=o(t,{type:"string",id:"string",body:"object"});if(!0!==r)throw r;var n=t.type,s=t.id,a=t.body;delete t.type,delete t.id,delete t.body;var u=n+"/"+encodeURIComponent(s)+"/_update";return this.performFetchRequest({method:"POST",path:u,params:t,body:a})}function j(e){var t=i(e),r=o(t,{type:"string",id:"string"});if(!0!==r)throw r;var n=t.type,s=t.id;delete t.type,delete t.id;var a=n+"/"+encodeURIComponent(s);return this.performFetchRequest({method:"DELETE",path:a,params:t})}function O(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;var n=t.type,s=t.body;delete t.type,delete t.body;var a=void 0;return a=n?n+"/_bulk":"/_bulk",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function x(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;var n=void 0;n=Array.isArray(t.type)?t.type.join():t.type;var s=t.body;delete t.type,delete t.body;var a=void 0;return a=n?n+"/_search":"_search",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function A(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;var n=void 0;n=Array.isArray(t.type)?t.type.join():t.type;var s=t.body;delete t.type,delete t.body;var a=void 0;return a=n?n+"/_msearch":"_msearch",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function S(e,t){var r=i(t),o=n(e);if(!0!==o)throw o;var s={settings:r,query:e};return this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:s,isRSAPI:!0})}function E(e){var t=i(e),r=o(t,{type:"string",id:"string"});if(!0!==r)throw r;var n=t.type,s=t.id;delete t.type,delete t.id,delete t.stream,!0===t.stream?t.stream="true":(delete t.stream,t.streamonly="true");for(var a=arguments.length,u=Array(a>1?a-1:0),f=1;f<a;f++)u[f-1]=arguments[f];return this.performWsRequest.apply(this,[{method:"GET",path:n+"/"+encodeURIComponent(s),params:t}].concat(u))}function R(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;if(void 0===t.type||Array.isArray(t.type)&&0===t.type.length)throw new Error("Missing fields: type");var n=void 0;n=Array.isArray(t.type)?t.type.join():t.type;var s=t.body;delete t.type,delete t.body,delete t.stream,t.streamonly="true";for(var a=arguments.length,u=Array(a>1?a-1:0),f=1;f<a;f++)u[f-1]=arguments[f];return this.performWsRequest.apply(this,[{method:"POST",path:n+"/_search",params:t,body:s}].concat(u))}var _,T,P,q,B={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},U=function(e){throw{name:"SyntaxError",message:e,at:_,text:P}},I=function(e){return e&&e!==T&&U("Expected '"+e+"' instead of '"+T+"'"),T=P.charAt(_),_+=1,T},F=function(){var e,t="";for("-"===T&&(t="-",I("-"));T>="0"&&T<="9";)t+=T,I();if("."===T)for(t+=".";I()&&T>="0"&&T<="9";)t+=T;if("e"===T||"E"===T)for(t+=T,I(),"-"!==T&&"+"!==T||(t+=T,I());T>="0"&&T<="9";)t+=T,I();if(e=+t,isFinite(e))return e;U("Bad number")},C=function(){var e,t,r,n="";if('"'===T)for(;I();){if('"'===T)return I(),n;if("\\"===T)if(I(),"u"===T){for(r=0,t=0;t<4&&(e=parseInt(I(),16),isFinite(e));t+=1)r=16*r+e;n+=String.fromCharCode(r)}else{if("string"!=typeof B[T])break;n+=B[T]}else n+=T}U("Bad string")},k=function(){for(;T&&T<=" ";)I()};q=function(){switch(k(),T){case"{":return function(){var e,t={};if("{"===T){if(I("{"),k(),"}"===T)return I("}"),t;for(;T;){if(e=C(),k(),I(":"),Object.hasOwnProperty.call(t,e)&&U('Duplicate key "'+e+'"'),t[e]=q(),k(),"}"===T)return I("}"),t;I(","),k()}}U("Bad object")}();case"[":return function(){var e=[];if("["===T){if(I("["),k(),"]"===T)return I("]"),e;for(;T;){if(e.push(q()),k(),"]"===T)return I("]"),e;I(","),k()}}U("Bad array")}();case'"':return C();case"-":return F();default:return T>="0"&&T<="9"?F():function(){switch(T){case"t":return I("t"),I("r"),I("u"),I("e"),!0;case"f":return I("f"),I("a"),I("l"),I("s"),I("e"),!1;case"n":return I("n"),I("u"),I("l"),I("l"),null}U("Unexpected '"+T+"'")}()}};var N,D,J,H=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,L={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};function G(e){return H.lastIndex=0,H.test(e)?'"'+e.replace(H,function(e){var t=L[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}var W="undefined"!=typeof JSON?JSON:{parse:function(e,t){var r;return P=e,_=0,T=" ",r=q(),k(),T&&U("Syntax error"),"function"==typeof t?function e(r,n){var o,i,s=r[n];if(s&&"object"==typeof s)for(o in s)Object.prototype.hasOwnProperty.call(s,o)&&(void 0!==(i=e(s,o))?s[o]=i:delete s[o]);return t.call(r,n,s)}({"":r},""):r},stringify:function(e,t,r){var n;if(N="",D="","number"==typeof r)for(n=0;n<r;n+=1)D+=" ";else"string"==typeof r&&(D=r);if(J=t,t&&"function"!=typeof t&&("object"!=typeof t||"number"!=typeof t.length))throw new Error("JSON.stringify");return function e(t,r){var n,o,i,s,a,u=N,f=r[t];switch(f&&"object"==typeof f&&"function"==typeof f.toJSON&&(f=f.toJSON(t)),"function"==typeof J&&(f=J.call(r,t,f)),typeof f){case"string":return G(f);case"number":return isFinite(f)?String(f):"null";case"boolean":case"null":return String(f);case"object":if(!f)return"null";if(N+=D,a=[],"[object Array]"===Object.prototype.toString.apply(f)){for(s=f.length,n=0;n<s;n+=1)a[n]=e(n,f)||"null";return i=0===a.length?"[]":N?"[\n"+N+a.join(",\n"+N)+"\n"+u+"]":"["+a.join(",")+"]",N=u,i}if(J&&"object"==typeof J)for(s=J.length,n=0;n<s;n+=1)"string"==typeof(o=J[n])&&(i=e(o,f))&&a.push(G(o)+(N?": ":":")+i);else for(o in f)Object.prototype.hasOwnProperty.call(f,o)&&(i=e(o,f))&&a.push(G(o)+(N?": ":":")+i);return i=0===a.length?"{}":N?"{\n"+N+a.join(",\n"+N)+"\n"+u+"}":"{"+a.join(",")+"}",N=u,i}}("",{"":e})}},M=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var r=t.space||"";"number"==typeof r&&(r=Array(r+1).join(" "));var n,o="boolean"==typeof t.cycles&&t.cycles,i=t.replacer||function(e,t){return t},s=t.cmp&&(n=t.cmp,function(e){return function(t,r){var o={key:t,value:e[t]},i={key:r,value:e[r]};return n(o,i)}}),a=[];return function e(t,n,u,f){var c=r?"\n"+new Array(f+1).join(r):"",p=r?": ":":";if(u&&u.toJSON&&"function"==typeof u.toJSON&&(u=u.toJSON()),void 0!==(u=i.call(t,n,u))){if("object"!=typeof u||null===u)return W.stringify(u);if(z(u)){for(var d=[],y=0;y<u.length;y++){var h=e(u,y,u[y],f+1)||W.stringify(null);d.push(c+r+h)}return"["+d.join(",")+c+"]"}if(-1!==a.indexOf(u)){if(o)return W.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}a.push(u);var l=K(u).sort(s&&s(u));for(d=[],y=0;y<l.length;y++){var b=e(u,n=l[y],u[n],f+1);if(b){var m=W.stringify(n)+p+b;d.push(c+r+m)}}return a.splice(a.indexOf(u),1),"{"+d.join(",")+c+"}"}}({"":e},"",e,0)},z=Array.isArray||function(e){return"[object Array]"==={}.toString.call(e)},K=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};function V(e,t){for(var n=arguments.length,s=Array(n>2?n-2:0),a=2;a<n;a++)s[a-2]=arguments[a];var u=this,f=i(e),c=f.body,p=void 0,d=void 0,y=o(f,{body:"object"});if(!0!==y)throw y;if(void 0===f.type||"string"!=typeof f.type&&!Array.isArray(f.type)||""===f.type||0===f.type.length)throw new Error("fields missing: type");if(!0!==(y=o(f.body,{query:"object"})))throw y;Array.isArray(f.type)?(p=f.type,d=f.type.join()):(p=[f.type],d=f.type);var h=[],l=c.query;if("string"==typeof t){var b={};b.url=t,b.method="GET",h.push(b)}else if(t.constructor===Array)h=t;else{if(t!==Object(t))throw new Error("fields missing: second argument(webhook) is necessary");h.push(t)}var m=function(){(c={}).webhooks=h,c.query=l,c.type=p};m();var v=".percolator/webhooks-0-"+d+"-0-"+r(M(l));return this.change=function(){if(h=[],"string"==typeof f){var e={};e.url=f,e.method="POST",h.push(e)}else if(f.constructor===Array)h=f;else{if(f!==Object(f))throw new Error("fields missing: one of webhook or url fields is required");h.push(f)}return m(),u.performRequest("POST")},this.stop=function(){return c=void 0,u.performRequest("DELETE")},this.performRequest=function(e){var t=u.performWsRequest.apply(u,[{method:e,path:v,body:c}].concat(s));return t.change=u.change,t.stop=u.stop,t},this.performRequest("POST")}function X(){var e=this;return new Promise(function(t,r){try{return e.performFetchRequest({method:"GET",path:"_mapping"}).then(function(r){var n=Object.keys(r[e.app].mappings).filter(function(e){return"_default_"!==e});return t(n)})}catch(e){return r(e)}})}function Q(){return this.performFetchRequest({method:"GET",path:"_mapping"})}function Y(e,t){var r=i(t),o=n(e,!0);if(!0!==o)throw o;var s={settings:r,query:e};return this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:s,isRSAPI:!0,isSuggestionsAPI:!0})}return function(e){var t=new s(e);return s.prototype.performFetchRequest=l,s.prototype.performWsRequest=m,s.prototype.index=v,s.prototype.get=g,s.prototype.update=w,s.prototype.delete=j,s.prototype.bulk=O,s.prototype.search=x,s.prototype.msearch=A,s.prototype.reactiveSearchv3=S,s.prototype.getQuerySuggestions=Y,s.prototype.getStream=E,s.prototype.searchStream=R,s.prototype.searchStreamToURL=V,s.prototype.getTypes=X,s.prototype.getMappings=Q,s.prototype.setHeaders=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.headers=t?function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r={};return t?Object.keys(e).forEach(function(t){r[t]=encodeURI(e[t])}):r=e,r}(e):e},"undefined"!=typeof window&&(window.Appbase=t),t}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Appbase=t()}(this,function(){"use strict";var e=function(e){var t=RegExp("^(([^:/?#]*)?://)?(((.*)?@)?([^/?#]*)?)([^?#]*)(\\?([^#]*))?(#(.*))?"),r=e.match(t);return{protocol:r[2],auth:r[5],host:r[6],path:r[7],query:r[9],hash:r[11]}},t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function r(){for(var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r="",n=0,o=0,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.charAt(0|o)||(i="=",o%1);r+=i.charAt(63&n>>8-o%1*8)){if((e=t.charCodeAt(o+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');n=n<<8|e}return r}function n(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e&&"[object Array]"===Object.prototype.toString.call(e)){for(var r=0;r<e.length;r+=1){var n=e[r];if(!n)return new Error("query object can not have an empty value");if(!n.id)return new Error("'id' field must be present in query object");if((n.type&&"search"!==n.type||t)&&!n.dataField)return new Error("'dataField' field must be present in query object");if(n.dataField&&"[object Array]"!==Object.prototype.toString.call(n.dataField))return new Error("'dataField' field must be an array")}return!0}return new Error("invalid query value, 'query' value must be an array")}function o(e,r){var n=[],o={object:null,string:""};Object.keys(r).forEach(function(i){var s=r[i];t(e[i])===s&&e[i]!==o[s]||n.push(i)});for(var i="",s=0;s<n.length;s+=1)i+=n[s]+", ";return!(n.length>0)||new Error("fields missing: "+i)}function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e||0!==Object.keys(e).length||e.constructor!==Object?JSON.parse(JSON.stringify(e)):null}function s(t){var r=e(t.url||""),n=r.auth,o=void 0===n?null:n,i=r.host,s=void 0===i?"":i,a=r.path,u=void 0===a?"":a,f=r.protocol,c=void 0===f?"":f,p=s+u;if("string"!=typeof p||""===p)throw new Error("URL not present in options.");if("string"!=typeof t.app||""===t.app)throw new Error("App name is not present in options.");if("string"!=typeof c||""===c)throw new Error("Protocol is not present in url. URL should be of the form https://scalr.api.appbase.io");"/"===p.slice(-1)&&(p=p.slice(0,-1));var d=o||null;if("string"==typeof t.credentials&&""!==t.credentials?d=t.credentials:"string"==typeof t.username&&""!==t.username&&"string"==typeof t.password&&""!==t.password&&(d=t.username+":"+t.password),function(e){return t="scalr.api.appbase.io",-1!==e.indexOf(t);var t}(p)&&null===d)throw new Error("Authentication information is not present. Did you add credentials?");this.url=p,this.protocol=c,this.app=t.app,this.credentials=d,this.headers={}}var a="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function u(e,t){return e(t={exports:{}},t.exports),t.exports}function f(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var c=function(e,t,r,n){t=t||"&",r=r||"=";var o={};if("string"!=typeof e||0===e.length)return o;var i=/\+/g;e=e.split(t);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var a=e.length;s>0&&a>s&&(a=s);for(var u=0;u<a;++u){var c,p,d,y,h=e[u].replace(i,"%20"),l=h.indexOf(r);l>=0?(c=h.substr(0,l),p=h.substr(l+1)):(c=h,p=""),d=decodeURIComponent(c),y=decodeURIComponent(p),f(o,d)?Array.isArray(o[d])?o[d].push(y):o[d]=[o[d],y]:o[d]=y}return o},p=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},d=function(e,t,r,n){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(n){var o=encodeURIComponent(p(n))+r;return Array.isArray(e[n])?e[n].map(function(e){return o+encodeURIComponent(p(e))}).join(t):o+encodeURIComponent(p(e[n]))}).join(t):n?encodeURIComponent(p(n))+r+encodeURIComponent(p(e)):""},y=u(function(e,t){t.decode=t.parse=c,t.encode=t.stringify=d}),h=(y.decode,y.parse,y.encode,y.stringify,u(function(e){var t=function(e){function t(){this.fetch=!1}return t.prototype=e,new t}("undefined"!=typeof self?self:a);(function(e){!function(e){if(!e.fetch){var t={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};if(t.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=function(e){return e&&DataView.prototype.isPrototypeOf(e)},o=ArrayBuffer.isView||function(e){return e&&r.indexOf(Object.prototype.toString.call(e))>-1};c.prototype.append=function(e,t){e=a(e),t=u(t);var r=this.map[e];this.map[e]=r?r+","+t:t},c.prototype.delete=function(e){delete this.map[a(e)]},c.prototype.get=function(e){return e=a(e),this.has(e)?this.map[e]:null},c.prototype.has=function(e){return this.map.hasOwnProperty(a(e))},c.prototype.set=function(e,t){this.map[a(e)]=u(t)},c.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},c.prototype.keys=function(){var e=[];return this.forEach(function(t,r){e.push(r)}),f(e)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),f(e)},c.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),f(e)},t.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var i=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},l.call(b.prototype),l.call(v.prototype),v.prototype.clone=function(){return new v(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},v.error=function(){var e=new v(null,{status:0,statusText:""});return e.type="error",e};var s=[301,302,303,307,308];v.redirect=function(e,t){if(-1===s.indexOf(t))throw new RangeError("Invalid status code");return new v(null,{status:t,headers:{location:e}})},e.Headers=c,e.Request=b,e.Response=v,e.fetch=function(e,r){return new Promise(function(n,o){var i=new b(e,r),s=new XMLHttpRequest;s.onload=function(){var e,t,r={status:s.status,statusText:s.statusText,headers:(e=s.getAllResponseHeaders()||"",t=new c,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(e){var r=e.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();t.append(n,o)}}),t)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var o="response"in s?s.response:s.responseText;n(new v(o,r))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.open(i.method,i.url,!0),"include"===i.credentials?s.withCredentials=!0:"omit"===i.credentials&&(s.withCredentials=!1),"responseType"in s&&t.blob&&(s.responseType="blob"),i.headers.forEach(function(e,t){s.setRequestHeader(t,e)}),s.send(void 0===i._bodyInit?null:i._bodyInit)})},e.fetch.polyfill=!0}function a(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function u(e){return"string"!=typeof e&&(e=String(e)),e}function f(e){var r={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return t.iterable&&(r[Symbol.iterator]=function(){return r}),r}function c(e){this.map={},e instanceof c?e.forEach(function(e,t){this.append(t,e)},this):Array.isArray(e)?e.forEach(function(e){this.append(e[0],e[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function p(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function d(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function y(e){var t=new FileReader,r=d(t);return t.readAsArrayBuffer(e),r}function h(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function l(){return this.bodyUsed=!1,this._initBody=function(e){if(this._bodyInit=e,e)if("string"==typeof e)this._bodyText=e;else if(t.blob&&Blob.prototype.isPrototypeOf(e))this._bodyBlob=e;else if(t.formData&&FormData.prototype.isPrototypeOf(e))this._bodyFormData=e;else if(t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e))this._bodyText=e.toString();else if(t.arrayBuffer&&t.blob&&n(e))this._bodyArrayBuffer=h(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!t.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(e)&&!o(e))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=h(e)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):t.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},t.blob&&(this.blob=function(){var e=p(this);if(e)return e;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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var e,t,r,n=p(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=d(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},t.formData&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}function b(e,t){var r,n,o=(t=t||{}).body;if(e instanceof b){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new c(e.headers)),this.method=e.method,this.mode=e.mode,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"omit",!t.headers&&this.headers||(this.headers=new c(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),i.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function m(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}}),t}function v(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new c(t.headers),this.url=t.url||"",this._initBody(e)}}(void 0!==e?e:this)}).call(t,void 0);var r=t.fetch;r.Response=t.Response,r.Request=t.Request,r.Headers=t.Headers;e.exports&&(e.exports=r,e.exports.default=r)}));function l(e){var t=this;return new Promise(function(n,o){var s=i(e);try{var a=s.method,u=s.path,f=s.params,c=s.body,p=s.isRSAPI,d=s.isSuggestionsAPI?".suggestions":t.app,l=c,b=u.endsWith("msearch")||u.endsWith("bulk")?"application/x-ndjson":"application/json",m=Object.assign({},{Accept:"application/json","Content-Type":b},t.headers),v=Date.now();t.credentials&&(m.Authorization="Basic "+r(t.credentials));var g={method:a,headers:m};if(Array.isArray(l)){var w="";l.forEach(function(e){w+=JSON.stringify(e),w+="\n"}),l=w}else l=JSON.stringify(l)||{};0!==Object.keys(l).length&&(g.body=l);var j={},O="";f&&(O="?"+y.stringify(f));var x=t.protocol+"://"+t.url+"/"+d+"/"+u+O;return function(e){if(t.transformRequest&&"function"==typeof t.transformRequest){var r=t.transformRequest(e);return r instanceof Promise?r:Promise.resolve(r)}return Promise.resolve(e)}(Object.assign({},{url:x},g)).then(function(e){var t=Object.assign({},e),r=t.url;return delete t.url,h(r||x,t).then(function(e){return e.status>=500?o(e):(j=e.headers,e.json().then(function(t){if(e.status>=400)return o(e);if(t&&t.error)return o(t);if(p&&t&&"[object Object]"===Object.prototype.toString.call(t)&&c&&c.query&&c.query instanceof Array){var r=0,i=c.query.filter(function(e){return e.execute||void 0===e.execute}).length;if(t&&Object.keys(t).forEach(function(e){t[e]&&Object.prototype.hasOwnProperty.call(t[e],"error")&&(r+=1)}),r>0&&i===r)return o(t)}if(t&&t.responses instanceof Array&&t.responses.length===t.responses.filter(function(e){return Object.prototype.hasOwnProperty.call(e,"error")}).length)return o(t);var s=Object.assign({},t,{_timestamp:v,_headers:j});return n(s)}).catch(function(e){return o(e)}))}).catch(function(e){return o(e)})}).catch(function(e){return o(e)})}catch(e){return o(e)}})}var b="undefined"!=typeof window?window.WebSocket:require("ws");function m(e,n,o,s){var a=this;try{var u=i(e),f=u.method,c=u.path,p=u.params,d=e.body;d&&"object"===(void 0===d?"undefined":t(d))||(d={});return this.wsClosed=function(){s&&s()},this.stop=function(){a.ws.onmessage=void 0,a.ws.onclose=void 0,a.ws.onerror=void 0,a.wsClosed();var e=JSON.parse(JSON.stringify(a.request));e.unsubscribe=!0,!0!==a.unsubscribed&&a.send(e),a.unsubscribed=!0},this.reconnect=function(){return a.stop(),m(e,n,o,s)},this.processError=function(e){o?o(e):console.warn(e)},this.processMessage=function(e){var t=JSON.parse(JSON.stringify(e));if(t.id||!t.message)return t.id===a.id?t.message?(delete t.id,void(o&&o(t))):(t.query_id&&(a.query_id=t.query_id),t.channel&&(a.channel=t.channel),void(t.body&&""!==t.body&&n&&n(t.body))):void(!t.id&&t.channel&&t.channel===a.channel&&n&&n(t.event));o&&o(t)},a.ws=new b("wss://"+a.url+"/"+a.app),a.id="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}),a.request={id:a.id,path:a.app+"/"+c+"?"+y.stringify(p),method:f,body:d},a.credentials&&(a.request.authorization="Basic "+r(a.credentials)),a.result={},a.closeHandler=function(){a.wsClosed()},a.errorHandler=function(e){a.processError.apply(a,[e])},a.messageHandler=function(e){var t=JSON.parse(e.data);t.body&&t.body.status>=400?a.processError.apply(a,[t]):a.processMessage.apply(a,[t])},a.send=function(e){!function e(t,r){setTimeout(function(){1===t.readyState?null!=r&&r():e(t,r)},5)}(a.ws,function(){try{a.ws.send(JSON.stringify(e))}catch(e){console.warn(e)}})},a.ws.onmessage=a.messageHandler,a.ws.onerror=a.errorHandler,a.ws.onclose=a.closeHandler,a.send(a.request),a.result.stop=a.stop,a.result.reconnect=a.reconnect,a.result}catch(e){return o?o(e):console.warn(e),null}}function v(e){var t=i(e),r=o(t,{type:"string",body:"object"});if(!0!==r)throw r;var n=t.type,s=t.id,a=t.body;delete t.type,delete t.body,delete t.id;var u=void 0;return u=s?n+"/"+encodeURIComponent(s):n,this.performFetchRequest({method:"POST",path:u,params:t,body:a})}function g(e){var t=i(e),r=o(t,{type:"string",id:"string"});if(!0!==r)throw r;var n=t.type,s=t.id;delete t.type,delete t.id;var a=n+"/"+encodeURIComponent(s);return this.performFetchRequest({method:"GET",path:a,params:t})}function w(e){var t=i(e),r=o(t,{type:"string",id:"string",body:"object"});if(!0!==r)throw r;var n=t.type,s=t.id,a=t.body;delete t.type,delete t.id,delete t.body;var u=n+"/"+encodeURIComponent(s)+"/_update";return this.performFetchRequest({method:"POST",path:u,params:t,body:a})}function j(e){var t=i(e),r=o(t,{type:"string",id:"string"});if(!0!==r)throw r;var n=t.type,s=t.id;delete t.type,delete t.id;var a=n+"/"+encodeURIComponent(s);return this.performFetchRequest({method:"DELETE",path:a,params:t})}function O(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;var n=t.type,s=t.body;delete t.type,delete t.body;var a=void 0;return a=n?n+"/_bulk":"/_bulk",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function x(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;var n=void 0;n=Array.isArray(t.type)?t.type.join():t.type;var s=t.body;delete t.type,delete t.body;var a=void 0;return a=n?n+"/_search":"_search",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function A(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;var n=void 0;n=Array.isArray(t.type)?t.type.join():t.type;var s=t.body;delete t.type,delete t.body;var a=void 0;return a=n?n+"/_msearch":"_msearch",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function S(e,t){var r=i(t),o=n(e);if(!0!==o)throw o;var s={settings:r,query:e};return this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:s,isRSAPI:!0})}function E(e){var t=i(e),r=o(t,{type:"string",id:"string"});if(!0!==r)throw r;var n=t.type,s=t.id;delete t.type,delete t.id,delete t.stream,!0===t.stream?t.stream="true":(delete t.stream,t.streamonly="true");for(var a=arguments.length,u=Array(a>1?a-1:0),f=1;f<a;f++)u[f-1]=arguments[f];return this.performWsRequest.apply(this,[{method:"GET",path:n+"/"+encodeURIComponent(s),params:t}].concat(u))}function R(e){var t=i(e),r=o(t,{body:"object"});if(!0!==r)throw r;if(void 0===t.type||Array.isArray(t.type)&&0===t.type.length)throw new Error("Missing fields: type");var n=void 0;n=Array.isArray(t.type)?t.type.join():t.type;var s=t.body;delete t.type,delete t.body,delete t.stream,t.streamonly="true";for(var a=arguments.length,u=Array(a>1?a-1:0),f=1;f<a;f++)u[f-1]=arguments[f];return this.performWsRequest.apply(this,[{method:"POST",path:n+"/_search",params:t,body:s}].concat(u))}var _,T,P,q,B={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"},U=function(e){throw{name:"SyntaxError",message:e,at:_,text:P}},I=function(e){return e&&e!==T&&U("Expected '"+e+"' instead of '"+T+"'"),T=P.charAt(_),_+=1,T},F=function(){var e,t="";for("-"===T&&(t="-",I("-"));T>="0"&&T<="9";)t+=T,I();if("."===T)for(t+=".";I()&&T>="0"&&T<="9";)t+=T;if("e"===T||"E"===T)for(t+=T,I(),"-"!==T&&"+"!==T||(t+=T,I());T>="0"&&T<="9";)t+=T,I();if(e=+t,isFinite(e))return e;U("Bad number")},C=function(){var e,t,r,n="";if('"'===T)for(;I();){if('"'===T)return I(),n;if("\\"===T)if(I(),"u"===T){for(r=0,t=0;t<4&&(e=parseInt(I(),16),isFinite(e));t+=1)r=16*r+e;n+=String.fromCharCode(r)}else{if("string"!=typeof B[T])break;n+=B[T]}else n+=T}U("Bad string")},k=function(){for(;T&&T<=" ";)I()};q=function(){switch(k(),T){case"{":return function(){var e,t={};if("{"===T){if(I("{"),k(),"}"===T)return I("}"),t;for(;T;){if(e=C(),k(),I(":"),Object.hasOwnProperty.call(t,e)&&U('Duplicate key "'+e+'"'),t[e]=q(),k(),"}"===T)return I("}"),t;I(","),k()}}U("Bad object")}();case"[":return function(){var e=[];if("["===T){if(I("["),k(),"]"===T)return I("]"),e;for(;T;){if(e.push(q()),k(),"]"===T)return I("]"),e;I(","),k()}}U("Bad array")}();case'"':return C();case"-":return F();default:return T>="0"&&T<="9"?F():function(){switch(T){case"t":return I("t"),I("r"),I("u"),I("e"),!0;case"f":return I("f"),I("a"),I("l"),I("s"),I("e"),!1;case"n":return I("n"),I("u"),I("l"),I("l"),null}U("Unexpected '"+T+"'")}()}};var N,D,J,H=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,L={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};function G(e){return H.lastIndex=0,H.test(e)?'"'+e.replace(H,function(e){var t=L[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}var W="undefined"!=typeof JSON?JSON:{parse:function(e,t){var r;return P=e,_=0,T=" ",r=q(),k(),T&&U("Syntax error"),"function"==typeof t?function e(r,n){var o,i,s=r[n];if(s&&"object"==typeof s)for(o in s)Object.prototype.hasOwnProperty.call(s,o)&&(void 0!==(i=e(s,o))?s[o]=i:delete s[o]);return t.call(r,n,s)}({"":r},""):r},stringify:function(e,t,r){var n;if(N="",D="","number"==typeof r)for(n=0;n<r;n+=1)D+=" ";else"string"==typeof r&&(D=r);if(J=t,t&&"function"!=typeof t&&("object"!=typeof t||"number"!=typeof t.length))throw new Error("JSON.stringify");return function e(t,r){var n,o,i,s,a,u=N,f=r[t];switch(f&&"object"==typeof f&&"function"==typeof f.toJSON&&(f=f.toJSON(t)),"function"==typeof J&&(f=J.call(r,t,f)),typeof f){case"string":return G(f);case"number":return isFinite(f)?String(f):"null";case"boolean":case"null":return String(f);case"object":if(!f)return"null";if(N+=D,a=[],"[object Array]"===Object.prototype.toString.apply(f)){for(s=f.length,n=0;n<s;n+=1)a[n]=e(n,f)||"null";return i=0===a.length?"[]":N?"[\n"+N+a.join(",\n"+N)+"\n"+u+"]":"["+a.join(",")+"]",N=u,i}if(J&&"object"==typeof J)for(s=J.length,n=0;n<s;n+=1)"string"==typeof(o=J[n])&&(i=e(o,f))&&a.push(G(o)+(N?": ":":")+i);else for(o in f)Object.prototype.hasOwnProperty.call(f,o)&&(i=e(o,f))&&a.push(G(o)+(N?": ":":")+i);return i=0===a.length?"{}":N?"{\n"+N+a.join(",\n"+N)+"\n"+u+"}":"{"+a.join(",")+"}",N=u,i}}("",{"":e})}},M=function(e,t){t||(t={}),"function"==typeof t&&(t={cmp:t});var r=t.space||"";"number"==typeof r&&(r=Array(r+1).join(" "));var n,o="boolean"==typeof t.cycles&&t.cycles,i=t.replacer||function(e,t){return t},s=t.cmp&&(n=t.cmp,function(e){return function(t,r){var o={key:t,value:e[t]},i={key:r,value:e[r]};return n(o,i)}}),a=[];return function e(t,n,u,f){var c=r?"\n"+new Array(f+1).join(r):"",p=r?": ":":";if(u&&u.toJSON&&"function"==typeof u.toJSON&&(u=u.toJSON()),void 0!==(u=i.call(t,n,u))){if("object"!=typeof u||null===u)return W.stringify(u);if(z(u)){for(var d=[],y=0;y<u.length;y++){var h=e(u,y,u[y],f+1)||W.stringify(null);d.push(c+r+h)}return"["+d.join(",")+c+"]"}if(-1!==a.indexOf(u)){if(o)return W.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}a.push(u);var l=K(u).sort(s&&s(u));for(d=[],y=0;y<l.length;y++){var b=e(u,n=l[y],u[n],f+1);if(b){var m=W.stringify(n)+p+b;d.push(c+r+m)}}return a.splice(a.indexOf(u),1),"{"+d.join(",")+c+"}"}}({"":e},"",e,0)},z=Array.isArray||function(e){return"[object Array]"==={}.toString.call(e)},K=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};function V(e,t){for(var n=arguments.length,s=Array(n>2?n-2:0),a=2;a<n;a++)s[a-2]=arguments[a];var u=this,f=i(e),c=f.body,p=void 0,d=void 0,y=o(f,{body:"object"});if(!0!==y)throw y;if(void 0===f.type||"string"!=typeof f.type&&!Array.isArray(f.type)||""===f.type||0===f.type.length)throw new Error("fields missing: type");if(!0!==(y=o(f.body,{query:"object"})))throw y;Array.isArray(f.type)?(p=f.type,d=f.type.join()):(p=[f.type],d=f.type);var h=[],l=c.query;if("string"==typeof t){var b={};b.url=t,b.method="GET",h.push(b)}else if(t.constructor===Array)h=t;else{if(t!==Object(t))throw new Error("fields missing: second argument(webhook) is necessary");h.push(t)}var m=function(){(c={}).webhooks=h,c.query=l,c.type=p};m();var v=".percolator/webhooks-0-"+d+"-0-"+r(M(l));return this.change=function(){if(h=[],"string"==typeof f){var e={};e.url=f,e.method="POST",h.push(e)}else if(f.constructor===Array)h=f;else{if(f!==Object(f))throw new Error("fields missing: one of webhook or url fields is required");h.push(f)}return m(),u.performRequest("POST")},this.stop=function(){return c=void 0,u.performRequest("DELETE")},this.performRequest=function(e){var t=u.performWsRequest.apply(u,[{method:e,path:v,body:c}].concat(s));return t.change=u.change,t.stop=u.stop,t},this.performRequest("POST")}function X(){var e=this;return new Promise(function(t,r){try{return e.performFetchRequest({method:"GET",path:"_mapping"}).then(function(r){var n=Object.keys(r[e.app].mappings).filter(function(e){return"_default_"!==e});return t(n)})}catch(e){return r(e)}})}function Q(){return this.performFetchRequest({method:"GET",path:"_mapping"})}function Y(e,t){var r=i(t),o=n(e,!0);if(!0!==o)throw o;var s={settings:r,query:e};return this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:s,isRSAPI:!0,isSuggestionsAPI:!0})}return function(e){var t=new s(e);return s.prototype.performFetchRequest=l,s.prototype.performWsRequest=m,s.prototype.index=v,s.prototype.get=g,s.prototype.update=w,s.prototype.delete=j,s.prototype.bulk=O,s.prototype.search=x,s.prototype.msearch=A,s.prototype.reactiveSearchv3=S,s.prototype.getQuerySuggestions=Y,s.prototype.getStream=E,s.prototype.searchStream=R,s.prototype.searchStreamToURL=V,s.prototype.getTypes=X,s.prototype.getMappings=Q,s.prototype.setHeaders=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.headers=t?function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r={};return t?Object.keys(e).forEach(function(t){r[t]=encodeURI(e[t])}):r=e,r}(e):e},"undefined"!=typeof window&&(window.Appbase=t),t}}); | ||
//# sourceMappingURL=appbase-js.umd.min.js.map |
{ | ||
"name": "appbase-js", | ||
"version": "4.1.2", | ||
"version": "4.1.3", | ||
"main": "dist/appbase-js.cjs.js", | ||
@@ -5,0 +5,0 @@ "jsnext:main": "dist/appbase-js.es.js", |
Sorry, the diff of this file is too big to display
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
379791
4010