doofinder
Advanced tools
Comparing version 6.0.0-beta.0 to 6.0.0-beta.1
@@ -1,2 +0,3 @@ | ||
import * as qs from 'qs'; | ||
import { parse } from 'qs'; | ||
import { stringify } from 'qs'; | ||
@@ -362,3 +363,3 @@ /** | ||
*/ | ||
export declare const decode: typeof qs.parse; | ||
export declare const decode: typeof parse; | ||
@@ -380,3 +381,3 @@ /** | ||
*/ | ||
export declare const encode: typeof qs.stringify; | ||
export declare const encode: typeof stringify; | ||
@@ -383,0 +384,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
var doofinder=function(e){"use strict";class QueryValueError extends Error{}const isString=e=>"[object String]"===Object.prototype.toString.call(e),isNumber=e=>"[object Number]"===Object.prototype.toString.call(e)&&!isNaN(e),isObject=e=>"[object Object]"===Object.prototype.toString.call(e);const isPlainObject=e=>isObject(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval,t=/^([0-9a-f]{32})@([\w-]+)@([0-9a-f]{32})$/i,r=/^([0-9a-f]{32})(-.*)?/i;function isValidDoofinderId(e){return isString(e)&&t.test(e)}function isValidHashId(e){return isString(e)&&r.test(e)}const isIdentical=function(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t},isShallowEqual=function(e,t){if(isIdentical(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])||!isIdentical(e[r[i]],t[r[i]]))return!1;return!0};class QueryTypes{constructor(){this._types=new Set}set(e){const t=Array.isArray(e)?e:[e];if(t.filter(isString).length!==t.length)throw new QueryValueError("types must be strings");this._types=new Set(t)}dump(){return Array.from(this._types)}clear(){this._types.clear()}add(e){if("string"!=typeof e)throw new QueryValueError("types must be strings");this._types.add(e)}has(e){return this._types.has(e)}remove(e){this._types.delete(e)}}const extend=function(...e){const t=e.length;let r,i,s,n,o,a,l=e[0]||{},c=1,u=!1;if("boolean"==typeof l&&(u=l,l=e[c]||{},c++),"object"!=typeof l&&"function"!=typeof l&&(l={}),c===t)return l;for(;c<t;c++)if(null!=(r=e[c]))for(i in r)n=r[i],"__proto__"!==i&&l!==n&&(u&&n&&(isPlainObject(n)||(o=Array.isArray(n)))?(s=l[i],a=o&&!Array.isArray(s)?[]:!o&&isPlainObject(s)?{}:s,o=!1,l[i]=extend(u,a,n)):void 0!==n&&(l[i]=n));return l};function clone(e){return Array.isArray(e)?extend(!0,[],e):isPlainObject(e)?extend(!0,{},e):e}class QueryFilter{constructor(){this._filters=new Map}get(e){return this._denormalize(this._filters.get(e))}set(e,t){const r=this._normalize(t);if(r instanceof Set)this._filters.set(e,r);else{if(isPlainObject(r)&&0===Object.entries(r).length)throw new QueryValueError("plain object filters can't be empty");this._filters.set(e,clone(r))}}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 isString(e)||isNumber(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 isShallowEqual(s,i)}}class QuerySort{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(clone(e[t])):this._addFieldSorting(t,e[t])}}get(){return clone(this._sortings)}clear(){this._sortings.length=0}_isLikeSorting(e){return isPlainObject(e)&&1===Object.keys(e).length}_addFieldSorting(e,t="asc"){if(["asc","desc"].includes(t))return this._sortings.push({[e]:t});throw new QueryValueError(`wrong sorting value for field '${e}': ${JSON.stringify(t)}`)}_addGeoDistanceSorting(e){if(isPlainObject(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 QueryValueError(`wrong sorting value for 'geo_distance': ${JSON.stringify(e)}`)}}class ValidationError extends Error{}function validateHashId(e){if(null==e)throw new ValidationError("hashid parameter is mandatory");if(isValidHashId(e))return e;throw new ValidationError("invalid hashid")}function validatePage(e){if(void 0!==e){const t=parseInt(`${e}`,10);if(!isNumber(t)||t<=0)throw new ValidationError("page must be an integer greater than 0");return t}}function validateRpp(e){if(void 0!==e){const t=parseInt(`${e}`,10);if(!isNumber(t)||t<=0||t>100)throw new ValidationError("rpp must be a number between 1 and 100");return t}}function validateRequired(e,t){if((Array.isArray(e)?e:[e]).filter(e=>null==e||"string"==typeof e&&0===e.trim().length).length>0)throw new ValidationError(t);return e}class Query{constructor(e={}){this._defaults={query:"",page:1,rpp:20},this._types=new QueryTypes,this._filters=new QueryFilter,this._excludes=new QueryFilter,this._sort=new QuerySort,this.reset(),this.load(e)}get defaults(){return this._defaults}set defaults(e){this._defaults=clone(e),this.reset()}reset(){this._types.clear(),this._filters.clear(),this._excludes.clear(),this._sort.clear(),this._params={},this.load(clone(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&&(validateHashId(this.hashid),validatePage(this.page),validateRpp(this.rpp));const t={...clone(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 Query;return e.defaults=clone(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=validateHashId(t):"page"===e?this._params.page=validatePage(t):"rpp"===e?this._params.rpp=validateRpp(t):"items"===e?this._params.items=function validateItems(e){if(Array.isArray(e)&&e.length===e.filter(isValidDoofinderId).length)return e;throw new ValidationError("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 processTermsFacet(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",terms:r}}function _processSearchResponse(e){const t=e;return null!=e.facets&&(t._rawFacets=clone(e.facets),t.facets=function processFacets(e){const t={};for(const r in e)"terms"in e[r]?t[r]=processTermsFacet(e[r]):"range"in e[r]&&(t[r]={type:"range",range:e[r].range.buckets[0].stats});return t}(e.facets)),t}var i=Object.prototype.hasOwnProperty,s=Array.isArray,n=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),o=function arrayToObject(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},a={arrayToObject:o,assign:function assignSingleSource(e,t){return Object.keys(t).reduce((function(e,r){return e[r]=t[r],e}),e)},combine:function combine(e,t){return[].concat(e,t)},compact:function compact(e){for(var t=[{obj:{o:e},prop:"o"}],r=[],i=0;i<t.length;++i)for(var n=t[i],o=n.obj[n.prop],a=Object.keys(o),l=0;l<a.length;++l){var c=a[l],u=o[c];"object"==typeof u&&null!==u&&-1===r.indexOf(u)&&(t.push({obj:o,prop:c}),r.push(u))}return function compactQueue(e){for(;e.length>1;){var t=e.pop(),r=t.obj[t.prop];if(s(r)){for(var i=[],n=0;n<r.length;++n)void 0!==r[n]&&i.push(r[n]);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 encode(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="",o=0;o<i.length;++o){var a=i.charCodeAt(o);45===a||46===a||95===a||126===a||a>=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122?s+=i.charAt(o):a<128?s+=n[a]:a<2048?s+=n[192|a>>6]+n[128|63&a]:a<55296||a>=57344?s+=n[224|a>>12]+n[128|a>>6&63]+n[128|63&a]:(o+=1,a=65536+((1023&a)<<10|1023&i.charCodeAt(o)),s+=n[240|a>>18]+n[128|a>>12&63]+n[128|a>>6&63]+n[128|63&a])}return s},isBuffer:function isBuffer(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function isRegExp(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function merge(e,t,r){if(!t)return e;if("object"!=typeof t){if(s(e))e.push(t);else{if(!e||"object"!=typeof e)return[e,t];(r&&(r.plainObjects||r.allowPrototypes)||!i.call(Object.prototype,t))&&(e[t]=!0)}return e}if(!e||"object"!=typeof e)return[e].concat(t);var n=e;return s(e)&&!s(t)&&(n=o(e,r)),s(e)&&s(t)?(t.forEach((function(t,s){if(i.call(e,s)){var n=e[s];n&&"object"==typeof n&&t&&"object"==typeof t?e[s]=merge(n,t,r):e.push(t)}else e[s]=t})),e):Object.keys(t).reduce((function(e,s){var n=t[s];return i.call(e,s)?e[s]=merge(e[s],n,r):e[s]=n,e}),n)}},l=String.prototype.replace,c=/%20/g,u={RFC1738:"RFC1738",RFC3986:"RFC3986"},d=a.assign({default:u.RFC3986,formatters:{RFC1738:function(e){return l.call(e,c,"+")},RFC3986:function(e){return String(e)}}},u),f=Object.prototype.hasOwnProperty,h={brackets:function brackets(e){return e+"[]"},comma:"comma",indices:function indices(e,t){return e+"["+t+"]"},repeat:function repeat(e){return e}},p=Array.isArray,y=Array.prototype.push,pushToArray=function(e,t){y.apply(e,p(t)?t:[t])},m=Date.prototype.toISOString,g=d.default,_={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:a.encode,encodeValuesOnly:!1,format:g,formatter:d.formatters[g],indices:!1,serializeDate:function serializeDate(e){return m.call(e)},skipNulls:!1,strictNullHandling:!1},b=function stringify(e,t,r,i,s,n,o,l,c,u,d,f,h){var y=e;if("function"==typeof o?y=o(t,y):y instanceof Date?y=u(y):"comma"===r&&p(y)&&(y=y.join(",")),null===y){if(i)return n&&!f?n(t,_.encoder,h,"key"):t;y=""}if(function isNonNullishPrimitive(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"symbol"==typeof e||"bigint"==typeof e}(y)||a.isBuffer(y))return n?[d(f?t:n(t,_.encoder,h,"key"))+"="+d(n(y,_.encoder,h,"value"))]:[d(t)+"="+d(String(y))];var m,g=[];if(void 0===y)return g;if(p(o))m=o;else{var b=Object.keys(y);m=l?b.sort(l):b}for(var v=0;v<m.length;++v){var w=m[v];s&&null===y[w]||(p(y)?pushToArray(g,stringify(y[w],"function"==typeof r?r(t,w):t,r,i,s,n,o,l,c,u,d,f,h)):pushToArray(g,stringify(y[w],t+(c?"."+w:"["+w+"]"),r,i,s,n,o,l,c,u,d,f,h)))}return g},v=Object.prototype.hasOwnProperty,w=Array.isArray,O={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:a.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},interpretNumericEntities=function(e){return e.replace(/&#(\d+);/g,(function(e,t){return String.fromCharCode(parseInt(t,10))}))},parseArrayValue=function(e,t){return e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1?e.split(","):e},j=function maybeMap(e,t){if(w(e)){for(var r=[],i=0;i<e.length;i+=1)r.push(t(e[i]));return r}return t(e)},S=function parseQueryStringKeys(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,l=[];if(a){if(!r.plainObjects&&v.call(Object.prototype,a)&&!r.allowPrototypes)return;l.push(a)}for(var c=0;r.depth>0&&null!==(o=n.exec(s))&&c<r.depth;){if(c+=1,!r.plainObjects&&v.call(Object.prototype,o[1].slice(1,-1))&&!r.allowPrototypes)return;l.push(o[1])}return o&&l.push("["+s.slice(o.index)+"]"),function(e,t,r,i){for(var s=i?t:parseArrayValue(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 l="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(l,10);r.parseArrays||""!==l?!isNaN(c)&&a!==l&&String(c)===l&&c>=0&&r.parseArrays&&c<=r.arrayLimit?(o=[])[c]=s:o[l]=s:o={0:s}}s=o}return s}(l,t,r,i)}};const encode$1=function(e,t){var r,i=e,s=function normalizeStringifyOptions(e){if(!e)return _;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||_.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(!f.call(d.formatters,e.format))throw new TypeError("Unknown format option provided.");r=e.format}var i=d.formatters[r],s=_.filter;return("function"==typeof e.filter||p(e.filter))&&(s=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:_.addQueryPrefix,allowDots:void 0===e.allowDots?_.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:_.charsetSentinel,delimiter:void 0===e.delimiter?_.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:_.encode,encoder:"function"==typeof e.encoder?e.encoder:_.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:_.encodeValuesOnly,filter:s,formatter:i,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:_.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:_.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:_.strictNullHandling}}(t);"function"==typeof s.filter?i=(0,s.filter)("",i):p(s.filter)&&(r=s.filter);var n,o=[];if("object"!=typeof i||null===i)return"";n=t&&t.arrayFormat in h?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=h[n];r||(r=Object.keys(i)),s.sort&&r.sort(s.sort);for(var l=0;l<r.length;++l){var c=r[l];s.skipNulls&&null===i[c]||pushToArray(o,b(i[c],c,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),y=!0===s.addQueryPrefix?"?":"";return s.charsetSentinel&&("iso-8859-1"===s.charset?y+="utf8=%26%2310003%3B&":y+="utf8=%E2%9C%93&"),u.length>0?y+u:""},decode$1=function(e,t){var r=function normalizeParseOptions(e){if(!e)return O;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?O.charset:e.charset;return{allowDots:void 0===e.allowDots?O.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:O.allowPrototypes,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:O.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:O.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:O.comma,decoder:"function"==typeof e.decoder?e.decoder:O.decoder,delimiter:"string"==typeof e.delimiter||a.isRegExp(e.delimiter)?e.delimiter:O.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:O.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:O.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:O.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:O.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:O.strictNullHandling}}(t);if(""===e||null==e)return r.plainObjects?Object.create(null):{};for(var i="string"==typeof e?function parseQueryStringValues(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),l=-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"),l=r,r=o.length);for(r=0;r<o.length;++r)if(r!==l){var u,d,f=o[r],h=f.indexOf("]="),p=-1===h?f.indexOf("="):h+1;-1===p?(u=t.decoder(f,O.decoder,c,"key"),d=t.strictNullHandling?null:""):(u=t.decoder(f.slice(0,p),O.decoder,c,"key"),d=j(parseArrayValue(f.slice(p+1),t),(function(e){return t.decoder(e,O.decoder,c,"value")}))),d&&t.interpretNumericEntities&&"iso-8859-1"===c&&(d=interpretNumericEntities(d)),f.indexOf("[]=")>-1&&(d=w(d)?[d]:d),v.call(i,u)?i[u]=a.combine(i[u],d):i[u]=d}return i}(e,r):e,s=r.plainObjects?Object.create(null):{},n=Object.keys(i),o=0;o<n.length;++o){var l=n[o],c=S(l,i[l],r,"string"==typeof e);s=a.merge(s,c,r)}return a.compact(s)},P=5;class ClientResponseError extends Error{constructor(e){super(e.statusText),this.name="ClientResponseError",this.statusCode=e.status,this.response=e}}class Client{constructor({server:e,secret:t,headers:r}={}){if(null==e)throw new ValidationError("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=encode$1({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,l=await fetch(s,{mode:"cors",headers:{...this.headers,...o},method:n,body:a});if(l.ok)return l;throw new ClientResponseError(l)}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 _processSearchResponse(await i.json())}async suggest(e){const t=this._buildSearchQueryObject(e).dump(!0),r=await this.request("/suggest",t);return _processSearchResponse(await r.json())}async stats(e,t){return validateRequired(t.session_id,"session_id is required"),validateHashId(t.hashid),await this.request(`/stats/${e}`,t)}async topStats(e,t){return validateHashId(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}/${P}${r}${s}`}toString(){return`Client(${this.endpoint}${this._secret?" (+secret)":""})`}_buildSearchQueryObject(e){return e instanceof Query?e:new Query(e)}}class StatsClient{constructor(e){if(!(e instanceof Client))throw new ValidationError("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=clone(e);return"dfid"in t?(!function validateDoofinderId(e){if(isValidDoofinderId(e))return e;throw new ValidationError("invalid doofinder id")}(t.dfid),delete t.id,delete t.datatype):(validateRequired([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 validateRequired(e.img_id,"img_id is required"),this.client.stats("img_click",e)}async registerRedirection(e){return validateRequired([e.redirection_id,e.link],"redirection_id and link are required"),this.client.stats("redirect",e)}async addToCart(e){return validateRequired([e.item_id,e.amount],"item_id and amount are required"),this.client.stats("add-to-cart",e)}async removeFromCart(e){return validateRequired([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 ClientPool{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 Client({...this._options,server:e})),this._clientsPool.get(e)}static getStatsClient(e){return this._statsClientsPool.has(e)||this._statsClientsPool.set(e,new StatsClient(this.getClient(e))),this._statsClientsPool.get(e)}static reset(){this.options={}}static clear(){this._clientsPool.clear(),this._statsClientsPool.clear()}}ClientPool._clientsPool=new Map,ClientPool._statsClientsPool=new Map,ClientPool._options={};return e.Client=Client,e.ClientPool=ClientPool,e.ClientResponseError=ClientResponseError,e.Query=Query,e.QueryFilter=QueryFilter,e.QuerySort=QuerySort,e.QueryTypes=QueryTypes,e.QueryValueError=QueryValueError,e.StatsClient=StatsClient,e.__API_VERSION__=P,e.__VERSION__="6.0.0",e._processSearchResponse=_processSearchResponse,e.clone=clone,e.decode=decode$1,e.encode=encode$1,e.extend=extend,e.isEmptyObject=function isEmptyObject(e){return 0===Object.keys(e).length&&e.constructor===Object},e.isIdentical=isIdentical,e.isNumber=isNumber,e.isObject=isObject,e.isPlainObject=isPlainObject,e.isShallowEqual=isShallowEqual,e.isString=isString,e.isValidDoofinderId=isValidDoofinderId,e.isValidHashId=isValidHashId,e.merge=function merge$1(...e){let t=e.shift();return null!=t&&(isPlainObject(t)||Array.isArray(t))||(t={}),e.filter(e=>isPlainObject(e)||Array.isArray(e)).forEach((function(e){if(null!=e)for(const r in e){if(!e.hasOwnProperty(r))continue;const i=e[r],s=t[r];t!==i&&(isPlainObject(i)?t[r]=merge$1(isPlainObject(s)?s:{},i):Array.isArray(i)?t[r]=merge$1(Array.isArray(s)?s:[],i):void 0!==i&&(t[r]=i))}})),t},e}({}); | ||
var doofinder=function(e){"use strict";class t extends Error{}const r=e=>"[object String]"===Object.prototype.toString.call(e),s=e=>"[object Number]"===Object.prototype.toString.call(e)&&!isNaN(e),i=e=>"[object Object]"===Object.prototype.toString.call(e);const n=e=>i(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval,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)}const u=function(e,t){return e===t?0!==e||0!==t||1/e==1/t:e!=e&&t!=t},f=function(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),s=Object.keys(t);if(r.length!==s.length)return!1;for(let s=0;s<r.length;s++)if(!Object.prototype.hasOwnProperty.call(t,r[s])||!u(e[r[s]],t[r[s]]))return!1;return!0};class h{constructor(){this._types=new Set}set(e){const s=Array.isArray(e)?e:[e];if(s.filter(r).length!==s.length)throw new t("types must be strings");this._types=new Set(s)}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)}}const d=function(...e){const t=e.length;let r,s,i,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(s in r)o=r[s],"__proto__"!==s&&l!==o&&(f&&o&&(n(o)||(a=Array.isArray(o)))?(i=l[s],c=a&&!Array.isArray(i)?[]:!a&&n(i)?{}:i,a=!1,l[s]=d(f,c,o)):void 0!==o&&(l[s]=o));return l};function p(e){return Array.isArray(e)?d(!0,[],e):n(e)?d(!0,{},e):e}class y{constructor(){this._filters=new Map}get(e){return this._denormalize(this._filters.get(e))}set(e,r){const s=this._normalize(r);if(s instanceof Set)this._filters.set(e,s);else{if(n(s)&&0===Object.entries(s).length)throw new t("plain object filters can't be empty");this._filters.set(e,p(s))}}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),s=this._filters.get(e);s instanceof Set?r instanceof Set?this._filters.set(e,new Set([...s,...r])):s.add(r):this._filters.set(e,r)}remove(e,t){const r=this._filters.get(e);if(r instanceof Set&&null!=t){const s=this._normalize(t);if(s instanceof Set)for(const e of s)r.delete(e);else r.delete(s);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)||s(e)?new Set([e]):Array.isArray(e)?new Set(e):e}_denormalize(e){return e instanceof Set?[...e]:e}_filterContainsOrEqualsValue(e,t,r){const s=this._normalize(t),i=this._filters.get(e);if(i instanceof Set&&s instanceof Set){if(r&&i.size!==s.size)return!1;for(const e of s)if(!i.has(e))return!1;return!0}return f(i,s)}}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(!s(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(!s(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 h,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,s=t.doc_count||0;return r<s?1:r>s?-1:e.key.localeCompare(t.key)}),{type:"terms",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 r in e)"terms"in e[r]?t[r]=O(e[r]):"range"in e[r]&&(t[r]={type:"range",range:e[r].range.buckets[0].stats});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):{},s=0;s<e.length;++s)void 0!==e[s]&&(r[s]=e[s]);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=[],s=0;s<t.length;++s)for(var i=t[s],n=i.obj[i.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 s=[],i=0;i<r.length;++i)void 0!==r[i]&&s.push(r[i]);t.obj[t.prop]=s}}}(t),e},decode:function(e,t,r){var s=e.replace(/\+/g," ");if("iso-8859-1"===r)return s.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(s)}catch(e){return s}},encode:function(e,t,r){if(0===e.length)return e;var s=e;if("symbol"==typeof e?s=Symbol.prototype.toString.call(e):"string"!=typeof e&&(s=String(e)),"iso-8859-1"===r)return escape(s).replace(/%u[0-9a-f]{4}/gi,(function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"}));for(var i="",n=0;n<s.length;++n){var o=s.charCodeAt(n);45===o||46===o||95===o||126===o||o>=48&&o<=57||o>=65&&o<=90||o>=97&&o<=122?i+=s.charAt(n):o<128?i+=A[o]:o<2048?i+=A[192|o>>6]+A[128|63&o]:o<55296||o>=57344?i+=A[224|o>>12]+A[128|o>>6&63]+A[128|63&o]:(n+=1,o=65536+((1023&o)<<10|1023&s.charCodeAt(n)),i+=A[240|o>>18]+A[128|o>>12&63]+A[128|o>>6&63]+A[128|63&o])}return i},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=[],s=0;s<e.length;s+=1)r.push(t(e[s]));return r}return t(e)},merge:function e(t,r,s){if(!r)return t;if("object"!=typeof r){if(k(t))t.push(r);else{if(!t||"object"!=typeof t)return[t,r];(s&&(s.plainObjects||s.allowPrototypes)||!P.call(Object.prototype,r))&&(t[r]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(r);var i=t;return k(t)&&!k(r)&&(i=C(t,s)),k(t)&&k(r)?(r.forEach((function(r,i){if(P.call(t,i)){var n=t[i];n&&"object"==typeof n&&r&&"object"==typeof r?t[i]=e(n,r,s):t.push(r)}else t[i]=r})),t):Object.keys(r).reduce((function(t,i){var n=r[i];return P.call(t,i)?t[i]=e(t[i],n,s):t[i]=n,t}),i)}},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,s,i,n,o,a,c,l,u,f,h,d){var p,y=t;if("function"==typeof a?y=a(r,y):y instanceof Date?y=u(y):"comma"===s&&R(y)&&(y=x.maybeMap(y,(function(e){return e instanceof Date?u(e):e})).join(",")),null===y){if(i)return o&&!h?o(r,V.encoder,d,"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(h?r:o(r,V.encoder,d,"key"))+"="+f(o(y,V.encoder,d,"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 s?s(r,w):r:r+(l?"."+w:"["+w+"]");F(g,e(v,j,s,i,n,o,a,c,l,u,f,h,d))}}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,s){if(e){var i=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,n=/(\[[^[\]]*])/g,o=r.depth>0&&/(\[[^[\]]*])/.exec(i),a=o?i.slice(0,o.index):i,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(i))&&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("["+i.slice(o.index)+"]"),function(e,t,r,s){for(var i=s?t:G(t,r),n=e.length-1;n>=0;--n){var o,a=e[n];if("[]"===a&&r.parseArrays)o=[].concat(i);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]=i:o[c]=i:o={0:i}}i=o}return i}(c,t,r,s)}};const K=function(e,t){var r,s=e,i=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 s=D.formatters[r],i=V.filter;return("function"==typeof e.filter||R(e.filter))&&(i=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:i,formatter:s,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 i.filter?s=(0,i.filter)("",s):R(i.filter)&&(r=i.filter);var n,o=[];if("object"!=typeof s||null===s)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(s)),i.sort&&r.sort(i.sort);for(var c=0;c<r.length;++c){var l=r[c];i.skipNulls&&null===s[l]||F(o,H(s[l],l,a,i.strictNullHandling,i.skipNulls,i.encode?i.encoder:null,i.filter,i.sort,i.allowDots,i.serializeDate,i.formatter,i.encodeValuesOnly,i.charset))}var u=o.join(i.delimiter),f=!0===i.addQueryPrefix?"?":"";return i.charsetSentinel&&("iso-8859-1"===i.charset?f+="utf8=%26%2310003%3B&":f+="utf8=%E2%9C%93&"),u.length>0?f+u:""},W=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 s="string"==typeof e?function(e,t){var r,s={},i=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,n=t.parameterLimit===1/0?void 0:t.parameterLimit,o=i.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],h=f.indexOf("]="),d=-1===h?f.indexOf("="):h+1;-1===d?(l=t.decoder(f,B.decoder,c,"key"),u=t.strictNullHandling?null:""):(l=t.decoder(f.slice(0,d),B.decoder,c,"key"),u=x.maybeMap(G(f.slice(d+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(s,l)?s[l]=x.combine(s[l],u):s[l]=u}return s}(e,r):e,i=r.plainObjects?Object.create(null):{},n=Object.keys(s),o=0;o<n.length;++o){var a=n[o],c=J(a,s[a],r,"string"==typeof e);i=x.merge(i,c,r)}return x.compact(i)};class X extends Error{constructor(e){super(e.statusText),this.name="ClientResponseError",this.statusCode=e.status,this.response=e}}class Y{constructor({server:e,secret:t,headers:r}={}){if(null==e)throw new g("search server is required");this._server=e;const s={...r||{}};let i="";null!=t&&(this._secret=t.trim(),s.Authorization="Token "+this._secret,i="https:"),this._endpoint=`${i}//${e}`,this._headers={Accept:"application/json",...s}}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 s=K({random:(new Date).getTime(),...t}),i=this._buildUrl(e,s),n=r?"POST":"GET",o=r?{"Content-Type":"application/json"}:{},a=r?JSON.stringify(r):void 0,c=await fetch(i,{mode:"cors",headers:{...this.headers,...o},method:n,body:a});if(c.ok)return c;throw new X(c)}async search(e){const t=this._buildSearchQueryObject(e).dump(!0);let r;null!=t.items&&(r={items:t.items},delete t.items);const s=await this.request("/search",t,r);return S(await s.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,s]=e.split("?");let i;return i=null!=s?`?${s}${t?"&"+t:""}`:t?"?"+t:"",`${this.endpoint}/5${r}${i}`}toString(){return`Client(${this.endpoint}${this._secret?" (+secret)":""})`}_buildSearchQueryObject(e){return e instanceof j?e:new j(e)}}class Z{constructor(e){if(!(e instanceof Y))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 ee{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,s={};t&&(s.server=t),r&&(s.headers=Object.freeze({...r})),this._options=Object.freeze(s),this.clear()}static getClient(e){return this._clientsPool.has(e)||this._clientsPool.set(e,new Y({...this._options,server:e})),this._clientsPool.get(e)}static getStatsClient(e){return this._statsClientsPool.has(e)||this._statsClientsPool.set(e,new Z(this.getClient(e))),this._statsClientsPool.get(e)}static reset(){this.options={}}static clear(){this._clientsPool.clear(),this._statsClientsPool.clear()}}ee._clientsPool=new Map,ee._statsClientsPool=new Map,ee._options={};return e.Client=Y,e.ClientPool=ee,e.ClientResponseError=X,e.Query=j,e.QueryFilter=y,e.QuerySort=m,e.QueryTypes=h,e.QueryValueError=t,e.StatsClient=Z,e.__API_VERSION__=5,e.__VERSION__="6.0.0",e._processSearchResponse=S,e.clone=p,e.decode=W,e.encode=K,e.extend=d,e.isEmptyObject=function(e){return 0===Object.keys(e).length&&e.constructor===Object},e.isIdentical=u,e.isNumber=s,e.isObject=i,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 s in t){if(!t.hasOwnProperty(s))continue;const i=t[s],o=r[s];r!==i&&(n(i)?r[s]=e(n(o)?o:{},i):Array.isArray(i)?r[s]=e(Array.isArray(o)?o:[],i):void 0!==i&&(r[s]=i))}})),r},e}({}); |
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.7.8" | ||
"packageVersion": "7.8.1" | ||
} | ||
] | ||
} |
{ | ||
"name": "doofinder", | ||
"version": "6.0.0-beta.0", | ||
"version": "6.0.0-beta.1", | ||
"description": "Javascript Library for Doofinder Search API", | ||
"main": "lib/index.js", | ||
"module": "lib/index.mjs", | ||
"browser": "lib/doofinder.min.js", | ||
"main": "lib/doofinder.common.js", | ||
"module": "lib/doofinder.mjs", | ||
"engines": { | ||
@@ -25,5 +24,4 @@ "node": ">=10.15.0" | ||
"compile": "rimraf lib && rollup -c", | ||
"minify-iife": "terser lib/doofinder.js -c -m --comments /^nothing/ --keep-classnames --keep-fnames -o lib/doofinder.min.js", | ||
"typings": "rimraf types && tsc --declaration --declarationMap --emitDeclarationOnly --outDir types && api-extractor run --local", | ||
"build": "yarn lint && yarn compile && yarn minify-iife && yarn typings", | ||
"build": "yarn lint && yarn compile && yarn typings", | ||
"docs": "api-documenter markdown -i ./temp -o ./docs/reference", | ||
@@ -65,2 +63,3 @@ "test": "export TS_NODE_PROJECT=tsconfig.test.json ; mocha --reporter spec --require ts-node/register \"test/**/*.ts\"", | ||
"@rollup/plugin-node-resolve": "^7.1.1", | ||
"@rollup/plugin-typescript": "^4.1.1", | ||
"@types/chai": "^4.2.3", | ||
@@ -87,5 +86,6 @@ "@types/chai-as-promised": "^7.1.2", | ||
"rollup-plugin-clear": "^2.0.7", | ||
"rollup-plugin-typescript2": "^0.24.3", | ||
"rollup-plugin-terser": "^5.3.0", | ||
"terser": "^4.3.9", | ||
"ts-node": "^8.4.1", | ||
"tslib": "^2.0.0", | ||
"typedoc": "^0.15.0", | ||
@@ -92,0 +92,0 @@ "typescript": "3.7.2" |
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
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
8358
294913
35