@algolia/client-abtesting
Advanced tools
Comparing version 5.3.2 to 5.4.0
@@ -429,3 +429,3 @@ import * as _algolia_client_common from '@algolia/client-common'; | ||
declare const apiClientVersion = "5.3.2"; | ||
declare const apiClientVersion = "5.4.0"; | ||
declare const REGIONS: readonly ["de", "us"]; | ||
@@ -432,0 +432,0 @@ type Region = (typeof REGIONS)[number]; |
@@ -14,3 +14,3 @@ // builds/browser.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common"; | ||
var apiClientVersion = "5.3.2"; | ||
var apiClientVersion = "5.4.0"; | ||
var REGIONS = ["de", "us"]; | ||
@@ -17,0 +17,0 @@ function getDefaultHosts(region) { |
@@ -1,2 +0,2 @@ | ||
function H(t,e,s="WithinHeaders"){let r={"x-algolia-api-key":e,"x-algolia-application-id":t};return{headers(){return s==="WithinHeaders"?r:{}},queryParameters(){return s==="WithinQueryParameters"?r:{}}}}function W(t){let e,s=`algolia-client-js-${t.key}`;function r(){return e===void 0&&(e=t.localStorage||window.localStorage),e}function n(){return JSON.parse(r().getItem(s)||"{}")}function m(a){r().setItem(s,JSON.stringify(a))}function f(){let a=t.timeToLive?t.timeToLive*1e3:null,o=n(),i=Object.fromEntries(Object.entries(o).filter(([,d])=>d.timestamp!==void 0));if(m(i),!a)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let l=new Date().getTime();return!(d.timestamp+a<l)}));m(u)}return{get(a,o,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(f(),n()[JSON.stringify(a)])).then(u=>Promise.all([u?u.value:o(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(a,o){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(a)]={timestamp:new Date().getTime(),value:o},r().setItem(s,JSON.stringify(i)),o})},delete(a){return Promise.resolve().then(()=>{let o=n();delete o[JSON.stringify(a)],r().setItem(s,JSON.stringify(o))})},clear(){return Promise.resolve().then(()=>{r().removeItem(s)})}}}function Y(){return{get(t,e,s={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,s.miss(n)])).then(([n])=>n)},set(t,e){return Promise.resolve(e)},delete(t){return Promise.resolve()},clear(){return Promise.resolve()}}}function q(t){let e=[...t.caches],s=e.shift();return s===void 0?Y():{get(r,n,m={miss:()=>Promise.resolve()}){return s.get(r,n,m).catch(()=>q({caches:e}).get(r,n,m))},set(r,n){return s.set(r,n).catch(()=>q({caches:e}).set(r,n))},delete(r){return s.delete(r).catch(()=>q({caches:e}).delete(r))},clear(){return s.clear().catch(()=>q({caches:e}).clear())}}}function O(t={serializable:!0}){let e={};return{get(s,r,n={miss:()=>Promise.resolve()}){let m=JSON.stringify(s);if(m in e)return Promise.resolve(t.serializable?JSON.parse(e[m]):e[m]);let f=r();return f.then(a=>n.miss(a)).then(()=>f)},set(s,r){return e[JSON.stringify(s)]=t.serializable?JSON.stringify(r):r,Promise.resolve(r)},delete(s){return delete e[JSON.stringify(s)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function L(t,e="up"){let s=Date.now();function r(){return e==="up"||Date.now()-s>k}function n(){return e==="timed out"&&Date.now()-s<=k}return{...t,status:e,lastUpdate:s,isUp:r,isTimedOut:n}}var j=class extends Error{name="AlgoliaError";constructor(t,e){super(t),e&&(this.name=e)}},J=class extends j{stackTrace;constructor(t,e,s){super(t,s),this.stackTrace=e}},Z=class extends J{constructor(t){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.",t,"RetryError")}},x=class extends J{status;constructor(t,e,s,r="ApiError"){super(t,s,r),this.status=e}},ee=class extends j{response;constructor(t,e){super(t,"DeserializationError"),this.response=e}},te=class extends x{error;constructor(t,e,s,r){super(t,e,r,"DetailedApiError"),this.error=s}};function re(t,e,s){let r=se(s),n=`${t.protocol}://${t.url}${t.port?`:${t.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return r.length&&(n+=`?${r}`),n}function se(t){return Object.keys(t).filter(e=>t[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(t[e])==="[object Array]"?t[e].join(","):t[e]).replaceAll("+","%20")}`).join("&")}function oe(t,e){if(t.method==="GET"||t.data===void 0&&e.data===void 0)return;let s=Array.isArray(t.data)?t.data:{...t.data,...e.data};return JSON.stringify(s)}function ae(t,e,s){let r={Accept:"application/json",...t,...e,...s},n={};return Object.keys(r).forEach(m=>{let f=r[m];n[m.toLowerCase()]=f}),n}function ne(t){try{return JSON.parse(t.content)}catch(e){throw new ee(e.message,t)}}function ie({content:t,status:e},s){try{let r=JSON.parse(t);return"error"in r?new te(r.message,e,r.error,s):new x(r.message,e,s)}catch{}return new x(t,e,s)}function ce({isTimedOut:t,status:e}){return!t&&~~e===0}function ue({isTimedOut:t,status:e}){return t||ce({isTimedOut:t,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function le({status:t}){return~~(t/100)===2}function me(t){return t.map(e=>$(e))}function $(t){let e=t.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...t,request:{...t.request,headers:{...t.request.headers,...e}}}}function Q({hosts:t,hostsCache:e,baseHeaders:s,baseQueryParameters:r,algoliaAgent:n,timeouts:m,requester:f,requestsCache:a,responsesCache:o}){async function i(l){let c=await Promise.all(l.map(p=>e.get(p,()=>Promise.resolve(L(p))))),P=c.filter(p=>p.isUp()),h=c.filter(p=>p.isTimedOut()),E=[...P,...h];return{hosts:E.length>0?E:l,getTimeout(p,y){return(h.length===0&&p===0?1:h.length+3+p)*y}}}async function u(l,c,P=!0){let h=[],E=oe(l,c),T=ae(s,l.headers,c.headers),p=l.method==="GET"?{...l.data,...c.data}:{},y={...r,...l.queryParameters,...p};if(n.value&&(y["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let g of Object.keys(c.queryParameters))!c.queryParameters[g]||Object.prototype.toString.call(c.queryParameters[g])==="[object Object]"?y[g]=c.queryParameters[g]:y[g]=c.queryParameters[g].toString();let w=0,N=async(g,S)=>{let R=g.pop();if(R===void 0)throw new Z(me(h));let b={...m,...c.timeouts},_={data:E,headers:T,method:l.method,url:re(R,l.path,y),connectTimeout:S(w,b.connect),responseTimeout:S(w,P?b.read:b.write)},U=B=>{let I={request:_,response:B,host:R,triesLeft:g.length};return h.push(I),I},A=await f.send(_);if(ue(A)){let B=U(A);return A.isTimedOut&&w++,console.log("Retryable failure",$(B)),await e.set(R,L(R,A.isTimedOut?"timed out":"down")),N(g,S)}if(le(A))return ne(A);throw U(A),ie(A,h)},V=t.filter(g=>g.accept==="readWrite"||(P?g.accept==="read":g.accept==="write")),D=await i(V);return N([...D.hosts].reverse(),D.getTimeout)}function d(l,c={}){let P=l.useReadTransporter||l.method==="GET";if(!P)return u(l,c,P);let h=()=>u(l,c);if((c.cacheable||l.cacheable)!==!0)return h();let T={request:l,requestOptions:c,transporter:{queryParameters:r,headers:s}};return o.get(T,()=>a.get(T,()=>a.set(T,h()).then(p=>Promise.all([a.delete(T),p]),p=>Promise.all([a.delete(T),Promise.reject(p)])).then(([p,y])=>y)),{miss:p=>o.set(T,p)})}return{hostsCache:e,requester:f,timeouts:m,algoliaAgent:n,baseHeaders:s,baseQueryParameters:r,hosts:t,request:d,requestsCache:a,responsesCache:o}}function de(t){let e={value:`Algolia for JavaScript (${t})`,add(s){let r=`; ${s.segment}${s.version!==void 0?` (${s.version})`:""}`;return e.value.indexOf(r)===-1&&(e.value=`${e.value}${r}`),e}};return e}function G({algoliaAgents:t,client:e,version:s}){let r=de(s).add({segment:e,version:s});return t.forEach(n=>r.add(n)),r}var M=1e3,z=2e3,F=3e4;function X(){function t(e){return new Promise(s=>{let r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach(a=>r.setRequestHeader(a,e.headers[a]));let n=(a,o)=>setTimeout(()=>{r.abort(),s({status:0,content:o,isTimedOut:!0})},a),m=n(e.connectTimeout,"Connection timeout"),f;r.onreadystatechange=()=>{r.readyState>r.OPENED&&f===void 0&&(clearTimeout(m),f=n(e.responseTimeout,"Socket timeout"))},r.onerror=()=>{r.status===0&&(clearTimeout(m),clearTimeout(f),s({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=()=>{clearTimeout(m),clearTimeout(f),s({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(e.data)})}return{send:t}}var v="5.3.2",C=["de","us"];function he(t){return[{url:t?"analytics.{region}.algolia.com".replace("{region}",t):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function K({appId:t,apiKey:e,authMode:s,algoliaAgents:r,region:n,...m}){let f=H(t,e,s),a=Q({hosts:he(n),...m,algoliaAgent:G({algoliaAgents:r,client:"Abtesting",version:v}),baseHeaders:{"content-type":"text/plain",...f.headers(),...m.baseHeaders},baseQueryParameters:{...f.queryParameters(),...m.baseQueryParameters}});return{transporter:a,appId:t,clearCache(){return Promise.all([a.requestsCache.clear(),a.responsesCache.clear()]).then(()=>{})},get _ua(){return a.algoliaAgent.value},addAlgoliaAgent(o,i){a.algoliaAgent.add({segment:o,version:i})},setClientApiKey({apiKey:o}){!s||s==="WithinHeaders"?a.baseHeaders["x-algolia-api-key"]=o:a.baseQueryParameters["x-algolia-api-key"]=o},addABTests(o,i){if(!o)throw new Error("Parameter `addABTestsRequest` is required when calling `addABTests`.");if(!o.name)throw new Error("Parameter `addABTestsRequest.name` is required when calling `addABTests`.");if(!o.variants)throw new Error("Parameter `addABTestsRequest.variants` is required when calling `addABTests`.");if(!o.endAt)throw new Error("Parameter `addABTestsRequest.endAt` is required when calling `addABTests`.");let c={method:"POST",path:"/2/abtests",queryParameters:{},headers:{},data:o};return a.request(c,i)},customDelete({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customDelete`.");let P={method:"DELETE",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customGet({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customGet`.");let P={method:"GET",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customPost({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPost`.");let h={method:"POST",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},customPut({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPut`.");let h={method:"PUT",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},deleteABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `deleteABTest`.");let c={method:"DELETE",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},getABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `getABTest`.");let c={method:"GET",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},listABTests({offset:o,limit:i,indexPrefix:u,indexSuffix:d}={},l=void 0){let c="/2/abtests",P={},h={};o!==void 0&&(h.offset=o.toString()),i!==void 0&&(h.limit=i.toString()),u!==void 0&&(h.indexPrefix=u.toString()),d!==void 0&&(h.indexSuffix=d.toString());let E={method:"GET",path:c,queryParameters:h,headers:P};return a.request(E,l)},scheduleABTest(o,i){if(!o)throw new Error("Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`.");if(!o.name)throw new Error("Parameter `scheduleABTestsRequest.name` is required when calling `scheduleABTest`.");if(!o.variants)throw new Error("Parameter `scheduleABTestsRequest.variants` is required when calling `scheduleABTest`.");if(!o.scheduledAt)throw new Error("Parameter `scheduleABTestsRequest.scheduledAt` is required when calling `scheduleABTest`.");if(!o.endAt)throw new Error("Parameter `scheduleABTestsRequest.endAt` is required when calling `scheduleABTest`.");let c={method:"POST",path:"/2/abtests/schedule",queryParameters:{},headers:{},data:o};return a.request(c,i)},stopABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `stopABTest`.");let c={method:"POST",path:"/2/abtests/{id}/stop".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)}}}function Ye(t,e,s,r){if(!t||typeof t!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(s&&(typeof s!="string"||!C.includes(s)))throw new Error(`\`region\` must be one of the following: ${C.join(", ")}`);return K({appId:t,apiKey:e,region:s,timeouts:{connect:M,read:z,write:F},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:q({caches:[W({key:`${v}-${t}`}),O()]}),...r})}export{Ye as abtestingClient,v as apiClientVersion}; | ||
function L(t,e,s="WithinHeaders"){let r={"x-algolia-api-key":e,"x-algolia-application-id":t};return{headers(){return s==="WithinHeaders"?r:{}},queryParameters(){return s==="WithinQueryParameters"?r:{}}}}function W(t){let e,s=`algolia-client-js-${t.key}`;function r(){return e===void 0&&(e=t.localStorage||window.localStorage),e}function n(){return JSON.parse(r().getItem(s)||"{}")}function m(a){r().setItem(s,JSON.stringify(a))}function f(){let a=t.timeToLive?t.timeToLive*1e3:null,o=n(),i=Object.fromEntries(Object.entries(o).filter(([,d])=>d.timestamp!==void 0));if(m(i),!a)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let l=new Date().getTime();return!(d.timestamp+a<l)}));m(u)}return{get(a,o,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(f(),n()[JSON.stringify(a)])).then(u=>Promise.all([u?u.value:o(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(a,o){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(a)]={timestamp:new Date().getTime(),value:o},r().setItem(s,JSON.stringify(i)),o})},delete(a){return Promise.resolve().then(()=>{let o=n();delete o[JSON.stringify(a)],r().setItem(s,JSON.stringify(o))})},clear(){return Promise.resolve().then(()=>{r().removeItem(s)})}}}function Y(){return{get(t,e,s={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,s.miss(n)])).then(([n])=>n)},set(t,e){return Promise.resolve(e)},delete(t){return Promise.resolve()},clear(){return Promise.resolve()}}}function E(t){let e=[...t.caches],s=e.shift();return s===void 0?Y():{get(r,n,m={miss:()=>Promise.resolve()}){return s.get(r,n,m).catch(()=>E({caches:e}).get(r,n,m))},set(r,n){return s.set(r,n).catch(()=>E({caches:e}).set(r,n))},delete(r){return s.delete(r).catch(()=>E({caches:e}).delete(r))},clear(){return s.clear().catch(()=>E({caches:e}).clear())}}}function O(t={serializable:!0}){let e={};return{get(s,r,n={miss:()=>Promise.resolve()}){let m=JSON.stringify(s);if(m in e)return Promise.resolve(t.serializable?JSON.parse(e[m]):e[m]);let f=r();return f.then(a=>n.miss(a)).then(()=>f)},set(s,r){return e[JSON.stringify(s)]=t.serializable?JSON.stringify(r):r,Promise.resolve(r)},delete(s){return delete e[JSON.stringify(s)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function H(t,e="up"){let s=Date.now();function r(){return e==="up"||Date.now()-s>k}function n(){return e==="timed out"&&Date.now()-s<=k}return{...t,status:e,lastUpdate:s,isUp:r,isTimedOut:n}}var $=class extends Error{name="AlgoliaError";constructor(t,e){super(t),e&&(this.name=e)}},j=class extends ${stackTrace;constructor(t,e,s){super(t,s),this.stackTrace=e}},Z=class extends j{constructor(t){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.",t,"RetryError")}},x=class extends j{status;constructor(t,e,s,r="ApiError"){super(t,s,r),this.status=e}},ee=class extends ${response;constructor(t,e){super(t,"DeserializationError"),this.response=e}},te=class extends x{error;constructor(t,e,s,r){super(t,e,r,"DetailedApiError"),this.error=s}};function re(t,e,s){let r=se(s),n=`${t.protocol}://${t.url}${t.port?`:${t.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return r.length&&(n+=`?${r}`),n}function se(t){return Object.keys(t).filter(e=>t[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(t[e])==="[object Array]"?t[e].join(","):t[e]).replaceAll("+","%20")}`).join("&")}function oe(t,e){if(t.method==="GET"||t.data===void 0&&e.data===void 0)return;let s=Array.isArray(t.data)?t.data:{...t.data,...e.data};return JSON.stringify(s)}function ae(t,e,s){let r={Accept:"application/json",...t,...e,...s},n={};return Object.keys(r).forEach(m=>{let f=r[m];n[m.toLowerCase()]=f}),n}function ne(t){try{return JSON.parse(t.content)}catch(e){throw new ee(e.message,t)}}function ie({content:t,status:e},s){try{let r=JSON.parse(t);return"error"in r?new te(r.message,e,r.error,s):new x(r.message,e,s)}catch{}return new x(t,e,s)}function ce({isTimedOut:t,status:e}){return!t&&~~e===0}function ue({isTimedOut:t,status:e}){return t||ce({isTimedOut:t,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function le({status:t}){return~~(t/100)===2}function me(t){return t.map(e=>J(e))}function J(t){let e=t.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...t,request:{...t.request,headers:{...t.request.headers,...e}}}}function Q({hosts:t,hostsCache:e,baseHeaders:s,baseQueryParameters:r,algoliaAgent:n,timeouts:m,requester:f,requestsCache:a,responsesCache:o}){async function i(l){let c=await Promise.all(l.map(p=>e.get(p,()=>Promise.resolve(H(p))))),P=c.filter(p=>p.isUp()),h=c.filter(p=>p.isTimedOut()),q=[...P,...h];return{hosts:q.length>0?q:l,getTimeout(p,y){return(h.length===0&&p===0?1:h.length+3+p)*y}}}async function u(l,c,P=!0){let h=[],q=oe(l,c),T=ae(s,l.headers,c.headers),p=l.method==="GET"?{...l.data,...c.data}:{},y={...r,...l.queryParameters,...p};if(n.value&&(y["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let g of Object.keys(c.queryParameters))!c.queryParameters[g]||Object.prototype.toString.call(c.queryParameters[g])==="[object Object]"?y[g]=c.queryParameters[g]:y[g]=c.queryParameters[g].toString();let R=0,D=async(g,S)=>{let w=g.pop();if(w===void 0)throw new Z(me(h));let B={...m,...c.timeouts},_={data:q,headers:T,method:l.method,url:re(w,l.path,y),connectTimeout:S(R,B.connect),responseTimeout:S(R,P?B.read:B.write)},I=b=>{let U={request:_,response:b,host:w,triesLeft:g.length};return h.push(U),U},A=await f.send(_);if(ue(A)){let b=I(A);return A.isTimedOut&&R++,console.log("Retryable failure",J(b)),await e.set(w,H(w,A.isTimedOut?"timed out":"down")),D(g,S)}if(le(A))return ne(A);throw I(A),ie(A,h)},V=t.filter(g=>g.accept==="readWrite"||(P?g.accept==="read":g.accept==="write")),N=await i(V);return D([...N.hosts].reverse(),N.getTimeout)}function d(l,c={}){let P=l.useReadTransporter||l.method==="GET";if(!P)return u(l,c,P);let h=()=>u(l,c);if((c.cacheable||l.cacheable)!==!0)return h();let T={request:l,requestOptions:c,transporter:{queryParameters:r,headers:s}};return o.get(T,()=>a.get(T,()=>a.set(T,h()).then(p=>Promise.all([a.delete(T),p]),p=>Promise.all([a.delete(T),Promise.reject(p)])).then(([p,y])=>y)),{miss:p=>o.set(T,p)})}return{hostsCache:e,requester:f,timeouts:m,algoliaAgent:n,baseHeaders:s,baseQueryParameters:r,hosts:t,request:d,requestsCache:a,responsesCache:o}}function de(t){let e={value:`Algolia for JavaScript (${t})`,add(s){let r=`; ${s.segment}${s.version!==void 0?` (${s.version})`:""}`;return e.value.indexOf(r)===-1&&(e.value=`${e.value}${r}`),e}};return e}function G({algoliaAgents:t,client:e,version:s}){let r=de(s).add({segment:e,version:s});return t.forEach(n=>r.add(n)),r}var M=1e3,z=2e3,F=3e4;function X(){function t(e){return new Promise(s=>{let r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach(a=>r.setRequestHeader(a,e.headers[a]));let n=(a,o)=>setTimeout(()=>{r.abort(),s({status:0,content:o,isTimedOut:!0})},a),m=n(e.connectTimeout,"Connection timeout"),f;r.onreadystatechange=()=>{r.readyState>r.OPENED&&f===void 0&&(clearTimeout(m),f=n(e.responseTimeout,"Socket timeout"))},r.onerror=()=>{r.status===0&&(clearTimeout(m),clearTimeout(f),s({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=()=>{clearTimeout(m),clearTimeout(f),s({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(e.data)})}return{send:t}}var v="5.4.0",C=["de","us"];function he(t){return[{url:t?"analytics.{region}.algolia.com".replace("{region}",t):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function K({appId:t,apiKey:e,authMode:s,algoliaAgents:r,region:n,...m}){let f=L(t,e,s),a=Q({hosts:he(n),...m,algoliaAgent:G({algoliaAgents:r,client:"Abtesting",version:v}),baseHeaders:{"content-type":"text/plain",...f.headers(),...m.baseHeaders},baseQueryParameters:{...f.queryParameters(),...m.baseQueryParameters}});return{transporter:a,appId:t,clearCache(){return Promise.all([a.requestsCache.clear(),a.responsesCache.clear()]).then(()=>{})},get _ua(){return a.algoliaAgent.value},addAlgoliaAgent(o,i){a.algoliaAgent.add({segment:o,version:i})},setClientApiKey({apiKey:o}){!s||s==="WithinHeaders"?a.baseHeaders["x-algolia-api-key"]=o:a.baseQueryParameters["x-algolia-api-key"]=o},addABTests(o,i){if(!o)throw new Error("Parameter `addABTestsRequest` is required when calling `addABTests`.");if(!o.name)throw new Error("Parameter `addABTestsRequest.name` is required when calling `addABTests`.");if(!o.variants)throw new Error("Parameter `addABTestsRequest.variants` is required when calling `addABTests`.");if(!o.endAt)throw new Error("Parameter `addABTestsRequest.endAt` is required when calling `addABTests`.");let c={method:"POST",path:"/2/abtests",queryParameters:{},headers:{},data:o};return a.request(c,i)},customDelete({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customDelete`.");let P={method:"DELETE",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customGet({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customGet`.");let P={method:"GET",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customPost({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPost`.");let h={method:"POST",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},customPut({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPut`.");let h={method:"PUT",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},deleteABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `deleteABTest`.");let c={method:"DELETE",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},getABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `getABTest`.");let c={method:"GET",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},listABTests({offset:o,limit:i,indexPrefix:u,indexSuffix:d}={},l=void 0){let c="/2/abtests",P={},h={};o!==void 0&&(h.offset=o.toString()),i!==void 0&&(h.limit=i.toString()),u!==void 0&&(h.indexPrefix=u.toString()),d!==void 0&&(h.indexSuffix=d.toString());let q={method:"GET",path:c,queryParameters:h,headers:P};return a.request(q,l)},scheduleABTest(o,i){if(!o)throw new Error("Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`.");if(!o.name)throw new Error("Parameter `scheduleABTestsRequest.name` is required when calling `scheduleABTest`.");if(!o.variants)throw new Error("Parameter `scheduleABTestsRequest.variants` is required when calling `scheduleABTest`.");if(!o.scheduledAt)throw new Error("Parameter `scheduleABTestsRequest.scheduledAt` is required when calling `scheduleABTest`.");if(!o.endAt)throw new Error("Parameter `scheduleABTestsRequest.endAt` is required when calling `scheduleABTest`.");let c={method:"POST",path:"/2/abtests/schedule",queryParameters:{},headers:{},data:o};return a.request(c,i)},stopABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `stopABTest`.");let c={method:"POST",path:"/2/abtests/{id}/stop".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)}}}function Ke(t,e,s,r){if(!t||typeof t!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(s&&(typeof s!="string"||!C.includes(s)))throw new Error(`\`region\` must be one of the following: ${C.join(", ")}`);return K({appId:t,apiKey:e,region:s,timeouts:{connect:M,read:z,write:F},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:E({caches:[W({key:`${v}-${t}`}),O()]}),...r})}export{Ke as abtestingClient,v as apiClientVersion}; | ||
//# sourceMappingURL=browser.min.js.map |
@@ -7,7 +7,7 @@ (function (global, factory) { | ||
function H(t,e,s="WithinHeaders"){let r={"x-algolia-api-key":e,"x-algolia-application-id":t};return {headers(){return s==="WithinHeaders"?r:{}},queryParameters(){return s==="WithinQueryParameters"?r:{}}}}function W(t){let e,s=`algolia-client-js-${t.key}`;function r(){return e===void 0&&(e=t.localStorage||window.localStorage),e}function n(){return JSON.parse(r().getItem(s)||"{}")}function m(a){r().setItem(s,JSON.stringify(a));}function f(){let a=t.timeToLive?t.timeToLive*1e3:null,o=n(),i=Object.fromEntries(Object.entries(o).filter(([,d])=>d.timestamp!==void 0));if(m(i),!a)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let l=new Date().getTime();return !(d.timestamp+a<l)}));m(u);}return {get(a,o,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(f(),n()[JSON.stringify(a)])).then(u=>Promise.all([u?u.value:o(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(a,o){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(a)]={timestamp:new Date().getTime(),value:o},r().setItem(s,JSON.stringify(i)),o})},delete(a){return Promise.resolve().then(()=>{let o=n();delete o[JSON.stringify(a)],r().setItem(s,JSON.stringify(o));})},clear(){return Promise.resolve().then(()=>{r().removeItem(s);})}}}function Y(){return {get(t,e,s={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,s.miss(n)])).then(([n])=>n)},set(t,e){return Promise.resolve(e)},delete(t){return Promise.resolve()},clear(){return Promise.resolve()}}}function q(t){let e=[...t.caches],s=e.shift();return s===void 0?Y():{get(r,n,m={miss:()=>Promise.resolve()}){return s.get(r,n,m).catch(()=>q({caches:e}).get(r,n,m))},set(r,n){return s.set(r,n).catch(()=>q({caches:e}).set(r,n))},delete(r){return s.delete(r).catch(()=>q({caches:e}).delete(r))},clear(){return s.clear().catch(()=>q({caches:e}).clear())}}}function O(t={serializable:!0}){let e={};return {get(s,r,n={miss:()=>Promise.resolve()}){let m=JSON.stringify(s);if(m in e)return Promise.resolve(t.serializable?JSON.parse(e[m]):e[m]);let f=r();return f.then(a=>n.miss(a)).then(()=>f)},set(s,r){return e[JSON.stringify(s)]=t.serializable?JSON.stringify(r):r,Promise.resolve(r)},delete(s){return delete e[JSON.stringify(s)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function L(t,e="up"){let s=Date.now();function r(){return e==="up"||Date.now()-s>k}function n(){return e==="timed out"&&Date.now()-s<=k}return {...t,status:e,lastUpdate:s,isUp:r,isTimedOut:n}}var j=class extends Error{name="AlgoliaError";constructor(t,e){super(t),e&&(this.name=e);}},J=class extends j{stackTrace;constructor(t,e,s){super(t,s),this.stackTrace=e;}},Z=class extends J{constructor(t){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.",t,"RetryError");}},x=class extends J{status;constructor(t,e,s,r="ApiError"){super(t,s,r),this.status=e;}},ee=class extends j{response;constructor(t,e){super(t,"DeserializationError"),this.response=e;}},te=class extends x{error;constructor(t,e,s,r){super(t,e,r,"DetailedApiError"),this.error=s;}};function re(t,e,s){let r=se(s),n=`${t.protocol}://${t.url}${t.port?`:${t.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return r.length&&(n+=`?${r}`),n}function se(t){return Object.keys(t).filter(e=>t[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(t[e])==="[object Array]"?t[e].join(","):t[e]).replaceAll("+","%20")}`).join("&")}function oe(t,e){if(t.method==="GET"||t.data===void 0&&e.data===void 0)return;let s=Array.isArray(t.data)?t.data:{...t.data,...e.data};return JSON.stringify(s)}function ae(t,e,s){let r={Accept:"application/json",...t,...e,...s},n={};return Object.keys(r).forEach(m=>{let f=r[m];n[m.toLowerCase()]=f;}),n}function ne(t){try{return JSON.parse(t.content)}catch(e){throw new ee(e.message,t)}}function ie({content:t,status:e},s){try{let r=JSON.parse(t);return "error"in r?new te(r.message,e,r.error,s):new x(r.message,e,s)}catch{}return new x(t,e,s)}function ce({isTimedOut:t,status:e}){return !t&&~~e===0}function ue({isTimedOut:t,status:e}){return t||ce({isTimedOut:t,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function le({status:t}){return ~~(t/100)===2}function me(t){return t.map(e=>$(e))}function $(t){let e=t.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...t,request:{...t.request,headers:{...t.request.headers,...e}}}}function Q({hosts:t,hostsCache:e,baseHeaders:s,baseQueryParameters:r,algoliaAgent:n,timeouts:m,requester:f,requestsCache:a,responsesCache:o}){async function i(l){let c=await Promise.all(l.map(p=>e.get(p,()=>Promise.resolve(L(p))))),P=c.filter(p=>p.isUp()),h=c.filter(p=>p.isTimedOut()),E=[...P,...h];return {hosts:E.length>0?E:l,getTimeout(p,y){return (h.length===0&&p===0?1:h.length+3+p)*y}}}async function u(l,c,P=!0){let h=[],E=oe(l,c),T=ae(s,l.headers,c.headers),p=l.method==="GET"?{...l.data,...c.data}:{},y={...r,...l.queryParameters,...p};if(n.value&&(y["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let g of Object.keys(c.queryParameters))!c.queryParameters[g]||Object.prototype.toString.call(c.queryParameters[g])==="[object Object]"?y[g]=c.queryParameters[g]:y[g]=c.queryParameters[g].toString();let w=0,N=async(g,S)=>{let R=g.pop();if(R===void 0)throw new Z(me(h));let b={...m,...c.timeouts},_={data:E,headers:T,method:l.method,url:re(R,l.path,y),connectTimeout:S(w,b.connect),responseTimeout:S(w,P?b.read:b.write)},U=B=>{let I={request:_,response:B,host:R,triesLeft:g.length};return h.push(I),I},A=await f.send(_);if(ue(A)){let B=U(A);return A.isTimedOut&&w++,console.log("Retryable failure",$(B)),await e.set(R,L(R,A.isTimedOut?"timed out":"down")),N(g,S)}if(le(A))return ne(A);throw U(A),ie(A,h)},V=t.filter(g=>g.accept==="readWrite"||(P?g.accept==="read":g.accept==="write")),D=await i(V);return N([...D.hosts].reverse(),D.getTimeout)}function d(l,c={}){let P=l.useReadTransporter||l.method==="GET";if(!P)return u(l,c,P);let h=()=>u(l,c);if((c.cacheable||l.cacheable)!==!0)return h();let T={request:l,requestOptions:c,transporter:{queryParameters:r,headers:s}};return o.get(T,()=>a.get(T,()=>a.set(T,h()).then(p=>Promise.all([a.delete(T),p]),p=>Promise.all([a.delete(T),Promise.reject(p)])).then(([p,y])=>y)),{miss:p=>o.set(T,p)})}return {hostsCache:e,requester:f,timeouts:m,algoliaAgent:n,baseHeaders:s,baseQueryParameters:r,hosts:t,request:d,requestsCache:a,responsesCache:o}}function de(t){let e={value:`Algolia for JavaScript (${t})`,add(s){let r=`; ${s.segment}${s.version!==void 0?` (${s.version})`:""}`;return e.value.indexOf(r)===-1&&(e.value=`${e.value}${r}`),e}};return e}function G({algoliaAgents:t,client:e,version:s}){let r=de(s).add({segment:e,version:s});return t.forEach(n=>r.add(n)),r}var M=1e3,z=2e3,F=3e4;function X(){function t(e){return new Promise(s=>{let r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach(a=>r.setRequestHeader(a,e.headers[a]));let n=(a,o)=>setTimeout(()=>{r.abort(),s({status:0,content:o,isTimedOut:!0});},a),m=n(e.connectTimeout,"Connection timeout"),f;r.onreadystatechange=()=>{r.readyState>r.OPENED&&f===void 0&&(clearTimeout(m),f=n(e.responseTimeout,"Socket timeout"));},r.onerror=()=>{r.status===0&&(clearTimeout(m),clearTimeout(f),s({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}));},r.onload=()=>{clearTimeout(m),clearTimeout(f),s({content:r.responseText,status:r.status,isTimedOut:!1});},r.send(e.data);})}return {send:t}}var v="5.3.2",C=["de","us"];function he(t){return [{url:t?"analytics.{region}.algolia.com".replace("{region}",t):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function K({appId:t,apiKey:e,authMode:s,algoliaAgents:r,region:n,...m}){let f=H(t,e,s),a=Q({hosts:he(n),...m,algoliaAgent:G({algoliaAgents:r,client:"Abtesting",version:v}),baseHeaders:{"content-type":"text/plain",...f.headers(),...m.baseHeaders},baseQueryParameters:{...f.queryParameters(),...m.baseQueryParameters}});return {transporter:a,appId:t,clearCache(){return Promise.all([a.requestsCache.clear(),a.responsesCache.clear()]).then(()=>{})},get _ua(){return a.algoliaAgent.value},addAlgoliaAgent(o,i){a.algoliaAgent.add({segment:o,version:i});},setClientApiKey({apiKey:o}){!s||s==="WithinHeaders"?a.baseHeaders["x-algolia-api-key"]=o:a.baseQueryParameters["x-algolia-api-key"]=o;},addABTests(o,i){if(!o)throw new Error("Parameter `addABTestsRequest` is required when calling `addABTests`.");if(!o.name)throw new Error("Parameter `addABTestsRequest.name` is required when calling `addABTests`.");if(!o.variants)throw new Error("Parameter `addABTestsRequest.variants` is required when calling `addABTests`.");if(!o.endAt)throw new Error("Parameter `addABTestsRequest.endAt` is required when calling `addABTests`.");let c={method:"POST",path:"/2/abtests",queryParameters:{},headers:{},data:o};return a.request(c,i)},customDelete({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customDelete`.");let P={method:"DELETE",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customGet({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customGet`.");let P={method:"GET",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customPost({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPost`.");let h={method:"POST",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},customPut({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPut`.");let h={method:"PUT",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},deleteABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `deleteABTest`.");let c={method:"DELETE",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},getABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `getABTest`.");let c={method:"GET",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},listABTests({offset:o,limit:i,indexPrefix:u,indexSuffix:d}={},l=void 0){let c="/2/abtests",P={},h={};o!==void 0&&(h.offset=o.toString()),i!==void 0&&(h.limit=i.toString()),u!==void 0&&(h.indexPrefix=u.toString()),d!==void 0&&(h.indexSuffix=d.toString());let E={method:"GET",path:c,queryParameters:h,headers:P};return a.request(E,l)},scheduleABTest(o,i){if(!o)throw new Error("Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`.");if(!o.name)throw new Error("Parameter `scheduleABTestsRequest.name` is required when calling `scheduleABTest`.");if(!o.variants)throw new Error("Parameter `scheduleABTestsRequest.variants` is required when calling `scheduleABTest`.");if(!o.scheduledAt)throw new Error("Parameter `scheduleABTestsRequest.scheduledAt` is required when calling `scheduleABTest`.");if(!o.endAt)throw new Error("Parameter `scheduleABTestsRequest.endAt` is required when calling `scheduleABTest`.");let c={method:"POST",path:"/2/abtests/schedule",queryParameters:{},headers:{},data:o};return a.request(c,i)},stopABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `stopABTest`.");let c={method:"POST",path:"/2/abtests/{id}/stop".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)}}}function Ye(t,e,s,r){if(!t||typeof t!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(s&&(typeof s!="string"||!C.includes(s)))throw new Error(`\`region\` must be one of the following: ${C.join(", ")}`);return K({appId:t,apiKey:e,region:s,timeouts:{connect:M,read:z,write:F},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:q({caches:[W({key:`${v}-${t}`}),O()]}),...r})} | ||
function L(t,e,s="WithinHeaders"){let r={"x-algolia-api-key":e,"x-algolia-application-id":t};return {headers(){return s==="WithinHeaders"?r:{}},queryParameters(){return s==="WithinQueryParameters"?r:{}}}}function W(t){let e,s=`algolia-client-js-${t.key}`;function r(){return e===void 0&&(e=t.localStorage||window.localStorage),e}function n(){return JSON.parse(r().getItem(s)||"{}")}function m(a){r().setItem(s,JSON.stringify(a));}function f(){let a=t.timeToLive?t.timeToLive*1e3:null,o=n(),i=Object.fromEntries(Object.entries(o).filter(([,d])=>d.timestamp!==void 0));if(m(i),!a)return;let u=Object.fromEntries(Object.entries(i).filter(([,d])=>{let l=new Date().getTime();return !(d.timestamp+a<l)}));m(u);}return {get(a,o,i={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(f(),n()[JSON.stringify(a)])).then(u=>Promise.all([u?u.value:o(),u!==void 0])).then(([u,d])=>Promise.all([u,d||i.miss(u)])).then(([u])=>u)},set(a,o){return Promise.resolve().then(()=>{let i=n();return i[JSON.stringify(a)]={timestamp:new Date().getTime(),value:o},r().setItem(s,JSON.stringify(i)),o})},delete(a){return Promise.resolve().then(()=>{let o=n();delete o[JSON.stringify(a)],r().setItem(s,JSON.stringify(o));})},clear(){return Promise.resolve().then(()=>{r().removeItem(s);})}}}function Y(){return {get(t,e,s={miss:()=>Promise.resolve()}){return e().then(n=>Promise.all([n,s.miss(n)])).then(([n])=>n)},set(t,e){return Promise.resolve(e)},delete(t){return Promise.resolve()},clear(){return Promise.resolve()}}}function E(t){let e=[...t.caches],s=e.shift();return s===void 0?Y():{get(r,n,m={miss:()=>Promise.resolve()}){return s.get(r,n,m).catch(()=>E({caches:e}).get(r,n,m))},set(r,n){return s.set(r,n).catch(()=>E({caches:e}).set(r,n))},delete(r){return s.delete(r).catch(()=>E({caches:e}).delete(r))},clear(){return s.clear().catch(()=>E({caches:e}).clear())}}}function O(t={serializable:!0}){let e={};return {get(s,r,n={miss:()=>Promise.resolve()}){let m=JSON.stringify(s);if(m in e)return Promise.resolve(t.serializable?JSON.parse(e[m]):e[m]);let f=r();return f.then(a=>n.miss(a)).then(()=>f)},set(s,r){return e[JSON.stringify(s)]=t.serializable?JSON.stringify(r):r,Promise.resolve(r)},delete(s){return delete e[JSON.stringify(s)],Promise.resolve()},clear(){return e={},Promise.resolve()}}}var k=2*60*1e3;function H(t,e="up"){let s=Date.now();function r(){return e==="up"||Date.now()-s>k}function n(){return e==="timed out"&&Date.now()-s<=k}return {...t,status:e,lastUpdate:s,isUp:r,isTimedOut:n}}var $=class extends Error{name="AlgoliaError";constructor(t,e){super(t),e&&(this.name=e);}},j=class extends ${stackTrace;constructor(t,e,s){super(t,s),this.stackTrace=e;}},Z=class extends j{constructor(t){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.",t,"RetryError");}},x=class extends j{status;constructor(t,e,s,r="ApiError"){super(t,s,r),this.status=e;}},ee=class extends ${response;constructor(t,e){super(t,"DeserializationError"),this.response=e;}},te=class extends x{error;constructor(t,e,s,r){super(t,e,r,"DetailedApiError"),this.error=s;}};function re(t,e,s){let r=se(s),n=`${t.protocol}://${t.url}${t.port?`:${t.port}`:""}/${e.charAt(0)==="/"?e.substring(1):e}`;return r.length&&(n+=`?${r}`),n}function se(t){return Object.keys(t).filter(e=>t[e]!==void 0).sort().map(e=>`${e}=${encodeURIComponent(Object.prototype.toString.call(t[e])==="[object Array]"?t[e].join(","):t[e]).replaceAll("+","%20")}`).join("&")}function oe(t,e){if(t.method==="GET"||t.data===void 0&&e.data===void 0)return;let s=Array.isArray(t.data)?t.data:{...t.data,...e.data};return JSON.stringify(s)}function ae(t,e,s){let r={Accept:"application/json",...t,...e,...s},n={};return Object.keys(r).forEach(m=>{let f=r[m];n[m.toLowerCase()]=f;}),n}function ne(t){try{return JSON.parse(t.content)}catch(e){throw new ee(e.message,t)}}function ie({content:t,status:e},s){try{let r=JSON.parse(t);return "error"in r?new te(r.message,e,r.error,s):new x(r.message,e,s)}catch{}return new x(t,e,s)}function ce({isTimedOut:t,status:e}){return !t&&~~e===0}function ue({isTimedOut:t,status:e}){return t||ce({isTimedOut:t,status:e})||~~(e/100)!==2&&~~(e/100)!==4}function le({status:t}){return ~~(t/100)===2}function me(t){return t.map(e=>J(e))}function J(t){let e=t.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...t,request:{...t.request,headers:{...t.request.headers,...e}}}}function Q({hosts:t,hostsCache:e,baseHeaders:s,baseQueryParameters:r,algoliaAgent:n,timeouts:m,requester:f,requestsCache:a,responsesCache:o}){async function i(l){let c=await Promise.all(l.map(p=>e.get(p,()=>Promise.resolve(H(p))))),P=c.filter(p=>p.isUp()),h=c.filter(p=>p.isTimedOut()),q=[...P,...h];return {hosts:q.length>0?q:l,getTimeout(p,y){return (h.length===0&&p===0?1:h.length+3+p)*y}}}async function u(l,c,P=!0){let h=[],q=oe(l,c),T=ae(s,l.headers,c.headers),p=l.method==="GET"?{...l.data,...c.data}:{},y={...r,...l.queryParameters,...p};if(n.value&&(y["x-algolia-agent"]=n.value),c&&c.queryParameters)for(let g of Object.keys(c.queryParameters))!c.queryParameters[g]||Object.prototype.toString.call(c.queryParameters[g])==="[object Object]"?y[g]=c.queryParameters[g]:y[g]=c.queryParameters[g].toString();let R=0,D=async(g,S)=>{let w=g.pop();if(w===void 0)throw new Z(me(h));let B={...m,...c.timeouts},_={data:q,headers:T,method:l.method,url:re(w,l.path,y),connectTimeout:S(R,B.connect),responseTimeout:S(R,P?B.read:B.write)},I=b=>{let U={request:_,response:b,host:w,triesLeft:g.length};return h.push(U),U},A=await f.send(_);if(ue(A)){let b=I(A);return A.isTimedOut&&R++,console.log("Retryable failure",J(b)),await e.set(w,H(w,A.isTimedOut?"timed out":"down")),D(g,S)}if(le(A))return ne(A);throw I(A),ie(A,h)},V=t.filter(g=>g.accept==="readWrite"||(P?g.accept==="read":g.accept==="write")),N=await i(V);return D([...N.hosts].reverse(),N.getTimeout)}function d(l,c={}){let P=l.useReadTransporter||l.method==="GET";if(!P)return u(l,c,P);let h=()=>u(l,c);if((c.cacheable||l.cacheable)!==!0)return h();let T={request:l,requestOptions:c,transporter:{queryParameters:r,headers:s}};return o.get(T,()=>a.get(T,()=>a.set(T,h()).then(p=>Promise.all([a.delete(T),p]),p=>Promise.all([a.delete(T),Promise.reject(p)])).then(([p,y])=>y)),{miss:p=>o.set(T,p)})}return {hostsCache:e,requester:f,timeouts:m,algoliaAgent:n,baseHeaders:s,baseQueryParameters:r,hosts:t,request:d,requestsCache:a,responsesCache:o}}function de(t){let e={value:`Algolia for JavaScript (${t})`,add(s){let r=`; ${s.segment}${s.version!==void 0?` (${s.version})`:""}`;return e.value.indexOf(r)===-1&&(e.value=`${e.value}${r}`),e}};return e}function G({algoliaAgents:t,client:e,version:s}){let r=de(s).add({segment:e,version:s});return t.forEach(n=>r.add(n)),r}var M=1e3,z=2e3,F=3e4;function X(){function t(e){return new Promise(s=>{let r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach(a=>r.setRequestHeader(a,e.headers[a]));let n=(a,o)=>setTimeout(()=>{r.abort(),s({status:0,content:o,isTimedOut:!0});},a),m=n(e.connectTimeout,"Connection timeout"),f;r.onreadystatechange=()=>{r.readyState>r.OPENED&&f===void 0&&(clearTimeout(m),f=n(e.responseTimeout,"Socket timeout"));},r.onerror=()=>{r.status===0&&(clearTimeout(m),clearTimeout(f),s({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}));},r.onload=()=>{clearTimeout(m),clearTimeout(f),s({content:r.responseText,status:r.status,isTimedOut:!1});},r.send(e.data);})}return {send:t}}var v="5.4.0",C=["de","us"];function he(t){return [{url:t?"analytics.{region}.algolia.com".replace("{region}",t):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function K({appId:t,apiKey:e,authMode:s,algoliaAgents:r,region:n,...m}){let f=L(t,e,s),a=Q({hosts:he(n),...m,algoliaAgent:G({algoliaAgents:r,client:"Abtesting",version:v}),baseHeaders:{"content-type":"text/plain",...f.headers(),...m.baseHeaders},baseQueryParameters:{...f.queryParameters(),...m.baseQueryParameters}});return {transporter:a,appId:t,clearCache(){return Promise.all([a.requestsCache.clear(),a.responsesCache.clear()]).then(()=>{})},get _ua(){return a.algoliaAgent.value},addAlgoliaAgent(o,i){a.algoliaAgent.add({segment:o,version:i});},setClientApiKey({apiKey:o}){!s||s==="WithinHeaders"?a.baseHeaders["x-algolia-api-key"]=o:a.baseQueryParameters["x-algolia-api-key"]=o;},addABTests(o,i){if(!o)throw new Error("Parameter `addABTestsRequest` is required when calling `addABTests`.");if(!o.name)throw new Error("Parameter `addABTestsRequest.name` is required when calling `addABTests`.");if(!o.variants)throw new Error("Parameter `addABTestsRequest.variants` is required when calling `addABTests`.");if(!o.endAt)throw new Error("Parameter `addABTestsRequest.endAt` is required when calling `addABTests`.");let c={method:"POST",path:"/2/abtests",queryParameters:{},headers:{},data:o};return a.request(c,i)},customDelete({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customDelete`.");let P={method:"DELETE",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customGet({path:o,parameters:i},u){if(!o)throw new Error("Parameter `path` is required when calling `customGet`.");let P={method:"GET",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{}};return a.request(P,u)},customPost({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPost`.");let h={method:"POST",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},customPut({path:o,parameters:i,body:u},d){if(!o)throw new Error("Parameter `path` is required when calling `customPut`.");let h={method:"PUT",path:"/{path}".replace("{path}",o),queryParameters:i||{},headers:{},data:u||{}};return a.request(h,d)},deleteABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `deleteABTest`.");let c={method:"DELETE",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},getABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `getABTest`.");let c={method:"GET",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)},listABTests({offset:o,limit:i,indexPrefix:u,indexSuffix:d}={},l=void 0){let c="/2/abtests",P={},h={};o!==void 0&&(h.offset=o.toString()),i!==void 0&&(h.limit=i.toString()),u!==void 0&&(h.indexPrefix=u.toString()),d!==void 0&&(h.indexSuffix=d.toString());let q={method:"GET",path:c,queryParameters:h,headers:P};return a.request(q,l)},scheduleABTest(o,i){if(!o)throw new Error("Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`.");if(!o.name)throw new Error("Parameter `scheduleABTestsRequest.name` is required when calling `scheduleABTest`.");if(!o.variants)throw new Error("Parameter `scheduleABTestsRequest.variants` is required when calling `scheduleABTest`.");if(!o.scheduledAt)throw new Error("Parameter `scheduleABTestsRequest.scheduledAt` is required when calling `scheduleABTest`.");if(!o.endAt)throw new Error("Parameter `scheduleABTestsRequest.endAt` is required when calling `scheduleABTest`.");let c={method:"POST",path:"/2/abtests/schedule",queryParameters:{},headers:{},data:o};return a.request(c,i)},stopABTest({id:o},i){if(!o)throw new Error("Parameter `id` is required when calling `stopABTest`.");let c={method:"POST",path:"/2/abtests/{id}/stop".replace("{id}",encodeURIComponent(o)),queryParameters:{},headers:{}};return a.request(c,i)}}}function Ke(t,e,s,r){if(!t||typeof t!="string")throw new Error("`appId` is missing.");if(!e||typeof e!="string")throw new Error("`apiKey` is missing.");if(s&&(typeof s!="string"||!C.includes(s)))throw new Error(`\`region\` must be one of the following: ${C.join(", ")}`);return K({appId:t,apiKey:e,region:s,timeouts:{connect:M,read:z,write:F},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:O(),requestsCache:O({serializable:!1}),hostsCache:E({caches:[W({key:`${v}-${t}`}),O()]}),...r})} | ||
exports.abtestingClient = Ye; | ||
exports.abtestingClient = Ke; | ||
exports.apiClientVersion = v; | ||
})); |
@@ -13,3 +13,3 @@ // builds/node.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common"; | ||
var apiClientVersion = "5.3.2"; | ||
var apiClientVersion = "5.4.0"; | ||
var REGIONS = ["de", "us"]; | ||
@@ -16,0 +16,0 @@ function getDefaultHosts(region) { |
@@ -429,3 +429,3 @@ import * as _algolia_client_common from '@algolia/client-common'; | ||
declare const apiClientVersion = "5.3.2"; | ||
declare const apiClientVersion = "5.4.0"; | ||
declare const REGIONS: readonly ["de", "us"]; | ||
@@ -432,0 +432,0 @@ type Region = (typeof REGIONS)[number]; |
// src/abtestingClient.ts | ||
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common"; | ||
var apiClientVersion = "5.3.2"; | ||
var apiClientVersion = "5.4.0"; | ||
var REGIONS = ["de", "us"]; | ||
@@ -5,0 +5,0 @@ function getDefaultHosts(region) { |
{ | ||
"version": "5.3.2", | ||
"version": "5.4.0", | ||
"repository": { | ||
@@ -29,2 +29,6 @@ "type": "git", | ||
}, | ||
"worker": { | ||
"types": "./dist/fetch.d.ts", | ||
"default": "./dist/builds/fetch.js" | ||
}, | ||
"default": { | ||
@@ -48,5 +52,6 @@ "types": "./dist/browser.d.ts", | ||
"dependencies": { | ||
"@algolia/client-common": "5.3.2", | ||
"@algolia/requester-browser-xhr": "5.3.2", | ||
"@algolia/requester-node-http": "5.3.2" | ||
"@algolia/client-common": "5.4.0", | ||
"@algolia/requester-browser-xhr": "5.4.0", | ||
"@algolia/requester-fetch": "5.4.0", | ||
"@algolia/requester-node-http": "5.4.0" | ||
}, | ||
@@ -53,0 +58,0 @@ "devDependencies": { |
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
422721
48
4619
4
+ Added@algolia/client-common@5.4.0(transitive)
+ Added@algolia/requester-browser-xhr@5.4.0(transitive)
+ Added@algolia/requester-fetch@5.4.0(transitive)
+ Added@algolia/requester-node-http@5.4.0(transitive)
- Removed@algolia/client-common@5.3.2(transitive)
- Removed@algolia/requester-browser-xhr@5.3.2(transitive)
- Removed@algolia/requester-node-http@5.3.2(transitive)
Updated@algolia/client-common@5.4.0