@algolia/recommend 5.55.1 → 5.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/browser.d.ts +146 -23
- package/dist/builds/browser.js +282 -1
- package/dist/builds/browser.js.map +1 -1
- package/dist/builds/browser.min.js +5 -5
- package/dist/builds/browser.min.js.map +1 -1
- package/dist/builds/browser.umd.js +6 -6
- package/dist/builds/fetch.js +282 -1
- package/dist/builds/fetch.js.map +1 -1
- package/dist/builds/node.cjs +282 -1
- package/dist/builds/node.cjs.map +1 -1
- package/dist/builds/node.js +282 -1
- package/dist/builds/node.js.map +1 -1
- package/dist/builds/worker.js +282 -1
- package/dist/builds/worker.js.map +1 -1
- package/dist/fetch.d.ts +146 -23
- package/dist/node.d.cts +146 -23
- package/dist/node.d.ts +146 -23
- package/dist/src/recommendClient.cjs +282 -1
- package/dist/src/recommendClient.cjs.map +1 -1
- package/dist/src/recommendClient.js +282 -1
- package/dist/src/recommendClient.js.map +1 -1
- package/dist/worker.d.ts +146 -23
- package/package.json +9 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function
|
|
2
|
-
`&&(a=1));a<
|
|
3
|
-
`,a);if(
|
|
4
|
-
`?2:1:(
|
|
5
|
-
`),event:e,id:this.lastEventId,retry:this.retry};return this.data=[],t}};async function*he(e){let t=new fe;for await(let o of pe(e)){let r=t.decode(o);r!==null&&(yield r)}}var Re=750,J=120*1e3;function M(e,t="up"){let o=Date.now();function r(){return t==="up"||Date.now()-o>J}function i(){return t==="timed out"&&Date.now()-o<=J}return{...e,status:t,lastUpdate:o,isUp:r,isTimedOut:i}}var te=class extends Error{name="AlgoliaError";constructor(e,t){super(e),t&&(this.name=t)}};var re=class extends te{stackTrace;constructor(e,t,o){super(e,o),this.stackTrace=t}},Q=class extends re{constructor(e){super("Unreachable hosts - your application id may be incorrect. If the error persists, please visit our help center https://alg.li/support-unreachable-hosts or reach out to the Algolia Support team: https://alg.li/support",e,"RetryError")}},j=class extends re{status;constructor(e,t,o,r="ApiError"){super(e,o,r),this.status=t}},xe=class extends te{response;constructor(e,t){super(e,"DeserializationError"),this.response=t}},ge=class extends j{error;constructor(e,t,o,r){super(e,t,r,"DetailedApiError"),this.error=o}};function oe(e){let t=e;for(let o=e.length-1;o>0;o--){let r=Math.floor(Math.random()*(o+1)),i=e[o];t[o]=e[r],t[r]=i}return t}function B(e,t,o){let r=ye(o),i=`${e.protocol}://${e.url}${e.port?`:${e.port}`:""}/${t.charAt(0)==="/"?t.substring(1):t}`;return r.length&&(i+=`?${r}`),i}function ye(e){return Object.keys(e).filter(t=>e[t]!==void 0).sort().map(t=>`${t}=${encodeURIComponent(Object.prototype.toString.call(e[t])==="[object Array]"?e[t].join(","):e[t]).replace(/\+/g,"%20")}`).join("&")}function X(e,t){if(e.method==="GET"||e.data===void 0&&t.data===void 0)return;let o=Array.isArray(e.data)?e.data:{...e.data,...t.data};return JSON.stringify(o)}function K(e,t,o){let r={Accept:"application/json",...e,...t,...o},i={};return Object.keys(r).forEach(d=>{let c=r[d];i[d.toLowerCase()]=c}),i}function Pe(e){if(!(e.status===204||e.content.length===0))try{return JSON.parse(e.content)}catch(t){throw new xe(t.message,e)}}function Te({content:e,status:t},o){try{let r=JSON.parse(e);return"error"in r?new ge(r.message,t,r.error,o):new j(r.message,t,o)}catch{}return new j(e,t,o)}function Ee({isTimedOut:e,status:t}){return!e&&~~t===0}function ve({isTimedOut:e,status:t}){return e||Ee({isTimedOut:e,status:t})||~~(t/100)!==2&&~~(t/100)!==4}function Se({status:e}){return~~(e/100)===2}function qe(e){return e.map(t=>se(t))}function se(e){let t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...e,request:{...e.request,headers:{...e.request.headers,...t}}}}function ne({hosts:e,hostsCache:t,baseHeaders:o,logger:r,baseQueryParameters:i,algoliaAgent:d,timeouts:c,requester:n,requestsCache:s,responsesCache:a,compress:m,compression:f}){async function R(u){let l=await Promise.all(u.map(h=>t.get(h,()=>Promise.resolve(M(h))))),S=l.filter(h=>h.isUp()),T=l.filter(h=>h.isTimedOut()),v=[...S,...T];return{hosts:v.length>0?v:u,getTimeout(h,q){return(T.length===0&&h===0?1:T.length+3+h)*q}}}async function p(u,l,S){let T=[],v=X(u,l),y=K(o,u.headers,l.headers),h=f==="gzip"&&v!==void 0&&v.length>Re&&(u.method==="POST"||u.method==="PUT");h&&m===void 0&&r.info("Compression is disabled because no compress method is available.");let q=h&&m!==void 0,_=q?await m(v):v;q&&(y["content-encoding"]="gzip");let D=u.method==="GET"?{...u.data,...l.data}:{},w={...i,...u.queryParameters,...D};if(d.value&&(w["x-algolia-agent"]=d.value),l&&l.queryParameters)for(let P of Object.keys(l.queryParameters))!l.queryParameters[P]||Object.prototype.toString.call(l.queryParameters[P])==="[object Object]"?w[P]=l.queryParameters[P]:w[P]=l.queryParameters[P].toString();let I=0,N=async(P,L)=>{let O=P.pop();if(O===void 0)throw new Q(qe(T));let H={...c,...l.timeouts},F={data:_,headers:y,method:u.method,url:B(O,u.path,w),connectTimeout:L(I,H.connect),responseTimeout:L(I,S?H.read:H.write)},W=$=>{let z={request:F,response:$,host:O,triesLeft:P.length};return T.push(z),z},b=await n.send(F);if(ve(b)){let $=W(b);return b.isTimedOut&&I++,r.info("Retryable failure",se($)),await t.set(O,M(O,b.isTimedOut?"timed out":"down")),N(P,L)}if(Se(b))return Pe(b);throw W(b),Te(b,T)},E=e.filter(P=>P.accept==="readWrite"||(S?P.accept==="read":P.accept==="write")),G=await R(E);return N([...G.hosts].reverse(),G.getTimeout)}function x(u,l={}){let S=()=>p(u,l,T),T=u.useReadTransporter||u.method==="GET";if((l.cacheable||u.cacheable)!==!0)return S();let y={request:u,requestOptions:l,transporter:{queryParameters:i,headers:o}};return a.get(y,()=>s.get(y,()=>s.set(y,S()).then(h=>Promise.all([s.delete(y),h]),h=>Promise.all([s.delete(y),Promise.reject(h)])).then(([h,q])=>q)),{miss:h=>a.set(y,h)})}async function*A(u,l={}){if(!n.sendStream)throw new Error("This requester does not support streaming");let S=X(u,l),T=K(o,u.headers,l.headers);T.accept="text/event-stream";let v=u.method==="GET"?{...u.data,...l.data}:{},y={...i,...u.queryParameters,...v};if(d.value&&(y["x-algolia-agent"]=d.value),l&&l.queryParameters)for(let E of Object.keys(l.queryParameters))!l.queryParameters[E]||Object.prototype.toString.call(l.queryParameters[E])==="[object Object]"?y[E]=l.queryParameters[E]:y[E]=l.queryParameters[E].toString();let h=u.useReadTransporter||u.method==="GET",q=e.filter(E=>E.accept==="readWrite"||(h?E.accept==="read":E.accept==="write")),D=(await R(q)).hosts[0];if(!D)throw new Q([]);let w={...c,...l.timeouts},I={data:S,headers:T,method:u.method,url:B(D,u.path,y),connectTimeout:w.connect,responseTimeout:h?w.read:w.write},N=await n.sendStream(I);yield*he(N)}return{hostsCache:t,requester:n,timeouts:c,logger:r,algoliaAgent:d,baseHeaders:o,baseQueryParameters:i,hosts:e,request:x,requestStream:A,requestsCache:s,responsesCache:a}}function g(e,t,o){if(o==null||typeof o=="string"&&o.length===0)throw new Error(`Parameter \`${e}\` is required when calling \`${t}\`.`)}function ae(){function e(t){return new Promise(o=>{let r=new XMLHttpRequest;r.open(t.method,t.url,!0),Object.keys(t.headers).forEach(n=>r.setRequestHeader(n,t.headers[n]));let i=(n,s)=>setTimeout(()=>{r.abort(),o({status:0,content:s,isTimedOut:!0})},n),d=i(t.connectTimeout,"Connection timeout"),c;r.onreadystatechange=()=>{r.readyState>r.OPENED&&c===void 0&&(clearTimeout(d),c=i(t.responseTimeout,"Socket timeout"))},r.onerror=()=>{r.status===0&&(clearTimeout(d),clearTimeout(c),o({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=()=>{clearTimeout(d),clearTimeout(c),o({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(t.data)})}return{send:e}}var U="5.55.1";function we(e){return[{url:`${e}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${e}.algolia.net`,accept:"write",protocol:"https"}].concat(oe([{url:`${e}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function ie({appId:e,apiKey:t,authMode:o,algoliaAgents:r,...i}){let d=Y(e,t,o),c=ne({hosts:we(e),...i,algoliaAgent:Z({algoliaAgents:r,client:"Recommend",version:U}),baseHeaders:{"content-type":"text/plain",...d.headers(),...i.baseHeaders},baseQueryParameters:{...d.queryParameters(),...i.baseQueryParameters}});return{transporter:c,appId:e,apiKey:t,clearCache(){return Promise.all([c.requestsCache.clear(),c.responsesCache.clear()]).then(()=>{})},get _ua(){return c.algoliaAgent.value},addAlgoliaAgent(n,s){c.algoliaAgent.add({segment:n,version:s})},setClientApiKey({apiKey:n}){!o||o==="WithinHeaders"?c.baseHeaders["x-algolia-api-key"]=n:c.baseQueryParameters["x-algolia-api-key"]=n},batchRecommendRules({indexName:n,model:s,recommendRule:a},m){g("indexName","batchRecommendRules",n),g("model","batchRecommendRules",s);let x={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}",encodeURIComponent(n)).replace("{model}",encodeURIComponent(s)),queryParameters:{},headers:{},data:a||{}};return c.request(x,m)},customDelete({path:n,parameters:s},a){g("path","customDelete",n);let p={method:"DELETE",path:"/{path}".replace("{path}",n),queryParameters:s||{},headers:{}};return c.request(p,a)},customGet({path:n,parameters:s},a){g("path","customGet",n);let p={method:"GET",path:"/{path}".replace("{path}",n),queryParameters:s||{},headers:{}};return c.request(p,a)},customPost({path:n,parameters:s,body:a},m){g("path","customPost",n);let x={method:"POST",path:"/{path}".replace("{path}",n),queryParameters:s||{},headers:{},data:a||{}};return c.request(x,m)},customPut({path:n,parameters:s,body:a},m){g("path","customPut",n);let x={method:"PUT",path:"/{path}".replace("{path}",n),queryParameters:s||{},headers:{},data:a||{}};return c.request(x,m)},deleteRecommendRule({indexName:n,model:s,objectID:a},m){g("indexName","deleteRecommendRule",n),g("model","deleteRecommendRule",s),g("objectID","deleteRecommendRule",a);let x={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(n)).replace("{model}",encodeURIComponent(s)).replace("{objectID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return c.request(x,m)},getRecommendRule({indexName:n,model:s,objectID:a},m){g("indexName","getRecommendRule",n),g("model","getRecommendRule",s),g("objectID","getRecommendRule",a);let x={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(n)).replace("{model}",encodeURIComponent(s)).replace("{objectID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return c.request(x,m)},getRecommendStatus({indexName:n,model:s,taskID:a},m){g("indexName","getRecommendStatus",n),g("model","getRecommendStatus",s),g("taskID","getRecommendStatus",a);let x={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(n)).replace("{model}",encodeURIComponent(s)).replace("{taskID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return c.request(x,m)},getRecommendations(n,s){n&&Array.isArray(n)&&(n={requests:n}),g("getRecommendationsParams","getRecommendations",n),g("getRecommendationsParams.requests","getRecommendations",n.requests);let R={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:n,useReadTransporter:!0,cacheable:!0};return c.request(R,s)},searchRecommendRules({indexName:n,model:s,searchRecommendRulesParams:a},m){g("indexName","searchRecommendRules",n),g("model","searchRecommendRules",s);let x={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(n)).replace("{model}",encodeURIComponent(s)),queryParameters:{},headers:{},data:a||{},useReadTransporter:!0,cacheable:!0};return c.request(x,m)}}}function Or(e,t,o){if(!e||typeof e!="string")throw new Error("`appId` is missing.");if(!t||typeof t!="string")throw new Error("`apiKey` is missing.");let{compression:r,...i}=o||{};return ie({appId:e,apiKey:t,timeouts:{connect:1e3,read:2e3,write:3e4},logger:ee(),requester:ae(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:k(),requestsCache:k({serializable:!1}),hostsCache:C({caches:[V({key:`${U}-${e}`}),k()]}),...i})}export{U as apiClientVersion,Or as recommendClient};
|
|
1
|
+
function Y(e){let t,o=`algolia-client-js-${e.key}`;function r(){return t===void 0&&(t=e.localStorage||window.localStorage),t}function m(){return JSON.parse(r().getItem(o)||"{}")}function P(n){r().setItem(o,JSON.stringify(n))}function i(){return new Promise(n=>setTimeout(n,0))}function s(){let n=e.timeToLive?e.timeToLive*1e3:null,a=m(),c=new Date().getTime(),p=!1;return{namespace:Object.fromEntries(Object.entries(a).filter(([,d])=>!d||d.timestamp===void 0||n&&d.timestamp+n<c?(p=!0,!1):!0)),changed:p}}return{get(n,a,c={miss:()=>Promise.resolve()}){return i().then(()=>{let{namespace:p,changed:h}=s(),d=p[JSON.stringify(n)];return h&&P(p),d?d.value:a().then(l=>c.miss(l).then(()=>l))})},set(n,a){return i().then(()=>{let c=m();return c[JSON.stringify(n)]={timestamp:new Date().getTime(),value:a},r().setItem(o,JSON.stringify(c)),a})},delete(n){return i().then(()=>{let a=m();delete a[JSON.stringify(n)],r().setItem(o,JSON.stringify(a))})},clear(){return Promise.resolve().then(()=>{r().removeItem(o)})}}}function ue(){return{get(e,t,o={miss:()=>Promise.resolve()}){return t().then(m=>Promise.all([m,o.miss(m)])).then(([m])=>m)},set(e,t){return Promise.resolve(t)},delete(e){return Promise.resolve()},clear(){return Promise.resolve()}}}function A(e){let t=[...e.caches],o=t.shift();return o===void 0?ue():{get(r,m,P={miss:()=>Promise.resolve()}){return o.get(r,m,P).catch(()=>A({caches:t}).get(r,m,P))},set(r,m){return o.set(r,m).catch(()=>A({caches:t}).set(r,m))},delete(r){return o.delete(r).catch(()=>A({caches:t}).delete(r))},clear(){return o.clear().catch(()=>A({caches:t}).clear())}}}function N(e={serializable:!0}){let t={};return{get(o,r,m={miss:()=>Promise.resolve()}){let P=JSON.stringify(o);if(P in t)return Promise.resolve(e.serializable?JSON.parse(t[P]):t[P]);let i=r();return i.then(s=>m.miss(s)).then(()=>i)},set(o,r){return t[JSON.stringify(o)]=e.serializable?JSON.stringify(r):r,Promise.resolve(r)},delete(o){return delete t[JSON.stringify(o)],Promise.resolve()},clear(){return t={},Promise.resolve()}}}function de(e){let t={value:`Algolia for JavaScript (${e})`,add(o){let r=`; ${o.segment}${o.version!==void 0?` (${o.version})`:""}`;return t.value.indexOf(r)===-1&&(t.value=`${t.value}${r}`),t}};return t}function Z(e,t,o="WithinHeaders"){let r={"x-algolia-api-key":t,"x-algolia-application-id":e};return{headers(){return o==="WithinHeaders"?r:{}},queryParameters(){return o==="WithinQueryParameters"?r:{}}}}function ee({algoliaAgents:e,client:t,version:o}){let r=de(o).add({segment:t,version:o});return e.forEach(m=>r.add(m)),r}function te(){return{debug(e,t){return Promise.resolve()},info(e,t){return Promise.resolve()},error(e,t){return Promise.resolve()}}}var le=10*1024*1024;async function*pe(e){let t=e.getReader();try{for(;;){let{done:o,value:r}=await t.read();if(o)return;yield r}}finally{t.releaseLock()}}function he(e){return Symbol.asyncIterator in e?e:pe(e)}async function*fe(e){let t=new TextDecoder("utf-8"),o=[],r=0,m=!1,P=!0;for await(let s of he(e)){let n=t.decode(s,{stream:!0}),a=0;for(m&&(m=!1,n.length>0&&n[0]===`
|
|
2
|
+
`&&(a=1));a<n.length;){let c=n.indexOf("\r",a),p=n.indexOf(`
|
|
3
|
+
`,a);if(c===-1&&p===-1){let O=n.slice(a);if(o.push(O),r+=O.length,r>le)throw new Error("SSE line buffer exceeded 10MB");break}let h,d;c!==-1&&(p===-1||c<p)?(h=c,c+1<n.length?d=n[c+1]===`
|
|
4
|
+
`?2:1:(m=!0,d=1)):(h=p,d=1);let l=n.slice(a,h);o.push(l);let w=o.length===1?o[0]:o.join("");o.length=0,r=0,P&&(w.startsWith("\uFEFF")&&(w=w.slice(1)),P=!1),yield w,a=h+d}}let i=t.decode();if(i&&o.push(i),o.length>0){let s=o.join("");P&&s.startsWith("\uFEFF")&&(s=s.slice(1)),yield s}}var Re=class{data=[];eventType="";lastEventId=null;retry=null;decode(e){if(e==="")return this.dispatch();if(e[0]===":")return null;let t=e.indexOf(":"),o,r;switch(t===-1?(o=e,r=""):(o=e.slice(0,t),r=e.slice(t+1),r[0]===" "&&(r=r.slice(1))),o){case"data":this.data.push(r);break;case"event":this.eventType=r;break;case"id":r.includes("\0")||(this.lastEventId=r);break;case"retry":/^[0-9]+$/.test(r)&&(this.retry=parseInt(r,10));break}return null}dispatch(){let e=this.eventType;if(this.eventType="",this.data.length===0)return null;let t={data:this.data.join(`
|
|
5
|
+
`),event:e,id:this.lastEventId,retry:this.retry};return this.data=[],t}};async function*Pe(e){let t=new Re;for await(let o of fe(e)){let r=t.decode(o);r!==null&&(yield r)}}var ye=750,J=120*1e3;function M(e,t="up"){let o=Date.now();function r(){return t==="up"||Date.now()-o>J}function m(){return t==="timed out"&&Date.now()-o<=J}return{...e,status:t,lastUpdate:o,isUp:r,isTimedOut:m}}var re=class extends Error{name="AlgoliaError";constructor(e,t){super(e),t&&(this.name=t)}};var oe=class extends re{stackTrace;constructor(e,t,o){super(e,o),this.stackTrace=t}},B=class extends oe{constructor(e){super("Unreachable hosts - your application id may be incorrect. If the error persists, please visit our help center https://alg.li/support-unreachable-hosts or reach out to the Algolia Support team: https://alg.li/support",e,"RetryError")}},j=class extends oe{status;constructor(e,t,o,r="ApiError"){super(e,o,r),this.status=t}},ge=class extends re{response;constructor(e,t){super(e,"DeserializationError"),this.response=t}},xe=class extends j{error;constructor(e,t,o,r){super(e,t,r,"DetailedApiError"),this.error=o}};function se(e){let t=e;for(let o=e.length-1;o>0;o--){let r=Math.floor(Math.random()*(o+1)),m=e[o];t[o]=e[r],t[r]=m}return t}function X(e,t,o){let r=Te(o),m=`${e.protocol}://${e.url}${e.port?`:${e.port}`:""}/${t.charAt(0)==="/"?t.substring(1):t}`;return r.length&&(m+=`?${r}`),m}function Te(e){return Object.keys(e).filter(t=>e[t]!==void 0).sort().map(t=>`${t}=${encodeURIComponent(Object.prototype.toString.call(e[t])==="[object Array]"?e[t].join(","):e[t]).replace(/\+/g,"%20")}`).join("&")}function K(e,t){if(e.method==="GET"||e.data===void 0&&t.data===void 0)return;let o=Array.isArray(e.data)?e.data:{...e.data,...t.data};return JSON.stringify(o)}function V(e,t,o){let r={Accept:"application/json",...e,...t,...o},m={};return Object.keys(r).forEach(P=>{let i=r[P];m[P.toLowerCase()]=i}),m}function ne(e){if(!(e.status===204||e.content.length===0))try{return JSON.parse(e.content)}catch(t){throw new ge(t.message,e)}}function qe(e){return{status:e.status,headers:e.headers,content:e.content,data:ne(e)}}function Ie({content:e,status:t},o){try{let r=JSON.parse(e);return"error"in r?new xe(r.message,t,r.error,o):new j(r.message,t,o)}catch{}return new j(e,t,o)}function Ee({isTimedOut:e,status:t}){return!e&&~~t===0}function ve({isTimedOut:e,status:t}){return e||Ee({isTimedOut:e,status:t})||~~(t/100)!==2&&~~(t/100)!==4}function He({status:e}){return~~(e/100)===2}function Se(e){return e.map(t=>ae(t))}function ae(e){let t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...e,request:{...e.request,headers:{...e.request.headers,...t}}}}function ce({hosts:e,hostsCache:t,baseHeaders:o,logger:r,baseQueryParameters:m,algoliaAgent:P,timeouts:i,requester:s,requestsCache:n,responsesCache:a,compress:c,compression:p}){async function h(f){let R=await Promise.all(f.map(y=>t.get(y,()=>Promise.resolve(M(y))))),I=R.filter(y=>y.isUp()),x=R.filter(y=>y.isTimedOut()),E=[...I,...x];return{hosts:E.length>0?E:f,getTimeout(y,v){return(x.length===0&&y===0?1:x.length+3+y)*v}}}async function d(f,R,I){let x=[],E=K(f,R),g=V(o,f.headers,R.headers),y=p==="gzip"&&E!==void 0&&E.length>ye&&(f.method==="POST"||f.method==="PUT");y&&c===void 0&&r.info("Compression is disabled because no compress method is available.");let v=y&&c!==void 0,k=v?await c(E):E;v&&(g["content-encoding"]="gzip");let W=f.method==="GET"?{...f.data,...R.data}:{},H={...m,...f.queryParameters,...W};if(P.value&&(H["x-algolia-agent"]=P.value),R&&R.queryParameters)for(let T of Object.keys(R.queryParameters))!R.queryParameters[T]||Object.prototype.toString.call(R.queryParameters[T])==="[object Object]"?H[T]=R.queryParameters[T]:H[T]=R.queryParameters[T].toString();let b=0,D=async(T,_)=>{let C=T.pop();if(C===void 0)throw new B(Se(x));let G={...i,...R.timeouts},Q={data:k,headers:g,method:f.method,url:X(C,f.path,H),connectTimeout:_(b,G.connect),responseTimeout:_(b,I?G.read:G.write)},F=L=>{let z={request:Q,response:L,host:C,triesLeft:T.length};return x.push(z),z},S=await s.send(Q);if(ve(S)){let L=F(S);return S.isTimedOut&&b++,r.info("Retryable failure",ae(L)),await t.set(C,M(C,S.isTimedOut?"timed out":"down")),D(T,_)}if(He(S))return S;throw F(S),Ie(S,x)},q=e.filter(T=>T.accept==="readWrite"||(I?T.accept==="read":T.accept==="write")),$=await h(q);return D([...$.hosts].reverse(),$.getTimeout)}function l(f,R={}){let I=()=>d(f,R,x).then(y=>ne(y)),x=f.useReadTransporter||f.method==="GET";if((R.cacheable||f.cacheable)!==!0)return I();let g={request:f,requestOptions:R,transporter:{queryParameters:m,headers:o}};return a.get(g,()=>n.get(g,()=>n.set(g,I()).then(y=>Promise.all([n.delete(g),y]),y=>Promise.all([n.delete(g),Promise.reject(y)])).then(([y,v])=>v)),{miss:y=>a.set(g,y)})}function w(f,R={}){let I=f.useReadTransporter||f.method==="GET";return d(f,R,I).then(x=>qe(x))}async function*O(f,R={}){if(!s.sendStream)throw new Error("This requester does not support streaming");let I=K(f,R),x=V(o,f.headers,R.headers);x.accept="text/event-stream";let E=f.method==="GET"?{...f.data,...R.data}:{},g={...m,...f.queryParameters,...E};if(P.value&&(g["x-algolia-agent"]=P.value),R&&R.queryParameters)for(let q of Object.keys(R.queryParameters))!R.queryParameters[q]||Object.prototype.toString.call(R.queryParameters[q])==="[object Object]"?g[q]=R.queryParameters[q]:g[q]=R.queryParameters[q].toString();let y=f.useReadTransporter||f.method==="GET",v=e.filter(q=>q.accept==="readWrite"||(y?q.accept==="read":q.accept==="write")),W=(await h(v)).hosts[0];if(!W)throw new B([]);let H={...i,...R.timeouts},b={data:I,headers:x,method:f.method,url:X(W,f.path,g),connectTimeout:H.connect,responseTimeout:y?H.read:H.write},D=await s.sendStream(b);yield*Pe(D)}return{hostsCache:t,requester:s,timeouts:i,logger:r,algoliaAgent:P,baseHeaders:o,baseQueryParameters:m,hosts:e,request:l,requestWithHttpInfo:w,requestStream:O,requestsCache:n,responsesCache:a}}function u(e,t,o){if(o==null||typeof o=="string"&&o.length===0)throw new Error(`Parameter \`${e}\` is required when calling \`${t}\`.`)}function we(e){let t={};for(let o of e.trim().split(/[\r\n]+/)){let r=o.indexOf(": ");r>0&&(t[o.slice(0,r).toLowerCase()]=o.slice(r+2))}return t}function ie(){function e(t){return new Promise(o=>{let r=new XMLHttpRequest;r.open(t.method,t.url,!0),Object.keys(t.headers).forEach(s=>r.setRequestHeader(s,t.headers[s]));let m=(s,n)=>setTimeout(()=>{r.abort(),o({status:0,content:n,isTimedOut:!0})},s),P=m(t.connectTimeout,"Connection timeout"),i;r.onreadystatechange=()=>{r.readyState>r.OPENED&&i===void 0&&(clearTimeout(P),i=m(t.responseTimeout,"Socket timeout"))},r.onerror=()=>{r.status===0&&(clearTimeout(P),clearTimeout(i),o({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=()=>{clearTimeout(P),clearTimeout(i),o({content:r.responseText,headers:we(r.getAllResponseHeaders()),status:r.status,isTimedOut:!1})},r.send(t.data)})}return{send:e}}var U="5.56.0";function Ae(e){return[{url:`${e}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${e}.algolia.net`,accept:"write",protocol:"https"}].concat(se([{url:`${e}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function me({appId:e,apiKey:t,authMode:o,algoliaAgents:r,...m}){let P=Z(e,t,o),i=ce({hosts:Ae(e),...m,algoliaAgent:ee({algoliaAgents:r,client:"Recommend",version:U}),baseHeaders:{"content-type":"text/plain",...P.headers(),...m.baseHeaders},baseQueryParameters:{...P.queryParameters(),...m.baseQueryParameters}});return{transporter:i,appId:e,apiKey:t,clearCache(){return Promise.all([i.requestsCache.clear(),i.responsesCache.clear()]).then(()=>{})},get _ua(){return i.algoliaAgent.value},addAlgoliaAgent(s,n){i.algoliaAgent.add({segment:s,version:n})},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?i.baseHeaders["x-algolia-api-key"]=s:i.baseQueryParameters["x-algolia-api-key"]=s},batchRecommendRules({indexName:s,model:n,recommendRule:a},c){u("indexName","batchRecommendRules",s),u("model","batchRecommendRules",n);let l={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)),queryParameters:{},headers:{},data:a||{}};return i.request(l,c)},batchRecommendRulesWithHTTPInfo({indexName:s,model:n,recommendRule:a},c){u("indexName","batchRecommendRulesWithHTTPInfo",s),u("model","batchRecommendRulesWithHTTPInfo",n);let l={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/batch".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)),queryParameters:{},headers:{},data:a||{}};return i.requestWithHttpInfo(l,c)},customDelete({path:s,parameters:n},a){u("path","customDelete",s);let d={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return i.request(d,a)},customDeleteWithHTTPInfo({path:s,parameters:n},a){u("path","customDeleteWithHTTPInfo",s);let d={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return i.requestWithHttpInfo(d,a)},customGet({path:s,parameters:n},a){u("path","customGet",s);let d={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return i.request(d,a)},customGetWithHTTPInfo({path:s,parameters:n},a){u("path","customGetWithHTTPInfo",s);let d={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{}};return i.requestWithHttpInfo(d,a)},customPost({path:s,parameters:n,body:a},c){u("path","customPost",s);let l={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:a||{}};return i.request(l,c)},customPostWithHTTPInfo({path:s,parameters:n,body:a},c){u("path","customPostWithHTTPInfo",s);let l={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:a||{}};return i.requestWithHttpInfo(l,c)},customPut({path:s,parameters:n,body:a},c){u("path","customPut",s);let l={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:a||{}};return i.request(l,c)},customPutWithHTTPInfo({path:s,parameters:n,body:a},c){u("path","customPutWithHTTPInfo",s);let l={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:n||{},headers:{},data:a||{}};return i.requestWithHttpInfo(l,c)},deleteRecommendRule({indexName:s,model:n,objectID:a},c){u("indexName","deleteRecommendRule",s),u("model","deleteRecommendRule",n),u("objectID","deleteRecommendRule",a);let l={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{objectID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return i.request(l,c)},deleteRecommendRuleWithHTTPInfo({indexName:s,model:n,objectID:a},c){u("indexName","deleteRecommendRuleWithHTTPInfo",s),u("model","deleteRecommendRuleWithHTTPInfo",n),u("objectID","deleteRecommendRuleWithHTTPInfo",a);let l={method:"DELETE",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{objectID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return i.requestWithHttpInfo(l,c)},getRecommendRule({indexName:s,model:n,objectID:a},c){u("indexName","getRecommendRule",s),u("model","getRecommendRule",n),u("objectID","getRecommendRule",a);let l={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{objectID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return i.request(l,c)},getRecommendRuleWithHTTPInfo({indexName:s,model:n,objectID:a},c){u("indexName","getRecommendRuleWithHTTPInfo",s),u("model","getRecommendRuleWithHTTPInfo",n),u("objectID","getRecommendRuleWithHTTPInfo",a);let l={method:"GET",path:"/1/indexes/{indexName}/{model}/recommend/rules/{objectID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{objectID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return i.requestWithHttpInfo(l,c)},getRecommendStatus({indexName:s,model:n,taskID:a},c){u("indexName","getRecommendStatus",s),u("model","getRecommendStatus",n),u("taskID","getRecommendStatus",a);let l={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{taskID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return i.request(l,c)},getRecommendStatusWithHTTPInfo({indexName:s,model:n,taskID:a},c){u("indexName","getRecommendStatusWithHTTPInfo",s),u("model","getRecommendStatusWithHTTPInfo",n),u("taskID","getRecommendStatusWithHTTPInfo",a);let l={method:"GET",path:"/1/indexes/{indexName}/{model}/task/{taskID}".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)).replace("{taskID}",encodeURIComponent(a)),queryParameters:{},headers:{}};return i.requestWithHttpInfo(l,c)},getRecommendations(s,n){s&&Array.isArray(s)&&(s={requests:s}),u("getRecommendationsParams","getRecommendations",s),u("getRecommendationsParams.requests","getRecommendations",s.requests);let h={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return i.request(h,n)},getRecommendationsWithHTTPInfo(s,n){s&&Array.isArray(s)&&(s={requests:s}),u("getRecommendationsParams","getRecommendationsWithHTTPInfo",s),u("getRecommendationsParams.requests","getRecommendationsWithHTTPInfo",s.requests);let h={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:s,useReadTransporter:!0,cacheable:!0};return i.requestWithHttpInfo(h,n)},searchRecommendRules({indexName:s,model:n,searchRecommendRulesParams:a},c){u("indexName","searchRecommendRules",s),u("model","searchRecommendRules",n);let l={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)),queryParameters:{},headers:{},data:a||{},useReadTransporter:!0,cacheable:!0};return i.request(l,c)},searchRecommendRulesWithHTTPInfo({indexName:s,model:n,searchRecommendRulesParams:a},c){u("indexName","searchRecommendRulesWithHTTPInfo",s),u("model","searchRecommendRulesWithHTTPInfo",n);let l={method:"POST",path:"/1/indexes/{indexName}/{model}/recommend/rules/search".replace("{indexName}",encodeURIComponent(s)).replace("{model}",encodeURIComponent(n)),queryParameters:{},headers:{},data:a||{},useReadTransporter:!0,cacheable:!0};return i.requestWithHttpInfo(l,c)}}}function Dr(e,t,o){if(!e||typeof e!="string")throw new Error("`appId` is missing.");if(!t||typeof t!="string")throw new Error("`apiKey` is missing.");let{compression:r,...m}=o||{};return me({appId:e,apiKey:t,timeouts:{connect:1e3,read:2e3,write:3e4},logger:te(),requester:ie(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:N(),requestsCache:N({serializable:!1}),hostsCache:A({caches:[Y({key:`${U}-${e}`}),N()]}),...m})}export{U as apiClientVersion,Dr as recommendClient};
|
|
6
6
|
//# sourceMappingURL=browser.min.js.map
|