@algolia/client-personalization
Advanced tools
Comparing version 5.8.1 to 5.9.0
@@ -167,8 +167,9 @@ import * as _algolia_client_common from '@algolia/client-common'; | ||
declare const apiClientVersion = "5.8.1"; | ||
declare const apiClientVersion = "5.9.0"; | ||
declare const REGIONS: readonly ["eu", "us"]; | ||
type Region = (typeof REGIONS)[number]; | ||
declare function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & { | ||
type RegionOptions = { | ||
region: Region; | ||
}): { | ||
}; | ||
declare function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & RegionOptions): { | ||
transporter: _algolia_client_common.Transporter; | ||
@@ -286,2 +287,2 @@ /** | ||
export { type CustomDeleteProps, type CustomGetProps, type CustomPostProps, type CustomPutProps, type DeleteUserProfileProps, type DeleteUserProfileResponse, type ErrorBase, type EventScoring, type EventType, type FacetScoring, type GetUserTokenProfileProps, type GetUserTokenResponse, type PersonalizationClient, type PersonalizationStrategyParams, type Region, type SetPersonalizationStrategyResponse, apiClientVersion, personalizationClient }; | ||
export { type CustomDeleteProps, type CustomGetProps, type CustomPostProps, type CustomPutProps, type DeleteUserProfileProps, type DeleteUserProfileResponse, type ErrorBase, type EventScoring, type EventType, type FacetScoring, type GetUserTokenProfileProps, type GetUserTokenResponse, type PersonalizationClient, type PersonalizationStrategyParams, type Region, type RegionOptions, type SetPersonalizationStrategyResponse, apiClientVersion, personalizationClient }; |
@@ -15,3 +15,3 @@ // builds/browser.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common"; | ||
var apiClientVersion = "5.8.1"; | ||
var apiClientVersion = "5.9.0"; | ||
var REGIONS = ["eu", "us"]; | ||
@@ -18,0 +18,0 @@ function getDefaultHosts(region) { |
@@ -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(n=>t.setRequestHeader(n,e.headers[n]));let a=(n,s)=>setTimeout(()=>{t.abort(),o({status:0,content:s,isTimedOut:!0})},n),m=a(e.connectTimeout,"Connection timeout"),p;t.onreadystatechange=()=>{t.readyState>t.OPENED&&p===void 0&&(clearTimeout(m),p=a(e.responseTimeout,"Socket timeout"))},t.onerror=()=>{t.status===0&&(clearTimeout(m),clearTimeout(p),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}))},t.onload=()=>{clearTimeout(m),clearTimeout(p),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 a(){return JSON.parse(t().getItem(o)||"{}")}function m(n){t().setItem(o,JSON.stringify(n))}function p(){let n=r.timeToLive?r.timeToLive*1e3:null,s=a(),i=Object.fromEntries(Object.entries(s).filter(([,d])=>d.timestamp!==void 0));if(m(i),!n)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let f=new Date().getTime();return!(d.timestamp+n<f)}));m(u)}return{get(n,s,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(p(),a()[JSON.stringify(n)])).then(u=>Promise.all([u?u.value:s(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(n,s){return Promise.resolve().then(()=>{let i=a();return i[JSON.stringify(n)]={timestamp:new Date().getTime(),value:s},t().setItem(o,JSON.stringify(i)),s})},delete(n){return Promise.resolve().then(()=>{let s=a();delete s[JSON.stringify(n)],t().setItem(o,JSON.stringify(s))})},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,m={miss:()=>Promise.resolve()}){return o.get(t,a,m).catch(()=>w({caches:e}).get(t,a,m))},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 m=JSON.stringify(o);if(m in e)return Promise.resolve(r.serializable?JSON.parse(e[m]):e[m]);let p=t();return p.then(n=>a.miss(n)).then(()=>p)},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 j=1e3,G=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 M(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 Q({algoliaAgents:r,client:e,version:o}){let t=re(o).add({segment:e,version:o});return r.forEach(a=>t.add(a)),t}function F(){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 W(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)}},X=class extends B{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e}},te=class extends X{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")}},x=class extends X{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 x{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o}};function ae(r,e,o){let t=ne(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}function ne(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 ce(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(m=>{let p=t[m];a[m.toLowerCase()]=p}),a}function ue(r){try{return JSON.parse(r.content)}catch(e){throw new oe(e.message,r)}}function le({content:r,status:e},o){try{let t=JSON.parse(r);return"error"in t?new se(t.message,e,t.error,o):new x(t.message,e,o)}catch{}return new x(r,e,o)}function me({isTimedOut:r,status:e}){return!r&&~~e===0}function de({isTimedOut:r,status:e}){return r||me({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function he({status:r}){return~~(r/100)===2}function pe(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:m,timeouts:p,requester:n,requestsCache:s,responsesCache:i}){async function u(c){let l=await Promise.all(c.map(h=>e.get(h,()=>Promise.resolve(W(h))))),g=l.filter(h=>h.isUp()),y=l.filter(h=>h.isTimedOut()),q=[...g,...y];return{hosts:q.length>0?q:c,getTimeout(h,E){return(y.length===0&&h===0?1:y.length+3+h)*E}}}async function d(c,l,g=!0){let y=[],q=ie(c,l),T=ce(o,c.headers,l.headers),h=c.method==="GET"?{...c.data,...l.data}:{},E={...a,...c.queryParameters,...h};if(m.value&&(E["x-algolia-agent"]=m.value),l&&l.queryParameters)for(let P of Object.keys(l.queryParameters))!l.queryParameters[P]||Object.prototype.toString.call(l.queryParameters[P])==="[object Object]"?E[P]=l.queryParameters[P]:E[P]=l.queryParameters[P].toString();let S=0,D=async(P,C)=>{let v=P.pop();if(v===void 0)throw new te(pe(y));let b={...p,...l.timeouts},N={data:q,headers:T,method:c.method,url:ae(v,c.path,E),connectTimeout:C(S,b.connect),responseTimeout:C(S,g?b.read:b.write)},k=U=>{let I={request:N,response:U,host:v,triesLeft:P.length};return y.push(I),I},R=await n.send(N);if(de(R)){let U=k(R);return R.isTimedOut&&S++,t.info("Retryable failure",K(U)),await e.set(v,W(v,R.isTimedOut?"timed out":"down")),D(P,C)}if(he(R))return ue(R);throw k(R),le(R,y)},Z=r.filter(P=>P.accept==="readWrite"||(g?P.accept==="read":P.accept==="write")),_=await u(Z);return D([..._.hosts].reverse(),_.getTimeout)}function f(c,l={}){let g=c.useReadTransporter||c.method==="GET";if(!g)return d(c,l,g);let y=()=>d(c,l);if((l.cacheable||c.cacheable)!==!0)return y();let T={request:c,requestOptions:l,transporter:{queryParameters:a,headers:o}};return i.get(T,()=>s.get(T,()=>s.set(T,y()).then(h=>Promise.all([s.delete(T),h]),h=>Promise.all([s.delete(T),Promise.reject(h)])).then(([h,E])=>E)),{miss:h=>i.set(T,h)})}return{hostsCache:e,requester:n,timeouts:p,logger:t,algoliaAgent:m,baseHeaders:o,baseQueryParameters:a,hosts:r,request:f,requestsCache:s,responsesCache:i}}var A="5.8.1",z=["eu","us"];function Pe(r){return[{url:"personalization.{region}.algolia.com".replace("{region}",r),accept:"readWrite",protocol:"https"}]}function Y({appId:r,apiKey:e,authMode:o,algoliaAgents:t,region:a,...m}){let p=M(r,e,o),n=V({hosts:Pe(a),...m,algoliaAgent:Q({algoliaAgents:t,client:"Personalization",version:A}),baseHeaders:{"content-type":"text/plain",...p.headers(),...m.baseHeaders},baseQueryParameters:{...p.queryParameters(),...m.baseQueryParameters}});return{transporter:n,appId:r,clearCache(){return Promise.all([n.requestsCache.clear(),n.responsesCache.clear()]).then(()=>{})},get _ua(){return n.algoliaAgent.value},addAlgoliaAgent(s,i){n.algoliaAgent.add({segment:s,version:i})},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?n.baseHeaders["x-algolia-api-key"]=s:n.baseQueryParameters["x-algolia-api-key"]=s},customDelete({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let l={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customGet({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let l={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customPost({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let g={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},customPut({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let g={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},deleteUserProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `deleteUserProfile`.");let c={method:"DELETE",path:"/1/profiles/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},getPersonalizationStrategy(s){let f={method:"GET",path:"/1/strategies/personalization",queryParameters:{},headers:{}};return n.request(f,s)},getUserTokenProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `getUserTokenProfile`.");let c={method:"GET",path:"/1/profiles/personalization/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},setPersonalizationStrategy(s,i){if(!s)throw new Error("Parameter `personalizationStrategyParams` is required when calling `setPersonalizationStrategy`.");if(!s.eventScoring)throw new Error("Parameter `personalizationStrategyParams.eventScoring` is required when calling `setPersonalizationStrategy`.");if(!s.facetScoring)throw new Error("Parameter `personalizationStrategyParams.facetScoring` is required when calling `setPersonalizationStrategy`.");if(!s.personalizationImpact)throw new Error("Parameter `personalizationStrategyParams.personalizationImpact` is required when calling `setPersonalizationStrategy`.");let c={method:"POST",path:"/1/strategies/personalization",queryParameters:{},headers:{},data:s};return n.request(c,i)}}}function $e(r,e,o,t){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(!o||o&&(typeof o!="string"||!z.includes(o)))throw new Error(`\`region\` is required and must be one of the following: ${z.join(", ")}`);return Y({appId:r,apiKey:e,region:o,timeouts:{connect:j,read:G,write:J},logger:F(),requester:L(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[$({key:`${A}-${r}`}),O()]}),...t})}export{A as apiClientVersion,$e as personalizationClient}; | ||
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(n=>t.setRequestHeader(n,e.headers[n]));let a=(n,s)=>setTimeout(()=>{t.abort(),o({status:0,content:s,isTimedOut:!0})},n),m=a(e.connectTimeout,"Connection timeout"),h;t.onreadystatechange=()=>{t.readyState>t.OPENED&&h===void 0&&(clearTimeout(m),h=a(e.responseTimeout,"Socket timeout"))},t.onerror=()=>{t.status===0&&(clearTimeout(m),clearTimeout(h),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}))},t.onload=()=>{clearTimeout(m),clearTimeout(h),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 a(){return JSON.parse(t().getItem(o)||"{}")}function m(n){t().setItem(o,JSON.stringify(n))}function h(){let n=r.timeToLive?r.timeToLive*1e3:null,s=a(),i=Object.fromEntries(Object.entries(s).filter(([,d])=>d.timestamp!==void 0));if(m(i),!n)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let f=new Date().getTime();return!(d.timestamp+n<f)}));m(u)}return{get(n,s,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(h(),a()[JSON.stringify(n)])).then(u=>Promise.all([u?u.value:s(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(n,s){return Promise.resolve().then(()=>{let i=a();return i[JSON.stringify(n)]={timestamp:new Date().getTime(),value:s},t().setItem(o,JSON.stringify(i)),s})},delete(n){return Promise.resolve().then(()=>{let s=a();delete s[JSON.stringify(n)],t().setItem(o,JSON.stringify(s))})},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,m={miss:()=>Promise.resolve()}){return o.get(t,a,m).catch(()=>w({caches:e}).get(t,a,m))},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 S(r={serializable:!0}){let e={};return{get(o,t,a={miss:()=>Promise.resolve()}){let m=JSON.stringify(o);if(m in e)return Promise.resolve(r.serializable?JSON.parse(e[m]):e[m]);let h=t();return h.then(n=>a.miss(n)).then(()=>h)},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 j=1e3,G=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 M(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 Q({algoliaAgents:r,client:e,version:o}){let t=re(o).add({segment:e,version:o});return r.forEach(a=>t.add(a)),t}function F(){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 W(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)}},X=class extends B{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e}},te=class extends X{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")}},x=class extends X{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 x{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o}};function ae(r,e,o){let t=ne(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}function ne(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 ce(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(m=>{let h=t[m];a[m.toLowerCase()]=h}),a}function ue(r){try{return JSON.parse(r.content)}catch(e){throw new oe(e.message,r)}}function le({content:r,status:e},o){try{let t=JSON.parse(r);return"error"in t?new se(t.message,e,t.error,o):new x(t.message,e,o)}catch{}return new x(r,e,o)}function me({isTimedOut:r,status:e}){return!r&&~~e===0}function de({isTimedOut:r,status:e}){return r||me({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function pe({status:r}){return~~(r/100)===2}function he(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:m,timeouts:h,requester:n,requestsCache:s,responsesCache:i}){async function u(c){let l=await Promise.all(c.map(p=>e.get(p,()=>Promise.resolve(W(p))))),g=l.filter(p=>p.isUp()),y=l.filter(p=>p.isTimedOut()),q=[...g,...y];return{hosts:q.length>0?q:c,getTimeout(p,E){return(y.length===0&&p===0?1:y.length+3+p)*E}}}async function d(c,l,g=!0){let y=[],q=ie(c,l),T=ce(o,c.headers,l.headers),p=c.method==="GET"?{...c.data,...l.data}:{},E={...a,...c.queryParameters,...p};if(m.value&&(E["x-algolia-agent"]=m.value),l&&l.queryParameters)for(let P of Object.keys(l.queryParameters))!l.queryParameters[P]||Object.prototype.toString.call(l.queryParameters[P])==="[object Object]"?E[P]=l.queryParameters[P]:E[P]=l.queryParameters[P].toString();let v=0,D=async(P,C)=>{let O=P.pop();if(O===void 0)throw new te(he(y));let b={...h,...l.timeouts},N={data:q,headers:T,method:c.method,url:ae(O,c.path,E),connectTimeout:C(v,b.connect),responseTimeout:C(v,g?b.read:b.write)},k=U=>{let I={request:N,response:U,host:O,triesLeft:P.length};return y.push(I),I},R=await n.send(N);if(de(R)){let U=k(R);return R.isTimedOut&&v++,t.info("Retryable failure",K(U)),await e.set(O,W(O,R.isTimedOut?"timed out":"down")),D(P,C)}if(pe(R))return ue(R);throw k(R),le(R,y)},Z=r.filter(P=>P.accept==="readWrite"||(g?P.accept==="read":P.accept==="write")),_=await u(Z);return D([..._.hosts].reverse(),_.getTimeout)}function f(c,l={}){let g=c.useReadTransporter||c.method==="GET";if(!g)return d(c,l,g);let y=()=>d(c,l);if((l.cacheable||c.cacheable)!==!0)return y();let T={request:c,requestOptions:l,transporter:{queryParameters:a,headers:o}};return i.get(T,()=>s.get(T,()=>s.set(T,y()).then(p=>Promise.all([s.delete(T),p]),p=>Promise.all([s.delete(T),Promise.reject(p)])).then(([p,E])=>E)),{miss:p=>i.set(T,p)})}return{hostsCache:e,requester:n,timeouts:h,logger:t,algoliaAgent:m,baseHeaders:o,baseQueryParameters:a,hosts:r,request:f,requestsCache:s,responsesCache:i}}var A="5.9.0",z=["eu","us"];function Pe(r){return[{url:"personalization.{region}.algolia.com".replace("{region}",r),accept:"readWrite",protocol:"https"}]}function Y({appId:r,apiKey:e,authMode:o,algoliaAgents:t,region:a,...m}){let h=M(r,e,o),n=V({hosts:Pe(a),...m,algoliaAgent:Q({algoliaAgents:t,client:"Personalization",version:A}),baseHeaders:{"content-type":"text/plain",...h.headers(),...m.baseHeaders},baseQueryParameters:{...h.queryParameters(),...m.baseQueryParameters}});return{transporter:n,appId:r,clearCache(){return Promise.all([n.requestsCache.clear(),n.responsesCache.clear()]).then(()=>{})},get _ua(){return n.algoliaAgent.value},addAlgoliaAgent(s,i){n.algoliaAgent.add({segment:s,version:i})},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?n.baseHeaders["x-algolia-api-key"]=s:n.baseQueryParameters["x-algolia-api-key"]=s},customDelete({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let l={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customGet({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let l={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customPost({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let g={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},customPut({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let g={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},deleteUserProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `deleteUserProfile`.");let c={method:"DELETE",path:"/1/profiles/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},getPersonalizationStrategy(s){let f={method:"GET",path:"/1/strategies/personalization",queryParameters:{},headers:{}};return n.request(f,s)},getUserTokenProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `getUserTokenProfile`.");let c={method:"GET",path:"/1/profiles/personalization/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},setPersonalizationStrategy(s,i){if(!s)throw new Error("Parameter `personalizationStrategyParams` is required when calling `setPersonalizationStrategy`.");if(!s.eventScoring)throw new Error("Parameter `personalizationStrategyParams.eventScoring` is required when calling `setPersonalizationStrategy`.");if(!s.facetScoring)throw new Error("Parameter `personalizationStrategyParams.facetScoring` is required when calling `setPersonalizationStrategy`.");if(!s.personalizationImpact)throw new Error("Parameter `personalizationStrategyParams.personalizationImpact` is required when calling `setPersonalizationStrategy`.");let c={method:"POST",path:"/1/strategies/personalization",queryParameters:{},headers:{},data:s};return n.request(c,i)}}}function $e(r,e,o,t){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(!o||o&&(typeof o!="string"||!z.includes(o)))throw new Error(`\`region\` is required and must be one of the following: ${z.join(", ")}`);return Y({appId:r,apiKey:e,region:o,timeouts:{connect:j,read:G,write:J},logger:F(),requester:L(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:S(),requestsCache:S({serializable:!1}),hostsCache:w({caches:[$({key:`${A}-${r}`}),S()]}),...t})}export{A as apiClientVersion,$e as personalizationClient}; | ||
//# sourceMappingURL=browser.min.js.map |
@@ -7,3 +7,3 @@ (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(n=>t.setRequestHeader(n,e.headers[n]));let a=(n,s)=>setTimeout(()=>{t.abort(),o({status:0,content:s,isTimedOut:!0});},n),m=a(e.connectTimeout,"Connection timeout"),p;t.onreadystatechange=()=>{t.readyState>t.OPENED&&p===void 0&&(clearTimeout(m),p=a(e.responseTimeout,"Socket timeout"));},t.onerror=()=>{t.status===0&&(clearTimeout(m),clearTimeout(p),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}));},t.onload=()=>{clearTimeout(m),clearTimeout(p),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 a(){return JSON.parse(t().getItem(o)||"{}")}function m(n){t().setItem(o,JSON.stringify(n));}function p(){let n=r.timeToLive?r.timeToLive*1e3:null,s=a(),i=Object.fromEntries(Object.entries(s).filter(([,d])=>d.timestamp!==void 0));if(m(i),!n)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let f=new Date().getTime();return !(d.timestamp+n<f)}));m(u);}return {get(n,s,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(p(),a()[JSON.stringify(n)])).then(u=>Promise.all([u?u.value:s(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(n,s){return Promise.resolve().then(()=>{let i=a();return i[JSON.stringify(n)]={timestamp:new Date().getTime(),value:s},t().setItem(o,JSON.stringify(i)),s})},delete(n){return Promise.resolve().then(()=>{let s=a();delete s[JSON.stringify(n)],t().setItem(o,JSON.stringify(s));})},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,m={miss:()=>Promise.resolve()}){return o.get(t,a,m).catch(()=>w({caches:e}).get(t,a,m))},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 m=JSON.stringify(o);if(m in e)return Promise.resolve(r.serializable?JSON.parse(e[m]):e[m]);let p=t();return p.then(n=>a.miss(n)).then(()=>p)},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 j=1e3,G=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 M(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 Q({algoliaAgents:r,client:e,version:o}){let t=re(o).add({segment:e,version:o});return r.forEach(a=>t.add(a)),t}function F(){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 W(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);}},X=class extends B{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e;}},te=class extends X{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");}},x=class extends X{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 x{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o;}};function ae(r,e,o){let t=ne(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}function ne(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 ce(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(m=>{let p=t[m];a[m.toLowerCase()]=p;}),a}function ue(r){try{return JSON.parse(r.content)}catch(e){throw new oe(e.message,r)}}function le({content:r,status:e},o){try{let t=JSON.parse(r);return "error"in t?new se(t.message,e,t.error,o):new x(t.message,e,o)}catch{}return new x(r,e,o)}function me({isTimedOut:r,status:e}){return !r&&~~e===0}function de({isTimedOut:r,status:e}){return r||me({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function he({status:r}){return ~~(r/100)===2}function pe(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:m,timeouts:p,requester:n,requestsCache:s,responsesCache:i}){async function u(c){let l=await Promise.all(c.map(h=>e.get(h,()=>Promise.resolve(W(h))))),g=l.filter(h=>h.isUp()),y=l.filter(h=>h.isTimedOut()),q=[...g,...y];return {hosts:q.length>0?q:c,getTimeout(h,E){return (y.length===0&&h===0?1:y.length+3+h)*E}}}async function d(c,l,g=!0){let y=[],q=ie(c,l),T=ce(o,c.headers,l.headers),h=c.method==="GET"?{...c.data,...l.data}:{},E={...a,...c.queryParameters,...h};if(m.value&&(E["x-algolia-agent"]=m.value),l&&l.queryParameters)for(let P of Object.keys(l.queryParameters))!l.queryParameters[P]||Object.prototype.toString.call(l.queryParameters[P])==="[object Object]"?E[P]=l.queryParameters[P]:E[P]=l.queryParameters[P].toString();let S=0,D=async(P,C)=>{let v=P.pop();if(v===void 0)throw new te(pe(y));let b={...p,...l.timeouts},N={data:q,headers:T,method:c.method,url:ae(v,c.path,E),connectTimeout:C(S,b.connect),responseTimeout:C(S,g?b.read:b.write)},k=U=>{let I={request:N,response:U,host:v,triesLeft:P.length};return y.push(I),I},R=await n.send(N);if(de(R)){let U=k(R);return R.isTimedOut&&S++,t.info("Retryable failure",K(U)),await e.set(v,W(v,R.isTimedOut?"timed out":"down")),D(P,C)}if(he(R))return ue(R);throw k(R),le(R,y)},Z=r.filter(P=>P.accept==="readWrite"||(g?P.accept==="read":P.accept==="write")),_=await u(Z);return D([..._.hosts].reverse(),_.getTimeout)}function f(c,l={}){let g=c.useReadTransporter||c.method==="GET";if(!g)return d(c,l,g);let y=()=>d(c,l);if((l.cacheable||c.cacheable)!==!0)return y();let T={request:c,requestOptions:l,transporter:{queryParameters:a,headers:o}};return i.get(T,()=>s.get(T,()=>s.set(T,y()).then(h=>Promise.all([s.delete(T),h]),h=>Promise.all([s.delete(T),Promise.reject(h)])).then(([h,E])=>E)),{miss:h=>i.set(T,h)})}return {hostsCache:e,requester:n,timeouts:p,logger:t,algoliaAgent:m,baseHeaders:o,baseQueryParameters:a,hosts:r,request:f,requestsCache:s,responsesCache:i}}var A="5.8.1",z=["eu","us"];function Pe(r){return [{url:"personalization.{region}.algolia.com".replace("{region}",r),accept:"readWrite",protocol:"https"}]}function Y({appId:r,apiKey:e,authMode:o,algoliaAgents:t,region:a,...m}){let p=M(r,e,o),n=V({hosts:Pe(a),...m,algoliaAgent:Q({algoliaAgents:t,client:"Personalization",version:A}),baseHeaders:{"content-type":"text/plain",...p.headers(),...m.baseHeaders},baseQueryParameters:{...p.queryParameters(),...m.baseQueryParameters}});return {transporter:n,appId:r,clearCache(){return Promise.all([n.requestsCache.clear(),n.responsesCache.clear()]).then(()=>{})},get _ua(){return n.algoliaAgent.value},addAlgoliaAgent(s,i){n.algoliaAgent.add({segment:s,version:i});},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?n.baseHeaders["x-algolia-api-key"]=s:n.baseQueryParameters["x-algolia-api-key"]=s;},customDelete({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let l={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customGet({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let l={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customPost({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let g={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},customPut({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let g={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},deleteUserProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `deleteUserProfile`.");let c={method:"DELETE",path:"/1/profiles/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},getPersonalizationStrategy(s){let f={method:"GET",path:"/1/strategies/personalization",queryParameters:{},headers:{}};return n.request(f,s)},getUserTokenProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `getUserTokenProfile`.");let c={method:"GET",path:"/1/profiles/personalization/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},setPersonalizationStrategy(s,i){if(!s)throw new Error("Parameter `personalizationStrategyParams` is required when calling `setPersonalizationStrategy`.");if(!s.eventScoring)throw new Error("Parameter `personalizationStrategyParams.eventScoring` is required when calling `setPersonalizationStrategy`.");if(!s.facetScoring)throw new Error("Parameter `personalizationStrategyParams.facetScoring` is required when calling `setPersonalizationStrategy`.");if(!s.personalizationImpact)throw new Error("Parameter `personalizationStrategyParams.personalizationImpact` is required when calling `setPersonalizationStrategy`.");let c={method:"POST",path:"/1/strategies/personalization",queryParameters:{},headers:{},data:s};return n.request(c,i)}}}function $e(r,e,o,t){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(!o||o&&(typeof o!="string"||!z.includes(o)))throw new Error(`\`region\` is required and must be one of the following: ${z.join(", ")}`);return Y({appId:r,apiKey:e,region:o,timeouts:{connect:j,read:G,write:J},logger:F(),requester:L(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:w({caches:[$({key:`${A}-${r}`}),O()]}),...t})} | ||
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(n=>t.setRequestHeader(n,e.headers[n]));let a=(n,s)=>setTimeout(()=>{t.abort(),o({status:0,content:s,isTimedOut:!0});},n),m=a(e.connectTimeout,"Connection timeout"),h;t.onreadystatechange=()=>{t.readyState>t.OPENED&&h===void 0&&(clearTimeout(m),h=a(e.responseTimeout,"Socket timeout"));},t.onerror=()=>{t.status===0&&(clearTimeout(m),clearTimeout(h),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:!1}));},t.onload=()=>{clearTimeout(m),clearTimeout(h),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 a(){return JSON.parse(t().getItem(o)||"{}")}function m(n){t().setItem(o,JSON.stringify(n));}function h(){let n=r.timeToLive?r.timeToLive*1e3:null,s=a(),i=Object.fromEntries(Object.entries(s).filter(([,d])=>d.timestamp!==void 0));if(m(i),!n)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let f=new Date().getTime();return !(d.timestamp+n<f)}));m(u);}return {get(n,s,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(h(),a()[JSON.stringify(n)])).then(u=>Promise.all([u?u.value:s(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(n,s){return Promise.resolve().then(()=>{let i=a();return i[JSON.stringify(n)]={timestamp:new Date().getTime(),value:s},t().setItem(o,JSON.stringify(i)),s})},delete(n){return Promise.resolve().then(()=>{let s=a();delete s[JSON.stringify(n)],t().setItem(o,JSON.stringify(s));})},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,m={miss:()=>Promise.resolve()}){return o.get(t,a,m).catch(()=>w({caches:e}).get(t,a,m))},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 S(r={serializable:!0}){let e={};return {get(o,t,a={miss:()=>Promise.resolve()}){let m=JSON.stringify(o);if(m in e)return Promise.resolve(r.serializable?JSON.parse(e[m]):e[m]);let h=t();return h.then(n=>a.miss(n)).then(()=>h)},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 j=1e3,G=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 M(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 Q({algoliaAgents:r,client:e,version:o}){let t=re(o).add({segment:e,version:o});return r.forEach(a=>t.add(a)),t}function F(){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 W(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);}},X=class extends B{stackTrace;constructor(r,e,o){super(r,o),this.stackTrace=e;}},te=class extends X{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");}},x=class extends X{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 x{error;constructor(r,e,o,t){super(r,e,t,"DetailedApiError"),this.error=o;}};function ae(r,e,o){let t=ne(o),a=`${r.protocol}://${r.url}${r.port?`:${r.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return t.length&&(a+=`?${t}`),a}function ne(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 ce(r,e,o){let t={Accept:"application/json",...r,...e,...o},a={};return Object.keys(t).forEach(m=>{let h=t[m];a[m.toLowerCase()]=h;}),a}function ue(r){try{return JSON.parse(r.content)}catch(e){throw new oe(e.message,r)}}function le({content:r,status:e},o){try{let t=JSON.parse(r);return "error"in t?new se(t.message,e,t.error,o):new x(t.message,e,o)}catch{}return new x(r,e,o)}function me({isTimedOut:r,status:e}){return !r&&~~e===0}function de({isTimedOut:r,status:e}){return r||me({isTimedOut:r,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function pe({status:r}){return ~~(r/100)===2}function he(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:m,timeouts:h,requester:n,requestsCache:s,responsesCache:i}){async function u(c){let l=await Promise.all(c.map(p=>e.get(p,()=>Promise.resolve(W(p))))),g=l.filter(p=>p.isUp()),y=l.filter(p=>p.isTimedOut()),q=[...g,...y];return {hosts:q.length>0?q:c,getTimeout(p,E){return (y.length===0&&p===0?1:y.length+3+p)*E}}}async function d(c,l,g=!0){let y=[],q=ie(c,l),T=ce(o,c.headers,l.headers),p=c.method==="GET"?{...c.data,...l.data}:{},E={...a,...c.queryParameters,...p};if(m.value&&(E["x-algolia-agent"]=m.value),l&&l.queryParameters)for(let P of Object.keys(l.queryParameters))!l.queryParameters[P]||Object.prototype.toString.call(l.queryParameters[P])==="[object Object]"?E[P]=l.queryParameters[P]:E[P]=l.queryParameters[P].toString();let v=0,D=async(P,C)=>{let O=P.pop();if(O===void 0)throw new te(he(y));let b={...h,...l.timeouts},N={data:q,headers:T,method:c.method,url:ae(O,c.path,E),connectTimeout:C(v,b.connect),responseTimeout:C(v,g?b.read:b.write)},k=U=>{let I={request:N,response:U,host:O,triesLeft:P.length};return y.push(I),I},R=await n.send(N);if(de(R)){let U=k(R);return R.isTimedOut&&v++,t.info("Retryable failure",K(U)),await e.set(O,W(O,R.isTimedOut?"timed out":"down")),D(P,C)}if(pe(R))return ue(R);throw k(R),le(R,y)},Z=r.filter(P=>P.accept==="readWrite"||(g?P.accept==="read":P.accept==="write")),_=await u(Z);return D([..._.hosts].reverse(),_.getTimeout)}function f(c,l={}){let g=c.useReadTransporter||c.method==="GET";if(!g)return d(c,l,g);let y=()=>d(c,l);if((l.cacheable||c.cacheable)!==!0)return y();let T={request:c,requestOptions:l,transporter:{queryParameters:a,headers:o}};return i.get(T,()=>s.get(T,()=>s.set(T,y()).then(p=>Promise.all([s.delete(T),p]),p=>Promise.all([s.delete(T),Promise.reject(p)])).then(([p,E])=>E)),{miss:p=>i.set(T,p)})}return {hostsCache:e,requester:n,timeouts:h,logger:t,algoliaAgent:m,baseHeaders:o,baseQueryParameters:a,hosts:r,request:f,requestsCache:s,responsesCache:i}}var A="5.9.0",z=["eu","us"];function Pe(r){return [{url:"personalization.{region}.algolia.com".replace("{region}",r),accept:"readWrite",protocol:"https"}]}function Y({appId:r,apiKey:e,authMode:o,algoliaAgents:t,region:a,...m}){let h=M(r,e,o),n=V({hosts:Pe(a),...m,algoliaAgent:Q({algoliaAgents:t,client:"Personalization",version:A}),baseHeaders:{"content-type":"text/plain",...h.headers(),...m.baseHeaders},baseQueryParameters:{...h.queryParameters(),...m.baseQueryParameters}});return {transporter:n,appId:r,clearCache(){return Promise.all([n.requestsCache.clear(),n.responsesCache.clear()]).then(()=>{})},get _ua(){return n.algoliaAgent.value},addAlgoliaAgent(s,i){n.algoliaAgent.add({segment:s,version:i});},setClientApiKey({apiKey:s}){!o||o==="WithinHeaders"?n.baseHeaders["x-algolia-api-key"]=s:n.baseQueryParameters["x-algolia-api-key"]=s;},customDelete({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customDelete`.");let l={method:"DELETE",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customGet({path:s,parameters:i},u){if(!s)throw new Error("Parameter `path` is required when calling `customGet`.");let l={method:"GET",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{}};return n.request(l,u)},customPost({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPost`.");let g={method:"POST",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},customPut({path:s,parameters:i,body:u},d){if(!s)throw new Error("Parameter `path` is required when calling `customPut`.");let g={method:"PUT",path:"/{path}".replace("{path}",s),queryParameters:i||{},headers:{},data:u||{}};return n.request(g,d)},deleteUserProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `deleteUserProfile`.");let c={method:"DELETE",path:"/1/profiles/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},getPersonalizationStrategy(s){let f={method:"GET",path:"/1/strategies/personalization",queryParameters:{},headers:{}};return n.request(f,s)},getUserTokenProfile({userToken:s},i){if(!s)throw new Error("Parameter `userToken` is required when calling `getUserTokenProfile`.");let c={method:"GET",path:"/1/profiles/personalization/{userToken}".replace("{userToken}",encodeURIComponent(s)),queryParameters:{},headers:{}};return n.request(c,i)},setPersonalizationStrategy(s,i){if(!s)throw new Error("Parameter `personalizationStrategyParams` is required when calling `setPersonalizationStrategy`.");if(!s.eventScoring)throw new Error("Parameter `personalizationStrategyParams.eventScoring` is required when calling `setPersonalizationStrategy`.");if(!s.facetScoring)throw new Error("Parameter `personalizationStrategyParams.facetScoring` is required when calling `setPersonalizationStrategy`.");if(!s.personalizationImpact)throw new Error("Parameter `personalizationStrategyParams.personalizationImpact` is required when calling `setPersonalizationStrategy`.");let c={method:"POST",path:"/1/strategies/personalization",queryParameters:{},headers:{},data:s};return n.request(c,i)}}}function $e(r,e,o,t){if(!r||typeof r!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(!o||o&&(typeof o!="string"||!z.includes(o)))throw new Error(`\`region\` is required and must be one of the following: ${z.join(", ")}`);return Y({appId:r,apiKey:e,region:o,timeouts:{connect:j,read:G,write:J},logger:F(),requester:L(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:S(),requestsCache:S({serializable:!1}),hostsCache:w({caches:[$({key:`${A}-${r}`}),S()]}),...t})} | ||
@@ -10,0 +10,0 @@ exports.apiClientVersion = A; |
@@ -14,3 +14,3 @@ // builds/fetch.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common"; | ||
var apiClientVersion = "5.8.1"; | ||
var apiClientVersion = "5.9.0"; | ||
var REGIONS = ["eu", "us"]; | ||
@@ -17,0 +17,0 @@ function getDefaultHosts(region) { |
@@ -14,3 +14,3 @@ // builds/node.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common"; | ||
var apiClientVersion = "5.8.1"; | ||
var apiClientVersion = "5.9.0"; | ||
var REGIONS = ["eu", "us"]; | ||
@@ -17,0 +17,0 @@ function getDefaultHosts(region) { |
@@ -167,8 +167,9 @@ import * as _algolia_client_common from '@algolia/client-common'; | ||
declare const apiClientVersion = "5.8.1"; | ||
declare const apiClientVersion = "5.9.0"; | ||
declare const REGIONS: readonly ["eu", "us"]; | ||
type Region = (typeof REGIONS)[number]; | ||
declare function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & { | ||
type RegionOptions = { | ||
region: Region; | ||
}): { | ||
}; | ||
declare function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & RegionOptions): { | ||
transporter: _algolia_client_common.Transporter; | ||
@@ -287,2 +288,2 @@ /** | ||
export { type CustomDeleteProps, type CustomGetProps, type CustomPostProps, type CustomPutProps, type DeleteUserProfileProps, type DeleteUserProfileResponse, type ErrorBase, type EventScoring, type EventType, type FacetScoring, type GetUserTokenProfileProps, type GetUserTokenResponse, type PersonalizationClient, type PersonalizationStrategyParams, type Region, type SetPersonalizationStrategyResponse, apiClientVersion, personalizationClient }; | ||
export { type CustomDeleteProps, type CustomGetProps, type CustomPostProps, type CustomPutProps, type DeleteUserProfileProps, type DeleteUserProfileResponse, type ErrorBase, type EventScoring, type EventType, type FacetScoring, type GetUserTokenProfileProps, type GetUserTokenResponse, type PersonalizationClient, type PersonalizationStrategyParams, type Region, type RegionOptions, type SetPersonalizationStrategyResponse, apiClientVersion, personalizationClient }; |
@@ -167,8 +167,9 @@ import * as _algolia_client_common from '@algolia/client-common'; | ||
declare const apiClientVersion = "5.8.1"; | ||
declare const apiClientVersion = "5.9.0"; | ||
declare const REGIONS: readonly ["eu", "us"]; | ||
type Region = (typeof REGIONS)[number]; | ||
declare function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & { | ||
type RegionOptions = { | ||
region: Region; | ||
}): { | ||
}; | ||
declare function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & RegionOptions): { | ||
transporter: _algolia_client_common.Transporter; | ||
@@ -287,2 +288,2 @@ /** | ||
export { type CustomDeleteProps, type CustomGetProps, type CustomPostProps, type CustomPutProps, type DeleteUserProfileProps, type DeleteUserProfileResponse, type ErrorBase, type EventScoring, type EventType, type FacetScoring, type GetUserTokenProfileProps, type GetUserTokenResponse, type PersonalizationClient, type PersonalizationStrategyParams, type Region, type SetPersonalizationStrategyResponse, apiClientVersion, personalizationClient }; | ||
export { type CustomDeleteProps, type CustomGetProps, type CustomPostProps, type CustomPutProps, type DeleteUserProfileProps, type DeleteUserProfileResponse, type ErrorBase, type EventScoring, type EventType, type FacetScoring, type GetUserTokenProfileProps, type GetUserTokenResponse, type PersonalizationClient, type PersonalizationStrategyParams, type Region, type RegionOptions, type SetPersonalizationStrategyResponse, apiClientVersion, personalizationClient }; |
// src/personalizationClient.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common"; | ||
var apiClientVersion = "5.8.1"; | ||
var apiClientVersion = "5.9.0"; | ||
var REGIONS = ["eu", "us"]; | ||
@@ -5,0 +5,0 @@ function getDefaultHosts(region) { |
{ | ||
"version": "5.8.1", | ||
"version": "5.9.0", | ||
"repository": { | ||
@@ -52,14 +52,14 @@ "type": "git", | ||
"dependencies": { | ||
"@algolia/client-common": "5.8.1", | ||
"@algolia/requester-browser-xhr": "5.8.1", | ||
"@algolia/requester-fetch": "5.8.1", | ||
"@algolia/requester-node-http": "5.8.1" | ||
"@algolia/client-common": "5.9.0", | ||
"@algolia/requester-browser-xhr": "5.9.0", | ||
"@algolia/requester-fetch": "5.9.0", | ||
"@algolia/requester-node-http": "5.9.0" | ||
}, | ||
"devDependencies": { | ||
"@arethetypeswrong/cli": "0.16.4", | ||
"@types/node": "22.7.4", | ||
"@types/node": "22.7.5", | ||
"publint": "0.2.11", | ||
"rollup": "4.24.0", | ||
"tsup": "8.3.0", | ||
"typescript": "5.6.2" | ||
"typescript": "5.6.3" | ||
}, | ||
@@ -66,0 +66,0 @@ "engines": { |
@@ -44,7 +44,7 @@ <p align="center"> | ||
```bash | ||
yarn add @algolia/client-personalization@5.8.1 | ||
yarn add @algolia/client-personalization@5.9.0 | ||
# or | ||
npm install @algolia/client-personalization@5.8.1 | ||
npm install @algolia/client-personalization@5.9.0 | ||
# or | ||
pnpm add @algolia/client-personalization@5.8.1 | ||
pnpm add @algolia/client-personalization@5.9.0 | ||
``` | ||
@@ -57,3 +57,3 @@ | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@algolia/client-personalization@5.8.1/dist/builds/browser.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@algolia/client-personalization@5.9.0/dist/builds/browser.umd.js"></script> | ||
``` | ||
@@ -60,0 +60,0 @@ |
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 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
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
337993
3014
+ Added@algolia/client-common@5.9.0(transitive)
+ Added@algolia/requester-browser-xhr@5.9.0(transitive)
+ Added@algolia/requester-fetch@5.9.0(transitive)
+ Added@algolia/requester-node-http@5.9.0(transitive)
- Removed@algolia/client-common@5.8.1(transitive)
- Removed@algolia/requester-browser-xhr@5.8.1(transitive)
- Removed@algolia/requester-fetch@5.8.1(transitive)
- Removed@algolia/requester-node-http@5.8.1(transitive)
Updated@algolia/client-common@5.9.0