appbase-js
Advanced tools
Comparing version 4.4.13-alpha to 4.4.14-alpha
@@ -793,3 +793,3 @@ 'use strict'; | ||
} | ||
console.log('reactive', body); | ||
return this.performFetchRequest({ | ||
@@ -831,2 +831,3 @@ method: 'POST', | ||
} | ||
console.log('reactivev3', body); | ||
return this.performFetchRequest({ | ||
@@ -833,0 +834,0 @@ method: 'POST', |
@@ -789,3 +789,3 @@ import URL from 'url-parser-lite'; | ||
} | ||
console.log('reactive', body); | ||
return this.performFetchRequest({ | ||
@@ -827,2 +827,3 @@ method: 'POST', | ||
} | ||
console.log('reactivev3', body); | ||
return this.performFetchRequest({ | ||
@@ -829,0 +830,0 @@ method: 'POST', |
@@ -1412,3 +1412,3 @@ (function (global, factory) { | ||
} | ||
console.log('reactive', body); | ||
return this.performFetchRequest({ | ||
@@ -1450,2 +1450,3 @@ method: 'POST', | ||
} | ||
console.log('reactivev3', body); | ||
return this.performFetchRequest({ | ||
@@ -1452,0 +1453,0 @@ method: 'POST', |
@@ -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(e){if(e&&"[object Array]"===Object.prototype.toString.call(e)){for(var t=0;t<e.length;t+=1){var r=e[t];if(!r)return new Error("query object can not have an empty value");if(!r.id)return new Error("'id' field must be present in query object")}return!0}return new Error("invalid query value, 'query' value must be an array")}function o(e,r){var o=[],n={object:null,string:"",number:0};Object.keys(r).forEach(function(i){var s=r[i].split("|").find(function(r){return t(e[i])===r});s&&e[i]!==n[s]||o.push(i)});for(var i="",s=0;s<o.length;s+=1)i+=o[s]+", ";return!(o.length>0)||new Error("fields missing: "+i)}function n(){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 i(e,t){var r={};return e&&(r.index=e),t&&(t.db&&(r.db=t.db),t.collection&&(r.collection=t.collection)),r}function s(e,t){var r={};return t?(Object.assign(r,{"X-Search-Client":"Appbase JS"}),!1===e&&Object.assign(r,{"X-Enable-Telemetry":e}),r):r}var a={MONGODB:"mongodb",ELASTICSEARCH:"elasticsearch"},u="array",d="object",c="boolean",p="string",h=function(e){return(void 0===e?"undefined":t(e))===d?Array.isArray(e)?u:d:void 0===e?"undefined":t(e)};var f={mongodb:{url:{type:p,required:!0},app:{type:p,required:!1},credentials:{type:p,required:!1},enableTelemetry:{type:c,required:!1},mongodb:{type:d,required:!0},username:{type:p,required:!1},password:{type:p,required:!1}},elasticsearch:{url:{type:p,required:!0},app:{type:p,required:!0},credentials:{type:p,required:!1},enableTelemetry:{type:c,required:!1},username:{type:p,required:!1},password:{type:p,required:!1}}};function y(t){var r=e(t.url||""),o=r.auth,n=void 0===o?null:o,i=r.host,s=void 0===i?"":i,u=r.path,d=void 0===u?"":u,c=r.protocol,p=void 0===c?"":c,y=t.url;"/"===(y=s+d).slice(-1)&&(y=y.slice(0,-1));var l=a[t.mongodb?"MONGODB":"ELASTICSEARCH"],b=f[l];if(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",o=Object.keys(e).filter(function(t){return!!e[t]}),n=Object.keys(t),i=[];n.forEach(function(e){t[e].required&&i.push(e)}),i.forEach(function(e){if(!o.includes(e))throw new Error(e+" is required when using the "+r+" Search backend.")}),o.forEach(function(o){if(!n.includes(o))throw new Error(o+" property isn't accepted property by "+r+" backend.");var i=Array.isArray(t[o].type)?t[o].type:[].concat(t[o].type),s=h(e[o]);if(!i.includes(s))throw new Error("The property "+o+" is expected with type(s) ["+i.join(", ")+"], but type was set as "+s+".")})}({url:t.url,app:t.app,credentials:t.credentials,username:t.username,password:t.password,enableTelemetry:t.enableTelemetry,mongodb:t.mongodb},b,l),"string"!=typeof p||""===p)throw new Error("Protocol is not present in url. URL should be of the form https://appbase-demo-ansible-abxiydt-arc.searchbase.io");var m=n||null;if(!t.mongodb&&function(e){return t="scalr.api.appbase.io",-1!==e.indexOf(t);var t}(y)&&null===m)throw new Error("Authentication information is not present. Did you add credentials?");"string"==typeof t.credentials&&""!==t.credentials?m=t.credentials:"string"==typeof t.username&&""!==t.username&&"string"==typeof t.password&&""!==t.password&&(m=t.username+":"+t.password),this.url=y,this.protocol=p,this.app=t.app,this.credentials=m,t.mongodb&&(this.mongodb=t.mongodb),"boolean"==typeof t.enableTelemetry&&(this.enableTelemetry=t.enableTelemetry)}var l="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function b(e,t){return e(t={exports:{}},t.exports),t.exports}function m(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var v=function(e,t,r,o){t=t||"&",r=r||"=";var n={};if("string"!=typeof e||0===e.length)return n;var i=/\+/g;e=e.split(t);var s=1e3;o&&"number"==typeof o.maxKeys&&(s=o.maxKeys);var a=e.length;s>0&&a>s&&(a=s);for(var u=0;u<a;++u){var d,c,p,h,f=e[u].replace(i,"%20"),y=f.indexOf(r);y>=0?(d=f.substr(0,y),c=f.substr(y+1)):(d=f,c=""),p=decodeURIComponent(d),h=decodeURIComponent(c),m(n,p)?Array.isArray(n[p])?n[p].push(h):n[p]=[n[p],h]:n[p]=h}return n},g=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},w=function(e,t,r,o){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(o){var n=encodeURIComponent(g(o))+r;return Array.isArray(e[o])?e[o].map(function(e){return n+encodeURIComponent(g(e))}).join(t):n+encodeURIComponent(g(e[o]))}).join(t):o?encodeURIComponent(g(o))+r+encodeURIComponent(g(e)):""},A=b(function(e,t){t.decode=t.parse=v,t.encode=t.stringify=w}),O=(A.decode,A.parse,A.encode,A.stringify,b(function(e){var t=function(e){function t(){this.fetch=!1}return t.prototype=e,new t}("undefined"!=typeof self?self:l);(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]"],o=function(e){return e&&DataView.prototype.isPrototypeOf(e)},n=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)}),d(e)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),d(e)},c.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),d(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(o,n){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(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();t.append(o,n)}}),t)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var n="response"in s?s.response:s.responseText;o(new v(n,r))},s.onerror=function(){n(new TypeError("Network request failed"))},s.ontimeout=function(){n(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 d(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 h(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function f(e){var t=new FileReader,r=h(t);return t.readAsArrayBuffer(e),r}function y(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&&o(e))this._bodyArrayBuffer=y(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!t.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(e)&&!n(e))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=y(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(f)}),this.text=function(){var e,t,r,o=p(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=h(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),o=0;o<t.length;o++)r[o]=String.fromCharCode(t[o]);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,o,n=(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,n||null==e._bodyInit||(n=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",o=r.toUpperCase(),i.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function m(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var r=e.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(n))}}),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 j(e){var t=this;return new Promise(function(r,o){var i=n(e);try{var s=i.method,a=i.path,u=i.params,d=i.body,c=i.isRSAPI,p=i.isSuggestionsAPI,h=i.isMongoRequest,f=void 0!==h&&h,y=p?".suggestions":t.app,l=d,b=a.endsWith("msearch")||a.endsWith("bulk")?"application/x-ndjson":"application/json",m=Object.assign({},{Accept:"application/json","Content-Type":b},e.headers,t.headers),v=Date.now();t.credentials&&(m.Authorization="Basic "+function(){for(var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r="",o=0,n=0,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.charAt(0|n)||(i="=",n%1);r+=i.charAt(63&o>>8-n%1*8)){if((e=t.charCodeAt(n+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');o=o<<8|e}return r}(t.credentials));var g={method:s,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),console.log("requestOptions",g);var j={},R="";u&&(R="?"+A.stringify(u));var T=t.mongodb?t.protocol+"://"+t.url:t.protocol+"://"+t.url+"/"+y+"/"+a+R;return console.log("finalURL",T),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:T},g)).then(function(e){var t=Object.assign({},e),n=t.url;return delete t.url,console.log("{ url } = transformedRequest",n),O(n||T,Object.assign({},t,{headers:c&&!f?Object.assign({},t.headers,{"x-timestamp":(new Date).getTime()}):t.headers})).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(c&&t&&"[object Object]"===Object.prototype.toString.call(t)&&d&&d.query&&d.query instanceof Array){var n=0,i=d.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")&&(n+=1)}),n>0&&i===n)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 r(s)}).catch(function(e){return o(e)}))}).catch(function(e){return o(e)})}).catch(function(e){return o(e)})}catch(e){return o(e)}})}function R(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id,u=t.body;delete t.type,delete t.body,delete t.id;var d=void 0;return d=a?s?s+"/"+encodeURIComponent(a):encodeURIComponent(a):s,this.performFetchRequest({method:"POST",path:d,params:t,body:u})}function T(e){var t=n(e),r=o(t,{id:"string|number"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id;delete t.type,delete t.id;var u=s+"/"+encodeURIComponent(a);return this.performFetchRequest({method:"GET",path:u,params:t})}function E(e){var t=n(e),r=o(t,{id:"string|number",body:"object"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id,u=t.body;delete t.type,delete t.id,delete t.body;var d=s+"/"+encodeURIComponent(a)+"/_update";return this.performFetchRequest({method:"POST",path:d,params:t,body:u})}function q(e){var t=n(e),r=o(t,{id:"string|number"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id;delete t.type,delete t.id;var u=s+"/"+encodeURIComponent(a);return this.performFetchRequest({method:"DELETE",path:u,params:t})}function _(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=t.type,s=t.body;delete t.type,delete t.body;var a=void 0;return a=i?i+"/_bulk":"_bulk",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function S(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=void 0;i=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=i?i+"/_search":"_search",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function P(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=void 0;i=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=i?i+"/_msearch":"_msearch",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function x(e,t){var o=n(t),a=r(e);if(!0!==a)throw a;var u={settings:o,query:e};return this.mongodb&&Object.assign(u,{mongodb:i(this.app,this.mongodb)}),this.performFetchRequest({method:"POST",path:"_reactivesearch",body:u,headers:s(this.enableTelemetry,!this.mongodb),isRSAPI:!0,isMongoRequest:!!this.mongodb})}function B(e,t){var o=n(t),a=r(e);if(!0!==a)throw a;var u={settings:o,query:e};return this.mongodb&&Object.assign(u,{mongodb:i(this.app,this.mongodb)}),this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:u,headers:s(this.enableTelemetry,!this.mongodb),isRSAPI:!this.mongodb,isMongoRequest:!!this.mongodb})}function U(){return this.performFetchRequest({method:"GET",path:"_mapping"})}function I(e,t){var o=n(t),i=r(e);if(!0!==i)throw i;var a={settings:o,query:e};return this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:a,headers:s(this.enableTelemetry),isRSAPI:!0,isSuggestionsAPI:!0})}return function(e){var t=new y(e);return y.prototype.performFetchRequest=j,y.prototype.index=R,y.prototype.get=T,y.prototype.update=E,y.prototype.delete=q,y.prototype.bulk=_,y.prototype.search=S,y.prototype.msearch=P,y.prototype.reactiveSearch=x,y.prototype.reactiveSearchv3=B,y.prototype.getQuerySuggestions=I,y.prototype.getMappings=U,y.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(e){if(e&&"[object Array]"===Object.prototype.toString.call(e)){for(var t=0;t<e.length;t+=1){var r=e[t];if(!r)return new Error("query object can not have an empty value");if(!r.id)return new Error("'id' field must be present in query object")}return!0}return new Error("invalid query value, 'query' value must be an array")}function o(e,r){var o=[],n={object:null,string:"",number:0};Object.keys(r).forEach(function(i){var s=r[i].split("|").find(function(r){return t(e[i])===r});s&&e[i]!==n[s]||o.push(i)});for(var i="",s=0;s<o.length;s+=1)i+=o[s]+", ";return!(o.length>0)||new Error("fields missing: "+i)}function n(){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 i(e,t){var r={};return e&&(r.index=e),t&&(t.db&&(r.db=t.db),t.collection&&(r.collection=t.collection)),r}function s(e,t){var r={};return t?(Object.assign(r,{"X-Search-Client":"Appbase JS"}),!1===e&&Object.assign(r,{"X-Enable-Telemetry":e}),r):r}var a={MONGODB:"mongodb",ELASTICSEARCH:"elasticsearch"},u="array",d="object",c="boolean",p="string",h=function(e){return(void 0===e?"undefined":t(e))===d?Array.isArray(e)?u:d:void 0===e?"undefined":t(e)};var f={mongodb:{url:{type:p,required:!0},app:{type:p,required:!1},credentials:{type:p,required:!1},enableTelemetry:{type:c,required:!1},mongodb:{type:d,required:!0},username:{type:p,required:!1},password:{type:p,required:!1}},elasticsearch:{url:{type:p,required:!0},app:{type:p,required:!0},credentials:{type:p,required:!1},enableTelemetry:{type:c,required:!1},username:{type:p,required:!1},password:{type:p,required:!1}}};function y(t){var r=e(t.url||""),o=r.auth,n=void 0===o?null:o,i=r.host,s=void 0===i?"":i,u=r.path,d=void 0===u?"":u,c=r.protocol,p=void 0===c?"":c,y=t.url;"/"===(y=s+d).slice(-1)&&(y=y.slice(0,-1));var l=a[t.mongodb?"MONGODB":"ELASTICSEARCH"],b=f[l];if(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",o=Object.keys(e).filter(function(t){return!!e[t]}),n=Object.keys(t),i=[];n.forEach(function(e){t[e].required&&i.push(e)}),i.forEach(function(e){if(!o.includes(e))throw new Error(e+" is required when using the "+r+" Search backend.")}),o.forEach(function(o){if(!n.includes(o))throw new Error(o+" property isn't accepted property by "+r+" backend.");var i=Array.isArray(t[o].type)?t[o].type:[].concat(t[o].type),s=h(e[o]);if(!i.includes(s))throw new Error("The property "+o+" is expected with type(s) ["+i.join(", ")+"], but type was set as "+s+".")})}({url:t.url,app:t.app,credentials:t.credentials,username:t.username,password:t.password,enableTelemetry:t.enableTelemetry,mongodb:t.mongodb},b,l),"string"!=typeof p||""===p)throw new Error("Protocol is not present in url. URL should be of the form https://appbase-demo-ansible-abxiydt-arc.searchbase.io");var m=n||null;if(!t.mongodb&&function(e){return t="scalr.api.appbase.io",-1!==e.indexOf(t);var t}(y)&&null===m)throw new Error("Authentication information is not present. Did you add credentials?");"string"==typeof t.credentials&&""!==t.credentials?m=t.credentials:"string"==typeof t.username&&""!==t.username&&"string"==typeof t.password&&""!==t.password&&(m=t.username+":"+t.password),this.url=y,this.protocol=p,this.app=t.app,this.credentials=m,t.mongodb&&(this.mongodb=t.mongodb),"boolean"==typeof t.enableTelemetry&&(this.enableTelemetry=t.enableTelemetry)}var l="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function b(e,t){return e(t={exports:{}},t.exports),t.exports}function m(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var v=function(e,t,r,o){t=t||"&",r=r||"=";var n={};if("string"!=typeof e||0===e.length)return n;var i=/\+/g;e=e.split(t);var s=1e3;o&&"number"==typeof o.maxKeys&&(s=o.maxKeys);var a=e.length;s>0&&a>s&&(a=s);for(var u=0;u<a;++u){var d,c,p,h,f=e[u].replace(i,"%20"),y=f.indexOf(r);y>=0?(d=f.substr(0,y),c=f.substr(y+1)):(d=f,c=""),p=decodeURIComponent(d),h=decodeURIComponent(c),m(n,p)?Array.isArray(n[p])?n[p].push(h):n[p]=[n[p],h]:n[p]=h}return n},g=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},w=function(e,t,r,o){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map(function(o){var n=encodeURIComponent(g(o))+r;return Array.isArray(e[o])?e[o].map(function(e){return n+encodeURIComponent(g(e))}).join(t):n+encodeURIComponent(g(e[o]))}).join(t):o?encodeURIComponent(g(o))+r+encodeURIComponent(g(e)):""},A=b(function(e,t){t.decode=t.parse=v,t.encode=t.stringify=w}),O=(A.decode,A.parse,A.encode,A.stringify,b(function(e){var t=function(e){function t(){this.fetch=!1}return t.prototype=e,new t}("undefined"!=typeof self?self:l);(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]"],o=function(e){return e&&DataView.prototype.isPrototypeOf(e)},n=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)}),d(e)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),d(e)},c.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),d(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(o,n){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(":"),o=r.shift().trim();if(o){var n=r.join(":").trim();t.append(o,n)}}),t)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var n="response"in s?s.response:s.responseText;o(new v(n,r))},s.onerror=function(){n(new TypeError("Network request failed"))},s.ontimeout=function(){n(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 d(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 h(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function f(e){var t=new FileReader,r=h(t);return t.readAsArrayBuffer(e),r}function y(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&&o(e))this._bodyArrayBuffer=y(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!t.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(e)&&!n(e))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=y(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(f)}),this.text=function(){var e,t,r,o=p(this);if(o)return o;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=h(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),o=0;o<t.length;o++)r[o]=String.fromCharCode(t[o]);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,o,n=(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,n||null==e._bodyInit||(n=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",o=r.toUpperCase(),i.indexOf(o)>-1?o:r),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function m(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var r=e.split("="),o=r.shift().replace(/\+/g," "),n=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(o),decodeURIComponent(n))}}),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 j(e){var t=this;return new Promise(function(r,o){var i=n(e);try{var s=i.method,a=i.path,u=i.params,d=i.body,c=i.isRSAPI,p=i.isSuggestionsAPI,h=i.isMongoRequest,f=void 0!==h&&h,y=p?".suggestions":t.app,l=d,b=a.endsWith("msearch")||a.endsWith("bulk")?"application/x-ndjson":"application/json",m=Object.assign({},{Accept:"application/json","Content-Type":b},e.headers,t.headers),v=Date.now();t.credentials&&(m.Authorization="Basic "+function(){for(var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r="",o=0,n=0,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.charAt(0|n)||(i="=",n%1);r+=i.charAt(63&o>>8-n%1*8)){if((e=t.charCodeAt(n+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');o=o<<8|e}return r}(t.credentials));var g={method:s,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),console.log("requestOptions",g);var j={},R="";u&&(R="?"+A.stringify(u));var T=t.mongodb?t.protocol+"://"+t.url:t.protocol+"://"+t.url+"/"+y+"/"+a+R;return console.log("finalURL",T),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:T},g)).then(function(e){var t=Object.assign({},e),n=t.url;return delete t.url,console.log("{ url } = transformedRequest",n),O(n||T,Object.assign({},t,{headers:c&&!f?Object.assign({},t.headers,{"x-timestamp":(new Date).getTime()}):t.headers})).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(c&&t&&"[object Object]"===Object.prototype.toString.call(t)&&d&&d.query&&d.query instanceof Array){var n=0,i=d.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")&&(n+=1)}),n>0&&i===n)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 r(s)}).catch(function(e){return o(e)}))}).catch(function(e){return o(e)})}).catch(function(e){return o(e)})}catch(e){return o(e)}})}function R(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id,u=t.body;delete t.type,delete t.body,delete t.id;var d=void 0;return d=a?s?s+"/"+encodeURIComponent(a):encodeURIComponent(a):s,this.performFetchRequest({method:"POST",path:d,params:t,body:u})}function T(e){var t=n(e),r=o(t,{id:"string|number"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id;delete t.type,delete t.id;var u=s+"/"+encodeURIComponent(a);return this.performFetchRequest({method:"GET",path:u,params:t})}function E(e){var t=n(e),r=o(t,{id:"string|number",body:"object"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id,u=t.body;delete t.type,delete t.id,delete t.body;var d=s+"/"+encodeURIComponent(a)+"/_update";return this.performFetchRequest({method:"POST",path:d,params:t,body:u})}function q(e){var t=n(e),r=o(t,{id:"string|number"});if(!0!==r)throw r;var i=t.type,s=void 0===i?"_doc":i,a=t.id;delete t.type,delete t.id;var u=s+"/"+encodeURIComponent(a);return this.performFetchRequest({method:"DELETE",path:u,params:t})}function _(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=t.type,s=t.body;delete t.type,delete t.body;var a=void 0;return a=i?i+"/_bulk":"_bulk",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function S(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=void 0;i=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=i?i+"/_search":"_search",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function P(e){var t=n(e),r=o(t,{body:"object"});if(!0!==r)throw r;var i=void 0;i=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=i?i+"/_msearch":"_msearch",this.performFetchRequest({method:"POST",path:a,params:t,body:s})}function x(e,t){var o=n(t),a=r(e);if(!0!==a)throw a;var u={settings:o,query:e};return this.mongodb&&Object.assign(u,{mongodb:i(this.app,this.mongodb)}),console.log("reactive",u),this.performFetchRequest({method:"POST",path:"_reactivesearch",body:u,headers:s(this.enableTelemetry,!this.mongodb),isRSAPI:!0,isMongoRequest:!!this.mongodb})}function B(e,t){var o=n(t),a=r(e);if(!0!==a)throw a;var u={settings:o,query:e};return this.mongodb&&Object.assign(u,{mongodb:i(this.app,this.mongodb)}),console.log("reactivev3",u),this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:u,headers:s(this.enableTelemetry,!this.mongodb),isRSAPI:!this.mongodb,isMongoRequest:!!this.mongodb})}function U(){return this.performFetchRequest({method:"GET",path:"_mapping"})}function I(e,t){var o=n(t),i=r(e);if(!0!==i)throw i;var a={settings:o,query:e};return this.performFetchRequest({method:"POST",path:"_reactivesearch.v3",body:a,headers:s(this.enableTelemetry),isRSAPI:!0,isSuggestionsAPI:!0})}return function(e){var t=new y(e);return y.prototype.performFetchRequest=j,y.prototype.index=R,y.prototype.get=T,y.prototype.update=E,y.prototype.delete=q,y.prototype.bulk=_,y.prototype.search=S,y.prototype.msearch=P,y.prototype.reactiveSearch=x,y.prototype.reactiveSearchv3=B,y.prototype.getQuerySuggestions=I,y.prototype.getMappings=U,y.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.4.13-alpha", | ||
"version": "4.4.14-alpha", | ||
"main": "dist/appbase-js.cjs.js", | ||
@@ -5,0 +5,0 @@ "jsnext:main": "dist/appbase-js.es.js", |
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
279790
3110