doofinder
Advanced tools
Comparing version 6.0.0 to 6.0.1
@@ -1,1 +0,1 @@ | ||
var doofinder=function(e){"use strict";class t extends Error{}function r(e){return"[object String]"===Object.prototype.toString.call(e)}function i(e){return"[object Number]"===Object.prototype.toString.call(e)&&!isNaN(e)}function s(e){return"[object Object]"===Object.prototype.toString.call(e)}function n(e){return s(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}const o=/^([0-9a-f]{32})@([\w-]+)@([0-9a-f]{32})$/i,a=/^([0-9a-f]{32})(-.*)?/i;function c(e){return r(e)&&o.test(e)}function l(e){return r(e)&&a.test(e)}function u(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function f(e,t){if(u(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const r=Object.keys(e),i=Object.keys(t);if(r.length!==i.length)return!1;for(let i=0;i<r.length;i++)if(!Object.prototype.hasOwnProperty.call(t,r[i])||!u(e[r[i]],t[r[i]]))return!1;return!0}class d{constructor(){this._types=new Set}set(e){const i=Array.isArray(e)?e:[e];if(i.filter(r).length!==i.length)throw new t("types must be strings");this._types=new Set(i)}dump(){return Array.from(this._types)}clear(){this._types.clear()}add(e){if("string"!=typeof e)throw new t("types must be strings");this._types.add(e)}has(e){return this._types.has(e)}remove(e){this._types.delete(e)}}function h(...e){const t=e.length;let r,i,s,o,a,c,l=e[0]||{},u=1,f=!1;if("boolean"==typeof l&&(f=l,l=e[u]||{},u++),"object"!=typeof l&&"function"!=typeof l&&(l={}),u===t)return l;for(;u<t;u++)if(null!=(r=e[u]))for(i in r)o=r[i],"__proto__"!==i&&l!==o&&(f&&o&&(n(o)||(a=Array.isArray(o)))?(s=l[i],c=a&&!Array.isArray(s)?[]:!a&&n(s)?{}:s,a=!1,l[i]=h(f,c,o)):void 0!==o&&(l[i]=o));return l}function p(e){return Array.isArray(e)?h(!0,[],e):n(e)?h(!0,{},e):e}class y{constructor(){this._filters=new Map}get(e){return this._denormalize(this._filters.get(e))}set(e,r){const i=this._normalize(r);if(i instanceof Set)this._filters.set(e,i);else{if(n(i)&&0===Object.entries(i).length)throw new t("plain object filters can't be empty");this._filters.set(e,p(i))}}has(e){return this._filters.has(e)}contains(e,t){return this.has(e)&&this._filterContainsOrEqualsValue(e,t,!1)}equals(e,t){return this.has(e)&&this._filterContainsOrEqualsValue(e,t,!0)}add(e,t){const r=this._normalize(t),i=this._filters.get(e);i instanceof Set?r instanceof Set?this._filters.set(e,new Set([...i,...r])):i.add(r):this._filters.set(e,r)}remove(e,t){const r=this._filters.get(e);if(r instanceof Set&&null!=t){const i=this._normalize(t);if(i instanceof Set)for(const e of i)r.delete(e);else r.delete(i);0===r.size&&this._filters.delete(e)}else this._filters.delete(e)}clear(){this._filters.clear()}setMany(e,t=!1){t&&this.clear();for(const t in e)this.set(t,e[t])}dump(){const e={};if(this._filters.forEach((t,r)=>{e[r]=this._denormalize(t)}),Object.keys(e).length>0)return e}_normalize(e){return r(e)||i(e)?new Set([e]):Array.isArray(e)?new Set(e):e}_denormalize(e){return e instanceof Set?[...e]:e}_filterContainsOrEqualsValue(e,t,r){const i=this._normalize(t),s=this._filters.get(e);if(s instanceof Set&&i instanceof Set){if(r&&s.size!==i.size)return!1;for(const e of i)if(!s.has(e))return!1;return!0}return f(s,i)}}class m{constructor(){this._sortings=[]}set(e,t){return this.clear(),"string"==typeof e?this.add(e,t):(Array.isArray(e)?e:[e]).forEach(e=>{"string"==typeof e?this.add({[e]:"asc"}):this.add(e)}),this._sortings.length}add(e,t){if("string"==typeof e)return this._addFieldSorting(e,t);if(this._isLikeSorting(e)){const t=Object.keys(e)[0];return"_geo_distance"===t?this._addGeoDistanceSorting(p(e[t])):this._addFieldSorting(t,e[t])}}get(){return p(this._sortings)}clear(){this._sortings.length=0}_isLikeSorting(e){return n(e)&&1===Object.keys(e).length}_addFieldSorting(e,r="asc"){if(["asc","desc"].includes(r))return this._sortings.push({[e]:r});throw new t(`wrong sorting value for field '${e}': ${JSON.stringify(r)}`)}_addGeoDistanceSorting(e){if(n(e)&&2===Object.keys(e).length&&"order"in e){if("string"==typeof e[Object.keys(e).find(e=>"order"!==e)])return this._sortings.push({_geo_distance:e})}throw new t("wrong sorting value for 'geo_distance': "+JSON.stringify(e))}}class g extends Error{}function _(e){if(null==e)throw new g("hashid parameter is mandatory");if(l(e))return e;throw new g("invalid hashid")}function b(e){if(void 0!==e){const t=parseInt(""+e,10);if(!i(t)||t<=0)throw new g("page must be an integer greater than 0");return t}}function w(e){if(void 0!==e){const t=parseInt(""+e,10);if(!i(t)||t<=0||t>100)throw new g("rpp must be a number between 1 and 100");return t}}function v(e,t){if((Array.isArray(e)?e:[e]).filter(e=>null==e||"string"==typeof e&&0===e.trim().length).length>0)throw new g(t);return e}class j{constructor(e={}){this._defaults={query:"",page:1,rpp:20},this._types=new d,this._filters=new y,this._excludes=new y,this._sort=new m,this.reset(),this.load(e)}get defaults(){return this._defaults}set defaults(e){this._defaults=p(e),this.reset()}reset(){this._types.clear(),this._filters.clear(),this._excludes.clear(),this._sort.clear(),this._params={},this.load(p(this.defaults))}load(e={}){Object.keys(e).forEach(t=>{"nostats"===t?this.noStats=!!e.nostats:"filter"===t?this._filters.setMany(e.filter):"exclude"===t?this._excludes.setMany(e.exclude):"type"===t?this._types.set(e.type):"sort"===t?this._sort.set(e.sort):this.setParam(t,e[t])})}dump(e=!1){e&&(_(this.hashid),b(this.page),w(this.rpp));const t={...p(this._params),type:this.types.dump(),filter:this.filters.dump(),exclude:this.excludes.dump(),sort:this.sort.get()};return["nostats","filter","exclude"].forEach(e=>{t[e]||delete t[e]}),["type","sort"].forEach(e=>{0===t[e].length&&delete t[e]}),"items"in t&&(t.items.length>0?delete t.query:delete t.items),t}copy(){const e=new j;return e.defaults=p(this.defaults),e.reset(),e.load(this.dump()),e}getParam(e){return this._params[e]}setParam(e,t){void 0!==t?"hashid"===e?this._params.hashid=_(t):"page"===e?this._params.page=b(t):"rpp"===e?this._params.rpp=w(t):"items"===e?this._params.items=function(e){if(Array.isArray(e)&&e.length===e.filter(c).length)return e;throw new g("items must be an array of doofinder ids")}(t):this._params[e]=t:delete this._params[e]}get hashid(){return this.getParam("hashid")}set hashid(e){this.setParam("hashid",e)}get text(){return this.getParam("query")}set text(e){this.setParam("query",e)}get items(){return this.getParam("items")}set items(e){this.setParam("items",e)}get page(){return this.getParam("page")}set page(e){this.setParam("page",e)}get rpp(){return this.getParam("rpp")}set rpp(e){this.setParam("rpp",e)}get transformer(){return this.getParam("transformer")}set transformer(e){this.setParam("transformer",e)}get queryName(){return this.getParam("query_name")}set queryName(e){this.setParam("query_name",e)}get queryCounter(){return this.getParam("query_counter")}set queryCounter(e){isNaN(e)?this.setParam("query_counter",void 0):this.setParam("query_counter",e)}get noStats(){return!!this.getParam("nostats")}set noStats(e){this.setParam("nostats",!!e)}get types(){return this._types}get filters(){return this._filters}get excludes(){return this._excludes}get sort(){return this._sort}}function O(e){const t=e.selected.buckets.map(e=>e.key),r=e.terms.buckets.map(e=>(t.includes(e.key)&&(e.selected=!0),e));return r.filter(e=>null==e.doc_count).length!==r.length&&r.sort((e,t)=>{const r=e.doc_count||0,i=t.doc_count||0;return r<i?1:r>i?-1:e.key.localeCompare(t.key)}),{type:"terms",label:e.label,visible:e.visible,order:e.order,terms:r}}function S(e){const t=e;return null!=e.facets&&(t._rawFacets=p(e.facets),t.facets=function(e){const t={};for(const i in e)"terms"in e[i]?t[i]=O(e[i]):"range"in e[i]&&(t[i]={type:"range",label:(r=e[i]).label,visible:r.visible,range:r.range.buckets[0].stats});var r;return t}(e.facets)),t}var P=Object.prototype.hasOwnProperty,k=Array.isArray,A=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),C=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},i=0;i<e.length;++i)void 0!==e[i]&&(r[i]=e[i]);return r},x={arrayToObject:C,assign:function(e,t){return Object.keys(t).reduce((function(e,r){return e[r]=t[r],e}),e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],i=0;i<t.length;++i)for(var s=t[i],n=s.obj[s.prop],o=Object.keys(n),a=0;a<o.length;++a){var c=o[a],l=n[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:n,prop:c}),r.push(l))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(k(r)){for(var i=[],s=0;s<r.length;++s)void 0!==r[s]&&i.push(r[s]);t.obj[t.prop]=i}}}(t),e},decode:function(e,t,r){var i=e.replace(/\+/g," ");if("iso-8859-1"===r)return i.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(i)}catch(e){return i}},encode:function(e,t,r){if(0===e.length)return e;var i=e;if("symbol"==typeof e?i=Symbol.prototype.toString.call(e):"string"!=typeof e&&(i=String(e)),"iso-8859-1"===r)return escape(i).replace(/%u[0-9a-f]{4}/gi,(function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"}));for(var s="",n=0;n<i.length;++n){var o=i.charCodeAt(n);45===o||46===o||95===o||126===o||o>=48&&o<=57||o>=65&&o<=90||o>=97&&o<=122?s+=i.charAt(n):o<128?s+=A[o]:o<2048?s+=A[192|o>>6]+A[128|63&o]:o<55296||o>=57344?s+=A[224|o>>12]+A[128|o>>6&63]+A[128|63&o]:(n+=1,o=65536+((1023&o)<<10|1023&i.charCodeAt(n)),s+=A[240|o>>18]+A[128|o>>12&63]+A[128|o>>6&63]+A[128|63&o])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(k(e)){for(var r=[],i=0;i<e.length;i+=1)r.push(t(e[i]));return r}return t(e)},merge:function e(t,r,i){if(!r)return t;if("object"!=typeof r){if(k(t))t.push(r);else{if(!t||"object"!=typeof t)return[t,r];(i&&(i.plainObjects||i.allowPrototypes)||!P.call(Object.prototype,r))&&(t[r]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(r);var s=t;return k(t)&&!k(r)&&(s=C(t,i)),k(t)&&k(r)?(r.forEach((function(r,s){if(P.call(t,s)){var n=t[s];n&&"object"==typeof n&&r&&"object"==typeof r?t[s]=e(n,r,i):t.push(r)}else t[s]=r})),t):Object.keys(r).reduce((function(t,s){var n=r[s];return P.call(t,s)?t[s]=e(t[s],n,i):t[s]=n,t}),s)}},E=String.prototype.replace,N=/%20/g,q={RFC1738:"RFC1738",RFC3986:"RFC3986"},D=x.assign({default:q.RFC3986,formatters:{RFC1738:function(e){return E.call(e,N,"+")},RFC3986:function(e){return String(e)}}},q),z=Object.prototype.hasOwnProperty,Q={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},R=Array.isArray,T=Array.prototype.push,F=function(e,t){T.apply(e,R(t)?t:[t])},I=Date.prototype.toISOString,L=D.default,V={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:x.encode,encodeValuesOnly:!1,format:L,formatter:D.formatters[L],indices:!1,serializeDate:function(e){return I.call(e)},skipNulls:!1,strictNullHandling:!1},H=function e(t,r,i,s,n,o,a,c,l,u,f,d,h){var p,y=t;if("function"==typeof a?y=a(r,y):y instanceof Date?y=u(y):"comma"===i&&R(y)&&(y=x.maybeMap(y,(function(e){return e instanceof Date?u(e):e})).join(",")),null===y){if(s)return o&&!d?o(r,V.encoder,h,"key"):r;y=""}if("string"==typeof(p=y)||"number"==typeof p||"boolean"==typeof p||"symbol"==typeof p||"bigint"==typeof p||x.isBuffer(y))return o?[f(d?r:o(r,V.encoder,h,"key"))+"="+f(o(y,V.encoder,h,"value"))]:[f(r)+"="+f(String(y))];var m,g=[];if(void 0===y)return g;if(R(a))m=a;else{var _=Object.keys(y);m=c?_.sort(c):_}for(var b=0;b<m.length;++b){var w=m[b],v=y[w];if(!n||null!==v){var j=R(y)?"function"==typeof i?i(r,w):r:r+(l?"."+w:"["+w+"]");F(g,e(v,j,i,s,n,o,a,c,l,u,f,d,h))}}return g},$=Object.prototype.hasOwnProperty,M=Array.isArray,B={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:x.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},U=function(e){return e.replace(/&#(\d+);/g,(function(e,t){return String.fromCharCode(parseInt(t,10))}))},G=function(e,t){return e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1?e.split(","):e},J=function(e,t,r,i){if(e){var s=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,n=/(\[[^[\]]*])/g,o=r.depth>0&&/(\[[^[\]]*])/.exec(s),a=o?s.slice(0,o.index):s,c=[];if(a){if(!r.plainObjects&&$.call(Object.prototype,a)&&!r.allowPrototypes)return;c.push(a)}for(var l=0;r.depth>0&&null!==(o=n.exec(s))&&l<r.depth;){if(l+=1,!r.plainObjects&&$.call(Object.prototype,o[1].slice(1,-1))&&!r.allowPrototypes)return;c.push(o[1])}return o&&c.push("["+s.slice(o.index)+"]"),function(e,t,r,i){for(var s=i?t:G(t,r),n=e.length-1;n>=0;--n){var o,a=e[n];if("[]"===a&&r.parseArrays)o=[].concat(s);else{o=r.plainObjects?Object.create(null):{};var c="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,l=parseInt(c,10);r.parseArrays||""!==c?!isNaN(l)&&a!==c&&String(l)===c&&l>=0&&r.parseArrays&&l<=r.arrayLimit?(o=[])[l]=s:o[c]=s:o={0:s}}s=o}return s}(c,t,r,i)}},K=function(e,t){var r=function(e){if(!e)return B;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?B.charset:e.charset;return{allowDots:void 0===e.allowDots?B.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:B.allowPrototypes,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:B.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:B.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:B.comma,decoder:"function"==typeof e.decoder?e.decoder:B.decoder,delimiter:"string"==typeof e.delimiter||x.isRegExp(e.delimiter)?e.delimiter:B.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:B.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:B.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:B.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:B.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:B.strictNullHandling}}(t);if(""===e||null==e)return r.plainObjects?Object.create(null):{};for(var i="string"==typeof e?function(e,t){var r,i={},s=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,n=t.parameterLimit===1/0?void 0:t.parameterLimit,o=s.split(t.delimiter,n),a=-1,c=t.charset;if(t.charsetSentinel)for(r=0;r<o.length;++r)0===o[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===o[r]?c="utf-8":"utf8=%26%2310003%3B"===o[r]&&(c="iso-8859-1"),a=r,r=o.length);for(r=0;r<o.length;++r)if(r!==a){var l,u,f=o[r],d=f.indexOf("]="),h=-1===d?f.indexOf("="):d+1;-1===h?(l=t.decoder(f,B.decoder,c,"key"),u=t.strictNullHandling?null:""):(l=t.decoder(f.slice(0,h),B.decoder,c,"key"),u=x.maybeMap(G(f.slice(h+1),t),(function(e){return t.decoder(e,B.decoder,c,"value")}))),u&&t.interpretNumericEntities&&"iso-8859-1"===c&&(u=U(u)),f.indexOf("[]=")>-1&&(u=M(u)?[u]:u),$.call(i,l)?i[l]=x.combine(i[l],u):i[l]=u}return i}(e,r):e,s=r.plainObjects?Object.create(null):{},n=Object.keys(i),o=0;o<n.length;++o){var a=n[o],c=J(a,i[a],r,"string"==typeof e);s=x.merge(s,c,r)}return x.compact(s)},W=function(e,t){var r,i=e,s=function(e){if(!e)return V;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||V.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=D.default;if(void 0!==e.format){if(!z.call(D.formatters,e.format))throw new TypeError("Unknown format option provided.");r=e.format}var i=D.formatters[r],s=V.filter;return("function"==typeof e.filter||R(e.filter))&&(s=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:V.addQueryPrefix,allowDots:void 0===e.allowDots?V.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:V.charsetSentinel,delimiter:void 0===e.delimiter?V.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:V.encode,encoder:"function"==typeof e.encoder?e.encoder:V.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:V.encodeValuesOnly,filter:s,formatter:i,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:V.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:V.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:V.strictNullHandling}}(t);"function"==typeof s.filter?i=(0,s.filter)("",i):R(s.filter)&&(r=s.filter);var n,o=[];if("object"!=typeof i||null===i)return"";n=t&&t.arrayFormat in Q?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=Q[n];r||(r=Object.keys(i)),s.sort&&r.sort(s.sort);for(var c=0;c<r.length;++c){var l=r[c];s.skipNulls&&null===i[l]||F(o,H(i[l],l,a,s.strictNullHandling,s.skipNulls,s.encode?s.encoder:null,s.filter,s.sort,s.allowDots,s.serializeDate,s.formatter,s.encodeValuesOnly,s.charset))}var u=o.join(s.delimiter),f=!0===s.addQueryPrefix?"?":"";return s.charsetSentinel&&("iso-8859-1"===s.charset?f+="utf8=%26%2310003%3B&":f+="utf8=%E2%9C%93&"),u.length>0?f+u:""};function X(e,t){return W(e,t)}class Y extends Error{constructor(e){super(e.statusText),this.name="ClientResponseError",this.statusCode=e.status,this.response=e}}class Z{constructor({server:e,secret:t,headers:r}={}){if(null==e)throw new g("search server is required");this._server=e;const i={...r||{}};let s="";null!=t&&(this._secret=t.trim(),i.Authorization="Token "+this._secret,s="https:"),this._endpoint=`${s}//${e}`,this._headers={Accept:"application/json",...i}}get server(){return this._server}get secret(){return this._secret}get headers(){return this._headers}get endpoint(){return this._endpoint}async request(e,t={},r){const i=X({random:(new Date).getTime(),...t}),s=this._buildUrl(e,i),n=r?"POST":"GET",o=r?{"Content-Type":"application/json"}:{},a=r?JSON.stringify(r):void 0,c=await fetch(s,{mode:"cors",headers:{...this.headers,...o},method:n,body:a});if(c.ok)return c;throw new Y(c)}async search(e){const t=this._buildSearchQueryObject(e).dump(!0);let r;null!=t.items&&(r={items:t.items},delete t.items);const i=await this.request("/search",t,r);return S(await i.json())}async suggest(e){const t=this._buildSearchQueryObject(e).dump(!0),r=await this.request("/suggest",t);return S(await r.json())}async stats(e,t){return v(t.session_id,"session_id is required"),_(t.hashid),await this.request("/stats/"+e,t)}async topStats(e,t){return _(t.hashid),await this.request("/topstats/"+e,t)}_buildUrl(e,t){const[r,i]=e.split("?");let s;return s=null!=i?`?${i}${t?"&"+t:""}`:t?"?"+t:"",`${this.endpoint}/5${r}${s}`}toString(){return`Client(${this.endpoint}${this._secret?" (+secret)":""})`}_buildSearchQueryObject(e){return e instanceof j?e:new j(e)}}class ee{constructor(e){if(!(e instanceof Z))throw new g("expected an instance of Client");this._client=e}get client(){return this._client}async registerSession(e){return this.client.stats("init",e)}async registerClick(e){const t=p(e);return"dfid"in t?(!function(e){if(c(e))return e;throw new g("invalid doofinder id")}(t.dfid),delete t.id,delete t.datatype):(v([t.id,t.datatype],"dfid or id + datatype are required"),delete t.dfid),this.client.stats("click",t)}async registerCheckout(e){return this.client.stats("checkout",e)}async registerImageClick(e){return v(e.img_id,"img_id is required"),this.client.stats("img_click",e)}async registerRedirection(e){return v([e.redirection_id,e.link],"redirection_id and link are required"),this.client.stats("redirect",e)}async addToCart(e){return v([e.item_id,e.amount],"item_id and amount are required"),this.client.stats("add-to-cart",e)}async removeFromCart(e){return v([e.item_id,e.amount],"item_id and amount are required"),this.client.stats("remove-from-cart",e)}async clearCart(e){return this.client.stats("clear-cart",e)}async registerEvent(e,t){return this.client.stats(e,t)}}class te{constructor(){throw new Error("can't create instances of this class")}static get options(){return this._options}static set options(e){const{server:t,headers:r}=e,i={};t&&(i.server=t),r&&(i.headers=Object.freeze({...r})),this._options=Object.freeze(i),this.clear()}static getClient(e){return this._clientsPool.has(e)||this._clientsPool.set(e,new Z({...this._options,server:e})),this._clientsPool.get(e)}static getStatsClient(e){return this._statsClientsPool.has(e)||this._statsClientsPool.set(e,new ee(this.getClient(e))),this._statsClientsPool.get(e)}static reset(){this.options={}}static clear(){this._clientsPool.clear(),this._statsClientsPool.clear()}}te._clientsPool=new Map,te._statsClientsPool=new Map,te._options={};return e.Client=Z,e.ClientPool=te,e.ClientResponseError=Y,e.Query=j,e.QueryFilter=y,e.QuerySort=m,e.QueryTypes=d,e.QueryValueError=t,e.StatsClient=ee,e.__API_VERSION__=5,e.__VERSION__="6.0.0",e._processSearchResponse=S,e.clone=p,e.decode=function(e,t){return K(e,t)},e.encode=X,e.extend=h,e.isEmptyObject=function(e){return 0===Object.keys(e).length&&e.constructor===Object},e.isIdentical=u,e.isNumber=i,e.isObject=s,e.isPlainObject=n,e.isShallowEqual=f,e.isString=r,e.isValidDoofinderId=c,e.isValidHashId=l,e.merge=function e(...t){let r=t.shift();return null!=r&&(n(r)||Array.isArray(r))||(r={}),t.filter(e=>n(e)||Array.isArray(e)).forEach((function(t){if(null!=t)for(const i in t){if(!t.hasOwnProperty(i))continue;const s=t[i],o=r[i];r!==s&&(n(s)?r[i]=e(n(o)?o:{},s):Array.isArray(s)?r[i]=e(Array.isArray(o)?o:[],s):void 0!==s&&(r[i]=s))}})),r},e}({}); | ||
var doofinder=function(e){"use strict";class t extends Error{}function r(e){return"[object String]"===Object.prototype.toString.call(e)}function i(e){return"[object Number]"===Object.prototype.toString.call(e)&&!isNaN(e)}function s(e){return"[object Object]"===Object.prototype.toString.call(e)}function n(e){return s(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}const o=/^([0-9a-f]{32})@([\w-]+)@([0-9a-f]{32})$/i,a=/^([0-9a-f]{32})(-.*)?/i;function c(e){return r(e)&&o.test(e)}function l(e){return r(e)&&a.test(e)}function u(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t}function f(e,t){if(u(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const r=Object.keys(e),i=Object.keys(t);if(r.length!==i.length)return!1;for(let i=0;i<r.length;i++)if(!Object.prototype.hasOwnProperty.call(t,r[i])||!u(e[r[i]],t[r[i]]))return!1;return!0}class d{constructor(){this._types=new Set}set(e){const i=Array.isArray(e)?e:[e];if(i.filter(r).length!==i.length)throw new t("types must be strings");this._types=new Set(i)}dump(){return Array.from(this._types)}clear(){this._types.clear()}add(e){if("string"!=typeof e)throw new t("types must be strings");this._types.add(e)}has(e){return this._types.has(e)}remove(e){this._types.delete(e)}}function h(...e){const t=e.length;let r,i,s,o,a,c,l=e[0]||{},u=1,f=!1;if("boolean"==typeof l&&(f=l,l=e[u]||{},u++),"object"!=typeof l&&"function"!=typeof l&&(l={}),u===t)return l;for(;u<t;u++)if(null!=(r=e[u]))for(i in r)o=r[i],"__proto__"!==i&&l!==o&&(f&&o&&(n(o)||(a=Array.isArray(o)))?(s=l[i],c=a&&!Array.isArray(s)?[]:!a&&n(s)?{}:s,a=!1,l[i]=h(f,c,o)):void 0!==o&&(l[i]=o));return l}function p(e){return Array.isArray(e)?h(!0,[],e):n(e)?h(!0,{},e):e}class y{constructor(){this._filters=new Map}get(e){return this._denormalize(this._filters.get(e))}set(e,r){const i=this._normalize(r);if(i instanceof Set)this._filters.set(e,i);else{if(n(i)&&0===Object.entries(i).length)throw new t("plain object filters can't be empty");this._filters.set(e,p(i))}}has(e){return this._filters.has(e)}contains(e,t){return this.has(e)&&this._filterContainsOrEqualsValue(e,t,!1)}equals(e,t){return this.has(e)&&this._filterContainsOrEqualsValue(e,t,!0)}add(e,t){const r=this._normalize(t),i=this._filters.get(e);i instanceof Set?r instanceof Set?this._filters.set(e,new Set([...i,...r])):i.add(r):this._filters.set(e,r)}remove(e,t){const r=this._filters.get(e);if(r instanceof Set&&null!=t){const i=this._normalize(t);if(i instanceof Set)for(const e of i)r.delete(e);else r.delete(i);0===r.size&&this._filters.delete(e)}else this._filters.delete(e)}clear(){this._filters.clear()}setMany(e,t=!1){t&&this.clear();for(const t in e)this.set(t,e[t])}dump(){const e={};if(this._filters.forEach((t,r)=>{e[r]=this._denormalize(t)}),Object.keys(e).length>0)return e}_normalize(e){return r(e)||i(e)?new Set([e]):Array.isArray(e)?new Set(e):e}_denormalize(e){return e instanceof Set?[...e]:e}_filterContainsOrEqualsValue(e,t,r){const i=this._normalize(t),s=this._filters.get(e);if(s instanceof Set&&i instanceof Set){if(r&&s.size!==i.size)return!1;for(const e of i)if(!s.has(e))return!1;return!0}return f(s,i)}}class m{constructor(){this._sortings=[]}set(e,t){return this.clear(),"string"==typeof e?this.add(e,t):(Array.isArray(e)?e:[e]).forEach(e=>{"string"==typeof e?this.add({[e]:"asc"}):this.add(e)}),this._sortings.length}add(e,t){if("string"==typeof e)return this._addFieldSorting(e,t);if(this._isLikeSorting(e)){const t=Object.keys(e)[0];return"_geo_distance"===t?this._addGeoDistanceSorting(p(e[t])):this._addFieldSorting(t,e[t])}}get(){return p(this._sortings)}clear(){this._sortings.length=0}_isLikeSorting(e){return n(e)&&1===Object.keys(e).length}_addFieldSorting(e,r="asc"){if(["asc","desc"].includes(r))return this._sortings.push({[e]:r});throw new t(`wrong sorting value for field '${e}': ${JSON.stringify(r)}`)}_addGeoDistanceSorting(e){if(n(e)&&2===Object.keys(e).length&&"order"in e){if("string"==typeof e[Object.keys(e).find(e=>"order"!==e)])return this._sortings.push({_geo_distance:e})}throw new t("wrong sorting value for 'geo_distance': "+JSON.stringify(e))}}class g extends Error{}function _(e){if(null==e)throw new g("hashid parameter is mandatory");if(l(e))return e;throw new g("invalid hashid")}function b(e){if(void 0!==e){const t=parseInt(""+e,10);if(!i(t)||t<=0)throw new g("page must be an integer greater than 0");return t}}function w(e){if(void 0!==e){const t=parseInt(""+e,10);if(!i(t)||t<=0||t>100)throw new g("rpp must be a number between 1 and 100");return t}}function v(e,t){if((Array.isArray(e)?e:[e]).filter(e=>null==e||"string"==typeof e&&0===e.trim().length).length>0)throw new g(t);return e}class j{constructor(e={}){this._defaults={query:"",page:1,rpp:20},this._types=new d,this._filters=new y,this._excludes=new y,this._sort=new m,this.reset(),this.load(e)}get defaults(){return this._defaults}set defaults(e){this._defaults=p(e),this.reset()}reset(){this._types.clear(),this._filters.clear(),this._excludes.clear(),this._sort.clear(),this._params={},this.load(p(this.defaults))}load(e={}){Object.keys(e).forEach(t=>{"nostats"===t?this.noStats=!!e.nostats:"filter"===t?this._filters.setMany(e.filter):"exclude"===t?this._excludes.setMany(e.exclude):"type"===t?this._types.set(e.type):"sort"===t?this._sort.set(e.sort):this.setParam(t,e[t])})}dump(e=!1){e&&(_(this.hashid),b(this.page),w(this.rpp));const t={...p(this._params),type:this.types.dump(),filter:this.filters.dump(),exclude:this.excludes.dump(),sort:this.sort.get()};return["nostats","filter","exclude"].forEach(e=>{t[e]||delete t[e]}),["type","sort"].forEach(e=>{0===t[e].length&&delete t[e]}),"items"in t&&(t.items.length>0?delete t.query:delete t.items),t}copy(){const e=new j;return e.defaults=p(this.defaults),e.reset(),e.load(this.dump()),e}getParam(e){return this._params[e]}setParam(e,t){void 0!==t?"hashid"===e?this._params.hashid=_(t):"page"===e?this._params.page=b(t):"rpp"===e?this._params.rpp=w(t):"items"===e?this._params.items=function(e){if(Array.isArray(e)&&e.length===e.filter(c).length)return e;throw new g("items must be an array of doofinder ids")}(t):this._params[e]=t:delete this._params[e]}get hashid(){return this.getParam("hashid")}set hashid(e){this.setParam("hashid",e)}get text(){return this.getParam("query")}set text(e){this.setParam("query",e)}get items(){return this.getParam("items")}set items(e){this.setParam("items",e)}get page(){return this.getParam("page")}set page(e){this.setParam("page",e)}get rpp(){return this.getParam("rpp")}set rpp(e){this.setParam("rpp",e)}get transformer(){return this.getParam("transformer")}set transformer(e){this.setParam("transformer",e)}get queryName(){return this.getParam("query_name")}set queryName(e){this.setParam("query_name",e)}get queryCounter(){return this.getParam("query_counter")}set queryCounter(e){isNaN(e)?this.setParam("query_counter",void 0):this.setParam("query_counter",e)}get noStats(){return!!this.getParam("nostats")}set noStats(e){this.setParam("nostats",!!e)}get types(){return this._types}get filters(){return this._filters}get excludes(){return this._excludes}get sort(){return this._sort}}function O(e){const t=e.selected.buckets.map(e=>e.key),r=e.terms.buckets.map(e=>(t.includes(e.key)&&(e.selected=!0),e));return r.filter(e=>null==e.doc_count).length!==r.length&&r.sort((e,t)=>{const r=e.doc_count||0,i=t.doc_count||0;return r<i?1:r>i?-1:e.key.localeCompare(t.key)}),{type:"terms",label:e.label,visible:e.visible,order:e.order,terms:r}}function S(e){const t=e;return null!=e.facets&&(t._rawFacets=p(e.facets),t.facets=function(e){const t={};for(const i in e)"terms"in e[i]?t[i]=O(e[i]):"range"in e[i]&&(t[i]={type:"range",label:(r=e[i]).label,visible:r.visible,range:r.range.buckets[0].stats});var r;return t}(e.facets)),t}var P=Object.prototype.hasOwnProperty,k=Array.isArray,A=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),C=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},i=0;i<e.length;++i)void 0!==e[i]&&(r[i]=e[i]);return r},x={arrayToObject:C,assign:function(e,t){return Object.keys(t).reduce((function(e,r){return e[r]=t[r],e}),e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],i=0;i<t.length;++i)for(var s=t[i],n=s.obj[s.prop],o=Object.keys(n),a=0;a<o.length;++a){var c=o[a],l=n[c];"object"==typeof l&&null!==l&&-1===r.indexOf(l)&&(t.push({obj:n,prop:c}),r.push(l))}return function(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(k(r)){for(var i=[],s=0;s<r.length;++s)void 0!==r[s]&&i.push(r[s]);t.obj[t.prop]=i}}}(t),e},decode:function(e,t,r){var i=e.replace(/\+/g," ");if("iso-8859-1"===r)return i.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(i)}catch(e){return i}},encode:function(e,t,r){if(0===e.length)return e;var i=e;if("symbol"==typeof e?i=Symbol.prototype.toString.call(e):"string"!=typeof e&&(i=String(e)),"iso-8859-1"===r)return escape(i).replace(/%u[0-9a-f]{4}/gi,(function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"}));for(var s="",n=0;n<i.length;++n){var o=i.charCodeAt(n);45===o||46===o||95===o||126===o||o>=48&&o<=57||o>=65&&o<=90||o>=97&&o<=122?s+=i.charAt(n):o<128?s+=A[o]:o<2048?s+=A[192|o>>6]+A[128|63&o]:o<55296||o>=57344?s+=A[224|o>>12]+A[128|o>>6&63]+A[128|63&o]:(n+=1,o=65536+((1023&o)<<10|1023&i.charCodeAt(n)),s+=A[240|o>>18]+A[128|o>>12&63]+A[128|o>>6&63]+A[128|63&o])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(k(e)){for(var r=[],i=0;i<e.length;i+=1)r.push(t(e[i]));return r}return t(e)},merge:function e(t,r,i){if(!r)return t;if("object"!=typeof r){if(k(t))t.push(r);else{if(!t||"object"!=typeof t)return[t,r];(i&&(i.plainObjects||i.allowPrototypes)||!P.call(Object.prototype,r))&&(t[r]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(r);var s=t;return k(t)&&!k(r)&&(s=C(t,i)),k(t)&&k(r)?(r.forEach((function(r,s){if(P.call(t,s)){var n=t[s];n&&"object"==typeof n&&r&&"object"==typeof r?t[s]=e(n,r,i):t.push(r)}else t[s]=r})),t):Object.keys(r).reduce((function(t,s){var n=r[s];return P.call(t,s)?t[s]=e(t[s],n,i):t[s]=n,t}),s)}},E=String.prototype.replace,N=/%20/g,q={RFC1738:"RFC1738",RFC3986:"RFC3986"},D=x.assign({default:q.RFC3986,formatters:{RFC1738:function(e){return E.call(e,N,"+")},RFC3986:function(e){return String(e)}}},q),z=Object.prototype.hasOwnProperty,Q={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},R=Array.isArray,T=Array.prototype.push,F=function(e,t){T.apply(e,R(t)?t:[t])},I=Date.prototype.toISOString,L=D.default,V={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:x.encode,encodeValuesOnly:!1,format:L,formatter:D.formatters[L],indices:!1,serializeDate:function(e){return I.call(e)},skipNulls:!1,strictNullHandling:!1},H=function e(t,r,i,s,n,o,a,c,l,u,f,d,h){var p,y=t;if("function"==typeof a?y=a(r,y):y instanceof Date?y=u(y):"comma"===i&&R(y)&&(y=x.maybeMap(y,(function(e){return e instanceof Date?u(e):e})).join(",")),null===y){if(s)return o&&!d?o(r,V.encoder,h,"key"):r;y=""}if("string"==typeof(p=y)||"number"==typeof p||"boolean"==typeof p||"symbol"==typeof p||"bigint"==typeof p||x.isBuffer(y))return o?[f(d?r:o(r,V.encoder,h,"key"))+"="+f(o(y,V.encoder,h,"value"))]:[f(r)+"="+f(String(y))];var m,g=[];if(void 0===y)return g;if(R(a))m=a;else{var _=Object.keys(y);m=c?_.sort(c):_}for(var b=0;b<m.length;++b){var w=m[b],v=y[w];if(!n||null!==v){var j=R(y)?"function"==typeof i?i(r,w):r:r+(l?"."+w:"["+w+"]");F(g,e(v,j,i,s,n,o,a,c,l,u,f,d,h))}}return g},$=Object.prototype.hasOwnProperty,M=Array.isArray,B={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:x.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},U=function(e){return e.replace(/&#(\d+);/g,(function(e,t){return String.fromCharCode(parseInt(t,10))}))},G=function(e,t){return e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1?e.split(","):e},J=function(e,t,r,i){if(e){var s=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,n=/(\[[^[\]]*])/g,o=r.depth>0&&/(\[[^[\]]*])/.exec(s),a=o?s.slice(0,o.index):s,c=[];if(a){if(!r.plainObjects&&$.call(Object.prototype,a)&&!r.allowPrototypes)return;c.push(a)}for(var l=0;r.depth>0&&null!==(o=n.exec(s))&&l<r.depth;){if(l+=1,!r.plainObjects&&$.call(Object.prototype,o[1].slice(1,-1))&&!r.allowPrototypes)return;c.push(o[1])}return o&&c.push("["+s.slice(o.index)+"]"),function(e,t,r,i){for(var s=i?t:G(t,r),n=e.length-1;n>=0;--n){var o,a=e[n];if("[]"===a&&r.parseArrays)o=[].concat(s);else{o=r.plainObjects?Object.create(null):{};var c="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,l=parseInt(c,10);r.parseArrays||""!==c?!isNaN(l)&&a!==c&&String(l)===c&&l>=0&&r.parseArrays&&l<=r.arrayLimit?(o=[])[l]=s:o[c]=s:o={0:s}}s=o}return s}(c,t,r,i)}},K=function(e,t){var r=function(e){if(!e)return B;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?B.charset:e.charset;return{allowDots:void 0===e.allowDots?B.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:B.allowPrototypes,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:B.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:B.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:B.comma,decoder:"function"==typeof e.decoder?e.decoder:B.decoder,delimiter:"string"==typeof e.delimiter||x.isRegExp(e.delimiter)?e.delimiter:B.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:B.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:B.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:B.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:B.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:B.strictNullHandling}}(t);if(""===e||null==e)return r.plainObjects?Object.create(null):{};for(var i="string"==typeof e?function(e,t){var r,i={},s=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,n=t.parameterLimit===1/0?void 0:t.parameterLimit,o=s.split(t.delimiter,n),a=-1,c=t.charset;if(t.charsetSentinel)for(r=0;r<o.length;++r)0===o[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===o[r]?c="utf-8":"utf8=%26%2310003%3B"===o[r]&&(c="iso-8859-1"),a=r,r=o.length);for(r=0;r<o.length;++r)if(r!==a){var l,u,f=o[r],d=f.indexOf("]="),h=-1===d?f.indexOf("="):d+1;-1===h?(l=t.decoder(f,B.decoder,c,"key"),u=t.strictNullHandling?null:""):(l=t.decoder(f.slice(0,h),B.decoder,c,"key"),u=x.maybeMap(G(f.slice(h+1),t),(function(e){return t.decoder(e,B.decoder,c,"value")}))),u&&t.interpretNumericEntities&&"iso-8859-1"===c&&(u=U(u)),f.indexOf("[]=")>-1&&(u=M(u)?[u]:u),$.call(i,l)?i[l]=x.combine(i[l],u):i[l]=u}return i}(e,r):e,s=r.plainObjects?Object.create(null):{},n=Object.keys(i),o=0;o<n.length;++o){var a=n[o],c=J(a,i[a],r,"string"==typeof e);s=x.merge(s,c,r)}return x.compact(s)},W=function(e,t){var r,i=e,s=function(e){if(!e)return V;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||V.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=D.default;if(void 0!==e.format){if(!z.call(D.formatters,e.format))throw new TypeError("Unknown format option provided.");r=e.format}var i=D.formatters[r],s=V.filter;return("function"==typeof e.filter||R(e.filter))&&(s=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:V.addQueryPrefix,allowDots:void 0===e.allowDots?V.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:V.charsetSentinel,delimiter:void 0===e.delimiter?V.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:V.encode,encoder:"function"==typeof e.encoder?e.encoder:V.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:V.encodeValuesOnly,filter:s,formatter:i,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:V.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:V.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:V.strictNullHandling}}(t);"function"==typeof s.filter?i=(0,s.filter)("",i):R(s.filter)&&(r=s.filter);var n,o=[];if("object"!=typeof i||null===i)return"";n=t&&t.arrayFormat in Q?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=Q[n];r||(r=Object.keys(i)),s.sort&&r.sort(s.sort);for(var c=0;c<r.length;++c){var l=r[c];s.skipNulls&&null===i[l]||F(o,H(i[l],l,a,s.strictNullHandling,s.skipNulls,s.encode?s.encoder:null,s.filter,s.sort,s.allowDots,s.serializeDate,s.formatter,s.encodeValuesOnly,s.charset))}var u=o.join(s.delimiter),f=!0===s.addQueryPrefix?"?":"";return s.charsetSentinel&&("iso-8859-1"===s.charset?f+="utf8=%26%2310003%3B&":f+="utf8=%E2%9C%93&"),u.length>0?f+u:""};function X(e,t){return W(e,t)}class Y extends Error{constructor(e){super(e.statusText),this.name="ClientResponseError",this.statusCode=e.status,this.response=e}}class Z{constructor({server:e,secret:t,headers:r}={}){if(null==e)throw new g("search server is required");this._server=e;const i={...r||{}};let s="";null!=t&&(this._secret=t.trim(),i.Authorization="Token "+this._secret,s="https:"),this._endpoint=`${s}//${e}`,this._headers={Accept:"application/json",...i}}get server(){return this._server}get secret(){return this._secret}get headers(){return this._headers}get endpoint(){return this._endpoint}async request(e,t={},r){const i=X({random:(new Date).getTime(),...t}),s=this._buildUrl(e,i),n=r?"POST":"GET",o=r?{"Content-Type":"application/json"}:{},a=r?JSON.stringify(r):void 0,c=await fetch(s,{mode:"cors",headers:{...this.headers,...o},method:n,body:a});if(c.ok)return c;throw new Y(c)}async search(e){const t=this._buildSearchQueryObject(e).dump(!0);let r;null!=t.items&&(r={items:t.items},delete t.items);const i=await this.request("/search",t,r);return S(await i.json())}async suggest(e){const t=this._buildSearchQueryObject(e).dump(!0),r=await this.request("/suggest",t);return S(await r.json())}async stats(e,t){return v(t.session_id,"session_id is required"),_(t.hashid),await this.request("/stats/"+e,t)}async topStats(e,t){return _(t.hashid),await this.request("/topstats/"+e,t)}_buildUrl(e,t){const[r,i]=e.split("?");let s;return s=null!=i?`?${i}${t?"&"+t:""}`:t?"?"+t:"",`${this.endpoint}/5${r}${s}`}toString(){return`Client(${this.endpoint}${this._secret?" (+secret)":""})`}_buildSearchQueryObject(e){return e instanceof j?e:new j(e)}}class ee{constructor(e){if(!(e instanceof Z))throw new g("expected an instance of Client");this._client=e}get client(){return this._client}async registerSession(e){return this.client.stats("init",e)}async registerClick(e){const t=p(e);return"dfid"in t?(!function(e){if(c(e))return e;throw new g("invalid doofinder id")}(t.dfid),delete t.id,delete t.datatype):(v([t.id,t.datatype],"dfid or id + datatype are required"),delete t.dfid),this.client.stats("click",t)}async registerCheckout(e){return this.client.stats("checkout",e)}async registerImageClick(e){return v(e.img_id,"img_id is required"),this.client.stats("img_click",e)}async registerRedirection(e){return v([e.redirection_id,e.link],"redirection_id and link are required"),this.client.stats("redirect",e)}async addToCart(e){return v([e.item_id,e.amount],"item_id and amount are required"),this.client.stats("add-to-cart",e)}async removeFromCart(e){return v([e.item_id,e.amount],"item_id and amount are required"),this.client.stats("remove-from-cart",e)}async clearCart(e){return this.client.stats("clear-cart",e)}async registerEvent(e,t){return this.client.stats(e,t)}}class te{constructor(){throw new Error("can't create instances of this class")}static get options(){return this._options}static set options(e){const{server:t,headers:r}=e,i={};t&&(i.server=t),r&&(i.headers=Object.freeze({...r})),this._options=Object.freeze(i),this.clear()}static getClient(e){return this._clientsPool.has(e)||this._clientsPool.set(e,new Z({...this._options,server:e})),this._clientsPool.get(e)}static getStatsClient(e){return this._statsClientsPool.has(e)||this._statsClientsPool.set(e,new ee(this.getClient(e))),this._statsClientsPool.get(e)}static reset(){this.options={}}static clear(){this._clientsPool.clear(),this._statsClientsPool.clear()}}te._clientsPool=new Map,te._statsClientsPool=new Map,te._options={};return e.Client=Z,e.ClientPool=te,e.ClientResponseError=Y,e.Query=j,e.QueryFilter=y,e.QuerySort=m,e.QueryTypes=d,e.QueryValueError=t,e.StatsClient=ee,e.__API_VERSION__=5,e.__VERSION__="6.0.1",e._processSearchResponse=S,e.clone=p,e.decode=function(e,t){return K(e,t)},e.encode=X,e.extend=h,e.isEmptyObject=function(e){return 0===Object.keys(e).length&&e.constructor===Object},e.isIdentical=u,e.isNumber=i,e.isObject=s,e.isPlainObject=n,e.isShallowEqual=f,e.isString=r,e.isValidDoofinderId=c,e.isValidHashId=l,e.merge=function e(...t){let r=t.shift();return null!=r&&(n(r)||Array.isArray(r))||(r={}),t.filter(e=>n(e)||Array.isArray(e)).forEach((function(t){if(null!=t)for(const i in t){if(!t.hasOwnProperty(i))continue;const s=t[i],o=r[i];r!==s&&(n(s)?r[i]=e(n(o)?o:{},s):Array.isArray(s)?r[i]=e(Array.isArray(o)?o:[],s):void 0!==s&&(r[i]=s))}})),r},e}({}); |
{ | ||
"name": "doofinder", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "Javascript Library for Doofinder Search API", | ||
"main": "lib/doofinder.common.js", | ||
"module": "lib/doofinder.mjs", | ||
"type": "module", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"browser": "lib/doofinder.js", | ||
"types": "lib/doofinder.d.ts", | ||
"engines": { | ||
@@ -17,3 +20,2 @@ "node": ">=10.15.0" | ||
}, | ||
"types": "lib/doofinder.d.ts", | ||
"repository": "git@github.com:doofinder/js-doofinder.git", | ||
@@ -24,3 +26,3 @@ "scripts": { | ||
"lint": "eslint --env browser --fix src/**/*.ts", | ||
"compile": "rimraf lib && rollup -c", | ||
"compile": "rimraf lib && rollup -c && cp package.cjs.json lib/cjs/package.json", | ||
"typings": "rimraf types && tsc --declaration --declarationMap --emitDeclarationOnly --outDir types && api-extractor run --local", | ||
@@ -27,0 +29,0 @@ "build": "yarn lint && yarn compile && yarn typings", |
Sorry, the diff of this file is too big to display
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
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
296966
11
8432
Yes
5