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