diff --git a/dist/integration/index.js b/dist/integration/index.js index c9c2f4e..64ac095 100644 --- a/dist/integration/index.js +++ b/dist/integration/index.js @@ -1 +1 @@ -(()=>{var e={818:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createFallbackableCache(e){const t=[...e.caches];const r=t.shift();if(r===undefined){return createNullCache()}return{get(e,s,a={miss:()=>Promise.resolve()}){return r.get(e,s,a).catch((()=>createFallbackableCache({caches:t}).get(e,s,a)))},set(e,s){return r.set(e,s).catch((()=>createFallbackableCache({caches:t}).set(e,s)))},delete(e){return r.delete(e).catch((()=>createFallbackableCache({caches:t}).delete(e)))},clear(){return r.clear().catch((()=>createFallbackableCache({caches:t}).clear()))}}}function createNullCache(){return{get(e,t,r={miss:()=>Promise.resolve()}){const s=t();return s.then((e=>Promise.all([e,r.miss(e)]))).then((([e])=>e))},set(e,t){return Promise.resolve(t)},delete(e){return Promise.resolve()},clear(){return Promise.resolve()}}}t.createFallbackableCache=createFallbackableCache;t.createNullCache=createNullCache},848:(e,t,r)=>{e.exports=r(818)},703:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createInMemoryCache(e={serializable:true}){let t={};return{get(r,s,a={miss:()=>Promise.resolve()}){const o=JSON.stringify(r);if(o in t){return Promise.resolve(e.serializable?JSON.parse(t[o]):t[o])}const n=s();const i=a&&a.miss||(()=>Promise.resolve());return n.then((e=>i(e))).then((()=>n))},set(r,s){t[JSON.stringify(r)]=e.serializable?JSON.stringify(s):s;return Promise.resolve(s)},delete(e){delete t[JSON.stringify(e)];return Promise.resolve()},clear(){t={};return Promise.resolve()}}}t.createInMemoryCache=createInMemoryCache},69:(e,t,r)=>{e.exports=r(703)},675:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(905);var a=r(193);var o=r(373);const createAnalyticsClient=e=>{const t=e.region||"us";const r=s.createAuth(s.AuthMode.WithinHeaders,e.appId,e.apiKey);const o=a.createTransporter({hosts:[{url:`analytics.${t}.algolia.com`}],...e,headers:{...r.headers(),...{"content-type":"application/json"},...e.headers},queryParameters:{...r.queryParameters(),...e.queryParameters}});const n=e.appId;return s.addMethods({appId:n,transporter:o},e.methods)};const addABTest=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Post,path:"2/abtests",data:t},r);const deleteABTest=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("2/abtests/%s",t)},r);const getABTest=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("2/abtests/%s",t)},r);const getABTests=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"2/abtests"},t);const stopABTest=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Post,path:s.encode("2/abtests/%s/stop",t)},r);t.addABTest=addABTest;t.createAnalyticsClient=createAnalyticsClient;t.deleteABTest=deleteABTest;t.getABTest=getABTest;t.getABTests=getABTests;t.stopABTest=stopABTest},538:(e,t,r)=>{e.exports=r(675)},526:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createAuth(e,t,r){const a={"x-algolia-api-key":r,"x-algolia-application-id":t};return{headers(){return e===s.WithinHeaders?a:{}},queryParameters(){return e===s.WithinQueryParameters?a:{}}}}function createRetryablePromise(e){let t=0;const retry=()=>{t++;return new Promise((r=>{setTimeout((()=>{r(e(retry))}),Math.min(100*t,1e3))}))};return e(retry)}function createWaitablePromise(e,t=((e,t)=>Promise.resolve())){return Object.assign(e,{wait(r){return createWaitablePromise(e.then((e=>Promise.all([t(e,r),e]))).then((e=>e[1])))}})}function shuffle(e){let t=e.length-1;for(t;t>0;t--){const r=Math.floor(Math.random()*(t+1));const s=e[t];e[t]=e[r];e[r]=s}return e}function addMethods(e,t){if(!t){return e}Object.keys(t).forEach((r=>{e[r]=t[r](e)}));return e}function encode(e,...t){let r=0;return e.replace(/%s/g,(()=>encodeURIComponent(t[r++])))}const r="4.11.0";const destroy=e=>()=>e.transporter.requester.destroy();const s={WithinQueryParameters:0,WithinHeaders:1};t.AuthMode=s;t.addMethods=addMethods;t.createAuth=createAuth;t.createRetryablePromise=createRetryablePromise;t.createWaitablePromise=createWaitablePromise;t.destroy=destroy;t.encode=encode;t.shuffle=shuffle;t.version=r},905:(e,t,r)=>{e.exports=r(526)},327:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(905);var a=r(193);var o=r(373);const createPersonalizationClient=e=>{const t=e.region||"us";const r=s.createAuth(s.AuthMode.WithinHeaders,e.appId,e.apiKey);const o=a.createTransporter({hosts:[{url:`personalization.${t}.algolia.com`}],...e,headers:{...r.headers(),...{"content-type":"application/json"},...e.headers},queryParameters:{...r.queryParameters(),...e.queryParameters}});return s.addMethods({appId:e.appId,transporter:o},e.methods)};const getPersonalizationStrategy=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/strategies/personalization"},t);const setPersonalizationStrategy=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Post,path:"1/strategies/personalization",data:t},r);t.createPersonalizationClient=createPersonalizationClient;t.getPersonalizationStrategy=getPersonalizationStrategy;t.setPersonalizationStrategy=setPersonalizationStrategy},762:(e,t,r)=>{e.exports=r(327)},102:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(905);var a=r(193);var o=r(373);var n=r(417);function createBrowsablePromise(e){const browse=t=>e.request(t).then((r=>{if(e.batch!==undefined){e.batch(r.hits)}if(e.shouldStop(r)){return undefined}if(r.cursor){return browse({cursor:r.cursor})}return browse({page:(t.page||0)+1})}));return browse({})}const createSearchClient=e=>{const t=e.appId;const r=s.createAuth(e.authMode!==undefined?e.authMode:s.AuthMode.WithinHeaders,t,e.apiKey);const o=a.createTransporter({hosts:[{url:`${t}-dsn.algolia.net`,accept:a.CallEnum.Read},{url:`${t}.algolia.net`,accept:a.CallEnum.Write}].concat(s.shuffle([{url:`${t}-1.algolianet.com`},{url:`${t}-2.algolianet.com`},{url:`${t}-3.algolianet.com`}])),...e,headers:{...r.headers(),...{"content-type":"application/x-www-form-urlencoded"},...e.headers},queryParameters:{...r.queryParameters(),...e.queryParameters}});const n={transporter:o,appId:t,addAlgoliaAgent(e,t){o.userAgent.add({segment:e,version:t})},clearCache(){return Promise.all([o.requestsCache.clear(),o.responsesCache.clear()]).then((()=>undefined))}};return s.addMethods(n,e.methods)};function createMissingObjectIDError(){return{name:"MissingObjectIDError",message:"All objects must have an unique objectID "+"(like a primary key) to be valid. "+"Algolia is also able to generate objectIDs "+"automatically but *it's not recommended*. "+"To do it, use the `{'autoGenerateObjectIDIfNotExist': true}` option."}}function createObjectNotFoundError(){return{name:"ObjectNotFoundError",message:"Object not found."}}function createValidUntilNotFoundError(){return{name:"ValidUntilNotFoundError",message:"ValidUntil not found in given secured api key."}}const addApiKey=e=>(t,r)=>{const{queryParameters:a,...n}=r||{};const i={acl:t,...a!==undefined?{queryParameters:a}:{}};const wait=(t,r)=>s.createRetryablePromise((s=>getApiKey(e)(t.key,r).catch((e=>{if(e.status!==404){throw e}return s()}))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:"1/keys",data:i},n),wait)};const assignUserID=e=>(t,r,s)=>{const n=a.createMappedRequestOptions(s);n.queryParameters["X-Algolia-User-ID"]=t;return e.transporter.write({method:o.MethodEnum.Post,path:"1/clusters/mapping",data:{cluster:r}},n)};const assignUserIDs=e=>(t,r,s)=>e.transporter.write({method:o.MethodEnum.Post,path:"1/clusters/mapping/batch",data:{users:t,cluster:r}},s);const clearDictionaryEntries=e=>(t,r)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:true,requests:{action:"addEntry",body:[]}}},r),((t,r)=>waitAppTask(e)(t.taskID,r)));const copyIndex=e=>(t,r,a)=>{const wait=(r,s)=>initIndex(e)(t,{methods:{waitTask:waitTask}}).waitTask(r.taskID,s);return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/operation",t),data:{operation:"copy",destination:r}},a),wait)};const copyRules=e=>(t,r,s)=>copyIndex(e)(t,r,{...s,scope:[d.Rules]});const copySettings=e=>(t,r,s)=>copyIndex(e)(t,r,{...s,scope:[d.Settings]});const copySynonyms=e=>(t,r,s)=>copyIndex(e)(t,r,{...s,scope:[d.Synonyms]});const customRequest=e=>(t,r)=>{if(t.method===o.MethodEnum.Get){return e.transporter.read(t,r)}return e.transporter.write(t,r)};const deleteApiKey=e=>(t,r)=>{const wait=(r,a)=>s.createRetryablePromise((r=>getApiKey(e)(t,a).then(r).catch((e=>{if(e.status!==404){throw e}}))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/keys/%s",t)},r),wait)};const deleteDictionaryEntries=e=>(t,r,a)=>{const n=r.map((e=>({action:"deleteEntry",body:{objectID:e}})));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:false,requests:n}},a),((t,r)=>waitAppTask(e)(t.taskID,r)))};const generateSecuredApiKey=()=>(e,t)=>{const r=a.serializeQueryParameters(t);const s=n.createHmac("sha256",e).update(r).digest("hex");return Buffer.from(s+r).toString("base64")};const getApiKey=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/keys/%s",t)},r);const getDictionarySettings=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"/1/dictionaries/*/settings"},t);const getLogs=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/logs"},t);const getSecuredApiKeyRemainingValidity=()=>e=>{const t=Buffer.from(e,"base64").toString("ascii");const r=/validUntil=(\d+)/;const s=t.match(r);if(s===null){throw createValidUntilNotFoundError()}return parseInt(s[1],10)-Math.round((new Date).getTime()/1e3)};const getTopUserIDs=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters/mapping/top"},t);const getAppTask=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/task/%s",t.toString())},r);const getUserID=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/clusters/mapping/%s",t)},r);const hasPendingMappings=e=>t=>{const{retrieveMappings:r,...s}=t||{};if(r===true){s.getClusters=true}return e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters/mapping/pending"},s)};const initIndex=e=>(t,r={})=>{const a={transporter:e.transporter,appId:e.appId,indexName:t};return s.addMethods(a,r.methods)};const listApiKeys=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/keys"},t);const listClusters=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters"},t);const listIndices=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/indexes"},t);const listUserIDs=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters/mapping"},t);const moveIndex=e=>(t,r,a)=>{const wait=(r,s)=>initIndex(e)(t,{methods:{waitTask:waitTask}}).waitTask(r.taskID,s);return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/operation",t),data:{operation:"move",destination:r}},a),wait)};const multipleBatch=e=>(t,r)=>{const wait=(t,r)=>Promise.all(Object.keys(t.taskID).map((s=>initIndex(e)(s,{methods:{waitTask:waitTask}}).waitTask(t.taskID[s],r))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:"1/indexes/*/batch",data:{requests:t}},r),wait)};const multipleGetObjects=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:t}},r);const multipleQueries=e=>(t,r)=>{const s=t.map((e=>({...e,params:a.serializeQueryParameters(e.params||{})})));return e.transporter.read({method:o.MethodEnum.Post,path:"1/indexes/*/queries",data:{requests:s},cacheable:true},r)};const multipleSearchForFacetValues=e=>(t,r)=>Promise.all(t.map((t=>{const{facetName:s,facetQuery:a,...o}=t.params;return initIndex(e)(t.indexName,{methods:{searchForFacetValues:searchForFacetValues}}).searchForFacetValues(s,a,{...r,...o})})));const removeUserID=e=>(t,r)=>{const s=a.createMappedRequestOptions(r);s.queryParameters["X-Algolia-User-ID"]=t;return e.transporter.write({method:o.MethodEnum.Delete,path:"1/clusters/mapping"},s)};const replaceDictionaryEntries=e=>(t,r,a)=>{const n=r.map((e=>({action:"addEntry",body:e})));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:true,requests:n}},a),((t,r)=>waitAppTask(e)(t.taskID,r)))};const restoreApiKey=e=>(t,r)=>{const wait=(r,a)=>s.createRetryablePromise((r=>getApiKey(e)(t,a).catch((e=>{if(e.status!==404){throw e}return r()}))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/keys/%s/restore",t)},r),wait)};const saveDictionaryEntries=e=>(t,r,a)=>{const n=r.map((e=>({action:"addEntry",body:e})));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:false,requests:n}},a),((t,r)=>waitAppTask(e)(t.taskID,r)))};const searchDictionaryEntries=e=>(t,r,a)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/search",t),data:{query:r},cacheable:true},a);const searchUserIDs=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:"1/clusters/mapping/search",data:{query:t}},r);const setDictionarySettings=e=>(t,r)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Put,path:"/1/dictionaries/*/settings",data:t},r),((t,r)=>waitAppTask(e)(t.taskID,r)));const updateApiKey=e=>(t,r)=>{const a=Object.assign({},r);const{queryParameters:n,...i}=r||{};const c=n?{queryParameters:n}:{};const d=["acl","indexes","referers","restrictSources","queryParameters","description","maxQueriesPerIPPerHour","maxHitsPerQuery"];const hasChanged=e=>Object.keys(a).filter((e=>d.indexOf(e)!==-1)).every((t=>e[t]===a[t]));const wait=(r,a)=>s.createRetryablePromise((r=>getApiKey(e)(t,a).then((e=>hasChanged(e)?Promise.resolve():r()))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Put,path:s.encode("1/keys/%s",t),data:c},i),wait)};const waitAppTask=e=>(t,r)=>s.createRetryablePromise((s=>getAppTask(e)(t,r).then((e=>e.status!=="published"?s():undefined))));const batch=e=>(t,r)=>{const wait=(t,r)=>waitTask(e)(t.taskID,r);return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/batch",e.indexName),data:{requests:t}},r),wait)};const browseObjects=e=>t=>createBrowsablePromise({shouldStop:e=>e.cursor===undefined,...t,request:r=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/browse",e.indexName),data:r},t)});const browseRules=e=>t=>{const r={hitsPerPage:1e3,...t};return createBrowsablePromise({shouldStop:e=>e.hits.length({...e,hits:e.hits.map((e=>{delete e._highlightResult;return e}))})))}})};const browseSynonyms=e=>t=>{const r={hitsPerPage:1e3,...t};return createBrowsablePromise({shouldStop:e=>e.hits.length({...e,hits:e.hits.map((e=>{delete e._highlightResult;return e}))})))}})};const chunkedBatch=e=>(t,r,a)=>{const{batchSize:o,...n}=a||{};const i={taskIDs:[],objectIDs:[]};const forEachBatch=(s=0)=>{const a=[];let c;for(c=s;c({action:r,body:e}))),n).then((e=>{i.objectIDs=i.objectIDs.concat(e.objectIDs);i.taskIDs.push(e.taskID);c++;return forEachBatch(c)}))};return s.createWaitablePromise(forEachBatch(),((t,r)=>Promise.all(t.taskIDs.map((t=>waitTask(e)(t,r))))))};const clearObjects=e=>t=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/clear",e.indexName)},t),((t,r)=>waitTask(e)(t.taskID,r)));const clearRules=e=>t=>{const{forwardToReplicas:r,...n}=t||{};const i=a.createMappedRequestOptions(n);if(r){i.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/rules/clear",e.indexName)},i),((t,r)=>waitTask(e)(t.taskID,r)))};const clearSynonyms=e=>t=>{const{forwardToReplicas:r,...n}=t||{};const i=a.createMappedRequestOptions(n);if(r){i.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/synonyms/clear",e.indexName)},i),((t,r)=>waitTask(e)(t.taskID,r)))};const deleteBy=e=>(t,r)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/deleteByQuery",e.indexName),data:t},r),((t,r)=>waitTask(e)(t.taskID,r)));const deleteIndex=e=>t=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/indexes/%s",e.indexName)},t),((t,r)=>waitTask(e)(t.taskID,r)));const deleteObject=e=>(t,r)=>s.createWaitablePromise(deleteObjects(e)([t],r).then((e=>({taskID:e.taskIDs[0]}))),((t,r)=>waitTask(e)(t.taskID,r)));const deleteObjects=e=>(t,r)=>{const s=t.map((e=>({objectID:e})));return chunkedBatch(e)(s,c.DeleteObject,r)};const deleteRule=e=>(t,r)=>{const{forwardToReplicas:n,...i}=r||{};const c=a.createMappedRequestOptions(i);if(n){c.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/indexes/%s/rules/%s",e.indexName,t)},c),((t,r)=>waitTask(e)(t.taskID,r)))};const deleteSynonym=e=>(t,r)=>{const{forwardToReplicas:n,...i}=r||{};const c=a.createMappedRequestOptions(i);if(n){c.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/indexes/%s/synonyms/%s",e.indexName,t)},c),((t,r)=>waitTask(e)(t.taskID,r)))};const exists=e=>t=>getSettings(e)(t).then((()=>true)).catch((e=>{if(e.status!==404){throw e}return false}));const findAnswers=e=>(t,r,a)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/answers/%s/prediction",e.indexName),data:{query:t,queryLanguages:r},cacheable:true},a);const findObject=e=>(t,r)=>{const{query:s,paginate:a,...o}=r||{};let n=0;const forEachPage=()=>search(e)(s||"",{...o,page:n}).then((e=>{for(const[r,s]of Object.entries(e.hits)){if(t(s)){return{object:s,position:parseInt(r,10),page:n}}}n++;if(a===false||n>=e.nbPages){throw createObjectNotFoundError()}return forEachPage()}));return forEachPage()};const getObject=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/%s",e.indexName,t)},r);const getObjectPosition=()=>(e,t)=>{for(const[r,s]of Object.entries(e.hits)){if(s.objectID===t){return parseInt(r,10)}}return-1};const getObjects=e=>(t,r)=>{const{attributesToRetrieve:s,...a}=r||{};const n=t.map((t=>({indexName:e.indexName,objectID:t,...s?{attributesToRetrieve:s}:{}})));return e.transporter.read({method:o.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:n}},a)};const getRule=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/rules/%s",e.indexName,t)},r);const getSettings=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/settings",e.indexName),data:{getVersion:2}},t);const getSynonym=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode(`1/indexes/%s/synonyms/%s`,e.indexName,t)},r);const getTask=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/task/%s",e.indexName,t.toString())},r);const partialUpdateObject=e=>(t,r)=>s.createWaitablePromise(partialUpdateObjects(e)([t],r).then((e=>({objectID:e.objectIDs[0],taskID:e.taskIDs[0]}))),((t,r)=>waitTask(e)(t.taskID,r)));const partialUpdateObjects=e=>(t,r)=>{const{createIfNotExists:s,...a}=r||{};const o=s?c.PartialUpdateObject:c.PartialUpdateObjectNoCreate;return chunkedBatch(e)(t,o,a)};const replaceAllObjects=e=>(t,r)=>{const{safe:a,autoGenerateObjectIDIfNotExist:n,batchSize:i,...c}=r||{};const operation=(t,r,a,n)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/operation",t),data:{operation:a,destination:r}},n),((t,r)=>waitTask(e)(t.taskID,r)));const d=Math.random().toString(36).substring(7);const u=`${e.indexName}_tmp_${d}`;const l=saveObjects({appId:e.appId,transporter:e.transporter,indexName:u});let p=[];const h=operation(e.indexName,u,"copy",{...c,scope:["settings","synonyms","rules"]});p.push(h);const m=(a?h.wait(c):h).then((()=>{const e=l(t,{...c,autoGenerateObjectIDIfNotExist:n,batchSize:i});p.push(e);return a?e.wait(c):e})).then((()=>{const t=operation(u,e.indexName,"move",c);p.push(t);return a?t.wait(c):t})).then((()=>Promise.all(p))).then((([e,t,r])=>({objectIDs:t.objectIDs,taskIDs:[e.taskID,...t.taskIDs,r.taskID]})));return s.createWaitablePromise(m,((e,t)=>Promise.all(p.map((e=>e.wait(t))))))};const replaceAllRules=e=>(t,r)=>saveRules(e)(t,{...r,clearExistingRules:true});const replaceAllSynonyms=e=>(t,r)=>saveSynonyms(e)(t,{...r,clearExistingSynonyms:true});const saveObject=e=>(t,r)=>s.createWaitablePromise(saveObjects(e)([t],r).then((e=>({objectID:e.objectIDs[0],taskID:e.taskIDs[0]}))),((t,r)=>waitTask(e)(t.taskID,r)));const saveObjects=e=>(t,r)=>{const{autoGenerateObjectIDIfNotExist:a,...o}=r||{};const n=a?c.AddObject:c.UpdateObject;if(n===c.UpdateObject){for(const e of t){if(e.objectID===undefined){return s.createWaitablePromise(Promise.reject(createMissingObjectIDError()))}}}return chunkedBatch(e)(t,n,o)};const saveRule=e=>(t,r)=>saveRules(e)([t],r);const saveRules=e=>(t,r)=>{const{forwardToReplicas:n,clearExistingRules:i,...c}=r||{};const d=a.createMappedRequestOptions(c);if(n){d.queryParameters.forwardToReplicas=1}if(i){d.queryParameters.clearExistingRules=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/rules/batch",e.indexName),data:t},d),((t,r)=>waitTask(e)(t.taskID,r)))};const saveSynonym=e=>(t,r)=>saveSynonyms(e)([t],r);const saveSynonyms=e=>(t,r)=>{const{forwardToReplicas:n,clearExistingSynonyms:i,replaceExistingSynonyms:c,...d}=r||{};const u=a.createMappedRequestOptions(d);if(n){u.queryParameters.forwardToReplicas=1}if(c||i){u.queryParameters.replaceExistingSynonyms=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/synonyms/batch",e.indexName),data:t},u),((t,r)=>waitTask(e)(t.taskID,r)))};const search=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/query",e.indexName),data:{query:t},cacheable:true},r);const searchForFacetValues=e=>(t,r,a)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/facets/%s/query",e.indexName,t),data:{facetQuery:r},cacheable:true},a);const searchRules=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/rules/search",e.indexName),data:{query:t}},r);const searchSynonyms=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/synonyms/search",e.indexName),data:{query:t}},r);const setSettings=e=>(t,r)=>{const{forwardToReplicas:n,...i}=r||{};const c=a.createMappedRequestOptions(i);if(n){c.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Put,path:s.encode("1/indexes/%s/settings",e.indexName),data:t},c),((t,r)=>waitTask(e)(t.taskID,r)))};const waitTask=e=>(t,r)=>s.createRetryablePromise((s=>getTask(e)(t,r).then((e=>e.status!=="published"?s():undefined))));const i={AddObject:"addObject",Analytics:"analytics",Browser:"browse",DeleteIndex:"deleteIndex",DeleteObject:"deleteObject",EditSettings:"editSettings",ListIndexes:"listIndexes",Logs:"logs",Personalization:"personalization",Recommendation:"recommendation",Search:"search",SeeUnretrievableAttributes:"seeUnretrievableAttributes",Settings:"settings",Usage:"usage"};const c={AddObject:"addObject",UpdateObject:"updateObject",PartialUpdateObject:"partialUpdateObject",PartialUpdateObjectNoCreate:"partialUpdateObjectNoCreate",DeleteObject:"deleteObject",DeleteIndex:"delete",ClearIndex:"clear"};const d={Settings:"settings",Synonyms:"synonyms",Rules:"rules"};const u={None:"none",StopIfEnoughMatches:"stopIfEnoughMatches"};const l={Synonym:"synonym",OneWaySynonym:"oneWaySynonym",AltCorrection1:"altCorrection1",AltCorrection2:"altCorrection2",Placeholder:"placeholder"};t.ApiKeyACLEnum=i;t.BatchActionEnum=c;t.ScopeEnum=d;t.StrategyEnum=u;t.SynonymEnum=l;t.addApiKey=addApiKey;t.assignUserID=assignUserID;t.assignUserIDs=assignUserIDs;t.batch=batch;t.browseObjects=browseObjects;t.browseRules=browseRules;t.browseSynonyms=browseSynonyms;t.chunkedBatch=chunkedBatch;t.clearDictionaryEntries=clearDictionaryEntries;t.clearObjects=clearObjects;t.clearRules=clearRules;t.clearSynonyms=clearSynonyms;t.copyIndex=copyIndex;t.copyRules=copyRules;t.copySettings=copySettings;t.copySynonyms=copySynonyms;t.createBrowsablePromise=createBrowsablePromise;t.createMissingObjectIDError=createMissingObjectIDError;t.createObjectNotFoundError=createObjectNotFoundError;t.createSearchClient=createSearchClient;t.createValidUntilNotFoundError=createValidUntilNotFoundError;t.customRequest=customRequest;t.deleteApiKey=deleteApiKey;t.deleteBy=deleteBy;t.deleteDictionaryEntries=deleteDictionaryEntries;t.deleteIndex=deleteIndex;t.deleteObject=deleteObject;t.deleteObjects=deleteObjects;t.deleteRule=deleteRule;t.deleteSynonym=deleteSynonym;t.exists=exists;t.findAnswers=findAnswers;t.findObject=findObject;t.generateSecuredApiKey=generateSecuredApiKey;t.getApiKey=getApiKey;t.getAppTask=getAppTask;t.getDictionarySettings=getDictionarySettings;t.getLogs=getLogs;t.getObject=getObject;t.getObjectPosition=getObjectPosition;t.getObjects=getObjects;t.getRule=getRule;t.getSecuredApiKeyRemainingValidity=getSecuredApiKeyRemainingValidity;t.getSettings=getSettings;t.getSynonym=getSynonym;t.getTask=getTask;t.getTopUserIDs=getTopUserIDs;t.getUserID=getUserID;t.hasPendingMappings=hasPendingMappings;t.initIndex=initIndex;t.listApiKeys=listApiKeys;t.listClusters=listClusters;t.listIndices=listIndices;t.listUserIDs=listUserIDs;t.moveIndex=moveIndex;t.multipleBatch=multipleBatch;t.multipleGetObjects=multipleGetObjects;t.multipleQueries=multipleQueries;t.multipleSearchForFacetValues=multipleSearchForFacetValues;t.partialUpdateObject=partialUpdateObject;t.partialUpdateObjects=partialUpdateObjects;t.removeUserID=removeUserID;t.replaceAllObjects=replaceAllObjects;t.replaceAllRules=replaceAllRules;t.replaceAllSynonyms=replaceAllSynonyms;t.replaceDictionaryEntries=replaceDictionaryEntries;t.restoreApiKey=restoreApiKey;t.saveDictionaryEntries=saveDictionaryEntries;t.saveObject=saveObject;t.saveObjects=saveObjects;t.saveRule=saveRule;t.saveRules=saveRules;t.saveSynonym=saveSynonym;t.saveSynonyms=saveSynonyms;t.search=search;t.searchDictionaryEntries=searchDictionaryEntries;t.searchForFacetValues=searchForFacetValues;t.searchRules=searchRules;t.searchSynonyms=searchSynonyms;t.searchUserIDs=searchUserIDs;t.setDictionarySettings=setDictionarySettings;t.setSettings=setSettings;t.updateApiKey=updateApiKey;t.waitAppTask=waitAppTask;t.waitTask=waitTask},425:(e,t,r)=>{e.exports=r(102)},242:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createNullLogger(){return{debug(e,t){return Promise.resolve()},info(e,t){return Promise.resolve()},error(e,t){return Promise.resolve()}}}const r={Debug:1,Info:2,Error:3};t.LogLevelEnum=r;t.createNullLogger=createNullLogger},564:(e,t,r)=>{e.exports=r(242)},721:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});const r={Delete:"DELETE",Get:"GET",Post:"POST",Put:"PUT"};t.MethodEnum=r},373:(e,t,r)=>{e.exports=r(721)},437:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(605);var a=r(211);var o=r(835);const n={keepAlive:true};const i=new s.Agent(n);const c=new a.Agent(n);function createNodeHttpRequester({agent:e,httpAgent:t,httpsAgent:r,requesterOptions:n={}}={}){const d=t||e||i;const u=r||e||c;return{send(e){return new Promise((t=>{const r=o.parse(e.url);const i=r.query===null?r.pathname:`${r.pathname}?${r.query}`;const c={...n,agent:r.protocol==="https:"?u:d,hostname:r.hostname,path:i,method:e.method,headers:{...n&&n.headers?n.headers:{},...e.headers},...r.port!==undefined?{port:r.port||""}:{}};const l=(r.protocol==="https:"?a:s).request(c,(e=>{let r=[];e.on("data",(e=>{r=r.concat(e)}));e.on("end",(()=>{clearTimeout(p);clearTimeout(h);t({status:e.statusCode||0,content:Buffer.concat(r).toString(),isTimedOut:false})}))}));const createTimeout=(e,r)=>setTimeout((()=>{l.abort();t({status:0,content:r,isTimedOut:true})}),e*1e3);const p=createTimeout(e.connectTimeout,"Connection timeout");let h;l.on("error",(e=>{clearTimeout(p);clearTimeout(h);t({status:0,content:e.message,isTimedOut:false})}));l.once("response",(()=>{clearTimeout(p);h=createTimeout(e.responseTimeout,"Socket timeout")}));if(e.data!==undefined){l.write(e.data)}l.end()}))},destroy(){d.destroy();u.destroy();return Promise.resolve()}}}t.createNodeHttpRequester=createNodeHttpRequester},724:(e,t,r)=>{e.exports=r(437)},56:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(373);function createMappedRequestOptions(e,t){const r=e||{};const s=r.data||{};Object.keys(r).forEach((e=>{if(["timeout","headers","queryParameters","data","cacheable"].indexOf(e)===-1){s[e]=r[e]}}));return{data:Object.entries(s).length>0?s:undefined,timeout:r.timeout||t,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}const a={Read:1,Write:2,Any:3};const o={Up:1,Down:2,Timeouted:3};const n=2*60*1e3;function createStatefulHost(e,t=o.Up){return{...e,status:t,lastUpdate:Date.now()}}function isStatefulHostUp(e){return e.status===o.Up||Date.now()-e.lastUpdate>n}function isStatefulHostTimeouted(e){return e.status===o.Timeouted&&Date.now()-e.lastUpdate<=n}function createStatelessHost(e){if(typeof e==="string"){return{protocol:"https",url:e,accept:a.Any}}return{protocol:e.protocol||"https",url:e.url,accept:e.accept||a.Any}}function createRetryableOptions(e,t){return Promise.all(t.map((t=>e.get(t,(()=>Promise.resolve(createStatefulHost(t))))))).then((e=>{const r=e.filter((e=>isStatefulHostUp(e)));const s=e.filter((e=>isStatefulHostTimeouted(e)));const a=[...r,...s];const o=a.length>0?a.map((e=>createStatelessHost(e))):t;return{getTimeout(e,t){const r=s.length===0&&e===0?1:s.length+3+e;return r*t},statelessHosts:o}}))}const isNetworkError=({isTimedOut:e,status:t})=>!e&&~~t===0;const isRetryable=e=>{const t=e.status;const r=e.isTimedOut;return r||isNetworkError(e)||~~(t/100)!==2&&~~(t/100)!==4};const isSuccess=({status:e})=>~~(e/100)===2;const retryDecision=(e,t)=>{if(isRetryable(e)){return t.onRetry(e)}if(isSuccess(e)){return t.onSuccess(e)}return t.onFail(e)};function retryableRequest(e,t,r,a){const n=[];const i=serializeData(r,a);const c=serializeHeaders(e,a);const d=r.method;const u=r.method!==s.MethodEnum.Get?{}:{...r.data,...a.data};const l={"x-algolia-agent":e.userAgent.value,...e.queryParameters,...u,...a.queryParameters};let p=0;const retry=(t,s)=>{const u=t.pop();if(u===undefined){throw createRetryError(stackTraceWithoutCredentials(n))}const h={data:i,headers:c,method:d,url:serializeUrl(u,r.path,l),connectTimeout:s(p,e.timeouts.connect),responseTimeout:s(p,a.timeout)};const pushToStackTrace=e=>{const r={request:h,response:e,host:u,triesLeft:t.length};n.push(r);return r};const m={onSuccess:e=>deserializeSuccess(e),onRetry(r){const a=pushToStackTrace(r);if(r.isTimedOut){p++}return Promise.all([e.logger.info("Retryable failure",stackFrameWithoutCredentials(a)),e.hostsCache.set(u,createStatefulHost(u,r.isTimedOut?o.Timeouted:o.Down))]).then((()=>retry(t,s)))},onFail(e){pushToStackTrace(e);throw deserializeFailure(e,stackTraceWithoutCredentials(n))}};return e.requester.send(h).then((e=>retryDecision(e,m)))};return createRetryableOptions(e.hostsCache,t).then((e=>retry([...e.statelessHosts].reverse(),e.getTimeout)))}function createTransporter(e){const{hostsCache:t,logger:r,requester:s,requestsCache:o,responsesCache:n,timeouts:i,userAgent:c,hosts:d,queryParameters:u,headers:l}=e;const p={hostsCache:t,logger:r,requester:s,requestsCache:o,responsesCache:n,timeouts:i,userAgent:c,headers:l,queryParameters:u,hosts:d.map((e=>createStatelessHost(e))),read(e,t){const r=createMappedRequestOptions(t,p.timeouts.read);const createRetryableRequest=()=>retryableRequest(p,p.hosts.filter((e=>(e.accept&a.Read)!==0)),e,r);const s=r.cacheable!==undefined?r.cacheable:e.cacheable;if(s!==true){return createRetryableRequest()}const o={request:e,mappedRequestOptions:r,transporter:{queryParameters:p.queryParameters,headers:p.headers}};return p.responsesCache.get(o,(()=>p.requestsCache.get(o,(()=>p.requestsCache.set(o,createRetryableRequest()).then((e=>Promise.all([p.requestsCache.delete(o),e])),(e=>Promise.all([p.requestsCache.delete(o),Promise.reject(e)]))).then((([e,t])=>t))))),{miss:e=>p.responsesCache.set(o,e)})},write(e,t){return retryableRequest(p,p.hosts.filter((e=>(e.accept&a.Write)!==0)),e,createMappedRequestOptions(t,p.timeouts.write))}};return p}function createUserAgent(e){const t={value:`Algolia for JavaScript (${e})`,add(e){const r=`; ${e.segment}${e.version!==undefined?` (${e.version})`:""}`;if(t.value.indexOf(r)===-1){t.value=`${t.value}${r}`}return t}};return t}function deserializeSuccess(e){try{return JSON.parse(e.content)}catch(t){throw createDeserializationError(t.message,e)}}function deserializeFailure({content:e,status:t},r){let s=e;try{s=JSON.parse(e).message}catch(e){}return createApiError(s,t,r)}function encode(e,...t){let r=0;return e.replace(/%s/g,(()=>encodeURIComponent(t[r++])))}function serializeUrl(e,t,r){const s=serializeQueryParameters(r);let a=`${e.protocol}://${e.url}/${t.charAt(0)==="/"?t.substr(1):t}`;if(s.length){a+=`?${s}`}return a}function serializeQueryParameters(e){const isObjectOrArray=e=>Object.prototype.toString.call(e)==="[object Object]"||Object.prototype.toString.call(e)==="[object Array]";return Object.keys(e).map((t=>encode("%s=%s",t,isObjectOrArray(e[t])?JSON.stringify(e[t]):e[t]))).join("&")}function serializeData(e,t){if(e.method===s.MethodEnum.Get||e.data===undefined&&t.data===undefined){return undefined}const r=Array.isArray(e.data)?e.data:{...e.data,...t.data};return JSON.stringify(r)}function serializeHeaders(e,t){const r={...e.headers,...t.headers};const s={};Object.keys(r).forEach((e=>{const t=r[e];s[e.toLowerCase()]=t}));return s}function stackTraceWithoutCredentials(e){return e.map((e=>stackFrameWithoutCredentials(e)))}function stackFrameWithoutCredentials(e){const t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...e,request:{...e.request,headers:{...e.request.headers,...t}}}}function createApiError(e,t,r){return{name:"ApiError",message:e,status:t,transporterStackTrace:r}}function createDeserializationError(e,t){return{name:"DeserializationError",message:e,response:t}}function createRetryError(e){return{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:e}}t.CallEnum=a;t.HostStatusEnum=o;t.createApiError=createApiError;t.createDeserializationError=createDeserializationError;t.createMappedRequestOptions=createMappedRequestOptions;t.createRetryError=createRetryError;t.createStatefulHost=createStatefulHost;t.createStatelessHost=createStatelessHost;t.createTransporter=createTransporter;t.createUserAgent=createUserAgent;t.deserializeFailure=deserializeFailure;t.deserializeSuccess=deserializeSuccess;t.isStatefulHostTimeouted=isStatefulHostTimeouted;t.isStatefulHostUp=isStatefulHostUp;t.serializeData=serializeData;t.serializeHeaders=serializeHeaders;t.serializeQueryParameters=serializeQueryParameters;t.serializeUrl=serializeUrl;t.stackFrameWithoutCredentials=stackFrameWithoutCredentials;t.stackTraceWithoutCredentials=stackTraceWithoutCredentials},193:(e,t,r)=>{e.exports=r(56)},447:(e,t,r)=>{"use strict";var s=r(848);var a=r(69);var o=r(538);var n=r(905);var i=r(762);var c=r(425);var d=r(564);var u=r(724);var l=r(193);function algoliasearch(e,t,r){const p={appId:e,apiKey:t,timeouts:{connect:2,read:5,write:30},requester:u.createNodeHttpRequester(),logger:d.createNullLogger(),responsesCache:s.createNullCache(),requestsCache:s.createNullCache(),hostsCache:a.createInMemoryCache(),userAgent:l.createUserAgent(n.version).add({segment:"Node.js",version:process.versions.node})};const h={...p,...r};const initPersonalization=()=>e=>i.createPersonalizationClient({...p,...e,methods:{getPersonalizationStrategy:i.getPersonalizationStrategy,setPersonalizationStrategy:i.setPersonalizationStrategy}});return c.createSearchClient({...h,methods:{search:c.multipleQueries,searchForFacetValues:c.multipleSearchForFacetValues,multipleBatch:c.multipleBatch,multipleGetObjects:c.multipleGetObjects,multipleQueries:c.multipleQueries,copyIndex:c.copyIndex,copySettings:c.copySettings,copyRules:c.copyRules,copySynonyms:c.copySynonyms,moveIndex:c.moveIndex,listIndices:c.listIndices,getLogs:c.getLogs,listClusters:c.listClusters,multipleSearchForFacetValues:c.multipleSearchForFacetValues,getApiKey:c.getApiKey,addApiKey:c.addApiKey,listApiKeys:c.listApiKeys,updateApiKey:c.updateApiKey,deleteApiKey:c.deleteApiKey,restoreApiKey:c.restoreApiKey,assignUserID:c.assignUserID,assignUserIDs:c.assignUserIDs,getUserID:c.getUserID,searchUserIDs:c.searchUserIDs,listUserIDs:c.listUserIDs,getTopUserIDs:c.getTopUserIDs,removeUserID:c.removeUserID,hasPendingMappings:c.hasPendingMappings,generateSecuredApiKey:c.generateSecuredApiKey,getSecuredApiKeyRemainingValidity:c.getSecuredApiKeyRemainingValidity,destroy:n.destroy,clearDictionaryEntries:c.clearDictionaryEntries,deleteDictionaryEntries:c.deleteDictionaryEntries,getDictionarySettings:c.getDictionarySettings,getAppTask:c.getAppTask,replaceDictionaryEntries:c.replaceDictionaryEntries,saveDictionaryEntries:c.saveDictionaryEntries,searchDictionaryEntries:c.searchDictionaryEntries,setDictionarySettings:c.setDictionarySettings,waitAppTask:c.waitAppTask,customRequest:c.customRequest,initIndex:e=>t=>c.initIndex(e)(t,{methods:{batch:c.batch,delete:c.deleteIndex,findAnswers:c.findAnswers,getObject:c.getObject,getObjects:c.getObjects,saveObject:c.saveObject,saveObjects:c.saveObjects,search:c.search,searchForFacetValues:c.searchForFacetValues,waitTask:c.waitTask,setSettings:c.setSettings,getSettings:c.getSettings,partialUpdateObject:c.partialUpdateObject,partialUpdateObjects:c.partialUpdateObjects,deleteObject:c.deleteObject,deleteObjects:c.deleteObjects,deleteBy:c.deleteBy,clearObjects:c.clearObjects,browseObjects:c.browseObjects,getObjectPosition:c.getObjectPosition,findObject:c.findObject,exists:c.exists,saveSynonym:c.saveSynonym,saveSynonyms:c.saveSynonyms,getSynonym:c.getSynonym,searchSynonyms:c.searchSynonyms,browseSynonyms:c.browseSynonyms,deleteSynonym:c.deleteSynonym,clearSynonyms:c.clearSynonyms,replaceAllObjects:c.replaceAllObjects,replaceAllSynonyms:c.replaceAllSynonyms,searchRules:c.searchRules,getRule:c.getRule,deleteRule:c.deleteRule,saveRule:c.saveRule,saveRules:c.saveRules,replaceAllRules:c.replaceAllRules,browseRules:c.browseRules,clearRules:c.clearRules}}),initAnalytics:()=>e=>o.createAnalyticsClient({...p,...e,methods:{addABTest:o.addABTest,getABTest:o.getABTest,getABTests:o.getABTests,stopABTest:o.stopABTest,deleteABTest:o.deleteABTest}}),initPersonalization:initPersonalization,initRecommendation:()=>e=>{h.logger.info("The `initRecommendation` method is deprecated. Use `initPersonalization` instead.");return initPersonalization()(e)}}})}algoliasearch.version=n.version;e.exports=algoliasearch},930:(e,t,r)=>{const s=r(447);e.exports=s;e.exports.default=s},430:function(e,t,r){"use strict";var s=this&&this.__awaiter||function(e,t,r,s){function adopt(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,a){function fulfilled(e){try{step(s.next(e))}catch(e){a(e)}}function rejected(e){try{step(s["throw"](e))}catch(e){a(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())}))};const a=r(930);const handler=(e,t)=>s(void 0,void 0,void 0,(function*(){var r,s;const o=yield t.integration();const{config:n}=o;if(!n.application_id||!n.admin_api_key){return{statusCode:503,body:"Either the application ID or admin API key is undefined, please check your configuration."}}const{products_index_name:i="products",categories_index_name:c="categories"}=n;const d=(0,a.default)(n.application_id,n.admin_api_key);const{payload:u}=e.body;let l;switch(e.body.event){case"integrations.ready":let a=0;let o=0;let n=1;let p=[];do{const{data:e,meta:s}=yield t.api.get(`v1/products?limit=200&page=${n}`);if(!e||!e.length){console.error("Unable to fetch products, there might not be any");break}e.map((e=>{p.push(saveProduct(d,i,e).then((()=>{a++})))}));yield Promise.all(p);if(!((r=s===null||s===void 0?void 0:s.pagination)===null||r===void 0?void 0:r.total_pages)||n===s.pagination.total_pages){n=0}else{n++}}while(n>=1);n=1;p=[];do{const{data:e,meta:r}=yield t.api.get(`v1/categories?limit=200&page=${n}`);if(!e||!e.length){console.error("Unable to fetch categories, there might not be any");break}e.map((e=>{p.push(saveCategory(d,c,e).then((()=>{o++})))}));yield Promise.all(p);if(!((s=r===null||r===void 0?void 0:r.pagination)===null||s===void 0?void 0:s.total_pages)||n===r.pagination.total_pages){n=0}else{n++}}while(n>=1);return{statusCode:201,body:JSON.stringify({message:"Sync completed!",products:a,categories:o})};case"products.create":case"products.update":l=yield saveProduct(d,i,e.body.payload);return{statusCode:e.body.event==="products.create"?201:200,body:JSON.stringify({objectID:l.objectID,taskID:l.taskID})};case"products.delete":yield d.initIndex(i).deleteObject(u.id);return{statusCode:204,body:""};case"categories.create":case"categories.update":l=yield saveCategory(d,c,e.body.payload);return{statusCode:e.body.event==="categories.create"?201:200,body:JSON.stringify({objectID:l.objectID,taskID:l.taskID})};case"categories.delete":yield d.initIndex(c).deleteObject(u.id);return{statusCode:204,body:""}}return{statusCode:200,body:"Nothing happened, might be an unwanted webhook event..."}}));function saveObject(e,t,r){return e.initIndex(t).saveObject(r)}function saveProduct(e,t,r){const s={objectID:r.id,name:r.name,description:r.description,permalink:r.permalink,sku:r.sku,inventory:r.inventory,price:r.price,assets:r.assets,image:r.image,seo:r.seo,sort_order:r.sort_order,extra_fields:r.extra_fields,attributes:r.attributes,categories:r.categories,related_products:r.related_products,meta:r.meta,active:r.active,created:r.created,updated:r.updated};return saveObject(e,t,s)}function saveCategory(e,t,r){const s={objectID:r.id,name:r.name,slug:r.slug,parent_id:r.parent_id,description:r.description,products:r.products,assets:r.assets,children:r.children,meta:r.meta,created:r.created,updated:r.updated};return saveObject(e,t,s)}e.exports=handler},417:e=>{"use strict";e.exports=require("crypto")},605:e=>{"use strict";e.exports=require("http")},211:e=>{"use strict";e.exports=require("https")},835:e=>{"use strict";e.exports=require("url")}};var t={};function __nccwpck_require__(r){var s=t[r];if(s!==undefined){return s.exports}var a=t[r]={exports:{}};var o=true;try{e[r].call(a.exports,a,a.exports,__nccwpck_require__);o=false}finally{if(o)delete t[r]}return a.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r=__nccwpck_require__(430);module.exports=r})(); \ No newline at end of file +(()=>{var e={818:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createFallbackableCache(e){const t=[...e.caches];const r=t.shift();if(r===undefined){return createNullCache()}return{get(e,s,a={miss:()=>Promise.resolve()}){return r.get(e,s,a).catch((()=>createFallbackableCache({caches:t}).get(e,s,a)))},set(e,s){return r.set(e,s).catch((()=>createFallbackableCache({caches:t}).set(e,s)))},delete(e){return r.delete(e).catch((()=>createFallbackableCache({caches:t}).delete(e)))},clear(){return r.clear().catch((()=>createFallbackableCache({caches:t}).clear()))}}}function createNullCache(){return{get(e,t,r={miss:()=>Promise.resolve()}){const s=t();return s.then((e=>Promise.all([e,r.miss(e)]))).then((([e])=>e))},set(e,t){return Promise.resolve(t)},delete(e){return Promise.resolve()},clear(){return Promise.resolve()}}}t.createFallbackableCache=createFallbackableCache;t.createNullCache=createNullCache},848:(e,t,r)=>{e.exports=r(818)},703:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createInMemoryCache(e={serializable:true}){let t={};return{get(r,s,a={miss:()=>Promise.resolve()}){const o=JSON.stringify(r);if(o in t){return Promise.resolve(e.serializable?JSON.parse(t[o]):t[o])}const n=s();const i=a&&a.miss||(()=>Promise.resolve());return n.then((e=>i(e))).then((()=>n))},set(r,s){t[JSON.stringify(r)]=e.serializable?JSON.stringify(s):s;return Promise.resolve(s)},delete(e){delete t[JSON.stringify(e)];return Promise.resolve()},clear(){t={};return Promise.resolve()}}}t.createInMemoryCache=createInMemoryCache},69:(e,t,r)=>{e.exports=r(703)},675:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(905);var a=r(193);var o=r(373);const createAnalyticsClient=e=>{const t=e.region||"us";const r=s.createAuth(s.AuthMode.WithinHeaders,e.appId,e.apiKey);const o=a.createTransporter({hosts:[{url:`analytics.${t}.algolia.com`}],...e,headers:{...r.headers(),...{"content-type":"application/json"},...e.headers},queryParameters:{...r.queryParameters(),...e.queryParameters}});const n=e.appId;return s.addMethods({appId:n,transporter:o},e.methods)};const addABTest=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Post,path:"2/abtests",data:t},r);const deleteABTest=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("2/abtests/%s",t)},r);const getABTest=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("2/abtests/%s",t)},r);const getABTests=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"2/abtests"},t);const stopABTest=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Post,path:s.encode("2/abtests/%s/stop",t)},r);t.addABTest=addABTest;t.createAnalyticsClient=createAnalyticsClient;t.deleteABTest=deleteABTest;t.getABTest=getABTest;t.getABTests=getABTests;t.stopABTest=stopABTest},538:(e,t,r)=>{e.exports=r(675)},526:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createAuth(e,t,r){const a={"x-algolia-api-key":r,"x-algolia-application-id":t};return{headers(){return e===s.WithinHeaders?a:{}},queryParameters(){return e===s.WithinQueryParameters?a:{}}}}function createRetryablePromise(e){let t=0;const retry=()=>{t++;return new Promise((r=>{setTimeout((()=>{r(e(retry))}),Math.min(100*t,1e3))}))};return e(retry)}function createWaitablePromise(e,t=((e,t)=>Promise.resolve())){return Object.assign(e,{wait(r){return createWaitablePromise(e.then((e=>Promise.all([t(e,r),e]))).then((e=>e[1])))}})}function shuffle(e){let t=e.length-1;for(t;t>0;t--){const r=Math.floor(Math.random()*(t+1));const s=e[t];e[t]=e[r];e[r]=s}return e}function addMethods(e,t){if(!t){return e}Object.keys(t).forEach((r=>{e[r]=t[r](e)}));return e}function encode(e,...t){let r=0;return e.replace(/%s/g,(()=>encodeURIComponent(t[r++])))}const r="4.11.0";const destroy=e=>()=>e.transporter.requester.destroy();const s={WithinQueryParameters:0,WithinHeaders:1};t.AuthMode=s;t.addMethods=addMethods;t.createAuth=createAuth;t.createRetryablePromise=createRetryablePromise;t.createWaitablePromise=createWaitablePromise;t.destroy=destroy;t.encode=encode;t.shuffle=shuffle;t.version=r},905:(e,t,r)=>{e.exports=r(526)},327:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(905);var a=r(193);var o=r(373);const createPersonalizationClient=e=>{const t=e.region||"us";const r=s.createAuth(s.AuthMode.WithinHeaders,e.appId,e.apiKey);const o=a.createTransporter({hosts:[{url:`personalization.${t}.algolia.com`}],...e,headers:{...r.headers(),...{"content-type":"application/json"},...e.headers},queryParameters:{...r.queryParameters(),...e.queryParameters}});return s.addMethods({appId:e.appId,transporter:o},e.methods)};const getPersonalizationStrategy=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/strategies/personalization"},t);const setPersonalizationStrategy=e=>(t,r)=>e.transporter.write({method:o.MethodEnum.Post,path:"1/strategies/personalization",data:t},r);t.createPersonalizationClient=createPersonalizationClient;t.getPersonalizationStrategy=getPersonalizationStrategy;t.setPersonalizationStrategy=setPersonalizationStrategy},762:(e,t,r)=>{e.exports=r(327)},102:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(905);var a=r(193);var o=r(373);var n=r(417);function createBrowsablePromise(e){const browse=t=>e.request(t).then((r=>{if(e.batch!==undefined){e.batch(r.hits)}if(e.shouldStop(r)){return undefined}if(r.cursor){return browse({cursor:r.cursor})}return browse({page:(t.page||0)+1})}));return browse({})}const createSearchClient=e=>{const t=e.appId;const r=s.createAuth(e.authMode!==undefined?e.authMode:s.AuthMode.WithinHeaders,t,e.apiKey);const o=a.createTransporter({hosts:[{url:`${t}-dsn.algolia.net`,accept:a.CallEnum.Read},{url:`${t}.algolia.net`,accept:a.CallEnum.Write}].concat(s.shuffle([{url:`${t}-1.algolianet.com`},{url:`${t}-2.algolianet.com`},{url:`${t}-3.algolianet.com`}])),...e,headers:{...r.headers(),...{"content-type":"application/x-www-form-urlencoded"},...e.headers},queryParameters:{...r.queryParameters(),...e.queryParameters}});const n={transporter:o,appId:t,addAlgoliaAgent(e,t){o.userAgent.add({segment:e,version:t})},clearCache(){return Promise.all([o.requestsCache.clear(),o.responsesCache.clear()]).then((()=>undefined))}};return s.addMethods(n,e.methods)};function createMissingObjectIDError(){return{name:"MissingObjectIDError",message:"All objects must have an unique objectID "+"(like a primary key) to be valid. "+"Algolia is also able to generate objectIDs "+"automatically but *it's not recommended*. "+"To do it, use the `{'autoGenerateObjectIDIfNotExist': true}` option."}}function createObjectNotFoundError(){return{name:"ObjectNotFoundError",message:"Object not found."}}function createValidUntilNotFoundError(){return{name:"ValidUntilNotFoundError",message:"ValidUntil not found in given secured api key."}}const addApiKey=e=>(t,r)=>{const{queryParameters:a,...n}=r||{};const i={acl:t,...a!==undefined?{queryParameters:a}:{}};const wait=(t,r)=>s.createRetryablePromise((s=>getApiKey(e)(t.key,r).catch((e=>{if(e.status!==404){throw e}return s()}))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:"1/keys",data:i},n),wait)};const assignUserID=e=>(t,r,s)=>{const n=a.createMappedRequestOptions(s);n.queryParameters["X-Algolia-User-ID"]=t;return e.transporter.write({method:o.MethodEnum.Post,path:"1/clusters/mapping",data:{cluster:r}},n)};const assignUserIDs=e=>(t,r,s)=>e.transporter.write({method:o.MethodEnum.Post,path:"1/clusters/mapping/batch",data:{users:t,cluster:r}},s);const clearDictionaryEntries=e=>(t,r)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:true,requests:{action:"addEntry",body:[]}}},r),((t,r)=>waitAppTask(e)(t.taskID,r)));const copyIndex=e=>(t,r,a)=>{const wait=(r,s)=>initIndex(e)(t,{methods:{waitTask:waitTask}}).waitTask(r.taskID,s);return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/operation",t),data:{operation:"copy",destination:r}},a),wait)};const copyRules=e=>(t,r,s)=>copyIndex(e)(t,r,{...s,scope:[d.Rules]});const copySettings=e=>(t,r,s)=>copyIndex(e)(t,r,{...s,scope:[d.Settings]});const copySynonyms=e=>(t,r,s)=>copyIndex(e)(t,r,{...s,scope:[d.Synonyms]});const customRequest=e=>(t,r)=>{if(t.method===o.MethodEnum.Get){return e.transporter.read(t,r)}return e.transporter.write(t,r)};const deleteApiKey=e=>(t,r)=>{const wait=(r,a)=>s.createRetryablePromise((r=>getApiKey(e)(t,a).then(r).catch((e=>{if(e.status!==404){throw e}}))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/keys/%s",t)},r),wait)};const deleteDictionaryEntries=e=>(t,r,a)=>{const n=r.map((e=>({action:"deleteEntry",body:{objectID:e}})));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:false,requests:n}},a),((t,r)=>waitAppTask(e)(t.taskID,r)))};const generateSecuredApiKey=()=>(e,t)=>{const r=a.serializeQueryParameters(t);const s=n.createHmac("sha256",e).update(r).digest("hex");return Buffer.from(s+r).toString("base64")};const getApiKey=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/keys/%s",t)},r);const getDictionarySettings=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"/1/dictionaries/*/settings"},t);const getLogs=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/logs"},t);const getSecuredApiKeyRemainingValidity=()=>e=>{const t=Buffer.from(e,"base64").toString("ascii");const r=/validUntil=(\d+)/;const s=t.match(r);if(s===null){throw createValidUntilNotFoundError()}return parseInt(s[1],10)-Math.round((new Date).getTime()/1e3)};const getTopUserIDs=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters/mapping/top"},t);const getAppTask=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/task/%s",t.toString())},r);const getUserID=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/clusters/mapping/%s",t)},r);const hasPendingMappings=e=>t=>{const{retrieveMappings:r,...s}=t||{};if(r===true){s.getClusters=true}return e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters/mapping/pending"},s)};const initIndex=e=>(t,r={})=>{const a={transporter:e.transporter,appId:e.appId,indexName:t};return s.addMethods(a,r.methods)};const listApiKeys=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/keys"},t);const listClusters=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters"},t);const listIndices=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/indexes"},t);const listUserIDs=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:"1/clusters/mapping"},t);const moveIndex=e=>(t,r,a)=>{const wait=(r,s)=>initIndex(e)(t,{methods:{waitTask:waitTask}}).waitTask(r.taskID,s);return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/operation",t),data:{operation:"move",destination:r}},a),wait)};const multipleBatch=e=>(t,r)=>{const wait=(t,r)=>Promise.all(Object.keys(t.taskID).map((s=>initIndex(e)(s,{methods:{waitTask:waitTask}}).waitTask(t.taskID[s],r))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:"1/indexes/*/batch",data:{requests:t}},r),wait)};const multipleGetObjects=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:t}},r);const multipleQueries=e=>(t,r)=>{const s=t.map((e=>({...e,params:a.serializeQueryParameters(e.params||{})})));return e.transporter.read({method:o.MethodEnum.Post,path:"1/indexes/*/queries",data:{requests:s},cacheable:true},r)};const multipleSearchForFacetValues=e=>(t,r)=>Promise.all(t.map((t=>{const{facetName:s,facetQuery:a,...o}=t.params;return initIndex(e)(t.indexName,{methods:{searchForFacetValues:searchForFacetValues}}).searchForFacetValues(s,a,{...r,...o})})));const removeUserID=e=>(t,r)=>{const s=a.createMappedRequestOptions(r);s.queryParameters["X-Algolia-User-ID"]=t;return e.transporter.write({method:o.MethodEnum.Delete,path:"1/clusters/mapping"},s)};const replaceDictionaryEntries=e=>(t,r,a)=>{const n=r.map((e=>({action:"addEntry",body:e})));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:true,requests:n}},a),((t,r)=>waitAppTask(e)(t.taskID,r)))};const restoreApiKey=e=>(t,r)=>{const wait=(r,a)=>s.createRetryablePromise((r=>getApiKey(e)(t,a).catch((e=>{if(e.status!==404){throw e}return r()}))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/keys/%s/restore",t)},r),wait)};const saveDictionaryEntries=e=>(t,r,a)=>{const n=r.map((e=>({action:"addEntry",body:e})));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:false,requests:n}},a),((t,r)=>waitAppTask(e)(t.taskID,r)))};const searchDictionaryEntries=e=>(t,r,a)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("/1/dictionaries/%s/search",t),data:{query:r},cacheable:true},a);const searchUserIDs=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:"1/clusters/mapping/search",data:{query:t}},r);const setDictionarySettings=e=>(t,r)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Put,path:"/1/dictionaries/*/settings",data:t},r),((t,r)=>waitAppTask(e)(t.taskID,r)));const updateApiKey=e=>(t,r)=>{const a=Object.assign({},r);const{queryParameters:n,...i}=r||{};const c=n?{queryParameters:n}:{};const d=["acl","indexes","referers","restrictSources","queryParameters","description","maxQueriesPerIPPerHour","maxHitsPerQuery"];const hasChanged=e=>Object.keys(a).filter((e=>d.indexOf(e)!==-1)).every((t=>e[t]===a[t]));const wait=(r,a)=>s.createRetryablePromise((r=>getApiKey(e)(t,a).then((e=>hasChanged(e)?Promise.resolve():r()))));return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Put,path:s.encode("1/keys/%s",t),data:c},i),wait)};const waitAppTask=e=>(t,r)=>s.createRetryablePromise((s=>getAppTask(e)(t,r).then((e=>e.status!=="published"?s():undefined))));const batch=e=>(t,r)=>{const wait=(t,r)=>waitTask(e)(t.taskID,r);return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/batch",e.indexName),data:{requests:t}},r),wait)};const browseObjects=e=>t=>createBrowsablePromise({shouldStop:e=>e.cursor===undefined,...t,request:r=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/browse",e.indexName),data:r},t)});const browseRules=e=>t=>{const r={hitsPerPage:1e3,...t};return createBrowsablePromise({shouldStop:e=>e.hits.length({...e,hits:e.hits.map((e=>{delete e._highlightResult;return e}))})))}})};const browseSynonyms=e=>t=>{const r={hitsPerPage:1e3,...t};return createBrowsablePromise({shouldStop:e=>e.hits.length({...e,hits:e.hits.map((e=>{delete e._highlightResult;return e}))})))}})};const chunkedBatch=e=>(t,r,a)=>{const{batchSize:o,...n}=a||{};const i={taskIDs:[],objectIDs:[]};const forEachBatch=(s=0)=>{const a=[];let c;for(c=s;c({action:r,body:e}))),n).then((e=>{i.objectIDs=i.objectIDs.concat(e.objectIDs);i.taskIDs.push(e.taskID);c++;return forEachBatch(c)}))};return s.createWaitablePromise(forEachBatch(),((t,r)=>Promise.all(t.taskIDs.map((t=>waitTask(e)(t,r))))))};const clearObjects=e=>t=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/clear",e.indexName)},t),((t,r)=>waitTask(e)(t.taskID,r)));const clearRules=e=>t=>{const{forwardToReplicas:r,...n}=t||{};const i=a.createMappedRequestOptions(n);if(r){i.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/rules/clear",e.indexName)},i),((t,r)=>waitTask(e)(t.taskID,r)))};const clearSynonyms=e=>t=>{const{forwardToReplicas:r,...n}=t||{};const i=a.createMappedRequestOptions(n);if(r){i.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/synonyms/clear",e.indexName)},i),((t,r)=>waitTask(e)(t.taskID,r)))};const deleteBy=e=>(t,r)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/deleteByQuery",e.indexName),data:t},r),((t,r)=>waitTask(e)(t.taskID,r)));const deleteIndex=e=>t=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/indexes/%s",e.indexName)},t),((t,r)=>waitTask(e)(t.taskID,r)));const deleteObject=e=>(t,r)=>s.createWaitablePromise(deleteObjects(e)([t],r).then((e=>({taskID:e.taskIDs[0]}))),((t,r)=>waitTask(e)(t.taskID,r)));const deleteObjects=e=>(t,r)=>{const s=t.map((e=>({objectID:e})));return chunkedBatch(e)(s,c.DeleteObject,r)};const deleteRule=e=>(t,r)=>{const{forwardToReplicas:n,...i}=r||{};const c=a.createMappedRequestOptions(i);if(n){c.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/indexes/%s/rules/%s",e.indexName,t)},c),((t,r)=>waitTask(e)(t.taskID,r)))};const deleteSynonym=e=>(t,r)=>{const{forwardToReplicas:n,...i}=r||{};const c=a.createMappedRequestOptions(i);if(n){c.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Delete,path:s.encode("1/indexes/%s/synonyms/%s",e.indexName,t)},c),((t,r)=>waitTask(e)(t.taskID,r)))};const exists=e=>t=>getSettings(e)(t).then((()=>true)).catch((e=>{if(e.status!==404){throw e}return false}));const findAnswers=e=>(t,r,a)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/answers/%s/prediction",e.indexName),data:{query:t,queryLanguages:r},cacheable:true},a);const findObject=e=>(t,r)=>{const{query:s,paginate:a,...o}=r||{};let n=0;const forEachPage=()=>search(e)(s||"",{...o,page:n}).then((e=>{for(const[r,s]of Object.entries(e.hits)){if(t(s)){return{object:s,position:parseInt(r,10),page:n}}}n++;if(a===false||n>=e.nbPages){throw createObjectNotFoundError()}return forEachPage()}));return forEachPage()};const getObject=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/%s",e.indexName,t)},r);const getObjectPosition=()=>(e,t)=>{for(const[r,s]of Object.entries(e.hits)){if(s.objectID===t){return parseInt(r,10)}}return-1};const getObjects=e=>(t,r)=>{const{attributesToRetrieve:s,...a}=r||{};const n=t.map((t=>({indexName:e.indexName,objectID:t,...s?{attributesToRetrieve:s}:{}})));return e.transporter.read({method:o.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:n}},a)};const getRule=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/rules/%s",e.indexName,t)},r);const getSettings=e=>t=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/settings",e.indexName),data:{getVersion:2}},t);const getSynonym=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode(`1/indexes/%s/synonyms/%s`,e.indexName,t)},r);const getTask=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Get,path:s.encode("1/indexes/%s/task/%s",e.indexName,t.toString())},r);const partialUpdateObject=e=>(t,r)=>s.createWaitablePromise(partialUpdateObjects(e)([t],r).then((e=>({objectID:e.objectIDs[0],taskID:e.taskIDs[0]}))),((t,r)=>waitTask(e)(t.taskID,r)));const partialUpdateObjects=e=>(t,r)=>{const{createIfNotExists:s,...a}=r||{};const o=s?c.PartialUpdateObject:c.PartialUpdateObjectNoCreate;return chunkedBatch(e)(t,o,a)};const replaceAllObjects=e=>(t,r)=>{const{safe:a,autoGenerateObjectIDIfNotExist:n,batchSize:i,...c}=r||{};const operation=(t,r,a,n)=>s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/operation",t),data:{operation:a,destination:r}},n),((t,r)=>waitTask(e)(t.taskID,r)));const d=Math.random().toString(36).substring(7);const u=`${e.indexName}_tmp_${d}`;const l=saveObjects({appId:e.appId,transporter:e.transporter,indexName:u});let p=[];const h=operation(e.indexName,u,"copy",{...c,scope:["settings","synonyms","rules"]});p.push(h);const m=(a?h.wait(c):h).then((()=>{const e=l(t,{...c,autoGenerateObjectIDIfNotExist:n,batchSize:i});p.push(e);return a?e.wait(c):e})).then((()=>{const t=operation(u,e.indexName,"move",c);p.push(t);return a?t.wait(c):t})).then((()=>Promise.all(p))).then((([e,t,r])=>({objectIDs:t.objectIDs,taskIDs:[e.taskID,...t.taskIDs,r.taskID]})));return s.createWaitablePromise(m,((e,t)=>Promise.all(p.map((e=>e.wait(t))))))};const replaceAllRules=e=>(t,r)=>saveRules(e)(t,{...r,clearExistingRules:true});const replaceAllSynonyms=e=>(t,r)=>saveSynonyms(e)(t,{...r,clearExistingSynonyms:true});const saveObject=e=>(t,r)=>s.createWaitablePromise(saveObjects(e)([t],r).then((e=>({objectID:e.objectIDs[0],taskID:e.taskIDs[0]}))),((t,r)=>waitTask(e)(t.taskID,r)));const saveObjects=e=>(t,r)=>{const{autoGenerateObjectIDIfNotExist:a,...o}=r||{};const n=a?c.AddObject:c.UpdateObject;if(n===c.UpdateObject){for(const e of t){if(e.objectID===undefined){return s.createWaitablePromise(Promise.reject(createMissingObjectIDError()))}}}return chunkedBatch(e)(t,n,o)};const saveRule=e=>(t,r)=>saveRules(e)([t],r);const saveRules=e=>(t,r)=>{const{forwardToReplicas:n,clearExistingRules:i,...c}=r||{};const d=a.createMappedRequestOptions(c);if(n){d.queryParameters.forwardToReplicas=1}if(i){d.queryParameters.clearExistingRules=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/rules/batch",e.indexName),data:t},d),((t,r)=>waitTask(e)(t.taskID,r)))};const saveSynonym=e=>(t,r)=>saveSynonyms(e)([t],r);const saveSynonyms=e=>(t,r)=>{const{forwardToReplicas:n,clearExistingSynonyms:i,replaceExistingSynonyms:c,...d}=r||{};const u=a.createMappedRequestOptions(d);if(n){u.queryParameters.forwardToReplicas=1}if(c||i){u.queryParameters.replaceExistingSynonyms=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/synonyms/batch",e.indexName),data:t},u),((t,r)=>waitTask(e)(t.taskID,r)))};const search=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/query",e.indexName),data:{query:t},cacheable:true},r);const searchForFacetValues=e=>(t,r,a)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/facets/%s/query",e.indexName,t),data:{facetQuery:r},cacheable:true},a);const searchRules=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/rules/search",e.indexName),data:{query:t}},r);const searchSynonyms=e=>(t,r)=>e.transporter.read({method:o.MethodEnum.Post,path:s.encode("1/indexes/%s/synonyms/search",e.indexName),data:{query:t}},r);const setSettings=e=>(t,r)=>{const{forwardToReplicas:n,...i}=r||{};const c=a.createMappedRequestOptions(i);if(n){c.queryParameters.forwardToReplicas=1}return s.createWaitablePromise(e.transporter.write({method:o.MethodEnum.Put,path:s.encode("1/indexes/%s/settings",e.indexName),data:t},c),((t,r)=>waitTask(e)(t.taskID,r)))};const waitTask=e=>(t,r)=>s.createRetryablePromise((s=>getTask(e)(t,r).then((e=>e.status!=="published"?s():undefined))));const i={AddObject:"addObject",Analytics:"analytics",Browser:"browse",DeleteIndex:"deleteIndex",DeleteObject:"deleteObject",EditSettings:"editSettings",ListIndexes:"listIndexes",Logs:"logs",Personalization:"personalization",Recommendation:"recommendation",Search:"search",SeeUnretrievableAttributes:"seeUnretrievableAttributes",Settings:"settings",Usage:"usage"};const c={AddObject:"addObject",UpdateObject:"updateObject",PartialUpdateObject:"partialUpdateObject",PartialUpdateObjectNoCreate:"partialUpdateObjectNoCreate",DeleteObject:"deleteObject",DeleteIndex:"delete",ClearIndex:"clear"};const d={Settings:"settings",Synonyms:"synonyms",Rules:"rules"};const u={None:"none",StopIfEnoughMatches:"stopIfEnoughMatches"};const l={Synonym:"synonym",OneWaySynonym:"oneWaySynonym",AltCorrection1:"altCorrection1",AltCorrection2:"altCorrection2",Placeholder:"placeholder"};t.ApiKeyACLEnum=i;t.BatchActionEnum=c;t.ScopeEnum=d;t.StrategyEnum=u;t.SynonymEnum=l;t.addApiKey=addApiKey;t.assignUserID=assignUserID;t.assignUserIDs=assignUserIDs;t.batch=batch;t.browseObjects=browseObjects;t.browseRules=browseRules;t.browseSynonyms=browseSynonyms;t.chunkedBatch=chunkedBatch;t.clearDictionaryEntries=clearDictionaryEntries;t.clearObjects=clearObjects;t.clearRules=clearRules;t.clearSynonyms=clearSynonyms;t.copyIndex=copyIndex;t.copyRules=copyRules;t.copySettings=copySettings;t.copySynonyms=copySynonyms;t.createBrowsablePromise=createBrowsablePromise;t.createMissingObjectIDError=createMissingObjectIDError;t.createObjectNotFoundError=createObjectNotFoundError;t.createSearchClient=createSearchClient;t.createValidUntilNotFoundError=createValidUntilNotFoundError;t.customRequest=customRequest;t.deleteApiKey=deleteApiKey;t.deleteBy=deleteBy;t.deleteDictionaryEntries=deleteDictionaryEntries;t.deleteIndex=deleteIndex;t.deleteObject=deleteObject;t.deleteObjects=deleteObjects;t.deleteRule=deleteRule;t.deleteSynonym=deleteSynonym;t.exists=exists;t.findAnswers=findAnswers;t.findObject=findObject;t.generateSecuredApiKey=generateSecuredApiKey;t.getApiKey=getApiKey;t.getAppTask=getAppTask;t.getDictionarySettings=getDictionarySettings;t.getLogs=getLogs;t.getObject=getObject;t.getObjectPosition=getObjectPosition;t.getObjects=getObjects;t.getRule=getRule;t.getSecuredApiKeyRemainingValidity=getSecuredApiKeyRemainingValidity;t.getSettings=getSettings;t.getSynonym=getSynonym;t.getTask=getTask;t.getTopUserIDs=getTopUserIDs;t.getUserID=getUserID;t.hasPendingMappings=hasPendingMappings;t.initIndex=initIndex;t.listApiKeys=listApiKeys;t.listClusters=listClusters;t.listIndices=listIndices;t.listUserIDs=listUserIDs;t.moveIndex=moveIndex;t.multipleBatch=multipleBatch;t.multipleGetObjects=multipleGetObjects;t.multipleQueries=multipleQueries;t.multipleSearchForFacetValues=multipleSearchForFacetValues;t.partialUpdateObject=partialUpdateObject;t.partialUpdateObjects=partialUpdateObjects;t.removeUserID=removeUserID;t.replaceAllObjects=replaceAllObjects;t.replaceAllRules=replaceAllRules;t.replaceAllSynonyms=replaceAllSynonyms;t.replaceDictionaryEntries=replaceDictionaryEntries;t.restoreApiKey=restoreApiKey;t.saveDictionaryEntries=saveDictionaryEntries;t.saveObject=saveObject;t.saveObjects=saveObjects;t.saveRule=saveRule;t.saveRules=saveRules;t.saveSynonym=saveSynonym;t.saveSynonyms=saveSynonyms;t.search=search;t.searchDictionaryEntries=searchDictionaryEntries;t.searchForFacetValues=searchForFacetValues;t.searchRules=searchRules;t.searchSynonyms=searchSynonyms;t.searchUserIDs=searchUserIDs;t.setDictionarySettings=setDictionarySettings;t.setSettings=setSettings;t.updateApiKey=updateApiKey;t.waitAppTask=waitAppTask;t.waitTask=waitTask},425:(e,t,r)=>{e.exports=r(102)},242:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});function createNullLogger(){return{debug(e,t){return Promise.resolve()},info(e,t){return Promise.resolve()},error(e,t){return Promise.resolve()}}}const r={Debug:1,Info:2,Error:3};t.LogLevelEnum=r;t.createNullLogger=createNullLogger},564:(e,t,r)=>{e.exports=r(242)},721:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});const r={Delete:"DELETE",Get:"GET",Post:"POST",Put:"PUT"};t.MethodEnum=r},373:(e,t,r)=>{e.exports=r(721)},437:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(605);var a=r(211);var o=r(835);const n={keepAlive:true};const i=new s.Agent(n);const c=new a.Agent(n);function createNodeHttpRequester({agent:e,httpAgent:t,httpsAgent:r,requesterOptions:n={}}={}){const d=t||e||i;const u=r||e||c;return{send(e){return new Promise((t=>{const r=o.parse(e.url);const i=r.query===null?r.pathname:`${r.pathname}?${r.query}`;const c={...n,agent:r.protocol==="https:"?u:d,hostname:r.hostname,path:i,method:e.method,headers:{...n&&n.headers?n.headers:{},...e.headers},...r.port!==undefined?{port:r.port||""}:{}};const l=(r.protocol==="https:"?a:s).request(c,(e=>{let r=[];e.on("data",(e=>{r=r.concat(e)}));e.on("end",(()=>{clearTimeout(p);clearTimeout(h);t({status:e.statusCode||0,content:Buffer.concat(r).toString(),isTimedOut:false})}))}));const createTimeout=(e,r)=>setTimeout((()=>{l.abort();t({status:0,content:r,isTimedOut:true})}),e*1e3);const p=createTimeout(e.connectTimeout,"Connection timeout");let h;l.on("error",(e=>{clearTimeout(p);clearTimeout(h);t({status:0,content:e.message,isTimedOut:false})}));l.once("response",(()=>{clearTimeout(p);h=createTimeout(e.responseTimeout,"Socket timeout")}));if(e.data!==undefined){l.write(e.data)}l.end()}))},destroy(){d.destroy();u.destroy();return Promise.resolve()}}}t.createNodeHttpRequester=createNodeHttpRequester},724:(e,t,r)=>{e.exports=r(437)},56:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});var s=r(373);function createMappedRequestOptions(e,t){const r=e||{};const s=r.data||{};Object.keys(r).forEach((e=>{if(["timeout","headers","queryParameters","data","cacheable"].indexOf(e)===-1){s[e]=r[e]}}));return{data:Object.entries(s).length>0?s:undefined,timeout:r.timeout||t,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}const a={Read:1,Write:2,Any:3};const o={Up:1,Down:2,Timeouted:3};const n=2*60*1e3;function createStatefulHost(e,t=o.Up){return{...e,status:t,lastUpdate:Date.now()}}function isStatefulHostUp(e){return e.status===o.Up||Date.now()-e.lastUpdate>n}function isStatefulHostTimeouted(e){return e.status===o.Timeouted&&Date.now()-e.lastUpdate<=n}function createStatelessHost(e){if(typeof e==="string"){return{protocol:"https",url:e,accept:a.Any}}return{protocol:e.protocol||"https",url:e.url,accept:e.accept||a.Any}}function createRetryableOptions(e,t){return Promise.all(t.map((t=>e.get(t,(()=>Promise.resolve(createStatefulHost(t))))))).then((e=>{const r=e.filter((e=>isStatefulHostUp(e)));const s=e.filter((e=>isStatefulHostTimeouted(e)));const a=[...r,...s];const o=a.length>0?a.map((e=>createStatelessHost(e))):t;return{getTimeout(e,t){const r=s.length===0&&e===0?1:s.length+3+e;return r*t},statelessHosts:o}}))}const isNetworkError=({isTimedOut:e,status:t})=>!e&&~~t===0;const isRetryable=e=>{const t=e.status;const r=e.isTimedOut;return r||isNetworkError(e)||~~(t/100)!==2&&~~(t/100)!==4};const isSuccess=({status:e})=>~~(e/100)===2;const retryDecision=(e,t)=>{if(isRetryable(e)){return t.onRetry(e)}if(isSuccess(e)){return t.onSuccess(e)}return t.onFail(e)};function retryableRequest(e,t,r,a){const n=[];const i=serializeData(r,a);const c=serializeHeaders(e,a);const d=r.method;const u=r.method!==s.MethodEnum.Get?{}:{...r.data,...a.data};const l={"x-algolia-agent":e.userAgent.value,...e.queryParameters,...u,...a.queryParameters};let p=0;const retry=(t,s)=>{const u=t.pop();if(u===undefined){throw createRetryError(stackTraceWithoutCredentials(n))}const h={data:i,headers:c,method:d,url:serializeUrl(u,r.path,l),connectTimeout:s(p,e.timeouts.connect),responseTimeout:s(p,a.timeout)};const pushToStackTrace=e=>{const r={request:h,response:e,host:u,triesLeft:t.length};n.push(r);return r};const m={onSuccess:e=>deserializeSuccess(e),onRetry(r){const a=pushToStackTrace(r);if(r.isTimedOut){p++}return Promise.all([e.logger.info("Retryable failure",stackFrameWithoutCredentials(a)),e.hostsCache.set(u,createStatefulHost(u,r.isTimedOut?o.Timeouted:o.Down))]).then((()=>retry(t,s)))},onFail(e){pushToStackTrace(e);throw deserializeFailure(e,stackTraceWithoutCredentials(n))}};return e.requester.send(h).then((e=>retryDecision(e,m)))};return createRetryableOptions(e.hostsCache,t).then((e=>retry([...e.statelessHosts].reverse(),e.getTimeout)))}function createTransporter(e){const{hostsCache:t,logger:r,requester:s,requestsCache:o,responsesCache:n,timeouts:i,userAgent:c,hosts:d,queryParameters:u,headers:l}=e;const p={hostsCache:t,logger:r,requester:s,requestsCache:o,responsesCache:n,timeouts:i,userAgent:c,headers:l,queryParameters:u,hosts:d.map((e=>createStatelessHost(e))),read(e,t){const r=createMappedRequestOptions(t,p.timeouts.read);const createRetryableRequest=()=>retryableRequest(p,p.hosts.filter((e=>(e.accept&a.Read)!==0)),e,r);const s=r.cacheable!==undefined?r.cacheable:e.cacheable;if(s!==true){return createRetryableRequest()}const o={request:e,mappedRequestOptions:r,transporter:{queryParameters:p.queryParameters,headers:p.headers}};return p.responsesCache.get(o,(()=>p.requestsCache.get(o,(()=>p.requestsCache.set(o,createRetryableRequest()).then((e=>Promise.all([p.requestsCache.delete(o),e])),(e=>Promise.all([p.requestsCache.delete(o),Promise.reject(e)]))).then((([e,t])=>t))))),{miss:e=>p.responsesCache.set(o,e)})},write(e,t){return retryableRequest(p,p.hosts.filter((e=>(e.accept&a.Write)!==0)),e,createMappedRequestOptions(t,p.timeouts.write))}};return p}function createUserAgent(e){const t={value:`Algolia for JavaScript (${e})`,add(e){const r=`; ${e.segment}${e.version!==undefined?` (${e.version})`:""}`;if(t.value.indexOf(r)===-1){t.value=`${t.value}${r}`}return t}};return t}function deserializeSuccess(e){try{return JSON.parse(e.content)}catch(t){throw createDeserializationError(t.message,e)}}function deserializeFailure({content:e,status:t},r){let s=e;try{s=JSON.parse(e).message}catch(e){}return createApiError(s,t,r)}function encode(e,...t){let r=0;return e.replace(/%s/g,(()=>encodeURIComponent(t[r++])))}function serializeUrl(e,t,r){const s=serializeQueryParameters(r);let a=`${e.protocol}://${e.url}/${t.charAt(0)==="/"?t.substr(1):t}`;if(s.length){a+=`?${s}`}return a}function serializeQueryParameters(e){const isObjectOrArray=e=>Object.prototype.toString.call(e)==="[object Object]"||Object.prototype.toString.call(e)==="[object Array]";return Object.keys(e).map((t=>encode("%s=%s",t,isObjectOrArray(e[t])?JSON.stringify(e[t]):e[t]))).join("&")}function serializeData(e,t){if(e.method===s.MethodEnum.Get||e.data===undefined&&t.data===undefined){return undefined}const r=Array.isArray(e.data)?e.data:{...e.data,...t.data};return JSON.stringify(r)}function serializeHeaders(e,t){const r={...e.headers,...t.headers};const s={};Object.keys(r).forEach((e=>{const t=r[e];s[e.toLowerCase()]=t}));return s}function stackTraceWithoutCredentials(e){return e.map((e=>stackFrameWithoutCredentials(e)))}function stackFrameWithoutCredentials(e){const t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...e,request:{...e.request,headers:{...e.request.headers,...t}}}}function createApiError(e,t,r){return{name:"ApiError",message:e,status:t,transporterStackTrace:r}}function createDeserializationError(e,t){return{name:"DeserializationError",message:e,response:t}}function createRetryError(e){return{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:e}}t.CallEnum=a;t.HostStatusEnum=o;t.createApiError=createApiError;t.createDeserializationError=createDeserializationError;t.createMappedRequestOptions=createMappedRequestOptions;t.createRetryError=createRetryError;t.createStatefulHost=createStatefulHost;t.createStatelessHost=createStatelessHost;t.createTransporter=createTransporter;t.createUserAgent=createUserAgent;t.deserializeFailure=deserializeFailure;t.deserializeSuccess=deserializeSuccess;t.isStatefulHostTimeouted=isStatefulHostTimeouted;t.isStatefulHostUp=isStatefulHostUp;t.serializeData=serializeData;t.serializeHeaders=serializeHeaders;t.serializeQueryParameters=serializeQueryParameters;t.serializeUrl=serializeUrl;t.stackFrameWithoutCredentials=stackFrameWithoutCredentials;t.stackTraceWithoutCredentials=stackTraceWithoutCredentials},193:(e,t,r)=>{e.exports=r(56)},447:(e,t,r)=>{"use strict";var s=r(848);var a=r(69);var o=r(538);var n=r(905);var i=r(762);var c=r(425);var d=r(564);var u=r(724);var l=r(193);function algoliasearch(e,t,r){const p={appId:e,apiKey:t,timeouts:{connect:2,read:5,write:30},requester:u.createNodeHttpRequester(),logger:d.createNullLogger(),responsesCache:s.createNullCache(),requestsCache:s.createNullCache(),hostsCache:a.createInMemoryCache(),userAgent:l.createUserAgent(n.version).add({segment:"Node.js",version:process.versions.node})};const h={...p,...r};const initPersonalization=()=>e=>i.createPersonalizationClient({...p,...e,methods:{getPersonalizationStrategy:i.getPersonalizationStrategy,setPersonalizationStrategy:i.setPersonalizationStrategy}});return c.createSearchClient({...h,methods:{search:c.multipleQueries,searchForFacetValues:c.multipleSearchForFacetValues,multipleBatch:c.multipleBatch,multipleGetObjects:c.multipleGetObjects,multipleQueries:c.multipleQueries,copyIndex:c.copyIndex,copySettings:c.copySettings,copyRules:c.copyRules,copySynonyms:c.copySynonyms,moveIndex:c.moveIndex,listIndices:c.listIndices,getLogs:c.getLogs,listClusters:c.listClusters,multipleSearchForFacetValues:c.multipleSearchForFacetValues,getApiKey:c.getApiKey,addApiKey:c.addApiKey,listApiKeys:c.listApiKeys,updateApiKey:c.updateApiKey,deleteApiKey:c.deleteApiKey,restoreApiKey:c.restoreApiKey,assignUserID:c.assignUserID,assignUserIDs:c.assignUserIDs,getUserID:c.getUserID,searchUserIDs:c.searchUserIDs,listUserIDs:c.listUserIDs,getTopUserIDs:c.getTopUserIDs,removeUserID:c.removeUserID,hasPendingMappings:c.hasPendingMappings,generateSecuredApiKey:c.generateSecuredApiKey,getSecuredApiKeyRemainingValidity:c.getSecuredApiKeyRemainingValidity,destroy:n.destroy,clearDictionaryEntries:c.clearDictionaryEntries,deleteDictionaryEntries:c.deleteDictionaryEntries,getDictionarySettings:c.getDictionarySettings,getAppTask:c.getAppTask,replaceDictionaryEntries:c.replaceDictionaryEntries,saveDictionaryEntries:c.saveDictionaryEntries,searchDictionaryEntries:c.searchDictionaryEntries,setDictionarySettings:c.setDictionarySettings,waitAppTask:c.waitAppTask,customRequest:c.customRequest,initIndex:e=>t=>c.initIndex(e)(t,{methods:{batch:c.batch,delete:c.deleteIndex,findAnswers:c.findAnswers,getObject:c.getObject,getObjects:c.getObjects,saveObject:c.saveObject,saveObjects:c.saveObjects,search:c.search,searchForFacetValues:c.searchForFacetValues,waitTask:c.waitTask,setSettings:c.setSettings,getSettings:c.getSettings,partialUpdateObject:c.partialUpdateObject,partialUpdateObjects:c.partialUpdateObjects,deleteObject:c.deleteObject,deleteObjects:c.deleteObjects,deleteBy:c.deleteBy,clearObjects:c.clearObjects,browseObjects:c.browseObjects,getObjectPosition:c.getObjectPosition,findObject:c.findObject,exists:c.exists,saveSynonym:c.saveSynonym,saveSynonyms:c.saveSynonyms,getSynonym:c.getSynonym,searchSynonyms:c.searchSynonyms,browseSynonyms:c.browseSynonyms,deleteSynonym:c.deleteSynonym,clearSynonyms:c.clearSynonyms,replaceAllObjects:c.replaceAllObjects,replaceAllSynonyms:c.replaceAllSynonyms,searchRules:c.searchRules,getRule:c.getRule,deleteRule:c.deleteRule,saveRule:c.saveRule,saveRules:c.saveRules,replaceAllRules:c.replaceAllRules,browseRules:c.browseRules,clearRules:c.clearRules}}),initAnalytics:()=>e=>o.createAnalyticsClient({...p,...e,methods:{addABTest:o.addABTest,getABTest:o.getABTest,getABTests:o.getABTests,stopABTest:o.stopABTest,deleteABTest:o.deleteABTest}}),initPersonalization:initPersonalization,initRecommendation:()=>e=>{h.logger.info("The `initRecommendation` method is deprecated. Use `initPersonalization` instead.");return initPersonalization()(e)}}})}algoliasearch.version=n.version;e.exports=algoliasearch},930:(e,t,r)=>{const s=r(447);e.exports=s;e.exports.default=s},430:function(e,t,r){"use strict";var s=this&&this.__awaiter||function(e,t,r,s){function adopt(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,a){function fulfilled(e){try{step(s.next(e))}catch(e){a(e)}}function rejected(e){try{step(s["throw"](e))}catch(e){a(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())}))};const a=r(930);const handler=(e,t)=>s(void 0,void 0,void 0,(function*(){var r,s;const o=yield t.integration();const{config:n}=o;if(!n.application_id||!n.admin_api_key){return{statusCode:503,body:"Either the application ID or admin API key is undefined, please check your configuration."}}const{products_index_name:i="products",categories_index_name:c="categories"}=n;const d=(0,a.default)(n.application_id,n.admin_api_key);const{payload:u}=e.body;let l;switch(e.body.event){case"integrations.ready":let a=0;let o=0;let n=1;let u=[];do{const{data:e,meta:s}=yield t.api.get(`v1/products?limit=200&page=${n}`);if(!e||!e.length){console.error("Unable to fetch products, there might not be any");break}e.map((e=>{u.push(saveProduct(d,i,e).then((()=>{a++})))}));yield Promise.all(u);if(!((r=s===null||s===void 0?void 0:s.pagination)===null||r===void 0?void 0:r.total_pages)||n===s.pagination.total_pages){n=0}else{n++}}while(n>=1);n=1;u=[];do{const{data:e,meta:r}=yield t.api.get(`v1/categories?limit=200&page=${n}`);if(!e||!e.length){console.error("Unable to fetch categories, there might not be any");break}e.map((e=>{u.push(saveCategory(d,c,e).then((()=>{o++})))}));yield Promise.all(u);if(!((s=r===null||r===void 0?void 0:r.pagination)===null||s===void 0?void 0:s.total_pages)||n===r.pagination.total_pages){n=0}else{n++}}while(n>=1);return{statusCode:201,body:JSON.stringify({message:"Sync completed!",products:a,categories:o})};case"products.create":case"products.update":l=yield saveProduct(d,i,e.body.payload);return{statusCode:e.body.event==="products.create"?201:200,body:JSON.stringify({objectID:l.objectID,taskID:l.taskID})};case"products.delete":yield d.initIndex(i).deleteObject(e.body.model_ids[0]);return{statusCode:204,body:""};case"categories.create":case"categories.update":l=yield saveCategory(d,c,e.body.payload);return{statusCode:e.body.event==="categories.create"?201:200,body:JSON.stringify({objectID:l.objectID,taskID:l.taskID})};case"categories.delete":yield d.initIndex(c).deleteObject(e.body.model_ids[0]);return{statusCode:204,body:""}}return{statusCode:200,body:"Nothing happened, might be an unwanted webhook event..."}}));function saveObject(e,t,r){return e.initIndex(t).saveObject(r)}function saveProduct(e,t,r){const s={objectID:r.id,id:r.id,name:r.name,description:r.description,permalink:r.permalink,sku:r.sku,inventory:r.inventory,price:r.price,assets:r.assets,image:r.image,seo:r.seo,sort_order:r.sort_order,extra_fields:r.extra_fields,attributes:r.attributes,categories:r.categories,related_products:r.related_products,meta:r.meta,active:r.active,created:r.created,updated:r.updated};return saveObject(e,t,s)}function saveCategory(e,t,r){const s={objectID:r.id,id:r.id,name:r.name,slug:r.slug,parent_id:r.parent_id,description:r.description,products:r.products,assets:r.assets,children:r.children,meta:r.meta,created:r.created,updated:r.updated};return saveObject(e,t,s)}e.exports=handler},417:e=>{"use strict";e.exports=require("crypto")},605:e=>{"use strict";e.exports=require("http")},211:e=>{"use strict";e.exports=require("https")},835:e=>{"use strict";e.exports=require("url")}};var t={};function __nccwpck_require__(r){var s=t[r];if(s!==undefined){return s.exports}var a=t[r]={exports:{}};var o=true;try{e[r].call(a.exports,a,a.exports,__nccwpck_require__);o=false}finally{if(o)delete t[r]}return a.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r=__nccwpck_require__(430);module.exports=r})(); \ No newline at end of file diff --git a/integration/index.ts b/integration/index.ts index 0ad88b5..10155c0 100644 --- a/integration/index.ts +++ b/integration/index.ts @@ -119,7 +119,8 @@ const handler: IntegrationHandler = async (request, context) => { case 'products.delete': // Delete product from index - await client.initIndex(products_index_name).deleteObject(payload.id); + // @ts-ignore-next-line + await client.initIndex(products_index_name).deleteObject(request.body.model_ids[0]); return { statusCode: 204, body: '', @@ -139,7 +140,8 @@ const handler: IntegrationHandler = async (request, context) => { case 'categories.delete': // Delete category from index - await client.initIndex(categories_index_name).deleteObject(payload.id); + // @ts-ignore-next-line + await client.initIndex(categories_index_name).deleteObject(request.body.model_ids[0]); return { statusCode: 204, body: '',