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.3.2 to 5.4.0

dist/builds/fetch.js

2

dist/builds/browser.js

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

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

@@ -17,0 +17,0 @@ return [

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

function L(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 G(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(a){t().setItem(o,JSON.stringify(a))}function c(){let a=r.timeToLive?r.timeToLive*1e3:null,s=n(),i=Object.fromEntries(Object.entries(s).filter(([,h])=>h.timestamp!==void 0));if(d(i),!a)return;let l=Object.fromEntries(Object.entries(i).filter(([,h])=>{let u=new Date().getTime();return!(h.timestamp+a<u)}));d(l)}return{get(a,s,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(c(),n()[JSON.stringify(a)])).then(l=>Promise.all([l?l.value:s(),l!==void 0])).then(([l,h])=>Promise.all([l,h||i.miss(l)])).then(([l])=>l)},set(a,s){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(a)]={timestamp:new Date().getTime(),value:s},t().setItem(o,JSON.stringify(i)),s})},delete(a){return Promise.resolve().then(()=>{let s=n();delete s[JSON.stringify(a)],t().setItem(o,JSON.stringify(s))})},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 c=t();return c.then(a=>n.miss(a)).then(()=>c)},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 H(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 ae(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 se(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(d=>{let c=t[d];n[d.toLowerCase()]=c}),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:d,requester:c,requestsCache:a,responsesCache:s}){async function i(u){let m=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(H(f))))),p=m.filter(f=>f.isUp()),R=m.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,m,p=!0){let R=[],E=ae(u,m),g=se(o,u.headers,m.headers),f=u.method==="GET"?{...u.data,...m.data}:{},x={...t,...u.queryParameters,...f};if(n.value&&(x["x-algolia-agent"]=n.value),m&&m.queryParameters)for(let P of Object.keys(m.queryParameters))!m.queryParameters[P]||Object.prototype.toString.call(m.queryParameters[P])==="[object Object]"?x[P]=m.queryParameters[P]:x[P]=m.queryParameters[P].toString();let T=0,D=async(P,A)=>{let q=P.pop();if(q===void 0)throw new Z(le(R));let S={...d,...m.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 c.send(U);if(me(y)){let C=I(y);return y.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,H(q,y.isTimedOut?"timed out":"down")),D(P,A)}if(ue(y))return ne(y);throw I(y),ie(y,R)},V=r.filter(P=>P.accept==="readWrite"||(p?P.accept==="read":P.accept==="write")),N=await i(V);return D([...N.hosts].reverse(),N.getTimeout)}function h(u,m={}){let p=u.useReadTransporter||u.method==="GET";if(!p)return l(u,m,p);let R=()=>l(u,m);if((m.cacheable||u.cacheable)!==!0)return R();let g={request:u,requestOptions:m,transporter:{queryParameters:t,headers:o}};return s.get(g,()=>a.get(g,()=>a.set(g,R()).then(f=>Promise.all([a.delete(g),f]),f=>Promise.all([a.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>s.set(g,f)})}return{hostsCache:e,requester:c,timeouts:d,algoliaAgent:n,baseHeaders:o,baseQueryParameters:t,hosts:r,request:h,requestsCache:a,responsesCache:s}}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(a=>t.setRequestHeader(a,e.headers[a]));let n=(a,s)=>setTimeout(()=>{t.abort(),o({status:0,content:s,isTimedOut:!0})},a),d=n(e.connectTimeout,"Connection timeout"),c;t.onreadystatechange=()=>{t.readyState>t.OPENED&&c===void 0&&(clearTimeout(d),c=n(e.responseTimeout,"Socket timeout"))},t.onerror=()=>{t.status===0&&(clearTimeout(d),clearTimeout(c),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}))},t.onload=()=>{clearTimeout(d),clearTimeout(c),o({content:t.responseText,status:t.status,isTimedOut:!1})},t.send(e.data)})}return{send:r}}var v="5.3.2";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 K({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let d=L(r,e,o),c=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:c,appId:r,clearCache(){return Promise.all([c.requestsCache.clear(),c.responsesCache.clear()]).then(()=>{})},get _ua(){return c.algoliaAgent.value},addAlgoliaAgent(a,s){c.algoliaAgent.add({segment:a,version:s})},setClientApiKey({apiKey:a}){!o||o==="WithinHeaders"?c.baseHeaders["x-algolia-api-key"]=a:c.baseQueryParameters["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 c.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 c.request(m,i)},customPost({path:a,parameters:s,body:i},l){if(!a)throw new Error("Parameter `path` is required when calling `customPost`.");let p={method:"POST",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return c.request(p,l)},customPut({path:a,parameters:s,body:i},l){if(!a)throw new Error("Parameter `path` is required when calling `customPut`.");let p={method:"PUT",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return c.request(p,l)},deleteRecommendRule({indexName:a,model:s,objectID:i},l){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 p={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 c.request(p,l)},getRecommendRule({indexName:a,model:s,objectID:i},l){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 p={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 c.request(p,l)},getRecommendStatus({indexName:a,model:s,taskID:i},l){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 p={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(p,l)},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 u={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:a,useReadTransporter:!0,cacheable:!0};return c.request(u,s)},searchRecommendRules({indexName:a,model:s,searchRecommendRulesParams:i},l){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 p={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 c.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 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:[G({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 W(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function a(){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,n=a(),i=Object.fromEntries(Object.entries(n).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,n,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(m(),a()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:n(),l!==void 0])).then(([l,h])=>Promise.all([l,h||i.miss(l)])).then(([l])=>l)},set(s,n){return Promise.resolve().then(()=>{let i=a();return i[JSON.stringify(s)]={timestamp:new Date().getTime(),value:n},t().setItem(o,JSON.stringify(i)),n})},delete(s){return Promise.resolve().then(()=>{let n=a();delete n[JSON.stringify(s)],t().setItem(o,JSON.stringify(n))})},clear(){return Promise.resolve().then(()=>{t().removeItem(o)})}}}function Y(){return{get(r,e,o={miss:()=>Promise.resolve()}){return e().then(a=>Promise.all([a,o.miss(a)])).then(([a])=>a)},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,a,d={miss:()=>Promise.resolve()}){return o.get(t,a,d).catch(()=>w({caches:e}).get(t,a,d))},set(t,a){return o.set(t,a).catch(()=>w({caches:e}).set(t,a))},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,a={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=>a.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 H(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>k}function a(){return e==="timed out"&&Date.now()-o<=k}return{...r,status:e,lastUpdate:o,isUp:t,isTimedOut:a}}var L=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e)}},$=class extends L{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 L{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)),a=r[o];e[o]=r[t],e[t]=a}return e}function te(r,e,o){let t=oe(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}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 ne(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(d=>{let m=t[d];a[d.toLowerCase()]=m}),a}function ae(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 me({isTimedOut:r,status:e}){return!r&&~~e===0}function ce({isTimedOut:r,status:e}){return r||me({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:a,timeouts:d,requester:m,requestsCache:s,responsesCache:n}){async function i(u){let c=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(H(f))))),p=c.filter(f=>f.isUp()),P=c.filter(f=>f.isTimedOut()),E=[...p,...P];return{hosts:E.length>0?E:u,getTimeout(f,x){return(P.length===0&&f===0?1:P.length+3+f)*x}}}async function l(u,c,p=!0){let P=[],E=se(u,c),g=ne(o,u.headers,c.headers),f=u.method==="GET"?{...u.data,...c.data}:{},x={...t,...u.queryParameters,...f};if(a.value&&(x["x-algolia-agent"]=a.value),c&&c.queryParameters)for(let R of Object.keys(c.queryParameters))!c.queryParameters[R]||Object.prototype.toString.call(c.queryParameters[R])==="[object Object]"?x[R]=c.queryParameters[R]:x[R]=c.queryParameters[R].toString();let T=0,D=async(R,A)=>{let q=R.pop();if(q===void 0)throw new Z(le(P));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:R.length};return P.push(_),_},y=await m.send(U);if(ce(y)){let C=I(y);return y.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,H(q,y.isTimedOut?"timed out":"down")),D(R,A)}if(ue(y))return ae(y);throw I(y),ie(y,P)},V=r.filter(R=>R.accept==="readWrite"||(p?R.accept==="read":R.accept==="write")),N=await i(V);return D([...N.hosts].reverse(),N.getTimeout)}function h(u,c={}){let p=u.useReadTransporter||u.method==="GET";if(!p)return l(u,c,p);let P=()=>l(u,c);if((c.cacheable||u.cacheable)!==!0)return P();let g={request:u,requestOptions:c,transporter:{queryParameters:t,headers:o}};return n.get(g,()=>s.get(g,()=>s.set(g,P()).then(f=>Promise.all([s.delete(g),f]),f=>Promise.all([s.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>n.set(g,f)})}return{hostsCache:e,requester:m,timeouts:d,algoliaAgent:a,baseHeaders:o,baseQueryParameters:t,hosts:r,request:h,requestsCache:s,responsesCache:n}}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(a=>t.add(a)),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 a=(s,n)=>setTimeout(()=>{t.abort(),o({status:0,content:n,isTimedOut:!0})},s),d=a(e.connectTimeout,"Connection timeout"),m;t.onreadystatechange=()=>{t.readyState>t.OPENED&&m===void 0&&(clearTimeout(d),m=a(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.4.0";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 K({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...a}){let d=G(r,e,o),m=M({hosts:pe(r),...a,algoliaAgent:Q({algoliaAgents:t,client:"Recommend",version:v}),baseHeaders:{"content-type":"text/plain",...d.headers(),...a.baseHeaders},baseQueryParameters:{...d.queryParameters(),...a.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,n){m.algoliaAgent.add({segment:s,version:n})},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?m.baseHeaders["x-algolia-api-key"]=s:m.baseQueryParameters["x-algolia-api-key"]=s},customDelete({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let c={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return m.request(c,i)},customGet({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let c={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return m.request(c,i)},customPost({path:s,parameters:n,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:n||{},headers:{},data:i||{}};return m.request(p,l)},customPut({path:s,parameters:n,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:n||{},headers:{},data:i||{}};return m.request(p,l)},deleteRecommendRule({indexName:s,model:n,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!n)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(n)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendRule({indexName:s,model:n,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!n)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(n)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendStatus({indexName:s,model:n,taskID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!n)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(n)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendations(s,n){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,n)},searchRecommendRules({indexName:s,model:n,searchRecommendRulesParams:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!n)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(n)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return m.request(p,l)}}}function pt(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:[W({key:`${v}-${r}`}),O()]}),...o})}export{v as apiClientVersion,pt as recommendClient};
//# sourceMappingURL=browser.min.js.map

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

function L(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 G(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(a){t().setItem(o,JSON.stringify(a));}function c(){let a=r.timeToLive?r.timeToLive*1e3:null,s=n(),i=Object.fromEntries(Object.entries(s).filter(([,h])=>h.timestamp!==void 0));if(d(i),!a)return;let l=Object.fromEntries(Object.entries(i).filter(([,h])=>{let u=new Date().getTime();return !(h.timestamp+a<u)}));d(l);}return {get(a,s,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(c(),n()[JSON.stringify(a)])).then(l=>Promise.all([l?l.value:s(),l!==void 0])).then(([l,h])=>Promise.all([l,h||i.miss(l)])).then(([l])=>l)},set(a,s){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(a)]={timestamp:new Date().getTime(),value:s},t().setItem(o,JSON.stringify(i)),s})},delete(a){return Promise.resolve().then(()=>{let s=n();delete s[JSON.stringify(a)],t().setItem(o,JSON.stringify(s));})},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 c=t();return c.then(a=>n.miss(a)).then(()=>c)},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 H(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 ae(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 se(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(d=>{let c=t[d];n[d.toLowerCase()]=c;}),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:d,requester:c,requestsCache:a,responsesCache:s}){async function i(u){let m=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(H(f))))),p=m.filter(f=>f.isUp()),R=m.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,m,p=!0){let R=[],E=ae(u,m),g=se(o,u.headers,m.headers),f=u.method==="GET"?{...u.data,...m.data}:{},x={...t,...u.queryParameters,...f};if(n.value&&(x["x-algolia-agent"]=n.value),m&&m.queryParameters)for(let P of Object.keys(m.queryParameters))!m.queryParameters[P]||Object.prototype.toString.call(m.queryParameters[P])==="[object Object]"?x[P]=m.queryParameters[P]:x[P]=m.queryParameters[P].toString();let T=0,D=async(P,A)=>{let q=P.pop();if(q===void 0)throw new Z(le(R));let S={...d,...m.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 c.send(U);if(me(y)){let C=I(y);return y.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,H(q,y.isTimedOut?"timed out":"down")),D(P,A)}if(ue(y))return ne(y);throw I(y),ie(y,R)},V=r.filter(P=>P.accept==="readWrite"||(p?P.accept==="read":P.accept==="write")),N=await i(V);return D([...N.hosts].reverse(),N.getTimeout)}function h(u,m={}){let p=u.useReadTransporter||u.method==="GET";if(!p)return l(u,m,p);let R=()=>l(u,m);if((m.cacheable||u.cacheable)!==!0)return R();let g={request:u,requestOptions:m,transporter:{queryParameters:t,headers:o}};return s.get(g,()=>a.get(g,()=>a.set(g,R()).then(f=>Promise.all([a.delete(g),f]),f=>Promise.all([a.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>s.set(g,f)})}return {hostsCache:e,requester:c,timeouts:d,algoliaAgent:n,baseHeaders:o,baseQueryParameters:t,hosts:r,request:h,requestsCache:a,responsesCache:s}}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(a=>t.setRequestHeader(a,e.headers[a]));let n=(a,s)=>setTimeout(()=>{t.abort(),o({status:0,content:s,isTimedOut:!0});},a),d=n(e.connectTimeout,"Connection timeout"),c;t.onreadystatechange=()=>{t.readyState>t.OPENED&&c===void 0&&(clearTimeout(d),c=n(e.responseTimeout,"Socket timeout"));},t.onerror=()=>{t.status===0&&(clearTimeout(d),clearTimeout(c),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}));},t.onload=()=>{clearTimeout(d),clearTimeout(c),o({content:t.responseText,status:t.status,isTimedOut:!1});},t.send(e.data);})}return {send:r}}var v="5.3.2";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 K({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let d=L(r,e,o),c=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:c,appId:r,clearCache(){return Promise.all([c.requestsCache.clear(),c.responsesCache.clear()]).then(()=>{})},get _ua(){return c.algoliaAgent.value},addAlgoliaAgent(a,s){c.algoliaAgent.add({segment:a,version:s});},setClientApiKey({apiKey:a}){!o||o==="WithinHeaders"?c.baseHeaders["x-algolia-api-key"]=a:c.baseQueryParameters["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 c.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 c.request(m,i)},customPost({path:a,parameters:s,body:i},l){if(!a)throw new Error("Parameter `path` is required when calling `customPost`.");let p={method:"POST",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return c.request(p,l)},customPut({path:a,parameters:s,body:i},l){if(!a)throw new Error("Parameter `path` is required when calling `customPut`.");let p={method:"PUT",path:"/{path}".replace("{path}",a),queryParameters:s||{},headers:{},data:i||{}};return c.request(p,l)},deleteRecommendRule({indexName:a,model:s,objectID:i},l){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 p={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 c.request(p,l)},getRecommendRule({indexName:a,model:s,objectID:i},l){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 p={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 c.request(p,l)},getRecommendStatus({indexName:a,model:s,taskID:i},l){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 p={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(a)).replace("{model}",encodeURIComponent(s)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(p,l)},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 u={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:a,useReadTransporter:!0,cacheable:!0};return c.request(u,s)},searchRecommendRules({indexName:a,model:s,searchRecommendRulesParams:i},l){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 p={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 c.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 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:[G({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 W(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function a(){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,n=a(),i=Object.fromEntries(Object.entries(n).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,n,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(m(),a()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:n(),l!==void 0])).then(([l,h])=>Promise.all([l,h||i.miss(l)])).then(([l])=>l)},set(s,n){return Promise.resolve().then(()=>{let i=a();return i[JSON.stringify(s)]={timestamp:new Date().getTime(),value:n},t().setItem(o,JSON.stringify(i)),n})},delete(s){return Promise.resolve().then(()=>{let n=a();delete n[JSON.stringify(s)],t().setItem(o,JSON.stringify(n));})},clear(){return Promise.resolve().then(()=>{t().removeItem(o);})}}}function Y(){return {get(r,e,o={miss:()=>Promise.resolve()}){return e().then(a=>Promise.all([a,o.miss(a)])).then(([a])=>a)},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,a,d={miss:()=>Promise.resolve()}){return o.get(t,a,d).catch(()=>w({caches:e}).get(t,a,d))},set(t,a){return o.set(t,a).catch(()=>w({caches:e}).set(t,a))},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,a={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=>a.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 H(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>k}function a(){return e==="timed out"&&Date.now()-o<=k}return {...r,status:e,lastUpdate:o,isUp:t,isTimedOut:a}}var L=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e);}},$=class extends L{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 L{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)),a=r[o];e[o]=r[t],e[t]=a;}return e}function te(r,e,o){let t=oe(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}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 ne(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(d=>{let m=t[d];a[d.toLowerCase()]=m;}),a}function ae(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 me({isTimedOut:r,status:e}){return !r&&~~e===0}function ce({isTimedOut:r,status:e}){return r||me({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:a,timeouts:d,requester:m,requestsCache:s,responsesCache:n}){async function i(u){let c=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(H(f))))),p=c.filter(f=>f.isUp()),P=c.filter(f=>f.isTimedOut()),E=[...p,...P];return {hosts:E.length>0?E:u,getTimeout(f,x){return (P.length===0&&f===0?1:P.length+3+f)*x}}}async function l(u,c,p=!0){let P=[],E=se(u,c),g=ne(o,u.headers,c.headers),f=u.method==="GET"?{...u.data,...c.data}:{},x={...t,...u.queryParameters,...f};if(a.value&&(x["x-algolia-agent"]=a.value),c&&c.queryParameters)for(let R of Object.keys(c.queryParameters))!c.queryParameters[R]||Object.prototype.toString.call(c.queryParameters[R])==="[object Object]"?x[R]=c.queryParameters[R]:x[R]=c.queryParameters[R].toString();let T=0,D=async(R,A)=>{let q=R.pop();if(q===void 0)throw new Z(le(P));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:R.length};return P.push(_),_},y=await m.send(U);if(ce(y)){let C=I(y);return y.isTimedOut&&T++,console.log("Retryable failure",J(C)),await e.set(q,H(q,y.isTimedOut?"timed out":"down")),D(R,A)}if(ue(y))return ae(y);throw I(y),ie(y,P)},V=r.filter(R=>R.accept==="readWrite"||(p?R.accept==="read":R.accept==="write")),N=await i(V);return D([...N.hosts].reverse(),N.getTimeout)}function h(u,c={}){let p=u.useReadTransporter||u.method==="GET";if(!p)return l(u,c,p);let P=()=>l(u,c);if((c.cacheable||u.cacheable)!==!0)return P();let g={request:u,requestOptions:c,transporter:{queryParameters:t,headers:o}};return n.get(g,()=>s.get(g,()=>s.set(g,P()).then(f=>Promise.all([s.delete(g),f]),f=>Promise.all([s.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>n.set(g,f)})}return {hostsCache:e,requester:m,timeouts:d,algoliaAgent:a,baseHeaders:o,baseQueryParameters:t,hosts:r,request:h,requestsCache:s,responsesCache:n}}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(a=>t.add(a)),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 a=(s,n)=>setTimeout(()=>{t.abort(),o({status:0,content:n,isTimedOut:!0});},s),d=a(e.connectTimeout,"Connection timeout"),m;t.onreadystatechange=()=>{t.readyState>t.OPENED&&m===void 0&&(clearTimeout(d),m=a(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.4.0";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 K({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...a}){let d=G(r,e,o),m=M({hosts:pe(r),...a,algoliaAgent:Q({algoliaAgents:t,client:"Recommend",version:v}),baseHeaders:{"content-type":"text/plain",...d.headers(),...a.baseHeaders},baseQueryParameters:{...d.queryParameters(),...a.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,n){m.algoliaAgent.add({segment:s,version:n});},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?m.baseHeaders["x-algolia-api-key"]=s:m.baseQueryParameters["x-algolia-api-key"]=s;},customDelete({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let c={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return m.request(c,i)},customGet({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let c={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return m.request(c,i)},customPost({path:s,parameters:n,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:n||{},headers:{},data:i||{}};return m.request(p,l)},customPut({path:s,parameters:n,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:n||{},headers:{},data:i||{}};return m.request(p,l)},deleteRecommendRule({indexName:s,model:n,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!n)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(n)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendRule({indexName:s,model:n,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!n)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(n)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendStatus({indexName:s,model:n,taskID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!n)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(n)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return m.request(p,l)},getRecommendations(s,n){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,n)},searchRecommendRules({indexName:s,model:n,searchRecommendRulesParams:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!n)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(n)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return m.request(p,l)}}}function pt(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:[W({key:`${v}-${r}`}),O()]}),...o})}
exports.apiClientVersion = v;
exports.recommendClient = ht;
exports.recommendClient = pt;
}));

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

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

@@ -16,0 +16,0 @@ return [

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

@@ -5,0 +5,0 @@ return [

{
"version": "5.3.2",
"version": "5.4.0",
"repository": {

@@ -29,2 +29,6 @@ "type": "git",

},
"worker": {
"types": "./dist/fetch.d.ts",
"default": "./dist/builds/fetch.js"
},
"default": {

@@ -48,5 +52,6 @@ "types": "./dist/browser.d.ts",

"dependencies": {
"@algolia/client-common": "5.3.2",
"@algolia/requester-browser-xhr": "5.3.2",
"@algolia/requester-node-http": "5.3.2"
"@algolia/client-common": "5.4.0",
"@algolia/requester-browser-xhr": "5.4.0",
"@algolia/requester-fetch": "5.4.0",
"@algolia/requester-node-http": "5.4.0"
},

@@ -53,0 +58,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