Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algolia/recommend-core

Package Overview
Dependencies
Maintainers
83
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/recommend-core - npm Package Compare versions

Comparing version 1.13.0 to 1.14.0

dist/esm/experimental-personalization/getAffinities.d.ts

5

dist/esm/getFrequentlyBoughtTogether.js

@@ -20,2 +20,7 @@ import { mapToRecommendations } from './utils';

recommendClient.addAlgoliaAgent('recommend-core', version);
if (queries.length === 0) {
return Promise.resolve({
recommendations: []
});
}
return recommendClient.getFrequentlyBoughtTogether(queries).then(response => mapToRecommendations({

@@ -22,0 +27,0 @@ maxRecommendations,

@@ -22,2 +22,7 @@ import { mapToRecommendations } from './utils';

recommendClient.addAlgoliaAgent('recommend-core', version);
if (queries.length === 0) {
return Promise.resolve({
recommendations: []
});
}
return recommendClient.getLookingSimilar(queries).then(response => mapToRecommendations({

@@ -24,0 +29,0 @@ maxRecommendations,

@@ -24,2 +24,7 @@ import { mapToRecommendations } from './utils';

recommendClient.addAlgoliaAgent('recommend-core', version);
if (queries.length === 0) {
return Promise.resolve({
recommendations: []
});
}
return recommendClient.getRecommendations(queries).then(response => mapToRecommendations({

@@ -26,0 +31,0 @@ maxRecommendations,

@@ -22,2 +22,7 @@ import { mapToRecommendations } from './utils';

recommendClient.addAlgoliaAgent('recommend-core', version);
if (queries.length === 0) {
return Promise.resolve({
recommendations: []
});
}
return recommendClient.getRelatedProducts(queries).then(response => mapToRecommendations({

@@ -24,0 +29,0 @@ maxRecommendations,

@@ -24,2 +24,7 @@ import { mapByScoreToRecommendations, uniqBy } from './utils';

recommendClient.addAlgoliaAgent('recommend-core', version);
if (!indexName) {
return Promise.resolve({
recommendations: []
});
}
return recommendClient.getTrendingItems([query]).then(response => mapByScoreToRecommendations({

@@ -26,0 +31,0 @@ maxRecommendations,

1

dist/esm/index.d.ts

@@ -9,2 +9,3 @@ export * from './getBatchRecommendations';

export * from './getRecommendedForYou';
export * from './experimental-personalization';
export * from './types';

@@ -9,2 +9,3 @@ export * from './getBatchRecommendations';

export * from './getRecommendedForYou';
export * from './experimental-personalization';
export * from './types';

2

dist/esm/version.d.ts

@@ -1,1 +0,1 @@

export declare const version = "1.13.0";
export declare const version = "1.14.0";

@@ -1,1 +0,1 @@

export const version = '1.13.0';
export const version = '1.14.0';

@@ -1,3 +0,3 @@

/*! @algolia/recommend-core 1.13.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/recommend */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/recommend-core"]={})}(this,(function(e){"use strict";function t({hits:e,maxRecommendations:t,nrOfObjs:n}){const o={};e.forEach((e=>{e.forEach(((e,t)=>{o[e.objectID]?o[e.objectID]={indexSum:o[e.objectID].indexSum+t,nr:o[e.objectID].nr+1}:o[e.objectID]={indexSum:t,nr:1}}))}));const m=((e,t)=>{const n=[];for(const o of Object.keys(e))e[o].nr<2&&(e[o].indexSum+=100),n.push({objectID:o,avgOfIndices:e[o].indexSum/t});return n.sort(((e,t)=>e.avgOfIndices>t.avgOfIndices?1:-1))})(o,n);return m.reduce(((t,n)=>{const o=e.flat().find((e=>e.objectID===n.objectID));return o?t.concat(o):t}),[]).slice(0,t&&t>0?t:void 0)}function n({hits:e,maxRecommendations:t}){return function(e,t){const n=[...t];return n.sort(e),n}(((e,t)=>(e._score||0)>(t._score||0)?-1:1),e).slice(0,t&&t>0?t:void 0)}const o="1.13.0";e.getBatchRecommendations=async function({keys:e,queries:m,recommendClient:a}){a.addAlgoliaAgent("recommend-core",o);const r=await a.getRecommendations(m);let s=0,c=0;const i={};return e.forEach((e=>{const{model:o}=JSON.parse(e.key);c+=e.value;const{maxRecommendations:a,transformItems:d=(e=>e)}=m[s],l=r?.results?.slice(s,c);s+=e.value;let h=[],u=[];"trending-facets"===o?u=l.map((e=>e.hits)).flat():h="trending-items"===o?n({maxRecommendations:a,hits:l.map((e=>e.hits)).flat()}):t({maxRecommendations:a,hits:l.map((e=>e.hits)),nrOfObjs:e.value}),h=d(h),i[e.key]={recommendations:h,trendingFacets:u}})),i},e.getFrequentlyBoughtTogether=function({objectIDs:e,recommendClient:n,transformItems:m=(e=>e),indexName:a,maxRecommendations:r,queryParameters:s,threshold:c}){const i=e.map((e=>({indexName:a,maxRecommendations:r,objectID:e,queryParameters:s,threshold:c})));return n.addAlgoliaAgent("recommend-core",o),n.getFrequentlyBoughtTogether(i).then((n=>t({maxRecommendations:r,hits:n.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:m(e)})))},e.getLookingSimilar=function({objectIDs:e,recommendClient:n,transformItems:m=(e=>e),fallbackParameters:a,indexName:r,maxRecommendations:s,queryParameters:c,threshold:i}){const d=e.map((e=>({fallbackParameters:a,indexName:r,maxRecommendations:s,objectID:e,queryParameters:c,threshold:i})));return n.addAlgoliaAgent("recommend-core",o),n.getLookingSimilar(d).then((n=>t({maxRecommendations:s,hits:n.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:m(e)})))},e.getRecommendations=function({objectIDs:e,recommendClient:n,transformItems:m=(e=>e),fallbackParameters:a,indexName:r,maxRecommendations:s,model:c,queryParameters:i,threshold:d}){const l=e.map((e=>({fallbackParameters:a,indexName:r,maxRecommendations:s,model:c,objectID:e,queryParameters:i,threshold:d})));return n.addAlgoliaAgent("recommend-core",o),n.getRecommendations(l).then((n=>t({maxRecommendations:s,hits:n.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:m(e)})))},e.getRecommendedForYou=function({indexName:e,threshold:t,queryParameters:n,recommendClient:m,maxRecommendations:a,transformItems:r=(e=>e)}){m.addAlgoliaAgent("recommend-core",o);const s=[{indexName:e,threshold:t,queryParameters:n,maxRecommendations:a}];return m.getRecommendedForYou(s).then((e=>({recommendations:r(e.results.map((e=>e.hits)).flat())})))},e.getRelatedProducts=function({objectIDs:e,recommendClient:n,transformItems:m=(e=>e),fallbackParameters:a,indexName:r,maxRecommendations:s,queryParameters:c,threshold:i}){const d=e.map((e=>({fallbackParameters:a,indexName:r,maxRecommendations:s,objectID:e,queryParameters:c,threshold:i})));return n.addAlgoliaAgent("recommend-core",o),n.getRelatedProducts(d).then((n=>t({maxRecommendations:s,hits:n.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:m(e)})))},e.getTrendingFacets=function({recommendClient:e,transformItems:t=(e=>e),indexName:m,maxRecommendations:a,threshold:r,facetName:s}){const c={indexName:m,maxRecommendations:a,threshold:r,facetName:s};return e.addAlgoliaAgent("recommend-core",o),e.getTrendingFacets([c]).then((e=>n({maxRecommendations:a,hits:e.results.map((e=>e.hits)).flat()}))).then((e=>({recommendations:t(e)})))},e.getTrendingItems=function({recommendClient:e,transformItems:t=(e=>e),fallbackParameters:m,indexName:a,maxRecommendations:r,queryParameters:s,threshold:c,facetName:i,facetValue:d}){const l={fallbackParameters:m,indexName:a,maxRecommendations:r,queryParameters:s,threshold:c,facetName:i,facetValue:d};return e.addAlgoliaAgent("recommend-core",o),e.getTrendingItems([l]).then((e=>{return n({maxRecommendations:r,hits:(t="objectID",o=e.results.map((e=>e.hits)).flat(),[...new Map(o.map((e=>[e[t],e]))).values()])});var t,o})).then((e=>({recommendations:t(e)})))}}));
/*! @algolia/recommend-core 1.14.0 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/recommend */
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/recommend-core"]={})}(this,(function(e){"use strict";function n({hits:e,maxRecommendations:n,nrOfObjs:t}){const o={};e.forEach((e=>{e.forEach(((e,n)=>{o[e.objectID]?o[e.objectID]={indexSum:o[e.objectID].indexSum+n,nr:o[e.objectID].nr+1}:o[e.objectID]={indexSum:n,nr:1}}))}));const a=((e,n)=>{const t=[];for(const o of Object.keys(e))e[o].nr<2&&(e[o].indexSum+=100),t.push({objectID:o,avgOfIndices:e[o].indexSum/n});return t.sort(((e,n)=>e.avgOfIndices>n.avgOfIndices?1:-1))})(o,t);return a.reduce(((n,t)=>{const o=e.flat().find((e=>e.objectID===t.objectID));return o?n.concat(o):n}),[]).slice(0,n&&n>0?n:void 0)}function t({hits:e,maxRecommendations:n}){return function(e,n){const t=[...n];return t.sort(e),t}(((e,n)=>(e._score||0)>(n._score||0)?-1:1),e).slice(0,n&&n>0?n:void 0)}const o="1.14.0";const a=async({userToken:e,region:n,apiKey:t,appId:o})=>{const a=await fetch(`https://personalization.${n}.algolia.com/1/profiles/personalization/${encodeURIComponent(e)}`,{headers:{"Content-Type":"application/json","X-Algolia-Application-Id":o,"X-Algolia-API-Key":t}});if(!a.ok)throw new Error(`Failed to fetch personalization affinities. Status: ${a.status}`);return await a.json()},r=async({region:e,apiKey:n,appId:t})=>{const o=await fetch(`https://personalization.${e}.algolia.com/1/strategies/personalization`,{headers:{"Content-Type":"application/json","X-Algolia-Application-Id":t,"X-Algolia-API-Key":n}});if(!o.ok)throw new Error(`Failed to fetch personalization strategy. Status: ${o.status}`);return await o.json()},s=e=>void 0!==e.region&&void 0!==e.userToken;e.getAffinities=a,e.getBatchRecommendations=async function({keys:e,queries:a,recommendClient:r}){r.addAlgoliaAgent("recommend-core",o);const s=await r.getRecommendations(a);let m=0,i=0;const c={};return e.forEach((e=>{const{model:o}=JSON.parse(e.key);i+=e.value;const{maxRecommendations:r,transformItems:d=(e=>e)}=a[m],l=s?.results?.slice(m,i);m+=e.value;let u=[],g=[];"trending-facets"===o?g=l.map((e=>e.hits)).flat():u="trending-items"===o?t({maxRecommendations:r,hits:l.map((e=>e.hits)).flat()}):n({maxRecommendations:r,hits:l.map((e=>e.hits)),nrOfObjs:e.value}),u=d(u),c[e.key]={recommendations:u,trendingFacets:g}})),c},e.getFrequentlyBoughtTogether=function({objectIDs:e,recommendClient:t,transformItems:a=(e=>e),indexName:r,maxRecommendations:s,queryParameters:m,threshold:i}){const c=e.map((e=>({indexName:r,maxRecommendations:s,objectID:e,queryParameters:m,threshold:i})));return t.addAlgoliaAgent("recommend-core",o),0===c.length?Promise.resolve({recommendations:[]}):t.getFrequentlyBoughtTogether(c).then((t=>n({maxRecommendations:s,hits:t.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:a(e)})))},e.getLookingSimilar=function({objectIDs:e,recommendClient:t,transformItems:a=(e=>e),fallbackParameters:r,indexName:s,maxRecommendations:m,queryParameters:i,threshold:c}){const d=e.map((e=>({fallbackParameters:r,indexName:s,maxRecommendations:m,objectID:e,queryParameters:i,threshold:c})));return t.addAlgoliaAgent("recommend-core",o),0===d.length?Promise.resolve({recommendations:[]}):t.getLookingSimilar(d).then((t=>n({maxRecommendations:m,hits:t.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:a(e)})))},e.getPersonalizationFilters=async({userToken:e,region:n,apiKey:t,appId:o})=>{if(!n)throw new Error("[Algolia Recommend] parameter `region` is required to enable personalization.");if(!e)return console.warn("[Algolia Recommend] Personalization couldn't be enabled because `userToken` is missing. Falling back to non-personalized recommendations."),[];try{const[s,m]=await Promise.all([a({userToken:e,apiKey:t,appId:o,region:n}),r({apiKey:t,appId:o,region:n})]),i=100,c=new Map(m.facetsScoring.map((e=>[e.facetName,e.score])));return Object.entries(s.scores).flatMap((([e,n])=>Object.entries(n).map((([n,t])=>{const o=c.get(e)??i,a=Math.floor(t*(o/100));return`${e}:${n}<score=${a}>`}))))}catch(e){const n=e instanceof Error?e.message:String(e);return console.error(`[Algolia Recommend] Personalization couldn't be enabled. Falling back to non-personalized recommendations. Error: ${n}`),[]}},e.getPersonalizationProps=e=>s(e)?{region:e.region,userToken:e.userToken,suppressExperimentalWarning:Boolean(e.suppressExperimentalWarning)}:{region:void 0,userToken:void 0,suppressExperimentalWarning:Boolean(e.suppressExperimentalWarning)},e.getRecommendations=function({objectIDs:e,recommendClient:t,transformItems:a=(e=>e),fallbackParameters:r,indexName:s,maxRecommendations:m,model:i,queryParameters:c,threshold:d}){const l=e.map((e=>({fallbackParameters:r,indexName:s,maxRecommendations:m,model:i,objectID:e,queryParameters:c,threshold:d})));return t.addAlgoliaAgent("recommend-core",o),0===l.length?Promise.resolve({recommendations:[]}):t.getRecommendations(l).then((t=>n({maxRecommendations:m,hits:t.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:a(e)})))},e.getRecommendedForYou=function({indexName:e,threshold:n,queryParameters:t,recommendClient:a,maxRecommendations:r,transformItems:s=(e=>e)}){a.addAlgoliaAgent("recommend-core",o);const m=[{indexName:e,threshold:n,queryParameters:t,maxRecommendations:r}];return a.getRecommendedForYou(m).then((e=>({recommendations:s(e.results.map((e=>e.hits)).flat())})))},e.getRelatedProducts=function({objectIDs:e,recommendClient:t,transformItems:a=(e=>e),fallbackParameters:r,indexName:s,maxRecommendations:m,queryParameters:i,threshold:c}){const d=e.map((e=>({fallbackParameters:r,indexName:s,maxRecommendations:m,objectID:e,queryParameters:i,threshold:c})));return t.addAlgoliaAgent("recommend-core",o),0===d.length?Promise.resolve({recommendations:[]}):t.getRelatedProducts(d).then((t=>n({maxRecommendations:m,hits:t.results.map((e=>e.hits)),nrOfObjs:e.length}))).then((e=>({recommendations:a(e)})))},e.getStrategy=r,e.getTrendingFacets=function({recommendClient:e,transformItems:n=(e=>e),indexName:a,maxRecommendations:r,threshold:s,facetName:m}){const i={indexName:a,maxRecommendations:r,threshold:s,facetName:m};return e.addAlgoliaAgent("recommend-core",o),e.getTrendingFacets([i]).then((e=>t({maxRecommendations:r,hits:e.results.map((e=>e.hits)).flat()}))).then((e=>({recommendations:n(e)})))},e.getTrendingItems=function({recommendClient:e,transformItems:n=(e=>e),fallbackParameters:a,indexName:r,maxRecommendations:s,queryParameters:m,threshold:i,facetName:c,facetValue:d}){const l={fallbackParameters:a,indexName:r,maxRecommendations:s,queryParameters:m,threshold:i,facetName:c,facetValue:d};return e.addAlgoliaAgent("recommend-core",o),r?e.getTrendingItems([l]).then((e=>{return t({maxRecommendations:s,hits:(n="objectID",o=e.results.map((e=>e.hits)).flat(),[...new Map(o.map((e=>[e[n],e]))).values()])});var n,o})).then((e=>({recommendations:n(e)}))):Promise.resolve({recommendations:[]})},e.isPersonalizationEnabled=s}));
//# sourceMappingURL=index.js.map
{
"name": "@algolia/recommend-core",
"version": "1.13.0",
"version": "1.14.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/algolia/recommend",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc