@algolia/recommend
Advanced tools
Comparing version 5.15.0 to 5.16.0
@@ -7,6 +7,3 @@ // builds/browser.ts | ||
createMemoryCache, | ||
createNullLogger, | ||
DEFAULT_CONNECT_TIMEOUT_BROWSER, | ||
DEFAULT_READ_TIMEOUT_BROWSER, | ||
DEFAULT_WRITE_TIMEOUT_BROWSER | ||
createNullLogger | ||
} from "@algolia/client-common"; | ||
@@ -16,3 +13,3 @@ | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.15.0"; | ||
var apiClientVersion = "5.16.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -416,5 +413,5 @@ return [ | ||
timeouts: { | ||
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER, | ||
read: DEFAULT_READ_TIMEOUT_BROWSER, | ||
write: DEFAULT_WRITE_TIMEOUT_BROWSER | ||
connect: 1e3, | ||
read: 2e3, | ||
write: 3e4 | ||
}, | ||
@@ -421,0 +418,0 @@ logger: createNullLogger(), |
@@ -1,2 +0,2 @@ | ||
function L(){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"),c;t.onreadystatechange=()=>{t.readyState>t.OPENED&&c===void 0&&(clearTimeout(d),c=a(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}}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 c(){let s=r.timeToLive?r.timeToLive*1e3:null,n=a(),i=Object.fromEntries(Object.entries(n).filter(([,p])=>p.timestamp!==void 0));if(d(i),!s)return;let l=Object.fromEntries(Object.entries(i).filter(([,p])=>{let h=new Date().getTime();return!(p.timestamp+s<h)}));d(l)}return{get(s,n,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(c(),a()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:n(),l!==void 0])).then(([l,p])=>Promise.all([l,p||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 ee(){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?ee():{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 c=t();return c.then(s=>a.miss(s)).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 $=1e3,j=2e3,J=3e4;function re(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(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 M({algoliaAgents:r,client:e,version:o}){let t=re(o).add({segment:e,version:o});return r.forEach(a=>t.add(a)),t}function z(){return{debug(r,e){return Promise.resolve()},info(r,e){return Promise.resolve()},error(r,e){return Promise.resolve()}}}var H=2*60*1e3;function G(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>H}function a(){return e==="timed out"&&Date.now()-o<=H}return{...r,status:e,lastUpdate:o,isUp:t,isTimedOut:a}}var B=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e)}},F=class extends B{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e}},te=class extends F{constructor(r){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",r,"RetryError")}},D=class extends F{status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e}},oe=class extends B{response;constructor(r,e){super(r,"DeserializationError"),this.response=e}},se=class extends D{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o}};function X(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 ne(r,e,o){let t=ae(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}function ae(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]).replace(/\+/g,"%20")}`).join("&")}function ie(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 me(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(d=>{let c=t[d];a[d.toLowerCase()]=c}),a}function ce(r){try{return JSON.parse(r.content)}catch(e){throw new oe(e.message,r)}}function ue({content:r,status:e},o){try{let t=JSON.parse(r);return"error"in t?new se(t.message,e,t.error,o):new D(t.message,e,o)}catch{}return new D(r,e,o)}function le({isTimedOut:r,status:e}){return!r&&~~e===0}function de({isTimedOut:r,status:e}){return r||le({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function pe({status:r}){return~~(r/100)===2}function fe(r){return r.map(e=>K(e))}function K(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 V({hosts:r,hostsCache:e,baseHeaders:o,logger:t,baseQueryParameters:a,algoliaAgent:d,timeouts:c,requester:s,requestsCache:n,responsesCache:i}){async function l(u){let m=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(G(f))))),q=m.filter(f=>f.isUp()),P=m.filter(f=>f.isTimedOut()),E=[...q,...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 p(u,m,q=!0){let P=[],E=ie(u,m),g=me(o,u.headers,m.headers),f=u.method==="GET"?{...u.data,...m.data}:{},x={...a,...u.queryParameters,...f};if(d.value&&(x["x-algolia-agent"]=d.value),m&&m.queryParameters)for(let R of Object.keys(m.queryParameters))!m.queryParameters[R]||Object.prototype.toString.call(m.queryParameters[R])==="[object Object]"?x[R]=m.queryParameters[R]:x[R]=m.queryParameters[R].toString();let v=0,N=async(R,S)=>{let T=R.pop();if(T===void 0)throw new te(fe(P));let C={...c,...m.timeouts},I={data:E,headers:g,method:u.method,url:ne(T,u.path,x),connectTimeout:S(v,C.connect),responseTimeout:S(v,q?C.read:C.write)},_=b=>{let k={request:I,response:b,host:T,triesLeft:R.length};return P.push(k),k},y=await s.send(I);if(de(y)){let b=_(y);return y.isTimedOut&&v++,t.info("Retryable failure",K(b)),await e.set(T,G(T,y.isTimedOut?"timed out":"down")),N(R,S)}if(pe(y))return ce(y);throw _(y),ue(y,P)},Z=r.filter(R=>R.accept==="readWrite"||(q?R.accept==="read":R.accept==="write")),U=await l(Z);return N([...U.hosts].reverse(),U.getTimeout)}function h(u,m={}){let q=u.useReadTransporter||u.method==="GET";if(!q)return p(u,m,q);let P=()=>p(u,m);if((m.cacheable||u.cacheable)!==!0)return P();let g={request:u,requestOptions:m,transporter:{queryParameters:a,headers:o}};return i.get(g,()=>n.get(g,()=>n.set(g,P()).then(f=>Promise.all([n.delete(g),f]),f=>Promise.all([n.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>i.set(g,f)})}return{hostsCache:e,requester:s,timeouts:c,logger:t,algoliaAgent:d,baseHeaders:o,baseQueryParameters:a,hosts:r,request:h,requestsCache:n,responsesCache:i}}var A="5.15.0";function he(r){return[{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(X([{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 Y({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...a}){let d=Q(r,e,o),c=V({hosts:he(r),...a,algoliaAgent:M({algoliaAgents:t,client:"Recommend",version:A}),baseHeaders:{"content-type":"text/plain",...d.headers(),...a.baseHeaders},baseQueryParameters:{...d.queryParameters(),...a.baseQueryParameters}});return{transporter:c,appId:r,clearCache(){return Promise.all([c.requestsCache.clear(),c.responsesCache.clear()]).then(()=>{})},get _ua(){return c.algoliaAgent.value},addAlgoliaAgent(s,n){c.algoliaAgent.add({segment:s,version:n})},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?c.baseHeaders["x-algolia-api-key"]=s:c.baseQueryParameters["x-algolia-api-key"]=s},batchRecommendRules({indexName:s,model:n,recommendRule:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `batchRecommendRules`.");if(!n)throw new Error("Parameter `model` is required when calling `batchRecommendRules`.");let m={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)),queryParameters:{},headers:{},data:i||{}};return c.request(m,l)},customDelete({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let u={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return c.request(u,i)},customGet({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let u={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return c.request(u,i)},customPost({path:s,parameters:n,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let m={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:i||{}};return c.request(m,l)},customPut({path:s,parameters:n,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let m={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:i||{}};return c.request(m,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 m={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 c.request(m,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 m={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 c.request(m,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 m={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,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 h={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return c.request(h,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 m={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 c.request(m,l)}}}function xt(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 Y({appId:r,apiKey:e,timeouts:{connect:$,read:j,write:J},logger:z(),requester:L(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[W({key:`${A}-${r}`}),O()]}),...o})}export{A as apiClientVersion,xt as recommendClient}; | ||
function H(){function r(e){return new Promise(o=>{let t=new XMLHttpRequest;t.open(e.method,e.url,!0),Object.keys(e.headers).forEach(s=>t.setRequestHeader(s,e.headers[s]));let n=(s,a)=>setTimeout(()=>{t.abort(),o({status:0,content:a,isTimedOut:!0})},s),d=n(e.connectTimeout,"Connection timeout"),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}}function $(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function n(){return JSON.parse(t().getItem(o)||"{}")}function d(s){t().setItem(o,JSON.stringify(s))}function c(){let s=r.timeToLive?r.timeToLive*1e3:null,a=n(),i=Object.fromEntries(Object.entries(a).filter(([,p])=>p.timestamp!==void 0));if(d(i),!s)return;let l=Object.fromEntries(Object.entries(i).filter(([,p])=>{let h=new Date().getTime();return!(p.timestamp+s<h)}));d(l)}return{get(s,a,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(c(),n()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:a(),l!==void 0])).then(([l,p])=>Promise.all([l,p||i.miss(l)])).then(([l])=>l)},set(s,a){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(s)]={timestamp:new Date().getTime(),value:a},t().setItem(o,JSON.stringify(i)),a})},delete(s){return Promise.resolve().then(()=>{let a=n();delete a[JSON.stringify(s)],t().setItem(o,JSON.stringify(a))})},clear(){return Promise.resolve().then(()=>{t().removeItem(o)})}}}function V(){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 q(r){let e=[...r.caches],o=e.shift();return o===void 0?V():{get(t,n,d={miss:()=>Promise.resolve()}){return o.get(t,n,d).catch(()=>q({caches:e}).get(t,n,d))},set(t,n){return o.set(t,n).catch(()=>q({caches:e}).set(t,n))},delete(t){return o.delete(t).catch(()=>q({caches:e}).delete(t))},clear(){return o.clear().catch(()=>q({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(s=>n.miss(s)).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()}}}function Y(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 j(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({algoliaAgents:r,client:e,version:o}){let t=Y(o).add({segment:e,version:o});return r.forEach(n=>t.add(n)),t}function J(){return{debug(r,e){return Promise.resolve()},info(r,e){return Promise.resolve()},error(r,e){return Promise.resolve()}}}var G=2*60*1e3;function L(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>G}function n(){return e==="timed out"&&Date.now()-o<=G}return{...r,status:e,lastUpdate:o,isUp:t,isTimedOut:n}}var Q=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e)}},z=class extends Q{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e}},Z=class extends z{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")}},N=class extends z{status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e}},ee=class extends Q{response;constructor(r,e){super(r,"DeserializationError"),this.response=e}},re=class extends N{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o}};function M(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]).replace(/\+/g,"%20")}`).join("&")}function se(r,e){if(r.method==="GET"||r.data===void 0&&e.data===void 0)return;let o=Array.isArray(r.data)?r.data:{...r.data,...e.data};return JSON.stringify(o)}function ae(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(d=>{let 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 N(t.message,e,o)}catch{}return new N(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=>B(e))}function B(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 F({hosts:r,hostsCache:e,baseHeaders:o,logger:t,baseQueryParameters:n,algoliaAgent:d,timeouts:c,requester:s,requestsCache:a,responsesCache:i}){async function l(u){let m=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(L(f))))),w=m.filter(f=>f.isUp()),R=m.filter(f=>f.isTimedOut()),E=[...w,...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 p(u,m,w=!0){let R=[],E=se(u,m),g=ae(o,u.headers,m.headers),f=u.method==="GET"?{...u.data,...m.data}:{},x={...n,...u.queryParameters,...f};if(d.value&&(x["x-algolia-agent"]=d.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 v=0,D=async(P,C)=>{let T=P.pop();if(T===void 0)throw new Z(le(R));let S={...c,...m.timeouts},I={data:E,headers:g,method:u.method,url:te(T,u.path,x),connectTimeout:C(v,S.connect),responseTimeout:C(v,w?S.read:S.write)},k=b=>{let _={request:I,response:b,host:T,triesLeft:P.length};return R.push(_),_},y=await s.send(I);if(ce(y)){let b=k(y);return y.isTimedOut&&v++,t.info("Retryable failure",B(b)),await e.set(T,L(T,y.isTimedOut?"timed out":"down")),D(P,C)}if(ue(y))return ne(y);throw k(y),ie(y,R)},K=r.filter(P=>P.accept==="readWrite"||(w?P.accept==="read":P.accept==="write")),U=await l(K);return D([...U.hosts].reverse(),U.getTimeout)}function h(u,m={}){let w=u.useReadTransporter||u.method==="GET";if(!w)return p(u,m,w);let R=()=>p(u,m);if((m.cacheable||u.cacheable)!==!0)return R();let g={request:u,requestOptions:m,transporter:{queryParameters:n,headers:o}};return i.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=>i.set(g,f)})}return{hostsCache:e,requester:s,timeouts:c,logger:t,algoliaAgent:d,baseHeaders:o,baseQueryParameters:n,hosts:r,request:h,requestsCache:a,responsesCache:i}}var A="5.16.0";function de(r){return[{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(M([{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 X({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let d=j(r,e,o),c=F({hosts:de(r),...n,algoliaAgent:W({algoliaAgents:t,client:"Recommend",version:A}),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(s,a){c.algoliaAgent.add({segment:s,version:a})},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?c.baseHeaders["x-algolia-api-key"]=s:c.baseQueryParameters["x-algolia-api-key"]=s},batchRecommendRules({indexName:s,model:a,recommendRule:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `batchRecommendRules`.");if(!a)throw new Error("Parameter `model` is required when calling `batchRecommendRules`.");let m={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)),queryParameters:{},headers:{},data:i||{}};return c.request(m,l)},customDelete({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let u={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return c.request(u,i)},customGet({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let u={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return c.request(u,i)},customPost({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let m={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return c.request(m,l)},customPut({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let m={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return c.request(m,l)},deleteRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `deleteRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `deleteRecommendRule`.");let m={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,l)},getRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `getRecommendRule`.");let m={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,l)},getRecommendStatus({indexName:s,model:a,taskID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendStatus`.");if(!i)throw new Error("Parameter `taskID` is required when calling `getRecommendStatus`.");let m={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,l)},getRecommendations(s,a){if(s&&Array.isArray(s)&&(s={requests:s}),!s)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!s.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");let h={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return c.request(h,a)},searchRecommendRules({indexName:s,model:a,searchRecommendRulesParams:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!a)throw new Error("Parameter `model` is required when calling `searchRecommendRules`.");let m={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return c.request(m,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 X({appId:r,apiKey:e,timeouts:{connect:1e3,read:2e3,write:3e4},logger:J(),requester:H(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:q({caches:[$({key:`${A}-${r}`}),O()]}),...o})}export{A as apiClientVersion,Pt as recommendClient}; | ||
//# sourceMappingURL=browser.min.js.map |
@@ -7,7 +7,7 @@ (function (global, factory) { | ||
function L(){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"),c;t.onreadystatechange=()=>{t.readyState>t.OPENED&&c===void 0&&(clearTimeout(d),c=a(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}}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 c(){let s=r.timeToLive?r.timeToLive*1e3:null,n=a(),i=Object.fromEntries(Object.entries(n).filter(([,p])=>p.timestamp!==void 0));if(d(i),!s)return;let l=Object.fromEntries(Object.entries(i).filter(([,p])=>{let h=new Date().getTime();return !(p.timestamp+s<h)}));d(l);}return {get(s,n,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(c(),a()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:n(),l!==void 0])).then(([l,p])=>Promise.all([l,p||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 ee(){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?ee():{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 c=t();return c.then(s=>a.miss(s)).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 $=1e3,j=2e3,J=3e4;function re(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(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 M({algoliaAgents:r,client:e,version:o}){let t=re(o).add({segment:e,version:o});return r.forEach(a=>t.add(a)),t}function z(){return {debug(r,e){return Promise.resolve()},info(r,e){return Promise.resolve()},error(r,e){return Promise.resolve()}}}var H=2*60*1e3;function G(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>H}function a(){return e==="timed out"&&Date.now()-o<=H}return {...r,status:e,lastUpdate:o,isUp:t,isTimedOut:a}}var B=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e);}},F=class extends B{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e;}},te=class extends F{constructor(r){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",r,"RetryError");}},D=class extends F{status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e;}},oe=class extends B{response;constructor(r,e){super(r,"DeserializationError"),this.response=e;}},se=class extends D{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o;}};function X(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 ne(r,e,o){let t=ae(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}function ae(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]).replace(/\+/g,"%20")}`).join("&")}function ie(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 me(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(d=>{let c=t[d];a[d.toLowerCase()]=c;}),a}function ce(r){try{return JSON.parse(r.content)}catch(e){throw new oe(e.message,r)}}function ue({content:r,status:e},o){try{let t=JSON.parse(r);return "error"in t?new se(t.message,e,t.error,o):new D(t.message,e,o)}catch{}return new D(r,e,o)}function le({isTimedOut:r,status:e}){return !r&&~~e===0}function de({isTimedOut:r,status:e}){return r||le({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function pe({status:r}){return ~~(r/100)===2}function fe(r){return r.map(e=>K(e))}function K(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 V({hosts:r,hostsCache:e,baseHeaders:o,logger:t,baseQueryParameters:a,algoliaAgent:d,timeouts:c,requester:s,requestsCache:n,responsesCache:i}){async function l(u){let m=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(G(f))))),q=m.filter(f=>f.isUp()),P=m.filter(f=>f.isTimedOut()),E=[...q,...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 p(u,m,q=!0){let P=[],E=ie(u,m),g=me(o,u.headers,m.headers),f=u.method==="GET"?{...u.data,...m.data}:{},x={...a,...u.queryParameters,...f};if(d.value&&(x["x-algolia-agent"]=d.value),m&&m.queryParameters)for(let R of Object.keys(m.queryParameters))!m.queryParameters[R]||Object.prototype.toString.call(m.queryParameters[R])==="[object Object]"?x[R]=m.queryParameters[R]:x[R]=m.queryParameters[R].toString();let v=0,N=async(R,S)=>{let T=R.pop();if(T===void 0)throw new te(fe(P));let C={...c,...m.timeouts},I={data:E,headers:g,method:u.method,url:ne(T,u.path,x),connectTimeout:S(v,C.connect),responseTimeout:S(v,q?C.read:C.write)},_=b=>{let k={request:I,response:b,host:T,triesLeft:R.length};return P.push(k),k},y=await s.send(I);if(de(y)){let b=_(y);return y.isTimedOut&&v++,t.info("Retryable failure",K(b)),await e.set(T,G(T,y.isTimedOut?"timed out":"down")),N(R,S)}if(pe(y))return ce(y);throw _(y),ue(y,P)},Z=r.filter(R=>R.accept==="readWrite"||(q?R.accept==="read":R.accept==="write")),U=await l(Z);return N([...U.hosts].reverse(),U.getTimeout)}function h(u,m={}){let q=u.useReadTransporter||u.method==="GET";if(!q)return p(u,m,q);let P=()=>p(u,m);if((m.cacheable||u.cacheable)!==!0)return P();let g={request:u,requestOptions:m,transporter:{queryParameters:a,headers:o}};return i.get(g,()=>n.get(g,()=>n.set(g,P()).then(f=>Promise.all([n.delete(g),f]),f=>Promise.all([n.delete(g),Promise.reject(f)])).then(([f,x])=>x)),{miss:f=>i.set(g,f)})}return {hostsCache:e,requester:s,timeouts:c,logger:t,algoliaAgent:d,baseHeaders:o,baseQueryParameters:a,hosts:r,request:h,requestsCache:n,responsesCache:i}}var A="5.15.0";function he(r){return [{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(X([{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 Y({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...a}){let d=Q(r,e,o),c=V({hosts:he(r),...a,algoliaAgent:M({algoliaAgents:t,client:"Recommend",version:A}),baseHeaders:{"content-type":"text/plain",...d.headers(),...a.baseHeaders},baseQueryParameters:{...d.queryParameters(),...a.baseQueryParameters}});return {transporter:c,appId:r,clearCache(){return Promise.all([c.requestsCache.clear(),c.responsesCache.clear()]).then(()=>{})},get _ua(){return c.algoliaAgent.value},addAlgoliaAgent(s,n){c.algoliaAgent.add({segment:s,version:n});},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?c.baseHeaders["x-algolia-api-key"]=s:c.baseQueryParameters["x-algolia-api-key"]=s;},batchRecommendRules({indexName:s,model:n,recommendRule:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `batchRecommendRules`.");if(!n)throw new Error("Parameter `model` is required when calling `batchRecommendRules`.");let m={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)),queryParameters:{},headers:{},data:i||{}};return c.request(m,l)},customDelete({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let u={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return c.request(u,i)},customGet({path:s,parameters:n},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let u={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return c.request(u,i)},customPost({path:s,parameters:n,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let m={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:i||{}};return c.request(m,l)},customPut({path:s,parameters:n,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let m={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:i||{}};return c.request(m,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 m={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 c.request(m,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 m={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 c.request(m,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 m={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,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 h={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return c.request(h,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 m={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 c.request(m,l)}}}function xt(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 Y({appId:r,apiKey:e,timeouts:{connect:$,read:j,write:J},logger:z(),requester:L(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[W({key:`${A}-${r}`}),O()]}),...o})} | ||
function H(){function r(e){return new Promise(o=>{let t=new XMLHttpRequest;t.open(e.method,e.url,!0),Object.keys(e.headers).forEach(s=>t.setRequestHeader(s,e.headers[s]));let n=(s,a)=>setTimeout(()=>{t.abort(),o({status:0,content:a,isTimedOut:!0});},s),d=n(e.connectTimeout,"Connection timeout"),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}}function $(r){let e,o=`algolia-client-js-${r.key}`;function t(){return e===void 0&&(e=r.localStorage||window.localStorage),e}function n(){return JSON.parse(t().getItem(o)||"{}")}function d(s){t().setItem(o,JSON.stringify(s));}function c(){let s=r.timeToLive?r.timeToLive*1e3:null,a=n(),i=Object.fromEntries(Object.entries(a).filter(([,p])=>p.timestamp!==void 0));if(d(i),!s)return;let l=Object.fromEntries(Object.entries(i).filter(([,p])=>{let h=new Date().getTime();return !(p.timestamp+s<h)}));d(l);}return {get(s,a,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(c(),n()[JSON.stringify(s)])).then(l=>Promise.all([l?l.value:a(),l!==void 0])).then(([l,p])=>Promise.all([l,p||i.miss(l)])).then(([l])=>l)},set(s,a){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(s)]={timestamp:new Date().getTime(),value:a},t().setItem(o,JSON.stringify(i)),a})},delete(s){return Promise.resolve().then(()=>{let a=n();delete a[JSON.stringify(s)],t().setItem(o,JSON.stringify(a));})},clear(){return Promise.resolve().then(()=>{t().removeItem(o);})}}}function V(){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 q(r){let e=[...r.caches],o=e.shift();return o===void 0?V():{get(t,n,d={miss:()=>Promise.resolve()}){return o.get(t,n,d).catch(()=>q({caches:e}).get(t,n,d))},set(t,n){return o.set(t,n).catch(()=>q({caches:e}).set(t,n))},delete(t){return o.delete(t).catch(()=>q({caches:e}).delete(t))},clear(){return o.clear().catch(()=>q({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(s=>n.miss(s)).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()}}}function Y(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 j(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({algoliaAgents:r,client:e,version:o}){let t=Y(o).add({segment:e,version:o});return r.forEach(n=>t.add(n)),t}function J(){return {debug(r,e){return Promise.resolve()},info(r,e){return Promise.resolve()},error(r,e){return Promise.resolve()}}}var G=2*60*1e3;function L(r,e="up"){let o=Date.now();function t(){return e==="up"||Date.now()-o>G}function n(){return e==="timed out"&&Date.now()-o<=G}return {...r,status:e,lastUpdate:o,isUp:t,isTimedOut:n}}var Q=class extends Error{name="AlgoliaError";constructor(r,e){super(r),e&&(this.name=e);}},z=class extends Q{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e;}},Z=class extends z{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");}},N=class extends z{status;constructor(r,e,o,t="ApiError"){super(r,o,t),this.status=e;}},ee=class extends Q{response;constructor(r,e){super(r,"DeserializationError"),this.response=e;}},re=class extends N{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o;}};function M(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]).replace(/\+/g,"%20")}`).join("&")}function se(r,e){if(r.method==="GET"||r.data===void 0&&e.data===void 0)return;let o=Array.isArray(r.data)?r.data:{...r.data,...e.data};return JSON.stringify(o)}function ae(r,e,o){let t={Accept:"application/json",...r,...e,...o},n={};return Object.keys(t).forEach(d=>{let 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 N(t.message,e,o)}catch{}return new N(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=>B(e))}function B(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 F({hosts:r,hostsCache:e,baseHeaders:o,logger:t,baseQueryParameters:n,algoliaAgent:d,timeouts:c,requester:s,requestsCache:a,responsesCache:i}){async function l(u){let m=await Promise.all(u.map(f=>e.get(f,()=>Promise.resolve(L(f))))),w=m.filter(f=>f.isUp()),R=m.filter(f=>f.isTimedOut()),E=[...w,...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 p(u,m,w=!0){let R=[],E=se(u,m),g=ae(o,u.headers,m.headers),f=u.method==="GET"?{...u.data,...m.data}:{},x={...n,...u.queryParameters,...f};if(d.value&&(x["x-algolia-agent"]=d.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 v=0,D=async(P,C)=>{let T=P.pop();if(T===void 0)throw new Z(le(R));let S={...c,...m.timeouts},I={data:E,headers:g,method:u.method,url:te(T,u.path,x),connectTimeout:C(v,S.connect),responseTimeout:C(v,w?S.read:S.write)},k=b=>{let _={request:I,response:b,host:T,triesLeft:P.length};return R.push(_),_},y=await s.send(I);if(ce(y)){let b=k(y);return y.isTimedOut&&v++,t.info("Retryable failure",B(b)),await e.set(T,L(T,y.isTimedOut?"timed out":"down")),D(P,C)}if(ue(y))return ne(y);throw k(y),ie(y,R)},K=r.filter(P=>P.accept==="readWrite"||(w?P.accept==="read":P.accept==="write")),U=await l(K);return D([...U.hosts].reverse(),U.getTimeout)}function h(u,m={}){let w=u.useReadTransporter||u.method==="GET";if(!w)return p(u,m,w);let R=()=>p(u,m);if((m.cacheable||u.cacheable)!==!0)return R();let g={request:u,requestOptions:m,transporter:{queryParameters:n,headers:o}};return i.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=>i.set(g,f)})}return {hostsCache:e,requester:s,timeouts:c,logger:t,algoliaAgent:d,baseHeaders:o,baseQueryParameters:n,hosts:r,request:h,requestsCache:a,responsesCache:i}}var A="5.16.0";function de(r){return [{url:`${r}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${r}.algolia.net`,accept:"write",protocol:"https"}].concat(M([{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 X({appId:r,apiKey:e,authMode:o,algoliaAgents:t,...n}){let d=j(r,e,o),c=F({hosts:de(r),...n,algoliaAgent:W({algoliaAgents:t,client:"Recommend",version:A}),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(s,a){c.algoliaAgent.add({segment:s,version:a});},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?c.baseHeaders["x-algolia-api-key"]=s:c.baseQueryParameters["x-algolia-api-key"]=s;},batchRecommendRules({indexName:s,model:a,recommendRule:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `batchRecommendRules`.");if(!a)throw new Error("Parameter `model` is required when calling `batchRecommendRules`.");let m={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)),queryParameters:{},headers:{},data:i||{}};return c.request(m,l)},customDelete({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let u={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return c.request(u,i)},customGet({path:s,parameters:a},i){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let u={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{}};return c.request(u,i)},customPost({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let m={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return c.request(m,l)},customPut({path:s,parameters:a,body:i},l){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let m={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:a||{},headers:{},data:i||{}};return c.request(m,l)},deleteRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `deleteRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `deleteRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `deleteRecommendRule`.");let m={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,l)},getRecommendRule({indexName:s,model:a,objectID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendRule`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendRule`.");if(!i)throw new Error("Parameter `objectID` is required when calling `getRecommendRule`.");let m={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{objectID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,l)},getRecommendStatus({indexName:s,model:a,taskID:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `getRecommendStatus`.");if(!a)throw new Error("Parameter `model` is required when calling `getRecommendStatus`.");if(!i)throw new Error("Parameter `taskID` is required when calling `getRecommendStatus`.");let m={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)).replace("{taskID}",encodeURIComponent(i)),queryParameters:{},headers:{}};return c.request(m,l)},getRecommendations(s,a){if(s&&Array.isArray(s)&&(s={requests:s}),!s)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!s.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");let h={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return c.request(h,a)},searchRecommendRules({indexName:s,model:a,searchRecommendRulesParams:i},l){if(!s)throw new Error("Parameter `indexName` is required when calling `searchRecommendRules`.");if(!a)throw new Error("Parameter `model` is required when calling `searchRecommendRules`.");let m={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(a)),queryParameters:{},headers:{},data:i||{},useReadTransporter:!0,cacheable:!0};return c.request(m,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 X({appId:r,apiKey:e,timeouts:{connect:1e3,read:2e3,write:3e4},logger:J(),requester:H(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:q({caches:[$({key:`${A}-${r}`}),O()]}),...o})} | ||
exports.apiClientVersion = A; | ||
exports.recommendClient = xt; | ||
exports.recommendClient = Pt; | ||
})); |
// builds/fetch.ts | ||
import { | ||
createMemoryCache, | ||
createNullCache, | ||
createNullLogger, | ||
DEFAULT_CONNECT_TIMEOUT_NODE, | ||
DEFAULT_READ_TIMEOUT_NODE, | ||
DEFAULT_WRITE_TIMEOUT_NODE | ||
} from "@algolia/client-common"; | ||
import { createMemoryCache, createNullCache, createNullLogger } from "@algolia/client-common"; | ||
import { createFetchRequester } from "@algolia/requester-fetch"; | ||
@@ -14,3 +7,3 @@ | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.15.0"; | ||
var apiClientVersion = "5.16.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -415,5 +408,5 @@ return [ | ||
timeouts: { | ||
connect: DEFAULT_CONNECT_TIMEOUT_NODE, | ||
read: DEFAULT_READ_TIMEOUT_NODE, | ||
write: DEFAULT_WRITE_TIMEOUT_NODE | ||
connect: 2e3, | ||
read: 5e3, | ||
write: 3e4 | ||
}, | ||
@@ -420,0 +413,0 @@ logger: createNullLogger(), |
// builds/node.ts | ||
import { createHttpRequester } from "@algolia/requester-node-http"; | ||
import { | ||
createMemoryCache, | ||
createNullCache, | ||
createNullLogger, | ||
DEFAULT_CONNECT_TIMEOUT_NODE, | ||
DEFAULT_READ_TIMEOUT_NODE, | ||
DEFAULT_WRITE_TIMEOUT_NODE | ||
} from "@algolia/client-common"; | ||
import { createMemoryCache, createNullCache, createNullLogger } from "@algolia/client-common"; | ||
// src/recommendClient.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.15.0"; | ||
var apiClientVersion = "5.16.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -414,5 +407,5 @@ return [ | ||
timeouts: { | ||
connect: DEFAULT_CONNECT_TIMEOUT_NODE, | ||
read: DEFAULT_READ_TIMEOUT_NODE, | ||
write: DEFAULT_WRITE_TIMEOUT_NODE | ||
connect: 2e3, | ||
read: 5e3, | ||
write: 3e4 | ||
}, | ||
@@ -419,0 +412,0 @@ logger: createNullLogger(), |
// src/recommendClient.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent, shuffle } from "@algolia/client-common"; | ||
var apiClientVersion = "5.15.0"; | ||
var apiClientVersion = "5.16.0"; | ||
function getDefaultHosts(appId) { | ||
@@ -5,0 +5,0 @@ return [ |
{ | ||
"version": "5.15.0", | ||
"version": "5.16.0", | ||
"repository": { | ||
@@ -7,2 +7,3 @@ "type": "git", | ||
}, | ||
"homepage": "https://github.com/algolia/algoliasearch-client-javascript/packages/recommend#readme", | ||
"type": "module", | ||
@@ -52,14 +53,14 @@ "license": "MIT", | ||
"dependencies": { | ||
"@algolia/client-common": "5.15.0", | ||
"@algolia/requester-browser-xhr": "5.15.0", | ||
"@algolia/requester-fetch": "5.15.0", | ||
"@algolia/requester-node-http": "5.15.0" | ||
"@algolia/client-common": "5.16.0", | ||
"@algolia/requester-browser-xhr": "5.16.0", | ||
"@algolia/requester-fetch": "5.16.0", | ||
"@algolia/requester-node-http": "5.16.0" | ||
}, | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "0.17.0", | ||
"@types/node": "22.9.0", | ||
"@arethetypeswrong/cli": "0.17.1", | ||
"@types/node": "22.10.1", | ||
"publint": "0.2.12", | ||
"rollup": "4.27.2", | ||
"rollup": "4.28.1", | ||
"tsup": "8.3.5", | ||
"typescript": "5.6.3" | ||
"typescript": "5.7.2" | ||
}, | ||
@@ -66,0 +67,0 @@ "engines": { |
@@ -44,7 +44,7 @@ <p align="center"> | ||
```bash | ||
yarn add @algolia/recommend@5.15.0 | ||
yarn add @algolia/recommend@5.16.0 | ||
# or | ||
npm install @algolia/recommend@5.15.0 | ||
npm install @algolia/recommend@5.16.0 | ||
# or | ||
pnpm add @algolia/recommend@5.15.0 | ||
pnpm add @algolia/recommend@5.16.0 | ||
``` | ||
@@ -57,3 +57,3 @@ | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@algolia/recommend@5.15.0/dist/builds/browser.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@algolia/recommend@5.16.0/dist/builds/browser.umd.js"></script> | ||
``` | ||
@@ -60,0 +60,0 @@ |
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
716608
7306
+ Added@algolia/client-common@5.16.0(transitive)
+ Added@algolia/requester-browser-xhr@5.16.0(transitive)
+ Added@algolia/requester-fetch@5.16.0(transitive)
+ Added@algolia/requester-node-http@5.16.0(transitive)
- Removed@algolia/client-common@5.15.0(transitive)
- Removed@algolia/requester-browser-xhr@5.15.0(transitive)
- Removed@algolia/requester-fetch@5.15.0(transitive)
- Removed@algolia/requester-node-http@5.15.0(transitive)