Socket
Socket
Sign inDemoInstall

@bva/recommendations

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bva/recommendations - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

changelog.md

2

dist/recommendations.min.js

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

!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(t,e,r){"use strict";var n=r(1),o="object"==typeof self&&self&&self.Object===Object&&self,i=n.a||o||Function("return this")();e.a=i},function(t,e,r){"use strict";(function(t){var r="object"==typeof t&&t&&t.Object===Object&&t;e.a=r}).call(this,r(6))},function(t,e,r){"use strict";(function(t){var n=r(1),o="object"==typeof exports&&exports&&!exports.nodeType&&exports,i=o&&"object"==typeof t&&t&&!t.nodeType&&t,c=i&&i.exports===o&&n.a.process,a=function(){try{var t=i&&i.require&&i.require("util").types;return t||c&&c.binding&&c.binding("util")}catch(t){}}();e.a=a}).call(this,r(3)(t))},function(t,e){t.exports=function(t){if(!t.webpackPolyfill){var e=Object.create(t);e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),Object.defineProperty(e,"exports",{enumerable:!0}),e.webpackPolyfill=1}return e}},function(t,e,r){"use strict";(function(t){var n=r(0),o=r(5),i="object"==typeof exports&&exports&&!exports.nodeType&&exports,c=i&&"object"==typeof t&&t&&!t.nodeType&&t,a=c&&c.exports===i?n.a.Buffer:void 0,u=(a?a.isBuffer:void 0)||o.a;e.a=u}).call(this,r(3)(t))},function(t,e,r){"use strict";e.a=function(){return!1}},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";r.r(e);var n=r(0),o=n.a.Symbol,i=Object.prototype,c=i.hasOwnProperty,a=i.toString,u=o?o.toStringTag:void 0;var s=function(t){var e=c.call(t,u),r=t[u];try{t[u]=void 0;var n=!0}catch(t){}var o=a.call(t);return n&&(e?t[u]=r:delete t[u]),o},l=Object.prototype.toString;var f=function(t){return l.call(t)},d="[object Null]",p="[object Undefined]",b=o?o.toStringTag:void 0;var m=function(t){return null==t?void 0===t?p:d:b&&b in Object(t)?s(t):f(t)};var v=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},y="[object AsyncFunction]",h="[object Function]",j="[object GeneratorFunction]",g="[object Proxy]";var w,O=function(t){if(!v(t))return!1;var e=m(t);return e==h||e==j||e==y||e==g},_=n.a["__core-js_shared__"],x=(w=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"";var A=function(t){return!!x&&x in t},I=Function.prototype.toString;var P=function(t){if(null!=t){try{return I.call(t)}catch(t){}try{return t+""}catch(t){}}return""},S=/^\[object .+?Constructor\]$/,$=Function.prototype,E=Object.prototype,z=$.toString,T=E.hasOwnProperty,F=RegExp("^"+z.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var M=function(t){return!(!v(t)||A(t))&&(O(t)?F:S).test(P(t))};var R=function(t,e){return null==t?void 0:t[e]};var C=function(t,e){var r=R(t,e);return M(r)?r:void 0},k=function(){try{var t=C(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var q=function(t,e,r){"__proto__"==e&&k?k(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var D=function(t,e){return t===e||t!=t&&e!=e},U=Object.prototype.hasOwnProperty;var B=function(t,e,r){var n=t[e];U.call(t,e)&&D(n,r)&&(void 0!==r||e in t)||q(t,e,r)};var N=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,c=e.length;++i<c;){var a=e[i],u=n?n(r[a],t[a],a,r,t):void 0;void 0===u&&(u=t[a]),o?q(r,a,u):B(r,a,u)}return r};var L=function(t){return t};var G=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},H=Math.max;var V=function(t,e,r){return e=H(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=H(n.length-e,0),c=Array(i);++o<i;)c[o]=n[e+o];o=-1;for(var a=Array(e+1);++o<e;)a[o]=n[o];return a[e]=r(c),G(t,this,a)}};var W=function(t){return function(){return t}},J=k?function(t,e){return k(t,"toString",{configurable:!0,enumerable:!1,value:W(e),writable:!0})}:L,K=800,Q=16,X=Date.now;var Y=function(t){var e=0,r=0;return function(){var n=X(),o=Q-(n-r);if(r=n,o>0){if(++e>=K)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(J);var Z=function(t,e){return Y(V(t,e,L),t+"")},tt=9007199254740991;var et=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=tt};var rt=function(t){return null!=t&&et(t.length)&&!O(t)},nt=9007199254740991,ot=/^(?:0|[1-9]\d*)$/;var it=function(t,e){var r=typeof t;return!!(e=null==e?nt:e)&&("number"==r||"symbol"!=r&&ot.test(t))&&t>-1&&t%1==0&&t<e};var ct=function(t,e,r){if(!v(r))return!1;var n=typeof e;return!!("number"==n?rt(r)&&it(e,r.length):"string"==n&&e in r)&&D(r[e],t)};var at=function(t){return Z(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,c=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,c&&ct(r[0],r[1],c)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var a=r[n];a&&t(e,a,n,i)}return e})},ut=Object.prototype;var st=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ut)};var lt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var ft=function(t){return null!=t&&"object"==typeof t},dt="[object Arguments]";var pt=function(t){return ft(t)&&m(t)==dt},bt=Object.prototype,mt=bt.hasOwnProperty,vt=bt.propertyIsEnumerable,yt=pt(function(){return arguments}())?pt:function(t){return ft(t)&&mt.call(t,"callee")&&!vt.call(t,"callee")},ht=Array.isArray,jt=r(4),gt={};gt["[object Float32Array]"]=gt["[object Float64Array]"]=gt["[object Int8Array]"]=gt["[object Int16Array]"]=gt["[object Int32Array]"]=gt["[object Uint8Array]"]=gt["[object Uint8ClampedArray]"]=gt["[object Uint16Array]"]=gt["[object Uint32Array]"]=!0,gt["[object Arguments]"]=gt["[object Array]"]=gt["[object ArrayBuffer]"]=gt["[object Boolean]"]=gt["[object DataView]"]=gt["[object Date]"]=gt["[object Error]"]=gt["[object Function]"]=gt["[object Map]"]=gt["[object Number]"]=gt["[object Object]"]=gt["[object RegExp]"]=gt["[object Set]"]=gt["[object String]"]=gt["[object WeakMap]"]=!1;var wt=function(t){return ft(t)&&et(t.length)&&!!gt[m(t)]};var Ot=function(t){return function(e){return t(e)}},_t=r(2),xt=_t.a&&_t.a.isTypedArray,At=xt?Ot(xt):wt,It=Object.prototype.hasOwnProperty;var Pt=function(t,e){var r=ht(t),n=!r&&yt(t),o=!r&&!n&&Object(jt.a)(t),i=!r&&!n&&!o&&At(t),c=r||n||o||i,a=c?lt(t.length,String):[],u=a.length;for(var s in t)!e&&!It.call(t,s)||c&&("length"==s||o&&("offset"==s||"parent"==s)||i&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||it(s,u))||a.push(s);return a};var St=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),$t=Object.prototype.hasOwnProperty;var Et=function(t){if(!st(t))return St(t);var e=[];for(var r in Object(t))$t.call(t,r)&&"constructor"!=r&&e.push(r);return e};var zt=function(t){return rt(t)?Pt(t):Et(t)},Tt=Object.prototype.hasOwnProperty,Ft=at(function(t,e){if(st(e)||rt(e))N(e,zt(e),t);else for(var r in e)Tt.call(e,r)&&B(t,r,e[r])}),Mt=(t,e)=>{document.dispatchEvent(new CustomEvent(t,{detail:e}))},Rt=(t,e)=>{const r=((t,e)=>{if(!t.products)throw new Error(`No products found for product ID: ${e.options.productId}`);return t.products.map(t=>t.tags.includes(e.options.hiddenTag)?"":e.options.template(t))})(t,e),n=document.querySelector(e.options.insertion);if(!n)throw new Error(`Insertion element does not exist - ${e.options.insertion}`);return n.innerHTML=r,n.setAttribute("data-recommendations-id",e.recommendationsId),!0},Ct=t=>{if(!t)return!1;if(t.limit&&"number"!=typeof t.limit)throw new Error("Recommendations: property `limit` needs to be of type Number");if(t.limit&&t.limit>10)throw new Error("Recommendations: property `limit` requires value less than 10")},kt={hiddenTag:"recommendations::hide",insertion:"[data-recommendations-insertion]",limit:4,template:function(t){const e=(t=>`$${parseFloat(t/100).toFixed(2)}`)(t.price);return`\n <div class="recommendation__product" data-recommendations-product-id="${t.id}">\n <a href="${t.url}" class="recommendation__wrapper">\n <div class="recommendation__product-image-wrapper">\n <img class="recommendation__product-image" src="${t.featured_image}" alt="${t.title} image" />\n </div>\n <div class="recommendation__product-details">\n <h3 class="recommendation__product-title">${t.title}</h3>\n <span class="recommendation__product-price">${e}</span>\n </div>\n </a>\n </div>\n `}},qt=t=>{const e=document.querySelector(t);if(!e)throw new Error("Could not find insertion element");return e.getAttribute("data-recommendations-main-product-id")};class Dt{constructor(t){let e;if(Ct(t),!(e=t&&t.productId?t.productId:t&&t.insertion?qt(t.insertion):qt(kt.insertion)))throw new Error("Product ID was not provided by config object nor insertion element");this.productId=e;const r={};Ft(r,kt),t&&Ft(r,t),this.options=r,this.isInitialized=!1,this.recommendationsId=Math.floor(1e8+9e8*Math.random())}initialize(){const t=`/recommendations/products.json?product_id=${this.productId}&limit=${this.options.limit}`,e=this;fetch(t).then(t=>t.json()).then(t=>{e.data=t,Rt(t,e),Mt("recommendations.initialized",{context:e,data:t}),this.isInitialized=!0}).catch(t=>{throw t})}updateOptions(t){Ft(this.options,t)}reinitialize(){if(!this.isInitialized)throw new Error("Cannot reinitialize Recommendations object (has not been initialized)");this.uninitialize(),this.initialize()}uninitialize(t){if(!this.isInitialized)throw new Error("Cannot unitialize Recommendations object (has not been initialized)");this.isInitialized=!1;const e=document.querySelectorAll(`[data-recommendations-id="${this.recommendationsId}"]`);if(!parent)throw new Error(`Cannot uninitiale Recommendations object (cannot find insertion with ID ${this.recommendationsId})`);e.forEach(t=>{for(;t.firstChild;)t.firstChild.remove()}),t||Mt("recommendations.uninitialized",{context:this,data:this.data})}}window&&(window.Shopify?window.Shopify.Recommendations=Dt:window.Recommendations=Dt);e.default=Dt}]);
!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(t,e,r){"use strict";var n=r(1),o="object"==typeof self&&self&&self.Object===Object&&self,i=n.a||o||Function("return this")();e.a=i},function(t,e,r){"use strict";(function(t){var r="object"==typeof t&&t&&t.Object===Object&&t;e.a=r}).call(this,r(6))},function(t,e,r){"use strict";(function(t){var n=r(1),o="object"==typeof exports&&exports&&!exports.nodeType&&exports,i=o&&"object"==typeof t&&t&&!t.nodeType&&t,c=i&&i.exports===o&&n.a.process,a=function(){try{var t=i&&i.require&&i.require("util").types;return t||c&&c.binding&&c.binding("util")}catch(t){}}();e.a=a}).call(this,r(3)(t))},function(t,e){t.exports=function(t){if(!t.webpackPolyfill){var e=Object.create(t);e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),Object.defineProperty(e,"exports",{enumerable:!0}),e.webpackPolyfill=1}return e}},function(t,e,r){"use strict";(function(t){var n=r(0),o=r(5),i="object"==typeof exports&&exports&&!exports.nodeType&&exports,c=i&&"object"==typeof t&&t&&!t.nodeType&&t,a=c&&c.exports===i?n.a.Buffer:void 0,u=(a?a.isBuffer:void 0)||o.a;e.a=u}).call(this,r(3)(t))},function(t,e,r){"use strict";e.a=function(){return!1}},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";r.r(e);var n=r(0),o=n.a.Symbol,i=Object.prototype,c=i.hasOwnProperty,a=i.toString,u=o?o.toStringTag:void 0;var s=function(t){var e=c.call(t,u),r=t[u];try{t[u]=void 0;var n=!0}catch(t){}var o=a.call(t);return n&&(e?t[u]=r:delete t[u]),o},l=Object.prototype.toString;var f=function(t){return l.call(t)},d="[object Null]",p="[object Undefined]",b=o?o.toStringTag:void 0;var v=function(t){return null==t?void 0===t?p:d:b&&b in Object(t)?s(t):f(t)};var m=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},y="[object AsyncFunction]",h="[object Function]",j="[object GeneratorFunction]",g="[object Proxy]";var w,O=function(t){if(!m(t))return!1;var e=v(t);return e==h||e==j||e==y||e==g},_=n.a["__core-js_shared__"],x=(w=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+w:"";var A=function(t){return!!x&&x in t},I=Function.prototype.toString;var P=function(t){if(null!=t){try{return I.call(t)}catch(t){}try{return t+""}catch(t){}}return""},S=/^\[object .+?Constructor\]$/,$=Function.prototype,E=Object.prototype,z=$.toString,T=E.hasOwnProperty,F=RegExp("^"+z.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var C=function(t){return!(!m(t)||A(t))&&(O(t)?F:S).test(P(t))};var M=function(t,e){return null==t?void 0:t[e]};var R=function(t,e){var r=M(t,e);return C(r)?r:void 0},D=function(){try{var t=R(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var k=function(t,e,r){"__proto__"==e&&D?D(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r};var q=function(t,e){return t===e||t!=t&&e!=e},U=Object.prototype.hasOwnProperty;var B=function(t,e,r){var n=t[e];U.call(t,e)&&q(n,r)&&(void 0!==r||e in t)||k(t,e,r)};var N=function(t,e,r,n){var o=!r;r||(r={});for(var i=-1,c=e.length;++i<c;){var a=e[i],u=n?n(r[a],t[a],a,r,t):void 0;void 0===u&&(u=t[a]),o?k(r,a,u):B(r,a,u)}return r};var L=function(t){return t};var G=function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)},H=Math.max;var V=function(t,e,r){return e=H(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=H(n.length-e,0),c=Array(i);++o<i;)c[o]=n[e+o];o=-1;for(var a=Array(e+1);++o<e;)a[o]=n[o];return a[e]=r(c),G(t,this,a)}};var W=function(t){return function(){return t}},J=D?function(t,e){return D(t,"toString",{configurable:!0,enumerable:!1,value:W(e),writable:!0})}:L,K=800,Q=16,X=Date.now;var Y=function(t){var e=0,r=0;return function(){var n=X(),o=Q-(n-r);if(r=n,o>0){if(++e>=K)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(J);var Z=function(t,e){return Y(V(t,e,L),t+"")},tt=9007199254740991;var et=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=tt};var rt=function(t){return null!=t&&et(t.length)&&!O(t)},nt=9007199254740991,ot=/^(?:0|[1-9]\d*)$/;var it=function(t,e){var r=typeof t;return!!(e=null==e?nt:e)&&("number"==r||"symbol"!=r&&ot.test(t))&&t>-1&&t%1==0&&t<e};var ct=function(t,e,r){if(!m(r))return!1;var n=typeof e;return!!("number"==n?rt(r)&&it(e,r.length):"string"==n&&e in r)&&q(r[e],t)};var at=function(t){return Z(function(e,r){var n=-1,o=r.length,i=o>1?r[o-1]:void 0,c=o>2?r[2]:void 0;for(i=t.length>3&&"function"==typeof i?(o--,i):void 0,c&&ct(r[0],r[1],c)&&(i=o<3?void 0:i,o=1),e=Object(e);++n<o;){var a=r[n];a&&t(e,a,n,i)}return e})},ut=Object.prototype;var st=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||ut)};var lt=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n};var ft=function(t){return null!=t&&"object"==typeof t},dt="[object Arguments]";var pt=function(t){return ft(t)&&v(t)==dt},bt=Object.prototype,vt=bt.hasOwnProperty,mt=bt.propertyIsEnumerable,yt=pt(function(){return arguments}())?pt:function(t){return ft(t)&&vt.call(t,"callee")&&!mt.call(t,"callee")},ht=Array.isArray,jt=r(4),gt={};gt["[object Float32Array]"]=gt["[object Float64Array]"]=gt["[object Int8Array]"]=gt["[object Int16Array]"]=gt["[object Int32Array]"]=gt["[object Uint8Array]"]=gt["[object Uint8ClampedArray]"]=gt["[object Uint16Array]"]=gt["[object Uint32Array]"]=!0,gt["[object Arguments]"]=gt["[object Array]"]=gt["[object ArrayBuffer]"]=gt["[object Boolean]"]=gt["[object DataView]"]=gt["[object Date]"]=gt["[object Error]"]=gt["[object Function]"]=gt["[object Map]"]=gt["[object Number]"]=gt["[object Object]"]=gt["[object RegExp]"]=gt["[object Set]"]=gt["[object String]"]=gt["[object WeakMap]"]=!1;var wt=function(t){return ft(t)&&et(t.length)&&!!gt[v(t)]};var Ot=function(t){return function(e){return t(e)}},_t=r(2),xt=_t.a&&_t.a.isTypedArray,At=xt?Ot(xt):wt,It=Object.prototype.hasOwnProperty;var Pt=function(t,e){var r=ht(t),n=!r&&yt(t),o=!r&&!n&&Object(jt.a)(t),i=!r&&!n&&!o&&At(t),c=r||n||o||i,a=c?lt(t.length,String):[],u=a.length;for(var s in t)!e&&!It.call(t,s)||c&&("length"==s||o&&("offset"==s||"parent"==s)||i&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||it(s,u))||a.push(s);return a};var St=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),$t=Object.prototype.hasOwnProperty;var Et=function(t){if(!st(t))return St(t);var e=[];for(var r in Object(t))$t.call(t,r)&&"constructor"!=r&&e.push(r);return e};var zt=function(t){return rt(t)?Pt(t):Et(t)},Tt=Object.prototype.hasOwnProperty,Ft=at(function(t,e){if(st(e)||rt(e))N(e,zt(e),t);else for(var r in e)Tt.call(e,r)&&B(t,r,e[r])}),Ct=(t,e)=>{document.dispatchEvent(new CustomEvent(t,{detail:e}))},Mt=(t,e)=>{const r=((t,e)=>{if(!t.products)throw new Error(`No products found for product ID: ${e.options.productId}`);return t.products.map(t=>t.tags.includes(e.options.hiddenTag)?"":e.options.template(t))})(t,e),n=document.querySelector(e.options.insertion);if(!n)throw new Error(`Insertion element does not exist - ${e.options.insertion}`);return n.innerHTML=r,n.setAttribute("data-recommendations-id",e.recommendationsId),!0},Rt=t=>{if(!t)return!1;if(t.limit&&"number"!=typeof t.limit)throw new Error("Recommendations: property `limit` needs to be of type Number");if(t.limit&&t.limit>10)throw new Error("Recommendations: property `limit` requires value less than 10")},Dt=t=>`$${parseFloat(t/100).toFixed(2)}`,kt={hiddenTag:"recommendations::hide",insertion:"[data-recommendations-insertion]",limit:4,template:function(t){const e=Dt(t.price);return`\n <div class="recommendation__product" data-recommendations-product-id="${t.id}">\n <a href="${t.url}" class="recommendation__wrapper">\n <div class="recommendation__product-image-wrapper">\n <img class="recommendation__product-image" src="${t.featured_image}" alt="${t.title} image" />\n </div>\n <div class="recommendation__product-details">\n <h3 class="recommendation__product-title">${t.title}</h3>\n <span class="recommendation__product-price">${e}</span>\n </div>\n </a>\n </div>\n `}},qt=t=>{const e=document.querySelector(t);if(!e)throw new Error("Could not find insertion element");return e.getAttribute("data-recommendations-main-product-id")};class Ut{constructor(t){let e;if(Rt(t),!(e=t&&t.productId?t.productId:t&&t.insertion?qt(t.insertion):qt(kt.insertion)))throw new Error("Product ID was not provided by config object nor insertion element");this.productId=e;const r={};Ft(r,kt),t&&Ft(r,t),this.options=r,this.isInitialized=!1,this.recommendationsId=Math.floor(1e8+9e8*Math.random())}initialize(){const t=`/recommendations/products.json?product_id=${this.productId}&limit=${this.options.limit}`,e=this;fetch(t).then(t=>t.json()).then(t=>{e.data=t,Mt(t,e),Ct("recommendations.initialized",{context:e,data:t}),this.isInitialized=!0}).catch(t=>{throw t})}updateOptions(t){Ft(this.options,t)}reinitialize(){if(!this.isInitialized)throw new Error("Cannot reinitialize Recommendations object (has not been initialized)");this.uninitialize(),this.initialize()}uninitialize(t){if(!this.isInitialized)throw new Error("Cannot unitialize Recommendations object (has not been initialized)");this.isInitialized=!1;const e=document.querySelectorAll(`[data-recommendations-id="${this.recommendationsId}"]`);if(!parent)throw new Error(`Cannot uninitiale Recommendations object (cannot find insertion with ID ${this.recommendationsId})`);e.forEach(t=>{for(;t.firstChild;)t.firstChild.remove()}),t||Ct("recommendations.uninitialized",{context:this,data:this.data})}}Ut.helpers={},Ut.helpers.convertCentsToDollars=Dt,window&&(window.Shopify?window.Shopify.Recommendations=Ut:window.Recommendations=Ut);e.default=Ut}]);
{
"name": "@bva/recommendations",
"version": "0.0.5",
"version": "0.0.6",
"description": "JS recommendations widget using Shopify native recommendations API",

@@ -8,8 +8,9 @@ "main": "src/index.js",

"license": "MIT",
"Keywords":["bva-module"],
"scripts": {
"build": "webpack"
"build": "webpack",
"test:browser": "open test/index.html"
},
"dependencies": {
"lodash-es": "^4.17.11",
"path": "^0.12.7"
"lodash-es": "^4.17.11"
},

@@ -20,3 +21,7 @@ "devDependencies": {

"@babel/preset-env": "^7.4.3",
"@babel/register": "^7.4.4",
"chai": "^4.2.0",
"eslint": "^5.16.0",
"mocha": "^6.1.4",
"path": "^0.12.7",
"webpack": "^4.29.6",

@@ -23,0 +28,0 @@ "webpack-cli": "^3.3.0"

@@ -167,1 +167,5 @@ Recommendations

- `recommendations.initialized`: Fires when a recommendation instance is initialized. The callback you will find the product data in `event.detail.data` and the current instance in `event.detail.context`.
## Changelog
To see any recent changes view the [CHANGELOG](changelog.md).

@@ -15,2 +15,4 @@ /**

import convertCentsToDollars from './helpers/convert-cents-to-dollars';
/**

@@ -150,2 +152,4 @@ * Sets up the Recommendations class

}
Recommendations.helpers = {};
Recommendations.helpers.convertCentsToDollars = convertCentsToDollars;

@@ -152,0 +156,0 @@ if (window) {

Sorry, the diff of this file is not supported yet

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