Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algolia/recommend

Package Overview
Dependencies
Maintainers
3
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/recommend - npm Package Compare versions

Comparing version 5.2.5 to 5.3.0

74

dist/builds/browser.js

@@ -14,3 +14,3 @@ // builds/browser.ts

import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common";
var apiClientVersion = "5.2.5";
var apiClientVersion = "5.3.0";
function getDefaultHosts(appId) {

@@ -56,22 +56,21 @@ return [

const auth = createAuth(appIdOption, apiKeyOption, authMode);
const transporter = createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: "Recommend",
version: apiClientVersion
return {
transporter: createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: "Recommend",
version: apiClientVersion
}),
baseHeaders: {
"content-type": "text/plain",
...auth.headers(),
...options.baseHeaders
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters
}
}),
baseHeaders: {
"content-type": "text/plain",
...auth.headers(),
...options.baseHeaders
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters
}
});
return {
transporter,
/**

@@ -85,3 +84,5 @@ * The `appId` currently in use.

clearCache() {
return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
() => void 0
);
},

@@ -92,3 +93,3 @@ /**

get _ua() {
return transporter.algoliaAgent.value;
return this.transporter.algoliaAgent.value;
},

@@ -102,5 +103,14 @@ /**

addAlgoliaAgent(segment, version) {
transporter.algoliaAgent.add({ segment, version });
this.transporter.algoliaAgent.add({ segment, version });
},
/**
* Helper method to switch the API key used to authenticate the requests.
*
* @param params - Method params.
* @param params.apiKey - The new API Key to use.
*/
setClientApiKey({ apiKey }) {
this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
},
/**
* This method allow you to send requests to the Algolia REST API.

@@ -126,3 +136,3 @@ *

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -150,3 +160,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -176,3 +186,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -202,3 +212,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -236,3 +246,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -270,3 +280,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -304,3 +314,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -341,3 +351,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -375,3 +385,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
}

@@ -378,0 +388,0 @@ };

@@ -1,2 +0,2 @@

function G(r,e,o="WithinHeaders"){let t={"x-algolia-api-key":e,"x-algolia-application-id":r};return{headers(){return o==="WithinHeaders"?t:{}},queryParameters(){return o==="WithinQueryParameters"?t:{}}}}function H(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function n(){return JSON.parse(t().getItem(o)||"{}")}function d(s){t().setItem(o,JSON.stringify(s))}function m(){let s=r.timeToLive?r.timeToLive*1e3:null,a=n(),i=Object.fromEntries(Object.entries(a).filter(([,h])=>h.timestamp!==void 0));if(d(i),!s)return;let l=Object.fromEntries(Object.entries(i).filter(([,h])=>{let u=new Date().getTime();return!(h.timestamp+s<u)}));d(l)}return{get(s,a,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(m(),n()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:a(),l!==void 0])).then(([l,h])=>Promise.all([l,h||i.miss(l)])).then(([l])=>l)},set(s,a){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(s)]={timestamp:new Date().getTime(),value:a},t().setItem(o,JSON.stringify(i)),a})},delete(s){return Promise.resolve().then(()=>{let a=n();delete a[JSON.stringify(s)],t().setItem(o,JSON.stringify(a))})},clear(){return Promise.resolve().then(()=>{t().removeItem(o)})}}}function Y(){return{get(r,e,o={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,o.miss(n)])).then(([n])=>n)},set(r,e){return Promise.resolve(e)},delete(r){return Promise.resolve()},clear(){return Promise.resolve()}}}function w(r){let e=[...r.caches],o=e.shift();return o===void 0?Y():{get(t,n,d={miss:()=>Promise.resolve()}){return o.get(t,n,d).catch(()=>w({caches:e}).get(t,n,d))},set(t,n){return o.set(t,n).catch(()=>w({caches:e}).set(t,n))},delete(t){return o.delete(t).catch(()=>w({caches:e}).delete(t))},clear(){return o.clear().catch(()=>w({caches:e}).clear())}}}function O(r={serializable:!0}){let e={};return{get(o,t,n={miss:()=>Promise.resolve()}){let d=JSON.stringify(o);if(d in e)return Promise.resolve(r.serializable?JSON.parse(e[d]):e[d]);let m=t();return m.then(s=>n.miss(s)).then(()=>m)},set(o,t){return e[JSON.stringify(o)]=r.serializable?JSON.stringify(t):t,Promise.resolve(t)},delete(o){return delete e[JSON.stringify(o)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function L(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>k}function n(){return e==="timed out"&&Date.now()-o<=k}return{...r,status:e,lastUpdate:o,isUp:t,isTimedOut:n}}var W=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e)}},$=class extends W{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e}},Z=class extends ${constructor(r){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",r,"RetryError")}},D=class extends ${status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e}},ee=class extends W{response;constructor(r,e){super(r,"DeserializationError"),this.response=e}},re=class extends D{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o}};function j(r){let e=r;for(let o=r.length-1;o>0;o--){let t=Math.floor(Math.random()*(o+1)),n=r[o];e[o]=r[t],e[t]=n}return e}function te(r,e,o){let t=oe(o),n=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(n+=`?${t}`),n}function oe(r){return Object.keys(r).filter(e=>r[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(r[e])==="[object Array]"?r[e].join(","):r[e]).replaceAll("+","%20")}`).join("&")}function se(r,e){if(r.method==="GET"||r.data===void 0&&e.data===void 0)return;let o=Array.isArray(r.data)?r.data:{...r.data,...e.data};return JSON.stringify(o)}function ae(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(d=>{let m=t[d];n[d.toLowerCase()]=m}),n}function ne(r){try{return JSON.parse(r.content)}catch(e){throw new ee(e.message,r)}}function ie({content:r,status:e},o){try{let t=JSON.parse(r);return"error"in t?new re(t.message,e,t.error,o):new D(t.message,e,o)}catch{}return new D(r,e,o)}function ce({isTimedOut:r,status:e}){return!r&&~~e===0}function me({isTimedOut:r,status:e}){return r||ce({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function ue({status:r}){return~~(r/100)===2}function le(r){return r.map(e=>J(e))}function J(r){let e=r.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...r,request:{...r.request,headers:{...r.request.headers,...e}}}}function M({hosts:r,hostsCache:e,baseHeaders:o,baseQueryParameters:t,algoliaAgent:n,timeouts:d,requester:m,requestsCache:s,responsesCache:a}){async function i(u){let c=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(L(f))))),p=c.filter(f=>f.isUp()),R=c.filter(f=>f.isTimedOut()),E=[...p,...R];return{hosts:E.length>0?E:u,getTimeout(f,x){return(R.length===0&&f===0?1:R.length+3+f)*x}}}async function l(u,c,p=!0){let R=[],E=se(u,c),g=ae(o,u.headers,c.headers),f=u.method==="GET"?{...u.data,...c.data}:{},x={...t,...u.queryParameters,...f};if(n.value&&(x["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let P of Object.keys(c.queryParameters))!c.queryParameters[P]||Object.prototype.toString.call(c.queryParameters[P])==="[object Object]"?x[P]=c.queryParameters[P]:x[P]=c.queryParameters[P].toString();let T=0,b=async(P,A)=>{let q=P.pop();if(q===void 0)throw new Z(le(R));let S={...d,...c.timeouts},U={data:E,headers:g,method:u.method,url:te(q,u.path,x),connectTimeout:A(T,S.connect),responseTimeout:A(T,p?S.read:S.write)},I=C=>{let _={request:U,response:C,host:q,triesLeft:P.length};return R.push(_),_},y=await m.send(U);if(me(y)){let C=I(y);return y.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,L(q,y.isTimedOut?"timed out":"down")),b(P,A)}if(ue(y))return ne(y);throw I(y),ie(y,R)},K=r.filter(P=>P.accept==="readWrite"||(p?P.accept==="read":P.accept==="write")),N=await i(K);return b([...N.hosts].reverse(),N.getTimeout)}function h(u,c={}){let p=u.useReadTransporter||u.method==="GET";if(!p)return l(u,c,p);let R=()=>l(u,c);if((c.cacheable||u.cacheable)!==!0)return R();let g={request:u,requestOptions:c,transporter:{queryParameters:t,headers:o}};return a.get(g,()=>s.get(g,()=>s.set(g,R()).then(f=>Promise.all([s.delete(g),f]),f=>Promise.all([s.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>a.set(g,f)})}return{hostsCache:e,requester:m,timeouts:d,algoliaAgent:n,baseHeaders:o,baseQueryParameters:t,hosts:r,request:h,requestsCache:s,responsesCache:a}}function de(r){let e={value:`Algolia for JavaScript (${r})`,add(o){let t=`; ${o.segment}${o.version!==void 0?` (${o.version})`:""}`;return e.value.indexOf(t)===-1&&(e.value=`${e.value}${t}`),e}};return e}function Q({algoliaAgents:r,client:e,version:o}){let t=de(o).add({segment:e,version:o});return r.forEach(n=>t.add(n)),t}var z=1e3,F=2e3,B=3e4;function X(){function r(e){return new Promise(o=>{let t=new XMLHttpRequest;t.open(e.method,e.url,!0),Object.keys(e.headers).forEach(s=>t.setRequestHeader(s,e.headers[s]));let n=(s,a)=>setTimeout(()=>{t.abort(),o({status:0,content:a,isTimedOut:!0})},s),d=n(e.connectTimeout,"Connection timeout"),m;t.onreadystatechange=()=>{t.readyState>t.OPENED&&m===void 0&&(clearTimeout(d),m=n(e.responseTimeout,"Socket timeout"))},t.onerror=()=>{t.status===0&&(clearTimeout(d),clearTimeout(m),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}))},t.onload=()=>{clearTimeout(d),clearTimeout(m),o({content:t.responseText,status:t.status,isTimedOut:!1})},t.send(e.data)})}return{send:r}}var v="5.2.5";function pe(r){return[{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(j([{url:`${r}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function V({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let d=G(r,e,o),m=M({hosts:pe(r),...n,algoliaAgent:Q({algoliaAgents:t,client:"Recommend",version:v}),baseHeaders:{"content-type":"text/plain",...d.headers(),...n.baseHeaders},baseQueryParameters:{...d.queryParameters(),...n.baseQueryParameters}});return{transporter:m,appId:r,clearCache(){return Promise.all([m.requestsCache.clear(),m.responsesCache.clear()]).then(()=>{})},get _ua(){return m.algoliaAgent.value},addAlgoliaAgent(s,a){m.algoliaAgent.add({segment:s,version:a})},customDelete({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let c={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return m.request(c,i)},customGet({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let c={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return m.request(c,i)},customPost({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let p={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return m.request(p,l)},customPut({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let p={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return m.request(p,l)},deleteRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `deleteRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `deleteRecommendRule`.");let p={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `getRecommendRule`.");let p={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendStatus({indexName:s,model:a,taskID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendStatus`.");if(!i)throw new Error("Parameter `taskID` is required when calling `getRecommendStatus`.");let p={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendations(s,a){if(s&&Array.isArray(s)&&(s={requests:s}),!s)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!s.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");let u={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return m.request(u,a)},searchRecommendRules({indexName:s,model:a,searchRecommendRulesParams:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!a)throw new Error("Parameter `model` is required when calling `searchRecommendRules`.");let p={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return m.request(p,l)}}}function ht(r,e,o){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");return V({appId:r,apiKey:e,timeouts:{connect:z,read:F,write:B},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[H({key:`${v}-${r}`}),O()]}),...o})}export{v as apiClientVersion,ht as recommendClient};
function G(r,e,o="WithinHeaders"){let t={"x-algolia-api-key":e,"x-algolia-application-id":r};return{headers(){return o==="WithinHeaders"?t:{}},queryParameters(){return o==="WithinQueryParameters"?t:{}}}}function H(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function n(){return JSON.parse(t().getItem(o)||"{}")}function l(s){t().setItem(o,JSON.stringify(s))}function a(){let s=r.timeToLive?r.timeToLive*1e3:null,i=n(),u=Object.fromEntries(Object.entries(i).filter(([,f])=>f.timestamp!==void 0));if(l(u),!s)return;let p=Object.fromEntries(Object.entries(u).filter(([,f])=>{let m=new Date().getTime();return!(f.timestamp+s<m)}));l(p)}return{get(s,i,u={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(a(),n()[JSON.stringify(s)])).then(p=>Promise.all([p?p.value:i(),p!==void 0])).then(([p,f])=>Promise.all([p,f||u.miss(p)])).then(([p])=>p)},set(s,i){return Promise.resolve().then(()=>{let u=n();return u[JSON.stringify(s)]={timestamp:new Date().getTime(),value:i},t().setItem(o,JSON.stringify(u)),i})},delete(s){return Promise.resolve().then(()=>{let i=n();delete i[JSON.stringify(s)],t().setItem(o,JSON.stringify(i))})},clear(){return Promise.resolve().then(()=>{t().removeItem(o)})}}}function Y(){return{get(r,e,o={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,o.miss(n)])).then(([n])=>n)},set(r,e){return Promise.resolve(e)},delete(r){return Promise.resolve()},clear(){return Promise.resolve()}}}function w(r){let e=[...r.caches],o=e.shift();return o===void 0?Y():{get(t,n,l={miss:()=>Promise.resolve()}){return o.get(t,n,l).catch(()=>w({caches:e}).get(t,n,l))},set(t,n){return o.set(t,n).catch(()=>w({caches:e}).set(t,n))},delete(t){return o.delete(t).catch(()=>w({caches:e}).delete(t))},clear(){return o.clear().catch(()=>w({caches:e}).clear())}}}function O(r={serializable:!0}){let e={};return{get(o,t,n={miss:()=>Promise.resolve()}){let l=JSON.stringify(o);if(l in e)return Promise.resolve(r.serializable?JSON.parse(e[l]):e[l]);let a=t();return a.then(s=>n.miss(s)).then(()=>a)},set(o,t){return e[JSON.stringify(o)]=r.serializable?JSON.stringify(t):t,Promise.resolve(t)},delete(o){return delete e[JSON.stringify(o)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function L(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>k}function n(){return e==="timed out"&&Date.now()-o<=k}return{...r,status:e,lastUpdate:o,isUp:t,isTimedOut:n}}var W=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e)}},$=class extends W{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e}},Z=class extends ${constructor(r){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",r,"RetryError")}},b=class extends ${status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e}},ee=class extends W{response;constructor(r,e){super(r,"DeserializationError"),this.response=e}},re=class extends b{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o}};function j(r){let e=r;for(let o=r.length-1;o>0;o--){let t=Math.floor(Math.random()*(o+1)),n=r[o];e[o]=r[t],e[t]=n}return e}function te(r,e,o){let t=oe(o),n=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(n+=`?${t}`),n}function oe(r){return Object.keys(r).filter(e=>r[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(r[e])==="[object Array]"?r[e].join(","):r[e]).replaceAll("+","%20")}`).join("&")}function se(r,e){if(r.method==="GET"||r.data===void 0&&e.data===void 0)return;let o=Array.isArray(r.data)?r.data:{...r.data,...e.data};return JSON.stringify(o)}function ae(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(l=>{let a=t[l];n[l.toLowerCase()]=a}),n}function ne(r){try{return JSON.parse(r.content)}catch(e){throw new ee(e.message,r)}}function ie({content:r,status:e},o){try{let t=JSON.parse(r);return"error"in t?new re(t.message,e,t.error,o):new b(t.message,e,o)}catch{}return new b(r,e,o)}function ce({isTimedOut:r,status:e}){return!r&&~~e===0}function me({isTimedOut:r,status:e}){return r||ce({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function ue({status:r}){return~~(r/100)===2}function le(r){return r.map(e=>J(e))}function J(r){let e=r.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...r,request:{...r.request,headers:{...r.request.headers,...e}}}}function M({hosts:r,hostsCache:e,baseHeaders:o,baseQueryParameters:t,algoliaAgent:n,timeouts:l,requester:a,requestsCache:s,responsesCache:i}){async function u(m){let c=await Promise.all(m.map(d=>e.get(d,()=>Promise.resolve(L(d))))),y=c.filter(d=>d.isUp()),R=c.filter(d=>d.isTimedOut()),E=[...y,...R];return{hosts:E.length>0?E:m,getTimeout(d,g){return(R.length===0&&d===0?1:R.length+3+d)*g}}}async function p(m,c,y=!0){let R=[],E=se(m,c),P=ae(o,m.headers,c.headers),d=m.method==="GET"?{...m.data,...c.data}:{},g={...t,...m.queryParameters,...d};if(n.value&&(g["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let h of Object.keys(c.queryParameters))!c.queryParameters[h]||Object.prototype.toString.call(c.queryParameters[h])==="[object Object]"?g[h]=c.queryParameters[h]:g[h]=c.queryParameters[h].toString();let T=0,D=async(h,A)=>{let q=h.pop();if(q===void 0)throw new Z(le(R));let S={...l,...c.timeouts},U={data:E,headers:P,method:m.method,url:te(q,m.path,g),connectTimeout:A(T,S.connect),responseTimeout:A(T,y?S.read:S.write)},I=C=>{let _={request:U,response:C,host:q,triesLeft:h.length};return R.push(_),_},x=await a.send(U);if(me(x)){let C=I(x);return x.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,L(q,x.isTimedOut?"timed out":"down")),D(h,A)}if(ue(x))return ne(x);throw I(x),ie(x,R)},V=r.filter(h=>h.accept==="readWrite"||(y?h.accept==="read":h.accept==="write")),N=await u(V);return D([...N.hosts].reverse(),N.getTimeout)}function f(m,c={}){let y=m.useReadTransporter||m.method==="GET";if(!y)return p(m,c,y);let R=()=>p(m,c);if((c.cacheable||m.cacheable)!==!0)return R();let P={request:m,requestOptions:c,transporter:{queryParameters:t,headers:o}};return i.get(P,()=>s.get(P,()=>s.set(P,R()).then(d=>Promise.all([s.delete(P),d]),d=>Promise.all([s.delete(P),Promise.reject(d)])).then(([d,g])=>g)),{miss:d=>i.set(P,d)})}return{hostsCache:e,requester:a,timeouts:l,algoliaAgent:n,baseHeaders:o,baseQueryParameters:t,hosts:r,request:f,requestsCache:s,responsesCache:i}}function pe(r){let e={value:`Algolia for JavaScript (${r})`,add(o){let t=`; ${o.segment}${o.version!==void 0?` (${o.version})`:""}`;return e.value.indexOf(t)===-1&&(e.value=`${e.value}${t}`),e}};return e}function Q({algoliaAgents:r,client:e,version:o}){let t=pe(o).add({segment:e,version:o});return r.forEach(n=>t.add(n)),t}var z=1e3,F=2e3,B=3e4;function X(){function r(e){return new Promise(o=>{let t=new XMLHttpRequest;t.open(e.method,e.url,!0),Object.keys(e.headers).forEach(s=>t.setRequestHeader(s,e.headers[s]));let n=(s,i)=>setTimeout(()=>{t.abort(),o({status:0,content:i,isTimedOut:!0})},s),l=n(e.connectTimeout,"Connection timeout"),a;t.onreadystatechange=()=>{t.readyState>t.OPENED&&a===void 0&&(clearTimeout(l),a=n(e.responseTimeout,"Socket timeout"))},t.onerror=()=>{t.status===0&&(clearTimeout(l),clearTimeout(a),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}))},t.onload=()=>{clearTimeout(l),clearTimeout(a),o({content:t.responseText,status:t.status,isTimedOut:!1})},t.send(e.data)})}return{send:r}}var v="5.3.0";function de(r){return[{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(j([{url:`${r}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function K({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let l=G(r,e,o);return{transporter:M({hosts:de(r),...n,algoliaAgent:Q({algoliaAgents:t,client:"Recommend",version:v}),baseHeaders:{"content-type":"text/plain",...l.headers(),...n.baseHeaders},baseQueryParameters:{...l.queryParameters(),...n.baseQueryParameters}}),appId:r,clearCache(){return Promise.all([this.transporter.requestsCache.clear(),this.transporter.responsesCache.clear()]).then(()=>{})},get _ua(){return this.transporter.algoliaAgent.value},addAlgoliaAgent(a,s){this.transporter.algoliaAgent.add({segment:a,version:s})},setClientApiKey({apiKey:a}){this.transporter.baseHeaders["x-algolia-api-key"]=a},customDelete({path:a,parameters:s},i){if(!a)throw new Error("Parameter `path` is required when calling `customDelete`.");let m={method:"DELETE",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{}};return this.transporter.request(m,i)},customGet({path:a,parameters:s},i){if(!a)throw new Error("Parameter `path` is required when calling `customGet`.");let m={method:"GET",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{}};return this.transporter.request(m,i)},customPost({path:a,parameters:s,body:i},u){if(!a)throw new Error("Parameter `path` is required when calling `customPost`.");let c={method:"POST",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return this.transporter.request(c,u)},customPut({path:a,parameters:s,body:i},u){if(!a)throw new Error("Parameter `path` is required when calling `customPut`.");let c={method:"PUT",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return this.transporter.request(c,u)},deleteRecommendRule({indexName:a,model:s,objectID:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!s)throw new Error("Parameter `model` is required when calling `deleteRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `deleteRecommendRule`.");let c={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return this.transporter.request(c,u)},getRecommendRule({indexName:a,model:s,objectID:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!s)throw new Error("Parameter `model` is required when calling `getRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `getRecommendRule`.");let c={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return this.transporter.request(c,u)},getRecommendStatus({indexName:a,model:s,taskID:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!s)throw new Error("Parameter `model` is required when calling `getRecommendStatus`.");if(!i)throw new Error("Parameter `taskID` is required when calling `getRecommendStatus`.");let c={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return this.transporter.request(c,u)},getRecommendations(a,s){if(a&&Array.isArray(a)&&(a={requests:a}),!a)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!a.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");let f={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:a,useReadTransporter:!0,cacheable:!0};return this.transporter.request(f,s)},searchRecommendRules({indexName:a,model:s,searchRecommendRulesParams:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!s)throw new Error("Parameter `model` is required when calling `searchRecommendRules`.");let c={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return this.transporter.request(c,u)}}}function ht(r,e,o){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");return K({appId:r,apiKey:e,timeouts:{connect:z,read:F,write:B},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[H({key:`${v}-${r}`}),O()]}),...o})}export{v as apiClientVersion,ht as recommendClient};
//# sourceMappingURL=browser.min.js.map

@@ -7,3 +7,3 @@ (function (global, factory) {

function G(r,e,o="WithinHeaders"){let t={"x-algolia-api-key":e,"x-algolia-application-id":r};return {headers(){return o==="WithinHeaders"?t:{}},queryParameters(){return o==="WithinQueryParameters"?t:{}}}}function H(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function n(){return JSON.parse(t().getItem(o)||"{}")}function d(s){t().setItem(o,JSON.stringify(s));}function m(){let s=r.timeToLive?r.timeToLive*1e3:null,a=n(),i=Object.fromEntries(Object.entries(a).filter(([,h])=>h.timestamp!==void 0));if(d(i),!s)return;let l=Object.fromEntries(Object.entries(i).filter(([,h])=>{let u=new Date().getTime();return !(h.timestamp+s<u)}));d(l);}return {get(s,a,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(m(),n()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:a(),l!==void 0])).then(([l,h])=>Promise.all([l,h||i.miss(l)])).then(([l])=>l)},set(s,a){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(s)]={timestamp:new Date().getTime(),value:a},t().setItem(o,JSON.stringify(i)),a})},delete(s){return Promise.resolve().then(()=>{let a=n();delete a[JSON.stringify(s)],t().setItem(o,JSON.stringify(a));})},clear(){return Promise.resolve().then(()=>{t().removeItem(o);})}}}function Y(){return {get(r,e,o={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,o.miss(n)])).then(([n])=>n)},set(r,e){return Promise.resolve(e)},delete(r){return Promise.resolve()},clear(){return Promise.resolve()}}}function w(r){let e=[...r.caches],o=e.shift();return o===void 0?Y():{get(t,n,d={miss:()=>Promise.resolve()}){return o.get(t,n,d).catch(()=>w({caches:e}).get(t,n,d))},set(t,n){return o.set(t,n).catch(()=>w({caches:e}).set(t,n))},delete(t){return o.delete(t).catch(()=>w({caches:e}).delete(t))},clear(){return o.clear().catch(()=>w({caches:e}).clear())}}}function O(r={serializable:!0}){let e={};return {get(o,t,n={miss:()=>Promise.resolve()}){let d=JSON.stringify(o);if(d in e)return Promise.resolve(r.serializable?JSON.parse(e[d]):e[d]);let m=t();return m.then(s=>n.miss(s)).then(()=>m)},set(o,t){return e[JSON.stringify(o)]=r.serializable?JSON.stringify(t):t,Promise.resolve(t)},delete(o){return delete e[JSON.stringify(o)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function L(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>k}function n(){return e==="timed out"&&Date.now()-o<=k}return {...r,status:e,lastUpdate:o,isUp:t,isTimedOut:n}}var W=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e);}},$=class extends W{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e;}},Z=class extends ${constructor(r){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",r,"RetryError");}},D=class extends ${status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e;}},ee=class extends W{response;constructor(r,e){super(r,"DeserializationError"),this.response=e;}},re=class extends D{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o;}};function j(r){let e=r;for(let o=r.length-1;o>0;o--){let t=Math.floor(Math.random()*(o+1)),n=r[o];e[o]=r[t],e[t]=n;}return e}function te(r,e,o){let t=oe(o),n=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(n+=`?${t}`),n}function oe(r){return Object.keys(r).filter(e=>r[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(r[e])==="[object Array]"?r[e].join(","):r[e]).replaceAll("+","%20")}`).join("&")}function se(r,e){if(r.method==="GET"||r.data===void 0&&e.data===void 0)return;let o=Array.isArray(r.data)?r.data:{...r.data,...e.data};return JSON.stringify(o)}function ae(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(d=>{let m=t[d];n[d.toLowerCase()]=m;}),n}function ne(r){try{return JSON.parse(r.content)}catch(e){throw new ee(e.message,r)}}function ie({content:r,status:e},o){try{let t=JSON.parse(r);return "error"in t?new re(t.message,e,t.error,o):new D(t.message,e,o)}catch{}return new D(r,e,o)}function ce({isTimedOut:r,status:e}){return !r&&~~e===0}function me({isTimedOut:r,status:e}){return r||ce({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function ue({status:r}){return ~~(r/100)===2}function le(r){return r.map(e=>J(e))}function J(r){let e=r.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...r,request:{...r.request,headers:{...r.request.headers,...e}}}}function M({hosts:r,hostsCache:e,baseHeaders:o,baseQueryParameters:t,algoliaAgent:n,timeouts:d,requester:m,requestsCache:s,responsesCache:a}){async function i(u){let c=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(L(f))))),p=c.filter(f=>f.isUp()),R=c.filter(f=>f.isTimedOut()),E=[...p,...R];return {hosts:E.length>0?E:u,getTimeout(f,x){return (R.length===0&&f===0?1:R.length+3+f)*x}}}async function l(u,c,p=!0){let R=[],E=se(u,c),g=ae(o,u.headers,c.headers),f=u.method==="GET"?{...u.data,...c.data}:{},x={...t,...u.queryParameters,...f};if(n.value&&(x["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let P of Object.keys(c.queryParameters))!c.queryParameters[P]||Object.prototype.toString.call(c.queryParameters[P])==="[object Object]"?x[P]=c.queryParameters[P]:x[P]=c.queryParameters[P].toString();let T=0,b=async(P,A)=>{let q=P.pop();if(q===void 0)throw new Z(le(R));let S={...d,...c.timeouts},U={data:E,headers:g,method:u.method,url:te(q,u.path,x),connectTimeout:A(T,S.connect),responseTimeout:A(T,p?S.read:S.write)},I=C=>{let _={request:U,response:C,host:q,triesLeft:P.length};return R.push(_),_},y=await m.send(U);if(me(y)){let C=I(y);return y.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,L(q,y.isTimedOut?"timed out":"down")),b(P,A)}if(ue(y))return ne(y);throw I(y),ie(y,R)},K=r.filter(P=>P.accept==="readWrite"||(p?P.accept==="read":P.accept==="write")),N=await i(K);return b([...N.hosts].reverse(),N.getTimeout)}function h(u,c={}){let p=u.useReadTransporter||u.method==="GET";if(!p)return l(u,c,p);let R=()=>l(u,c);if((c.cacheable||u.cacheable)!==!0)return R();let g={request:u,requestOptions:c,transporter:{queryParameters:t,headers:o}};return a.get(g,()=>s.get(g,()=>s.set(g,R()).then(f=>Promise.all([s.delete(g),f]),f=>Promise.all([s.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>a.set(g,f)})}return {hostsCache:e,requester:m,timeouts:d,algoliaAgent:n,baseHeaders:o,baseQueryParameters:t,hosts:r,request:h,requestsCache:s,responsesCache:a}}function de(r){let e={value:`Algolia for JavaScript (${r})`,add(o){let t=`; ${o.segment}${o.version!==void 0?` (${o.version})`:""}`;return e.value.indexOf(t)===-1&&(e.value=`${e.value}${t}`),e}};return e}function Q({algoliaAgents:r,client:e,version:o}){let t=de(o).add({segment:e,version:o});return r.forEach(n=>t.add(n)),t}var z=1e3,F=2e3,B=3e4;function X(){function r(e){return new Promise(o=>{let t=new XMLHttpRequest;t.open(e.method,e.url,!0),Object.keys(e.headers).forEach(s=>t.setRequestHeader(s,e.headers[s]));let n=(s,a)=>setTimeout(()=>{t.abort(),o({status:0,content:a,isTimedOut:!0});},s),d=n(e.connectTimeout,"Connection timeout"),m;t.onreadystatechange=()=>{t.readyState>t.OPENED&&m===void 0&&(clearTimeout(d),m=n(e.responseTimeout,"Socket timeout"));},t.onerror=()=>{t.status===0&&(clearTimeout(d),clearTimeout(m),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}));},t.onload=()=>{clearTimeout(d),clearTimeout(m),o({content:t.responseText,status:t.status,isTimedOut:!1});},t.send(e.data);})}return {send:r}}var v="5.2.5";function pe(r){return [{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(j([{url:`${r}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function V({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let d=G(r,e,o),m=M({hosts:pe(r),...n,algoliaAgent:Q({algoliaAgents:t,client:"Recommend",version:v}),baseHeaders:{"content-type":"text/plain",...d.headers(),...n.baseHeaders},baseQueryParameters:{...d.queryParameters(),...n.baseQueryParameters}});return {transporter:m,appId:r,clearCache(){return Promise.all([m.requestsCache.clear(),m.responsesCache.clear()]).then(()=>{})},get _ua(){return m.algoliaAgent.value},addAlgoliaAgent(s,a){m.algoliaAgent.add({segment:s,version:a});},customDelete({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let c={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return m.request(c,i)},customGet({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let c={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return m.request(c,i)},customPost({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let p={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return m.request(p,l)},customPut({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let p={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return m.request(p,l)},deleteRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `deleteRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `deleteRecommendRule`.");let p={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `getRecommendRule`.");let p={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendStatus({indexName:s,model:a,taskID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendStatus`.");if(!i)throw new Error("Parameter `taskID` is required when calling `getRecommendStatus`.");let p={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendations(s,a){if(s&&Array.isArray(s)&&(s={requests:s}),!s)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!s.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");let u={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return m.request(u,a)},searchRecommendRules({indexName:s,model:a,searchRecommendRulesParams:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!a)throw new Error("Parameter `model` is required when calling `searchRecommendRules`.");let p={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return m.request(p,l)}}}function ht(r,e,o){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");return V({appId:r,apiKey:e,timeouts:{connect:z,read:F,write:B},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[H({key:`${v}-${r}`}),O()]}),...o})}
function G(r,e,o="WithinHeaders"){let t={"x-algolia-api-key":e,"x-algolia-application-id":r};return {headers(){return o==="WithinHeaders"?t:{}},queryParameters(){return o==="WithinQueryParameters"?t:{}}}}function H(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function n(){return JSON.parse(t().getItem(o)||"{}")}function l(s){t().setItem(o,JSON.stringify(s));}function a(){let s=r.timeToLive?r.timeToLive*1e3:null,i=n(),u=Object.fromEntries(Object.entries(i).filter(([,f])=>f.timestamp!==void 0));if(l(u),!s)return;let p=Object.fromEntries(Object.entries(u).filter(([,f])=>{let m=new Date().getTime();return !(f.timestamp+s<m)}));l(p);}return {get(s,i,u={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(a(),n()[JSON.stringify(s)])).then(p=>Promise.all([p?p.value:i(),p!==void 0])).then(([p,f])=>Promise.all([p,f||u.miss(p)])).then(([p])=>p)},set(s,i){return Promise.resolve().then(()=>{let u=n();return u[JSON.stringify(s)]={timestamp:new Date().getTime(),value:i},t().setItem(o,JSON.stringify(u)),i})},delete(s){return Promise.resolve().then(()=>{let i=n();delete i[JSON.stringify(s)],t().setItem(o,JSON.stringify(i));})},clear(){return Promise.resolve().then(()=>{t().removeItem(o);})}}}function Y(){return {get(r,e,o={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,o.miss(n)])).then(([n])=>n)},set(r,e){return Promise.resolve(e)},delete(r){return Promise.resolve()},clear(){return Promise.resolve()}}}function w(r){let e=[...r.caches],o=e.shift();return o===void 0?Y():{get(t,n,l={miss:()=>Promise.resolve()}){return o.get(t,n,l).catch(()=>w({caches:e}).get(t,n,l))},set(t,n){return o.set(t,n).catch(()=>w({caches:e}).set(t,n))},delete(t){return o.delete(t).catch(()=>w({caches:e}).delete(t))},clear(){return o.clear().catch(()=>w({caches:e}).clear())}}}function O(r={serializable:!0}){let e={};return {get(o,t,n={miss:()=>Promise.resolve()}){let l=JSON.stringify(o);if(l in e)return Promise.resolve(r.serializable?JSON.parse(e[l]):e[l]);let a=t();return a.then(s=>n.miss(s)).then(()=>a)},set(o,t){return e[JSON.stringify(o)]=r.serializable?JSON.stringify(t):t,Promise.resolve(t)},delete(o){return delete e[JSON.stringify(o)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function L(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>k}function n(){return e==="timed out"&&Date.now()-o<=k}return {...r,status:e,lastUpdate:o,isUp:t,isTimedOut:n}}var W=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e);}},$=class extends W{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e;}},Z=class extends ${constructor(r){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",r,"RetryError");}},b=class extends ${status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e;}},ee=class extends W{response;constructor(r,e){super(r,"DeserializationError"),this.response=e;}},re=class extends b{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o;}};function j(r){let e=r;for(let o=r.length-1;o>0;o--){let t=Math.floor(Math.random()*(o+1)),n=r[o];e[o]=r[t],e[t]=n;}return e}function te(r,e,o){let t=oe(o),n=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(n+=`?${t}`),n}function oe(r){return Object.keys(r).filter(e=>r[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(r[e])==="[object Array]"?r[e].join(","):r[e]).replaceAll("+","%20")}`).join("&")}function se(r,e){if(r.method==="GET"||r.data===void 0&&e.data===void 0)return;let o=Array.isArray(r.data)?r.data:{...r.data,...e.data};return JSON.stringify(o)}function ae(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(l=>{let a=t[l];n[l.toLowerCase()]=a;}),n}function ne(r){try{return JSON.parse(r.content)}catch(e){throw new ee(e.message,r)}}function ie({content:r,status:e},o){try{let t=JSON.parse(r);return "error"in t?new re(t.message,e,t.error,o):new b(t.message,e,o)}catch{}return new b(r,e,o)}function ce({isTimedOut:r,status:e}){return !r&&~~e===0}function me({isTimedOut:r,status:e}){return r||ce({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function ue({status:r}){return ~~(r/100)===2}function le(r){return r.map(e=>J(e))}function J(r){let e=r.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...r,request:{...r.request,headers:{...r.request.headers,...e}}}}function M({hosts:r,hostsCache:e,baseHeaders:o,baseQueryParameters:t,algoliaAgent:n,timeouts:l,requester:a,requestsCache:s,responsesCache:i}){async function u(m){let c=await Promise.all(m.map(d=>e.get(d,()=>Promise.resolve(L(d))))),y=c.filter(d=>d.isUp()),R=c.filter(d=>d.isTimedOut()),E=[...y,...R];return {hosts:E.length>0?E:m,getTimeout(d,g){return (R.length===0&&d===0?1:R.length+3+d)*g}}}async function p(m,c,y=!0){let R=[],E=se(m,c),P=ae(o,m.headers,c.headers),d=m.method==="GET"?{...m.data,...c.data}:{},g={...t,...m.queryParameters,...d};if(n.value&&(g["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let h of Object.keys(c.queryParameters))!c.queryParameters[h]||Object.prototype.toString.call(c.queryParameters[h])==="[object Object]"?g[h]=c.queryParameters[h]:g[h]=c.queryParameters[h].toString();let T=0,D=async(h,A)=>{let q=h.pop();if(q===void 0)throw new Z(le(R));let S={...l,...c.timeouts},U={data:E,headers:P,method:m.method,url:te(q,m.path,g),connectTimeout:A(T,S.connect),responseTimeout:A(T,y?S.read:S.write)},I=C=>{let _={request:U,response:C,host:q,triesLeft:h.length};return R.push(_),_},x=await a.send(U);if(me(x)){let C=I(x);return x.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,L(q,x.isTimedOut?"timed out":"down")),D(h,A)}if(ue(x))return ne(x);throw I(x),ie(x,R)},V=r.filter(h=>h.accept==="readWrite"||(y?h.accept==="read":h.accept==="write")),N=await u(V);return D([...N.hosts].reverse(),N.getTimeout)}function f(m,c={}){let y=m.useReadTransporter||m.method==="GET";if(!y)return p(m,c,y);let R=()=>p(m,c);if((c.cacheable||m.cacheable)!==!0)return R();let P={request:m,requestOptions:c,transporter:{queryParameters:t,headers:o}};return i.get(P,()=>s.get(P,()=>s.set(P,R()).then(d=>Promise.all([s.delete(P),d]),d=>Promise.all([s.delete(P),Promise.reject(d)])).then(([d,g])=>g)),{miss:d=>i.set(P,d)})}return {hostsCache:e,requester:a,timeouts:l,algoliaAgent:n,baseHeaders:o,baseQueryParameters:t,hosts:r,request:f,requestsCache:s,responsesCache:i}}function pe(r){let e={value:`Algolia for JavaScript (${r})`,add(o){let t=`; ${o.segment}${o.version!==void 0?` (${o.version})`:""}`;return e.value.indexOf(t)===-1&&(e.value=`${e.value}${t}`),e}};return e}function Q({algoliaAgents:r,client:e,version:o}){let t=pe(o).add({segment:e,version:o});return r.forEach(n=>t.add(n)),t}var z=1e3,F=2e3,B=3e4;function X(){function r(e){return new Promise(o=>{let t=new XMLHttpRequest;t.open(e.method,e.url,!0),Object.keys(e.headers).forEach(s=>t.setRequestHeader(s,e.headers[s]));let n=(s,i)=>setTimeout(()=>{t.abort(),o({status:0,content:i,isTimedOut:!0});},s),l=n(e.connectTimeout,"Connection timeout"),a;t.onreadystatechange=()=>{t.readyState>t.OPENED&&a===void 0&&(clearTimeout(l),a=n(e.responseTimeout,"Socket timeout"));},t.onerror=()=>{t.status===0&&(clearTimeout(l),clearTimeout(a),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}));},t.onload=()=>{clearTimeout(l),clearTimeout(a),o({content:t.responseText,status:t.status,isTimedOut:!1});},t.send(e.data);})}return {send:r}}var v="5.3.0";function de(r){return [{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(j([{url:`${r}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${r}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function K({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let l=G(r,e,o);return {transporter:M({hosts:de(r),...n,algoliaAgent:Q({algoliaAgents:t,client:"Recommend",version:v}),baseHeaders:{"content-type":"text/plain",...l.headers(),...n.baseHeaders},baseQueryParameters:{...l.queryParameters(),...n.baseQueryParameters}}),appId:r,clearCache(){return Promise.all([this.transporter.requestsCache.clear(),this.transporter.responsesCache.clear()]).then(()=>{})},get _ua(){return this.transporter.algoliaAgent.value},addAlgoliaAgent(a,s){this.transporter.algoliaAgent.add({segment:a,version:s});},setClientApiKey({apiKey:a}){this.transporter.baseHeaders["x-algolia-api-key"]=a;},customDelete({path:a,parameters:s},i){if(!a)throw new Error("Parameter `path` is required when calling `customDelete`.");let m={method:"DELETE",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{}};return this.transporter.request(m,i)},customGet({path:a,parameters:s},i){if(!a)throw new Error("Parameter `path` is required when calling `customGet`.");let m={method:"GET",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{}};return this.transporter.request(m,i)},customPost({path:a,parameters:s,body:i},u){if(!a)throw new Error("Parameter `path` is required when calling `customPost`.");let c={method:"POST",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return this.transporter.request(c,u)},customPut({path:a,parameters:s,body:i},u){if(!a)throw new Error("Parameter `path` is required when calling `customPut`.");let c={method:"PUT",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return this.transporter.request(c,u)},deleteRecommendRule({indexName:a,model:s,objectID:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!s)throw new Error("Parameter `model` is required when calling `deleteRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `deleteRecommendRule`.");let c={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return this.transporter.request(c,u)},getRecommendRule({indexName:a,model:s,objectID:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!s)throw new Error("Parameter `model` is required when calling `getRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `getRecommendRule`.");let c={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return this.transporter.request(c,u)},getRecommendStatus({indexName:a,model:s,taskID:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!s)throw new Error("Parameter `model` is required when calling `getRecommendStatus`.");if(!i)throw new Error("Parameter `taskID` is required when calling `getRecommendStatus`.");let c={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return this.transporter.request(c,u)},getRecommendations(a,s){if(a&&Array.isArray(a)&&(a={requests:a}),!a)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!a.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");let f={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:a,useReadTransporter:!0,cacheable:!0};return this.transporter.request(f,s)},searchRecommendRules({indexName:a,model:s,searchRecommendRulesParams:i},u){if(!a)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!s)throw new Error("Parameter `model` is required when calling `searchRecommendRules`.");let c={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return this.transporter.request(c,u)}}}function ht(r,e,o){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");return K({appId:r,apiKey:e,timeouts:{connect:z,read:F,write:B},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[H({key:`${v}-${r}`}),O()]}),...o})}

@@ -10,0 +10,0 @@ exports.apiClientVersion = v;

@@ -13,3 +13,3 @@ // builds/node.ts

import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common";
var apiClientVersion = "5.2.5";
var apiClientVersion = "5.3.0";
function getDefaultHosts(appId) {

@@ -55,22 +55,21 @@ return [

const auth = createAuth(appIdOption, apiKeyOption, authMode);
const transporter = createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: "Recommend",
version: apiClientVersion
return {
transporter: createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: "Recommend",
version: apiClientVersion
}),
baseHeaders: {
"content-type": "text/plain",
...auth.headers(),
...options.baseHeaders
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters
}
}),
baseHeaders: {
"content-type": "text/plain",
...auth.headers(),
...options.baseHeaders
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters
}
});
return {
transporter,
/**

@@ -84,3 +83,5 @@ * The `appId` currently in use.

clearCache() {
return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
() => void 0
);
},

@@ -91,3 +92,3 @@ /**

get _ua() {
return transporter.algoliaAgent.value;
return this.transporter.algoliaAgent.value;
},

@@ -101,5 +102,14 @@ /**

addAlgoliaAgent(segment, version) {
transporter.algoliaAgent.add({ segment, version });
this.transporter.algoliaAgent.add({ segment, version });
},
/**
* Helper method to switch the API key used to authenticate the requests.
*
* @param params - Method params.
* @param params.apiKey - The new API Key to use.
*/
setClientApiKey({ apiKey }) {
this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
},
/**
* This method allow you to send requests to the Algolia REST API.

@@ -125,3 +135,3 @@ *

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -149,3 +159,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -175,3 +185,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -201,3 +211,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -235,3 +245,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -269,3 +279,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -303,3 +313,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -340,3 +350,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -374,3 +384,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
}

@@ -377,0 +387,0 @@ };

// src/recommendClient.ts
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common";
var apiClientVersion = "5.2.5";
var apiClientVersion = "5.3.0";
function getDefaultHosts(appId) {

@@ -44,22 +44,21 @@ return [

const auth = createAuth(appIdOption, apiKeyOption, authMode);
const transporter = createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: "Recommend",
version: apiClientVersion
return {
transporter: createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: "Recommend",
version: apiClientVersion
}),
baseHeaders: {
"content-type": "text/plain",
...auth.headers(),
...options.baseHeaders
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters
}
}),
baseHeaders: {
"content-type": "text/plain",
...auth.headers(),
...options.baseHeaders
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters
}
});
return {
transporter,
/**

@@ -73,3 +72,5 @@ * The `appId` currently in use.

clearCache() {
return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
() => void 0
);
},

@@ -80,3 +81,3 @@ /**

get _ua() {
return transporter.algoliaAgent.value;
return this.transporter.algoliaAgent.value;
},

@@ -90,5 +91,14 @@ /**

addAlgoliaAgent(segment, version) {
transporter.algoliaAgent.add({ segment, version });
this.transporter.algoliaAgent.add({ segment, version });
},
/**
* Helper method to switch the API key used to authenticate the requests.
*
* @param params - Method params.
* @param params.apiKey - The new API Key to use.
*/
setClientApiKey({ apiKey }) {
this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
},
/**
* This method allow you to send requests to the Algolia REST API.

@@ -114,3 +124,3 @@ *

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -138,3 +148,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -164,3 +174,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -190,3 +200,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -224,3 +234,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -258,3 +268,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -292,3 +302,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -329,3 +339,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
},

@@ -363,3 +373,3 @@ /**

};
return transporter.request(request, requestOptions);
return this.transporter.request(request, requestOptions);
}

@@ -366,0 +376,0 @@ };

{
"version": "5.2.5",
"version": "5.3.0",
"repository": {

@@ -47,5 +47,5 @@ "type": "git",

"dependencies": {
"@algolia/client-common": "5.2.5",
"@algolia/requester-browser-xhr": "5.2.5",
"@algolia/requester-node-http": "5.2.5"
"@algolia/client-common": "5.3.0",
"@algolia/requester-browser-xhr": "5.3.0",
"@algolia/requester-node-http": "5.3.0"
},

@@ -52,0 +52,0 @@ "devDependencies": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc