@algolia/recommend
Advanced tools
Comparing version 5.4.3 to 5.5.0
@@ -14,3 +14,3 @@ // builds/browser.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.4.3"; | ||
var apiClientVersion = "5.5.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -17,0 +17,0 @@ return [ |
@@ -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 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.3";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}; | ||
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.5.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,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 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.3";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})} | ||
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.5.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})} | ||
@@ -10,0 +10,0 @@ exports.apiClientVersion = v; |
@@ -13,3 +13,3 @@ // builds/fetch.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.4.3"; | ||
var apiClientVersion = "5.5.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -16,0 +16,0 @@ return [ |
@@ -13,3 +13,3 @@ // builds/node.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.4.3"; | ||
var apiClientVersion = "5.5.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -16,0 +16,0 @@ return [ |
// src/recommendClient.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.4.3"; | ||
var apiClientVersion = "5.5.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -5,0 +5,0 @@ return [ |
{ | ||
"version": "5.4.3", | ||
"version": "5.5.0", | ||
"repository": { | ||
@@ -44,2 +44,3 @@ "type": "git", | ||
"unpkg": "./dist/builds/browser.umd.js", | ||
"react-native": "./dist/builds/browser.js", | ||
"files": [ | ||
@@ -52,6 +53,6 @@ "dist", | ||
"dependencies": { | ||
"@algolia/client-common": "5.4.3", | ||
"@algolia/requester-browser-xhr": "5.4.3", | ||
"@algolia/requester-fetch": "5.4.3", | ||
"@algolia/requester-node-http": "5.4.3" | ||
"@algolia/client-common": "5.5.0", | ||
"@algolia/requester-browser-xhr": "5.5.0", | ||
"@algolia/requester-fetch": "5.5.0", | ||
"@algolia/requester-node-http": "5.5.0" | ||
}, | ||
@@ -58,0 +59,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 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
722745
+ Added@algolia/client-common@5.5.0(transitive)
+ Added@algolia/requester-browser-xhr@5.5.0(transitive)
+ Added@algolia/requester-fetch@5.5.0(transitive)
+ Added@algolia/requester-node-http@5.5.0(transitive)
- Removed@algolia/client-common@5.4.3(transitive)
- Removed@algolia/requester-browser-xhr@5.4.3(transitive)
- Removed@algolia/requester-fetch@5.4.3(transitive)
- Removed@algolia/requester-node-http@5.4.3(transitive)
Updated@algolia/client-common@5.5.0