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

@bcatalog/enhanced-ecommerce

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bcatalog/enhanced-ecommerce - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

package.json
{
"name": "@bcatalog/enhanced-ecommerce",
"version": "1.1.0",
"version": "1.1.1",
"description": "",

@@ -5,0 +5,0 @@ "source": "index.js",

(() => {
const $f57664131f4354de$export$7851e0b8935b3476 =
(groupName, collapsed = false) =>
(v) => {
if (collapsed) console.groupCollapsed(groupName);
else console.group(groupName);
console.log(v);
console.groupEnd();
return v;
};
const $f57664131f4354de$export$cc1de4045e855120 = (value) => value.toFixed(2);
const $f57664131f4354de$export$a4f4bb6b1453fff5 = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
const $f57664131f4354de$export$1cd13b593c4189ba = (key, arr) => {
const $f57664131f4354de$export$7851e0b8935b3476 = (groupName, collapsed = false)=>(v)=>{
if (collapsed) console.groupCollapsed(groupName);
else console.group(groupName);
console.log(v);
console.groupEnd();
return v;
}
;
const $f57664131f4354de$export$cc1de4045e855120 = (value)=>value.toFixed(2)
;
const $f57664131f4354de$export$a4f4bb6b1453fff5 = (obj, key)=>Object.prototype.hasOwnProperty.call(obj, key)
;
const $f57664131f4354de$export$1cd13b593c4189ba = (key, arr)=>{
if (!Array.isArray(arr)) return null;
return arr.reduce((acc, arrItem) => {
acc[arrItem[key]] = arrItem;
return acc;
}, {});
};
const $f57664131f4354de$export$61fc7d43ac8f84b0 = function (func, wait = 0) {
return arr.reduce((acc, arrItem)=>{
acc[arrItem[key]] = arrItem;
return acc;
}, {
});
};
const $f57664131f4354de$export$61fc7d43ac8f84b0 = function(func, wait = 0) {
let timer;
const cbFn = function () {
clearTimeout(timer);
timer = setTimeout(func.bind(this, ...arguments), wait);
const cbFn = function() {
clearTimeout(timer);
timer = setTimeout(func.bind(this, ...arguments), wait);
};
cbFn.cancel = () => clearTimeout(timer);
cbFn.cancel = ()=>clearTimeout(timer)
;
return cbFn;
};
};
/**
*
* @param catalogProduct
* @return {EcomProduct}
*/ function $5b85ef0cee40e693$var$catalogProductToEcom(catalogProduct) {
/**
*
* @param catalogProduct
* @return {EcomProduct}
*/ function $5b85ef0cee40e693$var$catalogProductToEcom(catalogProduct) {
const ecomProduct = {
id: catalogProduct.id,
name: catalogProduct.title,
category: catalogProduct?.category?.title,
id: catalogProduct.id,
name: catalogProduct.title,
category: catalogProduct?.category?.title
};
if ($f57664131f4354de$export$a4f4bb6b1453fff5(catalogProduct, 'price'))
ecomProduct.price = $f57664131f4354de$export$cc1de4045e855120(catalogProduct.price);
if ($f57664131f4354de$export$a4f4bb6b1453fff5(catalogProduct, 'price')) ecomProduct.price = $f57664131f4354de$export$cc1de4045e855120(catalogProduct.price);
return ecomProduct;
}
/**
*
* @param {BCatalogCartPosition} position
* @return {EcomProduct}
*/ function $5b85ef0cee40e693$var$catalogPositionToEcom(position) {
}
/**
*
* @param {BCatalogCartPosition} position
* @return {EcomProduct}
*/ function $5b85ef0cee40e693$var$catalogPositionToEcom(position) {
/** @type {EcomProduct} */ const ecomProduct = {
id: position.product.id,
price: $f57664131f4354de$export$cc1de4045e855120(position.price),
quantity: position.amount,
name: position.product.title,
id: position.product.id,
price: $f57664131f4354de$export$cc1de4045e855120(position.price),
quantity: position.amount,
name: position.product.title
};
if (position.option) ecomProduct.variant = position.option.title;
return ecomProduct;
}
class $5b85ef0cee40e693$export$a2f2547f010a5e2a {
}
class $5b85ef0cee40e693$export$a2f2547f010a5e2a {
/**
* @private
* @param {*} dataLayer
*/ constructor(dataLayer) {
this.dataLayer = dataLayer;
* @private
* @param {*} dataLayer
*/ constructor(dataLayer){
this.dataLayer = dataLayer;
}
static create(dataLayer) {
return new this(dataLayer);
return new this(dataLayer);
}
resetEcommerce() {
this.dataLayer.push({
ecommerce: null,
});
this.dataLayer.push({
ecommerce: null
});
}
createEvent(event, action, content) {
return {
event: event,
ecommerce: {
[action]: content,
},
};
return {
event: event,
ecommerce: {
[action]: content
}
};
}
createAction(action, content) {
return {
ecommerce: {
[action]: content,
},
};
return {
ecommerce: {
[action]: content
}
};
}
/**
*
* @param {Array<BCatalogCartPosition>} positions
*/ addPositions(positions) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(
this.createEvent('addToCart', 'add', {
products: positions.map($5b85ef0cee40e693$var$catalogPositionToEcom),
}),
);
*
* @param {Array<BCatalogCartPosition>} positions
*/ addPositions(positions) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(this.createEvent('addToCart', 'add', {
products: positions.map($5b85ef0cee40e693$var$catalogPositionToEcom)
}));
}
/**
*
* @param {Array<BCatalogCartPosition>} positions
*/ dropPosition(positions) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(
this.createEvent('removeFromCart', 'remove', {
products: positions.map($5b85ef0cee40e693$var$catalogPositionToEcom),
}),
);
*
* @param {Array<BCatalogCartPosition>} positions
*/ dropPosition(positions) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(this.createEvent('removeFromCart', 'remove', {
products: positions.map($5b85ef0cee40e693$var$catalogPositionToEcom)
}));
}
/**
*
* @param {?BCatalogCart} oldCart
* @param {?BCatalogCart} newCart
*/ updateCart({ oldCart: oldCart, newCart: newCart }) {
/** @type {Object<number, BCatalogCartPosition>} */ const oldPositionsMap =
(oldCart && $f57664131f4354de$export$1cd13b593c4189ba('id', oldCart.positions)) ?? {};
/** @type {Object<number, BCatalogCartPosition>} */ const newPositionsMap =
(newCart && $f57664131f4354de$export$1cd13b593c4189ba('id', newCart.positions)) ?? {};
const fullDataPositions = Object.assign({}, oldPositionsMap, newPositionsMap);
const toDeletePosIds = [];
const toAddPosIds = [];
// Ищем позиции, которые надо зафиксировать
for (const posId in newPositionsMap) {
if (!$f57664131f4354de$export$a4f4bb6b1453fff5(oldPositionsMap, posId)) {
toAddPosIds.push(posId);
break;
*
* @param {?BCatalogCart} oldCart
* @param {?BCatalogCart} newCart
*/ updateCart({ oldCart: oldCart , newCart: newCart }) {
/** @type {Object<number, BCatalogCartPosition>} */ const oldPositionsMap = (oldCart && $f57664131f4354de$export$1cd13b593c4189ba('id', oldCart.positions)) ?? {
};
/** @type {Object<number, BCatalogCartPosition>} */ const newPositionsMap = (newCart && $f57664131f4354de$export$1cd13b593c4189ba('id', newCart.positions)) ?? {
};
const fullDataPositions = Object.assign({
}, oldPositionsMap, newPositionsMap);
const toDeletePosIds = [];
const toAddPosIds = [];
// Ищем позиции, которые надо зафиксировать
for(const posId in newPositionsMap){
if (!$f57664131f4354de$export$a4f4bb6b1453fff5(oldPositionsMap, posId)) {
toAddPosIds.push(posId);
break;
}
if (oldPositionsMap[posId].amount !== newPositionsMap[posId].amount) {
toAddPosIds.push(posId);
break;
}
}
if (oldPositionsMap[posId].amount !== newPositionsMap[posId].amount) {
toAddPosIds.push(posId);
break;
}
}
// Ищем позиции, которые надо пометить как удаленные
for (const posId1 in oldPositionsMap)
if (!$f57664131f4354de$export$a4f4bb6b1453fff5(newPositionsMap, posId1)) toDeletePosIds.push(posId1);
if (toAddPosIds.length > 0) this.addPositions(toAddPosIds.map((i) => fullDataPositions[i]));
if (toDeletePosIds.length > 0) this.dropPosition(toDeletePosIds.map((i) => fullDataPositions[i]));
// Ищем позиции, которые надо пометить как удаленные
for(const posId1 in oldPositionsMap)if (!$f57664131f4354de$export$a4f4bb6b1453fff5(newPositionsMap, posId1)) toDeletePosIds.push(posId1);
if (toAddPosIds.length > 0) this.addPositions(toAddPosIds.map((i)=>fullDataPositions[i]
));
if (toDeletePosIds.length > 0) this.dropPosition(toDeletePosIds.map((i)=>fullDataPositions[i]
));
}
/**
*
* @param {BCatalogProduct} product
*/ clickProduct(product) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(
this.createEvent('productClick', 'click', {
products: [$5b85ef0cee40e693$var$catalogProductToEcom(product)],
}),
);
*
* @param {BCatalogProduct} product
*/ clickProduct(product) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(this.createEvent('productClick', 'click', {
products: [
$5b85ef0cee40e693$var$catalogProductToEcom(product)
]
}));
}
/**
*
* @param {BCatalogProduct} product
*/ detailViewProduct(product) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(
this.createEvent('detail', {
products: [$5b85ef0cee40e693$var$catalogProductToEcom(product)],
}),
);
*
* @param {BCatalogProduct} product
*/ detailViewProduct(product) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(this.createAction('detail', {
products: [
$5b85ef0cee40e693$var$catalogProductToEcom(product)
]
}));
}
/**
*
* @param {BCatalogOrder} order
*/ purchase({ order: order }) {
this.resetEcommerce();
dataLayer.push(
this.createAction('purchase', {
actionField: {
id: order.id,
shipping: order.total - order.subtotal,
revenue: order.total,
},
}),
);
*
* @param {BCatalogOrder} order
*/ purchase({ order: order }) {
this.resetEcommerce();
dataLayer.push(this.createAction('purchase', {
actionField: {
id: order.id,
shipping: order.total - order.subtotal,
revenue: order.total
}
}));
}
productsAppears({ products: products }) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(
this.createEvent('impressions', [
products.map((product, index) => ({
...$5b85ef0cee40e693$var$catalogProductToEcom(product),
position: index + 1,
})),
]),
);
productsAppears({ products: products }) {
const { dataLayer: dataLayer } = this;
this.resetEcommerce();
dataLayer.push(this.createAction('impressions', [
products.map((product, index)=>({
...$5b85ef0cee40e693$var$catalogProductToEcom(product),
position: index + 1
})
),
]));
}
}
}
const $fe14511c13de6fc9$export$3482381851ec9578 = {
const $fe14511c13de6fc9$export$3482381851ec9578 = {
product: 'PRODUCT',

@@ -202,22 +202,23 @@ cart: 'CART',

customPage: 'CUSTOM_PAGE',
search: 'SEARCH',
};
search: 'SEARCH'
};
function $1b6479369d7ad83c$export$310e73af8708799c({ dataLayer: dataLayer, bCatalog: bCatalog }) {
function $1b6479369d7ad83c$export$310e73af8708799c({ dataLayer: dataLayer , bCatalog: bCatalog }) {
const dataLayerShortcuts = $5b85ef0cee40e693$export$a2f2547f010a5e2a.create(dataLayer);
function onPageMove(pageObj) {
switch (pageObj.type) {
case $fe14511c13de6fc9$export$3482381851ec9578.product:
dataLayerShortcuts.clickProduct({
id: pageObj.params.productId,
});
break;
}
switch(pageObj.type){
case $fe14511c13de6fc9$export$3482381851ec9578.product:
dataLayerShortcuts.clickProduct({
id: pageObj.params.productId
});
break;
}
}
function onPageLoaded(pageObj) {
switch (pageObj.type) {
case $fe14511c13de6fc9$export$3482381851ec9578.product:
dataLayerShortcuts.detailViewProduct(pageObj.params.product);
break;
}
switch(pageObj.type){
case $fe14511c13de6fc9$export$3482381851ec9578.product:
dataLayerShortcuts.detailViewProduct(pageObj.params.product);
break;
}
}

@@ -227,48 +228,44 @@ bCatalog.events.onPageSwitch(onPageMove);

/** @type {?BCatalogCart} */ let currentCart;
bCatalog.events.onCartChanged(
/** @param {?BCatalogCart} updatedCart */ (updatedCart) => {
bCatalog.events.onCartChanged(/** @param {?BCatalogCart} updatedCart */ (updatedCart)=>{
dataLayerShortcuts.updateCart({
newCart: updatedCart,
oldCart: currentCart,
newCart: updatedCart,
oldCart: currentCart
});
currentCart = updatedCart;
},
});
bCatalog.events.appEvents('category:productAppears', ({ products: products })=>dataLayerShortcuts.productsAppears({
products: products
})
);
bCatalog.events.appEvents('category:productAppears', ({ products: products }) =>
dataLayerShortcuts.productsAppears({
products: products,
}),
bCatalog.events.appEvents('order:created', ({ order: order })=>dataLayerShortcuts.purchase({
order: order
})
);
bCatalog.events.appEvents('order:created', ({ order: order }) =>
dataLayerShortcuts.purchase({
order: order,
}),
);
const handleCheckoutFormChange = $f57664131f4354de$export$61fc7d43ac8f84b0(
$f57664131f4354de$export$7851e0b8935b3476('checkout:formChange'),
1000,
);
const handleCheckoutFormChange = $f57664131f4354de$export$61fc7d43ac8f84b0($f57664131f4354de$export$7851e0b8935b3476('checkout:formChange'), 1000);
bCatalog.events.appEvents('checkout:formChange', handleCheckoutFormChange);
}
/**
*
* @param {*} dataLayer
* @param {BCatalogType} bCatalog
* @returns
*/ function $1b6479369d7ad83c$var$init(dataLayer, bCatalog) {
}
/**
*
* @param {*} dataLayer
* @param {BCatalogType} bCatalog
* @returns
*/ function $1b6479369d7ad83c$var$init(dataLayer, bCatalog) {
if (!dataLayer) {
console.error(`Can't find dataLayer`);
return;
console.error(`Can't find dataLayer`);
return;
}
if (!bCatalog) {
console.error(`Can't find BCatalog storefront`);
return;
console.error(`Can't find BCatalog storefront`);
return;
}
$1b6479369d7ad83c$export$310e73af8708799c({
bCatalog: bCatalog,
dataLayer: dataLayer,
bCatalog: bCatalog,
dataLayer: dataLayer
});
}
$1b6479369d7ad83c$var$init(window.dataLayer, window.BCatalog);
if (null) null.accept();
}
$1b6479369d7ad83c$var$init(window.dataLayer, window.BCatalog);
if (null) null.accept();
})();

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

(() => {
const t = (t) => t.toFixed(2),
e = (t, e) => Object.prototype.hasOwnProperty.call(t, e),
o = (t, e) => (Array.isArray(e) ? e.reduce((e, o) => ((e[o[t]] = o), e), {}) : null);
function r(o) {
const r = { id: o.id, name: o.title, category: o?.category?.title };
return e(o, 'price') && (r.price = t(o.price)), r;
}
function a(e) {
const o = { id: e.product.id, price: t(e.price), quantity: e.amount, name: e.product.title };
return e.option && (o.variant = e.option.title), o;
}
class c {
constructor(t) {
this.dataLayer = t;
}
static create(t) {
return new this(t);
}
resetEcommerce() {
this.dataLayer.push({ ecommerce: null });
}
createEvent(t, e, o) {
return { event: t, ecommerce: { [e]: o } };
}
createAction(t, e) {
return { ecommerce: { [t]: e } };
}
addPositions(t) {
const { dataLayer: e } = this;
this.resetEcommerce(), e.push(this.createEvent('addToCart', 'add', { products: t.map(a) }));
}
dropPosition(t) {
const { dataLayer: e } = this;
this.resetEcommerce(), e.push(this.createEvent('removeFromCart', 'remove', { products: t.map(a) }));
}
updateCart({ oldCart: t, newCart: r }) {
const a = (t && o('id', t.positions)) ?? {},
c = (r && o('id', r.positions)) ?? {},
s = Object.assign({}, a, c),
n = [],
i = [];
for (const t in c) {
if (!e(a, t)) {
i.push(t);
break;
}
if (a[t].amount !== c[t].amount) {
i.push(t);
break;
}
}
for (const t in a) e(c, t) || n.push(t);
i.length > 0 && this.addPositions(i.map((t) => s[t])), n.length > 0 && this.dropPosition(n.map((t) => s[t]));
}
clickProduct(t) {
const { dataLayer: e } = this;
this.resetEcommerce(), e.push(this.createEvent('productClick', 'click', { products: [r(t)] }));
}
detailViewProduct(t) {
const { dataLayer: e } = this;
this.resetEcommerce(), e.push(this.createEvent('detail', { products: [r(t)] }));
}
purchase({ order: t }) {
this.resetEcommerce(),
dataLayer.push(
this.createAction('purchase', {
actionField: { id: t.id, shipping: t.total - t.subtotal, revenue: t.total },
}),
);
}
productsAppears({ products: t }) {
const { dataLayer: e } = this;
this.resetEcommerce(), e.push(this.createEvent('impressions', [t.map((t, e) => ({ ...r(t), position: e + 1 }))]));
}
}
const s = 'PRODUCT';
function n({ dataLayer: t, bCatalog: e }) {
const o = c.create(t);
let r;
e.events.onPageSwitch(function (t) {
if (t.type === s) o.clickProduct({ id: t.params.productId });
}),
e.events.onPageLoaded(function (t) {
if (t.type === s) o.detailViewProduct(t.params.product);
}),
e.events.onCartChanged((t) => {
o.updateCart({ newCart: t, oldCart: r }), (r = t);
}),
e.events.appEvents('category:productAppears', ({ products: t }) => o.productsAppears({ products: t })),
e.events.appEvents('order:created', ({ order: t }) => o.purchase({ order: t }));
const a = (function (t, e = 0) {
let o;
const r = function () {
clearTimeout(o), (o = setTimeout(t.bind(this, ...arguments), e));
};
return (r.cancel = () => clearTimeout(o)), r;
})(
(
(t, e = !1) =>
(o) => (e ? console.groupCollapsed(t) : console.group(t), console.log(o), console.groupEnd(), o)
)('checkout:formChange'),
1e3,
);
e.events.appEvents('checkout:formChange', a);
}
!(function (t, e) {
t
? e
? n({ bCatalog: e, dataLayer: t })
: console.error("Can't find BCatalog storefront")
: console.error("Can't find dataLayer");
})(window.dataLayer, window.BCatalog);
})();
(()=>{const t=t=>t.toFixed(2),e=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o=(t,e)=>Array.isArray(e)?e.reduce(((e,o)=>(e[o[t]]=o,e)),{}):null;function r(o){const r={id:o.id,name:o.title,category:o?.category?.title};return e(o,"price")&&(r.price=t(o.price)),r}function a(e){const o={id:e.product.id,price:t(e.price),quantity:e.amount,name:e.product.title};return e.option&&(o.variant=e.option.title),o}class c{constructor(t){this.dataLayer=t}static create(t){return new this(t)}resetEcommerce(){this.dataLayer.push({ecommerce:null})}createEvent(t,e,o){return{event:t,ecommerce:{[e]:o}}}createAction(t,e){return{ecommerce:{[t]:e}}}addPositions(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("addToCart","add",{products:t.map(a)}))}dropPosition(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("removeFromCart","remove",{products:t.map(a)}))}updateCart({oldCart:t,newCart:r}){const a=(t&&o("id",t.positions))??{},c=(r&&o("id",r.positions))??{},s=Object.assign({},a,c),n=[],i=[];for(const t in c){if(!e(a,t)){i.push(t);break}if(a[t].amount!==c[t].amount){i.push(t);break}}for(const t in a)e(c,t)||n.push(t);i.length>0&&this.addPositions(i.map((t=>s[t]))),n.length>0&&this.dropPosition(n.map((t=>s[t])))}clickProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("productClick","click",{products:[r(t)]}))}detailViewProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("detail",{products:[r(t)]}))}purchase({order:t}){this.resetEcommerce(),dataLayer.push(this.createAction("purchase",{actionField:{id:t.id,shipping:t.total-t.subtotal,revenue:t.total}}))}productsAppears({products:t}){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("impressions",[t.map(((t,e)=>({...r(t),position:e+1})))]))}}const s="PRODUCT";function n({dataLayer:t,bCatalog:e}){const o=c.create(t);let r;e.events.onPageSwitch((function(t){if(t.type===s)o.clickProduct({id:t.params.productId})})),e.events.onPageLoaded((function(t){if(t.type===s)o.detailViewProduct(t.params.product)})),e.events.onCartChanged((t=>{o.updateCart({newCart:t,oldCart:r}),r=t})),e.events.appEvents("category:productAppears",(({products:t})=>o.productsAppears({products:t}))),e.events.appEvents("order:created",(({order:t})=>o.purchase({order:t})));const a=function(t,e=0){let o;const r=function(){clearTimeout(o),o=setTimeout(t.bind(this,...arguments),e)};return r.cancel=()=>clearTimeout(o),r}(((t,e=!1)=>o=>(e?console.groupCollapsed(t):console.group(t),console.log(o),console.groupEnd(),o))("checkout:formChange"),1e3);e.events.appEvents("checkout:formChange",a)}!function(t,e){t?e?n({bCatalog:e,dataLayer:t}):console.error("Can't find BCatalog storefront"):console.error("Can't find dataLayer")}(window.dataLayer,window.BCatalog)})();
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