@algolia/recommend 4.12.2 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/recommend.cjs.js +44 -0
- package/dist/recommend.d.ts +52 -1
- package/dist/recommend.esm.browser.js +45 -1
- package/dist/recommend.umd.js +2 -2
- package/package.json +12 -12
package/dist/recommend.cjs.js
CHANGED
|
@@ -86,6 +86,48 @@ const getRelatedProducts = base => {
|
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
const getTrendingFacets = base => {
|
|
90
|
+
return (queries, requestOptions) => {
|
|
91
|
+
const requests = queries.map(query => ({
|
|
92
|
+
...query,
|
|
93
|
+
model: 'trending-facets',
|
|
94
|
+
// The `threshold` param is required by the endpoint to make it easier
|
|
95
|
+
// to provide a default value later, so we default it in the client
|
|
96
|
+
// so that users don't have to provide a value.
|
|
97
|
+
threshold: query.threshold || 0,
|
|
98
|
+
}));
|
|
99
|
+
return base.transporter.read({
|
|
100
|
+
method: requesterCommon.MethodEnum.Post,
|
|
101
|
+
path: '1/indexes/*/recommendations',
|
|
102
|
+
data: {
|
|
103
|
+
requests,
|
|
104
|
+
},
|
|
105
|
+
cacheable: true,
|
|
106
|
+
}, requestOptions);
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const getTrendingItems = base => {
|
|
111
|
+
return (queries, requestOptions) => {
|
|
112
|
+
const requests = queries.map(query => ({
|
|
113
|
+
...query,
|
|
114
|
+
model: 'trending-items',
|
|
115
|
+
// The `threshold` param is required by the endpoint to make it easier
|
|
116
|
+
// to provide a default value later, so we default it in the client
|
|
117
|
+
// so that users don't have to provide a value.
|
|
118
|
+
threshold: query.threshold || 0,
|
|
119
|
+
}));
|
|
120
|
+
return base.transporter.read({
|
|
121
|
+
method: requesterCommon.MethodEnum.Post,
|
|
122
|
+
path: '1/indexes/*/recommendations',
|
|
123
|
+
data: {
|
|
124
|
+
requests,
|
|
125
|
+
},
|
|
126
|
+
cacheable: true,
|
|
127
|
+
}, requestOptions);
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
89
131
|
function recommend(appId, apiKey, options) {
|
|
90
132
|
const commonOptions = {
|
|
91
133
|
appId,
|
|
@@ -112,6 +154,8 @@ function recommend(appId, apiKey, options) {
|
|
|
112
154
|
getFrequentlyBoughtTogether,
|
|
113
155
|
getRecommendations,
|
|
114
156
|
getRelatedProducts,
|
|
157
|
+
getTrendingFacets,
|
|
158
|
+
getTrendingItems,
|
|
115
159
|
},
|
|
116
160
|
});
|
|
117
161
|
}
|
package/dist/recommend.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export declare type RecommendClientOptions = {
|
|
|
85
85
|
readonly authMode?: AuthModeType;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
export declare type RecommendModel = 'related-products' | 'bought-together';
|
|
88
|
+
export declare type RecommendModel = 'related-products' | 'bought-together' | TrendingModel;
|
|
89
89
|
|
|
90
90
|
export declare type RecommendOptions = Partial<ClientTransporterOptions>;
|
|
91
91
|
|
|
@@ -93,6 +93,49 @@ export declare type RecommendSearchOptions = Omit<SearchOptions, 'page' | 'hitsP
|
|
|
93
93
|
|
|
94
94
|
export declare type RelatedProductsQuery = Omit<RecommendationsQuery, 'model'>;
|
|
95
95
|
|
|
96
|
+
export declare type TrendingFacetsQuery = Omit<TrendingQuery, 'model' | 'facetValue'>;
|
|
97
|
+
|
|
98
|
+
export declare type TrendingItemsQuery = Omit<TrendingQuery, 'model'>;
|
|
99
|
+
|
|
100
|
+
export declare type TrendingModel = 'trending-items' | 'trending-facets';
|
|
101
|
+
|
|
102
|
+
export declare type TrendingQuery = {
|
|
103
|
+
/**
|
|
104
|
+
* The name of the target index.
|
|
105
|
+
*/
|
|
106
|
+
readonly indexName: string;
|
|
107
|
+
/**
|
|
108
|
+
* The name of the Recommendation model to use.
|
|
109
|
+
*/
|
|
110
|
+
readonly model: TrendingModel;
|
|
111
|
+
/**
|
|
112
|
+
* Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
|
|
113
|
+
*/
|
|
114
|
+
readonly threshold?: number;
|
|
115
|
+
/**
|
|
116
|
+
* How many recommendations to retrieve.
|
|
117
|
+
*/
|
|
118
|
+
readonly maxRecommendations?: number;
|
|
119
|
+
/**
|
|
120
|
+
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
|
|
121
|
+
*/
|
|
122
|
+
readonly queryParameters?: RecommendSearchOptions;
|
|
123
|
+
/**
|
|
124
|
+
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
|
|
125
|
+
*
|
|
126
|
+
* Additional filters to use as fallback when there aren’t enough recommendations.
|
|
127
|
+
*/
|
|
128
|
+
readonly fallbackParameters?: RecommendSearchOptions;
|
|
129
|
+
/**
|
|
130
|
+
* Used for trending model
|
|
131
|
+
*/
|
|
132
|
+
readonly facetName?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Used for trending model
|
|
135
|
+
*/
|
|
136
|
+
readonly facetValue?: string;
|
|
137
|
+
};
|
|
138
|
+
|
|
96
139
|
export declare type WithRecommendMethods<TType> = TType & {
|
|
97
140
|
/**
|
|
98
141
|
* Returns recommendations.
|
|
@@ -106,6 +149,14 @@ export declare type WithRecommendMethods<TType> = TType & {
|
|
|
106
149
|
* Returns [Frequently Bought Together](https://algolia.com/doc/guides/algolia-ai/recommend/#frequently-bought-together) products.
|
|
107
150
|
*/
|
|
108
151
|
readonly getFrequentlyBoughtTogether: <TObject>(queries: readonly FrequentlyBoughtTogetherQuery[], requestOptions?: RequestOptions & SearchOptions) => Readonly<Promise<MultipleQueriesResponse<TObject>>>;
|
|
152
|
+
/**
|
|
153
|
+
* Returns trending items
|
|
154
|
+
*/
|
|
155
|
+
readonly getTrendingItems: <TObject>(queries: readonly TrendingItemsQuery[], requestOptions?: RequestOptions & SearchOptions) => Readonly<Promise<MultipleQueriesResponse<TObject>>>;
|
|
156
|
+
/**
|
|
157
|
+
* Returns trending items per facet
|
|
158
|
+
*/
|
|
159
|
+
readonly getTrendingFacets: <TObject>(queries: readonly TrendingFacetsQuery[], requestOptions?: RequestOptions & SearchOptions) => Readonly<Promise<MultipleQueriesResponse<TObject>>>;
|
|
109
160
|
};
|
|
110
161
|
|
|
111
162
|
export { }
|
|
@@ -181,7 +181,7 @@ function encode(format, ...args) {
|
|
|
181
181
|
return format.replace(/%s/g, () => encodeURIComponent(args[i++]));
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
const version = '4.
|
|
184
|
+
const version = '4.13.0';
|
|
185
185
|
|
|
186
186
|
const AuthMode = {
|
|
187
187
|
/**
|
|
@@ -813,6 +813,48 @@ const getRelatedProducts = base => {
|
|
|
813
813
|
};
|
|
814
814
|
};
|
|
815
815
|
|
|
816
|
+
const getTrendingFacets = base => {
|
|
817
|
+
return (queries, requestOptions) => {
|
|
818
|
+
const requests = queries.map(query => ({
|
|
819
|
+
...query,
|
|
820
|
+
model: 'trending-facets',
|
|
821
|
+
// The `threshold` param is required by the endpoint to make it easier
|
|
822
|
+
// to provide a default value later, so we default it in the client
|
|
823
|
+
// so that users don't have to provide a value.
|
|
824
|
+
threshold: query.threshold || 0,
|
|
825
|
+
}));
|
|
826
|
+
return base.transporter.read({
|
|
827
|
+
method: MethodEnum.Post,
|
|
828
|
+
path: '1/indexes/*/recommendations',
|
|
829
|
+
data: {
|
|
830
|
+
requests,
|
|
831
|
+
},
|
|
832
|
+
cacheable: true,
|
|
833
|
+
}, requestOptions);
|
|
834
|
+
};
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
const getTrendingItems = base => {
|
|
838
|
+
return (queries, requestOptions) => {
|
|
839
|
+
const requests = queries.map(query => ({
|
|
840
|
+
...query,
|
|
841
|
+
model: 'trending-items',
|
|
842
|
+
// The `threshold` param is required by the endpoint to make it easier
|
|
843
|
+
// to provide a default value later, so we default it in the client
|
|
844
|
+
// so that users don't have to provide a value.
|
|
845
|
+
threshold: query.threshold || 0,
|
|
846
|
+
}));
|
|
847
|
+
return base.transporter.read({
|
|
848
|
+
method: MethodEnum.Post,
|
|
849
|
+
path: '1/indexes/*/recommendations',
|
|
850
|
+
data: {
|
|
851
|
+
requests,
|
|
852
|
+
},
|
|
853
|
+
cacheable: true,
|
|
854
|
+
}, requestOptions);
|
|
855
|
+
};
|
|
856
|
+
};
|
|
857
|
+
|
|
816
858
|
function recommend(appId, apiKey, options) {
|
|
817
859
|
const commonOptions = {
|
|
818
860
|
appId,
|
|
@@ -844,6 +886,8 @@ function recommend(appId, apiKey, options) {
|
|
|
844
886
|
getFrequentlyBoughtTogether,
|
|
845
887
|
getRecommendations,
|
|
846
888
|
getRelatedProducts,
|
|
889
|
+
getTrendingFacets,
|
|
890
|
+
getTrendingItems,
|
|
847
891
|
},
|
|
848
892
|
});
|
|
849
893
|
}
|
package/dist/recommend.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! recommend.umd.js | 4.
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self)["@algolia/recommend"]=t()}(this,(function(){"use strict";function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(r){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}))}return r}function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function o(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function a(e){var t,r="algoliasearch-client-js-".concat(e.key),o=function(){return void 0===t&&(t=e.localStorage||window.localStorage),t},a=function(){return JSON.parse(o().getItem(r)||"{}")};return{get:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return Promise.resolve().then((function(){var r=JSON.stringify(e),n=a()[r];return Promise.all([n||t(),void 0!==n])})).then((function(e){var t=n(e,2),o=t[0],a=t[1];return Promise.all([o,a||r.miss(o)])})).then((function(e){return n(e,1)[0]}))},set:function(e,t){return Promise.resolve().then((function(){var n=a();return n[JSON.stringify(e)]=t,o().setItem(r,JSON.stringify(n)),t}))},delete:function(e){return Promise.resolve().then((function(){var t=a();delete t[JSON.stringify(e)],o().setItem(r,JSON.stringify(t))}))},clear:function(){return Promise.resolve().then((function(){o().removeItem(r)}))}}}function u(e){var t=o(e.caches),r=t.shift();return void 0===r?{get:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},o=t();return o.then((function(e){return Promise.all([e,r.miss(e)])})).then((function(e){return n(e,1)[0]}))},set:function(e,t){return Promise.resolve(t)},delete:function(e){return Promise.resolve()},clear:function(){return Promise.resolve()}}:{get:function(e,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return r.get(e,n,o).catch((function(){return u({caches:t}).get(e,n,o)}))},set:function(e,n){return r.set(e,n).catch((function(){return u({caches:t}).set(e,n)}))},delete:function(e){return r.delete(e).catch((function(){return u({caches:t}).delete(e)}))},clear:function(){return r.clear().catch((function(){return u({caches:t}).clear()}))}}}function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{serializable:!0},t={};return{get:function(r,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},a=JSON.stringify(r);if(a in t)return Promise.resolve(e.serializable?JSON.parse(t[a]):t[a]);var u=n(),i=o&&o.miss||function(){return Promise.resolve()};return u.then((function(e){return i(e)})).then((function(){return u}))},set:function(r,n){return t[JSON.stringify(r)]=e.serializable?JSON.stringify(n):n,Promise.resolve(n)},delete:function(e){return delete t[JSON.stringify(e)],Promise.resolve()},clear:function(){return t={},Promise.resolve()}}}function s(e){for(var t=e.length-1;t>0;t--){var r=Math.floor(Math.random()*(t+1)),n=e[t];e[t]=e[r],e[r]=n}return e}var c={WithinQueryParameters:0,WithinHeaders:1},l=1,f=2,h=3;function d(e,t){var r=e||{},n=r.data||{};return Object.keys(r).forEach((function(e){-1===["timeout","headers","queryParameters","data","cacheable"].indexOf(e)&&(n[e]=r[e])})),{data:Object.entries(n).length>0?n:void 0,timeout:r.timeout||t,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}var m={Read:1,Write:2,Any:3},p=1,v=2,g=3;function y(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p;return r(r({},e),{},{status:t,lastUpdate:Date.now()})}function b(e){return"string"==typeof e?{protocol:"https",url:e,accept:m.Any}:{protocol:e.protocol||"https",url:e.url,accept:e.accept||m.Any}}var P="GET",O="POST";function q(e,t){return Promise.all(t.map((function(t){return e.get(t,(function(){return Promise.resolve(y(t))}))}))).then((function(e){var r=e.filter((function(e){return function(e){return e.status===p||Date.now()-e.lastUpdate>12e4}(e)})),n=e.filter((function(e){return function(e){return e.status===g&&Date.now()-e.lastUpdate<=12e4}(e)})),a=[].concat(o(r),o(n));return{getTimeout:function(e,t){return(0===n.length&&0===e?1:n.length+3+e)*t},statelessHosts:a.length>0?a.map((function(e){return b(e)})):t}}))}function S(e,t,n,a){var u=[],i=function(e,t){if(e.method===P||void 0===e.data&&void 0===t.data)return;var n=Array.isArray(e.data)?e.data:r(r({},e.data),t.data);return JSON.stringify(n)}(n,a),s=function(e,t){var n=r(r({},e.headers),t.headers),o={};return Object.keys(n).forEach((function(e){var t=n[e];o[e.toLowerCase()]=t})),o}(e,a),c=n.method,l=n.method!==P?{}:r(r({},n.data),a.data),f=r(r(r({"x-algolia-agent":e.userAgent.value},e.queryParameters),l),a.queryParameters),h=0,d=function t(r,o){var l=r.pop();if(void 0===l)throw{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:T(u)};var d={data:i,headers:s,method:c,url:w(l,n.path,f),connectTimeout:o(h,e.timeouts.connect),responseTimeout:o(h,a.timeout)},m=function(e){var t={request:d,response:e,host:l,triesLeft:r.length};return u.push(t),t},p={onSuccess:function(e){return function(e){try{return JSON.parse(e.content)}catch(t){throw function(e,t){return{name:"DeserializationError",message:e,response:t}}(t.message,e)}}(e)},onRetry:function(n){var a=m(n);return n.isTimedOut&&h++,Promise.all([e.logger.info("Retryable failure",A(a)),e.hostsCache.set(l,y(l,n.isTimedOut?g:v))]).then((function(){return t(r,o)}))},onFail:function(e){throw m(e),function(e,t){var r=e.content,n=e.status,o=r;try{o=JSON.parse(r).message}catch(e){}return function(e,t,r){return{name:"ApiError",message:e,status:t,transporterStackTrace:r}}(o,n,t)}(e,T(u))}};return e.requester.send(d).then((function(e){return function(e,t){return function(e){var t=e.status;return e.isTimedOut||function(e){var t=e.isTimedOut,r=e.status;return!t&&0==~~r}(e)||2!=~~(t/100)&&4!=~~(t/100)}(e)?t.onRetry(e):2==~~(e.status/100)?t.onSuccess(e):t.onFail(e)}(e,p)}))};return q(e.hostsCache,t).then((function(e){return d(o(e.statelessHosts).reverse(),e.getTimeout)}))}function j(e){var t={value:"Algolia for JavaScript (".concat(e,")"),add:function(e){var r="; ".concat(e.segment).concat(void 0!==e.version?" (".concat(e.version,")"):"");return-1===t.value.indexOf(r)&&(t.value="".concat(t.value).concat(r)),t}};return t}function w(e,t,r){var n,o=(n=r,Object.keys(n).map((function(e){return function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o=0;return e.replace(/%s/g,(function(){return encodeURIComponent(r[o++])}))}("%s=%s",e,(t=n[e],"[object Object]"===Object.prototype.toString.call(t)||"[object Array]"===Object.prototype.toString.call(t)?JSON.stringify(n[e]):n[e]));var t})).join("&")),a="".concat(e.protocol,"://").concat(e.url,"/").concat("/"===t.charAt(0)?t.substr(1):t);return o.length&&(a+="?".concat(o)),a}function T(e){return e.map((function(e){return A(e)}))}function A(e){var t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return r(r({},e),{},{request:r(r({},e.request),{},{headers:r(r({},e.request.headers),t)})})}var C=function(e){var t=e.appId,o=function(e,t,r){var n={"x-algolia-api-key":r,"x-algolia-application-id":t};return{headers:function(){return e===c.WithinHeaders?n:{}},queryParameters:function(){return e===c.WithinQueryParameters?n:{}}}}(void 0!==e.authMode?e.authMode:c.WithinHeaders,t,e.apiKey),a=function(e){var t=e.hostsCache,r=e.logger,o=e.requester,a=e.requestsCache,u=e.responsesCache,i=e.timeouts,s=e.userAgent,c=e.hosts,l=e.queryParameters,f={hostsCache:t,logger:r,requester:o,requestsCache:a,responsesCache:u,timeouts:i,userAgent:s,headers:e.headers,queryParameters:l,hosts:c.map((function(e){return b(e)})),read:function(e,t){var r=d(t,f.timeouts.read),o=function(){return S(f,f.hosts.filter((function(e){return 0!=(e.accept&m.Read)})),e,r)};if(!0!==(void 0!==r.cacheable?r.cacheable:e.cacheable))return o();var a={request:e,mappedRequestOptions:r,transporter:{queryParameters:f.queryParameters,headers:f.headers}};return f.responsesCache.get(a,(function(){return f.requestsCache.get(a,(function(){return f.requestsCache.set(a,o()).then((function(e){return Promise.all([f.requestsCache.delete(a),e])}),(function(e){return Promise.all([f.requestsCache.delete(a),Promise.reject(e)])})).then((function(e){var t=n(e,2);t[0];return t[1]}))}))}),{miss:function(e){return f.responsesCache.set(a,e)}})},write:function(e,t){return S(f,f.hosts.filter((function(e){return 0!=(e.accept&m.Write)})),e,d(t,f.timeouts.write))}};return f}(r(r({hosts:[{url:"".concat(t,"-dsn.algolia.net"),accept:m.Read},{url:"".concat(t,".algolia.net"),accept:m.Write}].concat(s([{url:"".concat(t,"-1.algolianet.com")},{url:"".concat(t,"-2.algolianet.com")},{url:"".concat(t,"-3.algolianet.com")}]))},e),{},{headers:r(r(r({},o.headers()),{"content-type":"application/x-www-form-urlencoded"}),e.headers),queryParameters:r(r({},o.queryParameters()),e.queryParameters)}));return function(e,t){return t?(Object.keys(t).forEach((function(r){e[r]=t[r](e)})),e):e}({transporter:a,appId:t,addAlgoliaAgent:function(e,t){a.userAgent.add({segment:e,version:t})},clearCache:function(){return Promise.all([a.requestsCache.clear(),a.responsesCache.clear()]).then((function(){}))}},e.methods)},N=function(e){return function(t,n){var o=t.map((function(e){return r(r({},e),{},{threshold:e.threshold||0})}));return e.transporter.read({method:O,path:"1/indexes/*/recommendations",data:{requests:o},cacheable:!0},n)}},k=function(e){return function(t,n){return N(e)(t.map((function(e){return r(r({},e),{},{fallbackParameters:{},model:"bought-together"})})),n)}},J=function(e){return function(t,n){return N(e)(t.map((function(e){return r(r({},e),{},{model:"related-products"})})),n)}};function x(e,t,n){var o,s={appId:e,apiKey:t,timeouts:{connect:1,read:2,write:30},requester:{send:function(e){return new Promise((function(t){var r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach((function(t){return r.setRequestHeader(t,e.headers[t])}));var n,o=function(e,n){return setTimeout((function(){r.abort(),t({status:0,content:n,isTimedOut:!0})}),1e3*e)},a=o(e.connectTimeout,"Connection timeout");r.onreadystatechange=function(){r.readyState>r.OPENED&&void 0===n&&(clearTimeout(a),n=o(e.responseTimeout,"Socket timeout"))},r.onerror=function(){0===r.status&&(clearTimeout(a),clearTimeout(n),t({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=function(){clearTimeout(a),clearTimeout(n),t({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(e.data)}))}},logger:(o=h,{debug:function(e,t){return l>=o&&console.debug(e,t),Promise.resolve()},info:function(e,t){return f>=o&&console.info(e,t),Promise.resolve()},error:function(e,t){return console.error(e,t),Promise.resolve()}}),responsesCache:i(),requestsCache:i({serializable:!1}),hostsCache:u({caches:[a({key:"".concat("4.12.2","-").concat(e)}),i()]}),userAgent:j("4.12.2").add({segment:"Recommend",version:"4.12.2"}).add({segment:"Browser"}),authMode:c.WithinQueryParameters};return C(r(r(r({},s),n),{},{methods:{getFrequentlyBoughtTogether:k,getRecommendations:N,getRelatedProducts:J}}))}return x.version="4.12.2",x}));
|
|
1
|
+
/*! recommend.umd.js | 4.13.0 | © Algolia, inc. | https://github.com/algolia/algoliasearch-client-javascript */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self)["@algolia/recommend"]=t()}(this,(function(){"use strict";function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(r){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}))}return r}function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var u,i=e[Symbol.iterator]();!(n=(u=i.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw a}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function o(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function a(e){var t,r="algoliasearch-client-js-".concat(e.key),o=function(){return void 0===t&&(t=e.localStorage||window.localStorage),t},a=function(){return JSON.parse(o().getItem(r)||"{}")};return{get:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return Promise.resolve().then((function(){var r=JSON.stringify(e),n=a()[r];return Promise.all([n||t(),void 0!==n])})).then((function(e){var t=n(e,2),o=t[0],a=t[1];return Promise.all([o,a||r.miss(o)])})).then((function(e){return n(e,1)[0]}))},set:function(e,t){return Promise.resolve().then((function(){var n=a();return n[JSON.stringify(e)]=t,o().setItem(r,JSON.stringify(n)),t}))},delete:function(e){return Promise.resolve().then((function(){var t=a();delete t[JSON.stringify(e)],o().setItem(r,JSON.stringify(t))}))},clear:function(){return Promise.resolve().then((function(){o().removeItem(r)}))}}}function u(e){var t=o(e.caches),r=t.shift();return void 0===r?{get:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},o=t();return o.then((function(e){return Promise.all([e,r.miss(e)])})).then((function(e){return n(e,1)[0]}))},set:function(e,t){return Promise.resolve(t)},delete:function(e){return Promise.resolve()},clear:function(){return Promise.resolve()}}:{get:function(e,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return r.get(e,n,o).catch((function(){return u({caches:t}).get(e,n,o)}))},set:function(e,n){return r.set(e,n).catch((function(){return u({caches:t}).set(e,n)}))},delete:function(e){return r.delete(e).catch((function(){return u({caches:t}).delete(e)}))},clear:function(){return r.clear().catch((function(){return u({caches:t}).clear()}))}}}function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{serializable:!0},t={};return{get:function(r,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},a=JSON.stringify(r);if(a in t)return Promise.resolve(e.serializable?JSON.parse(t[a]):t[a]);var u=n(),i=o&&o.miss||function(){return Promise.resolve()};return u.then((function(e){return i(e)})).then((function(){return u}))},set:function(r,n){return t[JSON.stringify(r)]=e.serializable?JSON.stringify(n):n,Promise.resolve(n)},delete:function(e){return delete t[JSON.stringify(e)],Promise.resolve()},clear:function(){return t={},Promise.resolve()}}}function s(e){for(var t=e.length-1;t>0;t--){var r=Math.floor(Math.random()*(t+1)),n=e[t];e[t]=e[r],e[r]=n}return e}var c={WithinQueryParameters:0,WithinHeaders:1},l=1,f=2,d=3;function h(e,t){var r=e||{},n=r.data||{};return Object.keys(r).forEach((function(e){-1===["timeout","headers","queryParameters","data","cacheable"].indexOf(e)&&(n[e]=r[e])})),{data:Object.entries(n).length>0?n:void 0,timeout:r.timeout||t,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}var m={Read:1,Write:2,Any:3},p=1,g=2,v=3;function y(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p;return r(r({},e),{},{status:t,lastUpdate:Date.now()})}function b(e){return"string"==typeof e?{protocol:"https",url:e,accept:m.Any}:{protocol:e.protocol||"https",url:e.url,accept:e.accept||m.Any}}var P="GET",O="POST";function q(e,t){return Promise.all(t.map((function(t){return e.get(t,(function(){return Promise.resolve(y(t))}))}))).then((function(e){var r=e.filter((function(e){return function(e){return e.status===p||Date.now()-e.lastUpdate>12e4}(e)})),n=e.filter((function(e){return function(e){return e.status===v&&Date.now()-e.lastUpdate<=12e4}(e)})),a=[].concat(o(r),o(n));return{getTimeout:function(e,t){return(0===n.length&&0===e?1:n.length+3+e)*t},statelessHosts:a.length>0?a.map((function(e){return b(e)})):t}}))}function S(e,t,n,a){var u=[],i=function(e,t){if(e.method===P||void 0===e.data&&void 0===t.data)return;var n=Array.isArray(e.data)?e.data:r(r({},e.data),t.data);return JSON.stringify(n)}(n,a),s=function(e,t){var n=r(r({},e.headers),t.headers),o={};return Object.keys(n).forEach((function(e){var t=n[e];o[e.toLowerCase()]=t})),o}(e,a),c=n.method,l=n.method!==P?{}:r(r({},n.data),a.data),f=r(r(r({"x-algolia-agent":e.userAgent.value},e.queryParameters),l),a.queryParameters),d=0,h=function t(r,o){var l=r.pop();if(void 0===l)throw{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:T(u)};var h={data:i,headers:s,method:c,url:w(l,n.path,f),connectTimeout:o(d,e.timeouts.connect),responseTimeout:o(d,a.timeout)},m=function(e){var t={request:h,response:e,host:l,triesLeft:r.length};return u.push(t),t},p={onSuccess:function(e){return function(e){try{return JSON.parse(e.content)}catch(t){throw function(e,t){return{name:"DeserializationError",message:e,response:t}}(t.message,e)}}(e)},onRetry:function(n){var a=m(n);return n.isTimedOut&&d++,Promise.all([e.logger.info("Retryable failure",A(a)),e.hostsCache.set(l,y(l,n.isTimedOut?v:g))]).then((function(){return t(r,o)}))},onFail:function(e){throw m(e),function(e,t){var r=e.content,n=e.status,o=r;try{o=JSON.parse(r).message}catch(e){}return function(e,t,r){return{name:"ApiError",message:e,status:t,transporterStackTrace:r}}(o,n,t)}(e,T(u))}};return e.requester.send(h).then((function(e){return function(e,t){return function(e){var t=e.status;return e.isTimedOut||function(e){var t=e.isTimedOut,r=e.status;return!t&&0==~~r}(e)||2!=~~(t/100)&&4!=~~(t/100)}(e)?t.onRetry(e):2==~~(e.status/100)?t.onSuccess(e):t.onFail(e)}(e,p)}))};return q(e.hostsCache,t).then((function(e){return h(o(e.statelessHosts).reverse(),e.getTimeout)}))}function j(e){var t={value:"Algolia for JavaScript (".concat(e,")"),add:function(e){var r="; ".concat(e.segment).concat(void 0!==e.version?" (".concat(e.version,")"):"");return-1===t.value.indexOf(r)&&(t.value="".concat(t.value).concat(r)),t}};return t}function w(e,t,r){var n,o=(n=r,Object.keys(n).map((function(e){return function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o=0;return e.replace(/%s/g,(function(){return encodeURIComponent(r[o++])}))}("%s=%s",e,(t=n[e],"[object Object]"===Object.prototype.toString.call(t)||"[object Array]"===Object.prototype.toString.call(t)?JSON.stringify(n[e]):n[e]));var t})).join("&")),a="".concat(e.protocol,"://").concat(e.url,"/").concat("/"===t.charAt(0)?t.substr(1):t);return o.length&&(a+="?".concat(o)),a}function T(e){return e.map((function(e){return A(e)}))}function A(e){var t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return r(r({},e),{},{request:r(r({},e.request),{},{headers:r(r({},e.request.headers),t)})})}var C=function(e){var t=e.appId,o=function(e,t,r){var n={"x-algolia-api-key":r,"x-algolia-application-id":t};return{headers:function(){return e===c.WithinHeaders?n:{}},queryParameters:function(){return e===c.WithinQueryParameters?n:{}}}}(void 0!==e.authMode?e.authMode:c.WithinHeaders,t,e.apiKey),a=function(e){var t=e.hostsCache,r=e.logger,o=e.requester,a=e.requestsCache,u=e.responsesCache,i=e.timeouts,s=e.userAgent,c=e.hosts,l=e.queryParameters,f={hostsCache:t,logger:r,requester:o,requestsCache:a,responsesCache:u,timeouts:i,userAgent:s,headers:e.headers,queryParameters:l,hosts:c.map((function(e){return b(e)})),read:function(e,t){var r=h(t,f.timeouts.read),o=function(){return S(f,f.hosts.filter((function(e){return 0!=(e.accept&m.Read)})),e,r)};if(!0!==(void 0!==r.cacheable?r.cacheable:e.cacheable))return o();var a={request:e,mappedRequestOptions:r,transporter:{queryParameters:f.queryParameters,headers:f.headers}};return f.responsesCache.get(a,(function(){return f.requestsCache.get(a,(function(){return f.requestsCache.set(a,o()).then((function(e){return Promise.all([f.requestsCache.delete(a),e])}),(function(e){return Promise.all([f.requestsCache.delete(a),Promise.reject(e)])})).then((function(e){var t=n(e,2);t[0];return t[1]}))}))}),{miss:function(e){return f.responsesCache.set(a,e)}})},write:function(e,t){return S(f,f.hosts.filter((function(e){return 0!=(e.accept&m.Write)})),e,h(t,f.timeouts.write))}};return f}(r(r({hosts:[{url:"".concat(t,"-dsn.algolia.net"),accept:m.Read},{url:"".concat(t,".algolia.net"),accept:m.Write}].concat(s([{url:"".concat(t,"-1.algolianet.com")},{url:"".concat(t,"-2.algolianet.com")},{url:"".concat(t,"-3.algolianet.com")}]))},e),{},{headers:r(r(r({},o.headers()),{"content-type":"application/x-www-form-urlencoded"}),e.headers),queryParameters:r(r({},o.queryParameters()),e.queryParameters)}));return function(e,t){return t?(Object.keys(t).forEach((function(r){e[r]=t[r](e)})),e):e}({transporter:a,appId:t,addAlgoliaAgent:function(e,t){a.userAgent.add({segment:e,version:t})},clearCache:function(){return Promise.all([a.requestsCache.clear(),a.responsesCache.clear()]).then((function(){}))}},e.methods)},N=function(e){return function(t,n){var o=t.map((function(e){return r(r({},e),{},{threshold:e.threshold||0})}));return e.transporter.read({method:O,path:"1/indexes/*/recommendations",data:{requests:o},cacheable:!0},n)}},k=function(e){return function(t,n){return N(e)(t.map((function(e){return r(r({},e),{},{fallbackParameters:{},model:"bought-together"})})),n)}},x=function(e){return function(t,n){return N(e)(t.map((function(e){return r(r({},e),{},{model:"related-products"})})),n)}},J=function(e){return function(t,n){var o=t.map((function(e){return r(r({},e),{},{model:"trending-facets",threshold:e.threshold||0})}));return e.transporter.read({method:O,path:"1/indexes/*/recommendations",data:{requests:o},cacheable:!0},n)}},E=function(e){return function(t,n){var o=t.map((function(e){return r(r({},e),{},{model:"trending-items",threshold:e.threshold||0})}));return e.transporter.read({method:O,path:"1/indexes/*/recommendations",data:{requests:o},cacheable:!0},n)}};function R(e,t,n){var o,s={appId:e,apiKey:t,timeouts:{connect:1,read:2,write:30},requester:{send:function(e){return new Promise((function(t){var r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach((function(t){return r.setRequestHeader(t,e.headers[t])}));var n,o=function(e,n){return setTimeout((function(){r.abort(),t({status:0,content:n,isTimedOut:!0})}),1e3*e)},a=o(e.connectTimeout,"Connection timeout");r.onreadystatechange=function(){r.readyState>r.OPENED&&void 0===n&&(clearTimeout(a),n=o(e.responseTimeout,"Socket timeout"))},r.onerror=function(){0===r.status&&(clearTimeout(a),clearTimeout(n),t({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=function(){clearTimeout(a),clearTimeout(n),t({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(e.data)}))}},logger:(o=d,{debug:function(e,t){return l>=o&&console.debug(e,t),Promise.resolve()},info:function(e,t){return f>=o&&console.info(e,t),Promise.resolve()},error:function(e,t){return console.error(e,t),Promise.resolve()}}),responsesCache:i(),requestsCache:i({serializable:!1}),hostsCache:u({caches:[a({key:"".concat("4.13.0","-").concat(e)}),i()]}),userAgent:j("4.13.0").add({segment:"Recommend",version:"4.13.0"}).add({segment:"Browser"}),authMode:c.WithinQueryParameters};return C(r(r(r({},s),n),{},{methods:{getFrequentlyBoughtTogether:k,getRecommendations:N,getRelatedProducts:x,getTrendingFacets:J,getTrendingItems:E}}))}return R.version="4.13.0",R}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/recommend",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The perfect starting point to integrate Algolia Recommend within your JavaScript project.",
|
|
6
6
|
"repository": {
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"index.d.ts"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@algolia/cache-browser-local-storage": "4.
|
|
26
|
-
"@algolia/cache-common": "4.
|
|
27
|
-
"@algolia/cache-in-memory": "4.
|
|
28
|
-
"@algolia/client-common": "4.
|
|
29
|
-
"@algolia/client-search": "4.
|
|
30
|
-
"@algolia/logger-common": "4.
|
|
31
|
-
"@algolia/logger-console": "4.
|
|
32
|
-
"@algolia/requester-browser-xhr": "4.
|
|
33
|
-
"@algolia/requester-common": "4.
|
|
34
|
-
"@algolia/requester-node-http": "4.
|
|
35
|
-
"@algolia/transporter": "4.
|
|
25
|
+
"@algolia/cache-browser-local-storage": "4.13.0",
|
|
26
|
+
"@algolia/cache-common": "4.13.0",
|
|
27
|
+
"@algolia/cache-in-memory": "4.13.0",
|
|
28
|
+
"@algolia/client-common": "4.13.0",
|
|
29
|
+
"@algolia/client-search": "4.13.0",
|
|
30
|
+
"@algolia/logger-common": "4.13.0",
|
|
31
|
+
"@algolia/logger-console": "4.13.0",
|
|
32
|
+
"@algolia/requester-browser-xhr": "4.13.0",
|
|
33
|
+
"@algolia/requester-common": "4.13.0",
|
|
34
|
+
"@algolia/requester-node-http": "4.13.0",
|
|
35
|
+
"@algolia/transporter": "4.13.0"
|
|
36
36
|
}
|
|
37
37
|
}
|