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

commercelayer

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commercelayer - npm Package Compare versions

Comparing version 1.9.15 to 1.9.16

2

package.json
{
"name": "commercelayer",
"version": "1.9.15",
"version": "1.9.16",
"description": "The Official Commerce Layer JS library",

@@ -5,0 +5,0 @@ "main": "./src/main.js",

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

const config = require('./config')
const utils = require('./utils')
const ui = require('./ui')
const clsdk = require('@commercelayer/sdk')
const config = require("./config");
const utils = require("./utils");
const ui = require("./ui");
const clsdk = require("@commercelayer/sdk");
module.exports = {
getPrices: function() {
let prices = document.querySelectorAll('.clayer-price')
let prices = document.querySelectorAll(".clayer-price");
if (prices.length > 0) {
let skuCodes = []
let skuCodes = [];
prices.forEach(function(price) {
skuCodes.push(price.dataset.skuCode)
})
skuCodes.push(price.dataset.skuCode);
});
let qf = new clsdk.query.QueryFilter()
.filter('codes', skuCodes.join(','))
.include('prices')
.pageSize(25)
.filter("codes", skuCodes.join(","))
.include("prices")
.pageSize(25);
clsdk.listSkus(qf.build()).then(data => {
let skuAttributes = [
'id',
'code',
'prices.formatted_amount',
'prices.formatted_compare_at_amount',
'prices.amount_cents',
'prices.compare_at_amount_cents'
]
"id",
"code",
"prices.formatted_amount",
"prices.formatted_compare_at_amount",
"prices.amount_cents",
"prices.compare_at_amount_cents"
];
ui.updatePrices(data.get(skuAttributes))
ui.updatePrices(data.get(skuAttributes));
let pageCount = data.dataset.meta.page_count
let pageCount = data.dataset.meta.page_count;
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p)
qf.pageNumber(p);
clsdk
.listSkus(qf)
.then(data => ui.updatePrices(data.get(skuAttributes)))
.then(data => ui.updatePrices(data.get(skuAttributes)));
}
}
document.dispatchEvent(new Event('clayer-prices-ready'))
document.dispatchEvent(new Event("clayer-prices-ready"));
if (data.get(skuAttributes).length === 0) {
document.dispatchEvent(new Event('clayer-skus-empty'))
document.dispatchEvent(new Event("clayer-skus-empty"));
}
})
});
}

@@ -55,32 +55,32 @@ },

getVariants: function() {
let variants = document.querySelectorAll('.clayer-variant')
let variants = document.querySelectorAll(".clayer-variant");
if (variants.length > 0) {
let skuCodes = []
let skuCodes = [];
variants.forEach(function(variant) {
skuCodes.push(variant.dataset.skuCode)
})
skuCodes.push(variant.dataset.skuCode);
});
let qf = new clsdk.query.QueryFilter()
.filter('codes', skuCodes.join(','))
.pageSize(25)
.filter("codes", skuCodes.join(","))
.pageSize(25);
let skuAttributes = ['id', 'code']
let skuAttributes = ["id", "code"];
clsdk.listSkus(qf.build()).then(data => {
ui.updateVariants(data.get(skuAttributes), true)
ui.updateVariants(data.get(skuAttributes), true);
let pageCount = data.dataset.meta.page_count
let pageCount = data.dataset.meta.page_count;
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p)
qf.pageNumber(p);
clsdk
.listSkus(qf)
.then(data => ui.updateVariants(data.get(skuAttributes), false))
.then(data => ui.updateVariants(data.get(skuAttributes), false));
}
}
document.dispatchEvent(new Event('clayer-variants-ready'))
})
document.dispatchEvent(new Event("clayer-variants-ready"));
});
}

@@ -91,25 +91,25 @@ },

let variantQuantity = document.querySelectorAll(
'.clayer-add-to-bag-quantity'
)
".clayer-add-to-bag-quantity"
);
if (variantQuantity.length > 0) {
let skuCodes = []
let skuCodes = [];
variantQuantity.forEach(function(variant) {
skuCodes.push(variant.dataset.skuCode)
})
skuCodes.push(variant.dataset.skuCode);
});
let qf = new clsdk.query.QueryFilter()
.filter('codes', skuCodes.join(','))
.pageSize(25)
.filter("codes", skuCodes.join(","))
.pageSize(25);
let skuAttributes = ['id', 'code']
let skuAttributes = ["id", "code"];
clsdk.listSkus(qf.build()).then(data => {
ui.updateVariantsQuantity(data.get(skuAttributes), true)
ui.updateVariantsQuantity(data.get(skuAttributes), true);
let pageCount = data.dataset.meta.page_count
let pageCount = data.dataset.meta.page_count;
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p)
qf.pageNumber(p);
clsdk

@@ -119,7 +119,7 @@ .listSkus(qf)

ui.updateVariantsQuantity(data.get(skuAttributes), false)
)
);
}
}
document.dispatchEvent(new Event('clayer-variants-quantity-ready'))
})
document.dispatchEvent(new Event("clayer-variants-quantity-ready"));
});
}

@@ -129,32 +129,32 @@ },

getAddToBags: function() {
let addToBags = document.querySelectorAll('.clayer-add-to-bag')
let addToBags = document.querySelectorAll(".clayer-add-to-bag");
if (addToBags.length > 0) {
let skuCodes = []
let skuCodes = [];
addToBags.forEach(function(addToBag) {
skuCodes.push(addToBag.dataset.skuCode)
})
skuCodes.push(addToBag.dataset.skuCode);
});
let qf = new clsdk.query.QueryFilter()
.filter('codes', skuCodes.join(','))
.pageSize(25)
.filter("codes", skuCodes.join(","))
.pageSize(25);
let skuAttributes = ['id', 'code']
let skuAttributes = ["id", "code"];
clsdk.listSkus(qf.build()).then(data => {
ui.updateAddToBags(data.get(skuAttributes))
ui.updateAddToBags(data.get(skuAttributes));
let pageCount = data.dataset.meta.page_count
let pageCount = data.dataset.meta.page_count;
if (pageCount > 1) {
for (p = 2; p <= pageCount; p++) {
qf.pageNumber(p)
qf.pageNumber(p);
clsdk
.listSkus(qf)
.then(data => ui.updateAddToBags(data.get(skuAttributes)))
.then(data => ui.updateAddToBags(data.get(skuAttributes)));
}
}
document.dispatchEvent(new Event('clayer-add-to-bags-ready'))
})
document.dispatchEvent(new Event("clayer-add-to-bags-ready"));
});
}

@@ -173,22 +173,22 @@ },

) {
console.log('addToBagQuantityId :', addToBagQuantityId)
let qf = new clsdk.query.QueryFilter().include('prices').pageSize(25)
console.log("addToBagQuantityId :", addToBagQuantityId);
let qf = new clsdk.query.QueryFilter().include("prices").pageSize(25);
clsdk.retrieveSku(skuId, qf.build()).then(data => {
let skuAttributes = [
'id',
'code',
'inventory',
'prices.formatted_amount',
'prices.formatted_compare_at_amount',
'prices.amount_cents',
'prices.compare_at_amount_cents'
]
"id",
"code",
"inventory",
"prices.formatted_amount",
"prices.formatted_compare_at_amount",
"prices.amount_cents",
"prices.compare_at_amount_cents"
];
let sku = data.get(skuAttributes)
ui.updatePrice(sku, priceContainerId)
let sku = data.get(skuAttributes);
ui.updatePrice(sku, priceContainerId);
ui.updateAvailabilityMessage(
sku.inventory,
availabilityMessageContainerId
)
);
if (sku.inventory.available) {

@@ -202,3 +202,3 @@ ui.updateAddToBagSKU(

addToBagQuantityId
)
);
ui.updateAddVariantQuantitySKU(

@@ -211,13 +211,13 @@ skuId,

addToBagQuantityId
)
);
// TODO: enable quantity
ui.enableAddToBag(addToBagId)
ui.enableAddVariantQuantity(addToBagQuantityId)
ui.enableAddToBag(addToBagId);
ui.enableAddVariantQuantity(addToBagQuantityId);
} else {
// TODO: disable quantity
ui.disableAddToBag(addToBagId)
ui.disableAddVariantQuantity(addToBagQuantityId)
ui.disableAddToBag(addToBagId);
ui.disableAddVariantQuantity(addToBagQuantityId);
}
document.dispatchEvent(new Event('clayer-variant-selected'))
})
document.dispatchEvent(new Event("clayer-variant-selected"));
});
},

@@ -228,3 +228,3 @@

.createOrder({
type: 'orders',
type: "orders",
shipping_country_code_lock: config.countryCode,

@@ -238,38 +238,25 @@ language_code: config.languageCode,

.then(response => {
utils.setOrderToken(response.dataset.data.id)
return response.dataset.data
})
utils.setOrderToken(response.dataset.data.id);
return response.dataset.data;
});
},
getOrder: function() {
api = this
api = this;
let qf = new clsdk.query.QueryFilter()
let qf = new clsdk.query.QueryFilter();
qf.include('line_items')
qf.include("line_items");
return clsdk.retrieveOrder(utils.getOrderToken(), qf).then(response => {
if (response.dataset.data.attributes) {
api.updateShoppingBagItems(response)
ui.updateShoppingBagSummary(response.dataset.data)
ui.updateShoppingBagCheckout(response)
api.updateShoppingBagItems(response);
ui.updateShoppingBagSummary(response.dataset.data);
ui.updateShoppingBagCheckout(response);
if (response.dataset.data.attributes.skus_count === 0) {
ui.clearShoppingBag()
ui.clearShoppingBag();
}
document.dispatchEvent(new Event('clayer-order-ready'))
return response.dataset.data
document.dispatchEvent(new Event("clayer-order-ready"));
return response.dataset.data;
}
})
return clsdk.listOrders(qf).then(function(response) {
if (response.get(['line_items']).length > 0) {
api.updateShoppingBagItems(response)
ui.updateShoppingBagSummary(response.dataset.data[0])
ui.updateShoppingBagCheckout(response)
if (response.get('skus_count') == 0) {
ui.clearShoppingBag()
}
document.dispatchEvent(new Event('clayer-order-ready'))
return response.dataset.data[0]
}
})
});
},

@@ -280,7 +267,7 @@

this.getOrder().then(function(order) {
if (!order || order.attributes.status == 'placed') {
utils.deleteOrderToken()
ui.clearShoppingBag()
if (!order || order.attributes.status == "placed") {
utils.deleteOrderToken();
ui.clearShoppingBag();
}
})
});
}

@@ -298,3 +285,3 @@ },

let lineItemData = {
type: 'line_items',
type: "line_items",
attributes: {

@@ -307,3 +294,3 @@ quantity,

data: {
type: 'orders',
type: "orders",
id: orderId

@@ -314,3 +301,3 @@ }

data: {
type: 'skus',
type: "skus",
id: skuId

@@ -320,8 +307,8 @@ }

}
}
};
if (skuName) lineItemData.attributes.name = skuName
if (skuReference) lineItemData.attributes.reference = skuReference
if (skuImageUrl) lineItemData.attributes.image_url = skuImageUrl
if (quantity) lineItemData.attributes.quantity = quantity
if (skuName) lineItemData.attributes.name = skuName;
if (skuReference) lineItemData.attributes.reference = skuReference;
if (skuImageUrl) lineItemData.attributes.image_url = skuImageUrl;
if (quantity) lineItemData.attributes.quantity = quantity;

@@ -333,5 +320,5 @@ return clsdk

.then(function(response) {
document.dispatchEvent(new Event('clayer-line-item-created'))
return response
})
document.dispatchEvent(new Event("clayer-line-item-created"));
return response;
});
},

@@ -341,5 +328,5 @@

return clsdk.deleteLineItem(lineItemId).then(function(response) {
document.dispatchEvent(new Event('clayer-line-item-deleted'))
return response
})
document.dispatchEvent(new Event("clayer-line-item-deleted"));
return response;
});
},

@@ -351,3 +338,3 @@

data: {
type: 'line_items',
type: "line_items",
id: lineItemId,

@@ -358,5 +345,5 @@ attributes: attributes

.then(function(response) {
document.dispatchEvent(new Event('clayer-line-item-updated'))
return response
})
document.dispatchEvent(new Event("clayer-line-item-updated"));
return response;
});
},

@@ -369,7 +356,7 @@

) {
api = this
api = this;
api
.updateLineItem(lineItemId, { quantity: quantity })
.then(function() {
api.getOrder()
api.getOrder();
})

@@ -381,44 +368,44 @@ .catch(function(error) {

if (availabilityMessageContainer) {
ui.displayUnavailableMessage(availabilityMessageContainer)
ui.displayUnavailableMessage(availabilityMessageContainer);
}
break
break;
}
}
})
});
},
updateShoppingBagItems: function(order) {
api = this
api = this;
let shoppingBagItemsContainer = document.querySelector(
'#clayer-shopping-bag-items-container'
)
"#clayer-shopping-bag-items-container"
);
if (shoppingBagItemsContainer) {
normalized_order = order.get([
'id',
'formatted_subtotal_amount',
'formatted_discount_amount',
'formatted_shipping_amount',
'formatted_payment_method_amount',
'formatted_total_tax_amount',
'formatted_total_amount_with_taxes',
'line_items.id',
'line_items.item_type',
'line_items.image_url',
'line_items.name',
'line_items.reference',
'line_items.quantity',
'line_items.formatted_unit_amount',
'line_items.formatted_total_amount'
])
"id",
"formatted_subtotal_amount",
"formatted_discount_amount",
"formatted_shipping_amount",
"formatted_payment_method_amount",
"formatted_total_tax_amount",
"formatted_total_amount_with_taxes",
"line_items.id",
"line_items.item_type",
"line_items.image_url",
"line_items.name",
"line_items.reference",
"line_items.quantity",
"line_items.formatted_unit_amount",
"line_items.formatted_total_amount"
]);
if (normalized_order.line_items) {
shoppingBagItemsContainer.innerHTML = ''
shoppingBagItemsContainer.innerHTML = "";
for (i = 0; i < normalized_order.line_items.length; i++) {
line_item = normalized_order.line_items[i]
line_item = normalized_order.line_items[i];
if (line_item.item_type == 'skus') {
if (line_item.item_type == "skus") {
let shoppingBagItemTemplate = document.querySelector(
'#clayer-shopping-bag-item-template'
)
"#clayer-shopping-bag-item-template"
);

@@ -428,10 +415,10 @@ if (shoppingBagItemTemplate) {

shoppingBagItemTemplate
)
);
// image
let shoppingBagItemImage = shoppingBagItem.querySelector(
'.clayer-shopping-bag-item-image'
)
".clayer-shopping-bag-item-image"
);
if (shoppingBagItemImage) {
shoppingBagItemImage.src = line_item.image_url
shoppingBagItemImage.src = line_item.image_url;
}

@@ -441,6 +428,6 @@

let shoppingBagItemName = shoppingBagItem.querySelector(
'.clayer-shopping-bag-item-name'
)
".clayer-shopping-bag-item-name"
);
if (shoppingBagItemName) {
shoppingBagItemName.innerHTML = line_item.name
shoppingBagItemName.innerHTML = line_item.name;
}

@@ -450,6 +437,6 @@

let shoppingBagItemReference = shoppingBagItem.querySelector(
'.clayer-shopping-bag-item-reference'
)
".clayer-shopping-bag-item-reference"
);
if (shoppingBagItemReference) {
shoppingBagItemReference.innerHTML = line_item.reference
shoppingBagItemReference.innerHTML = line_item.reference;
}

@@ -459,23 +446,23 @@

let shoppingBagItemQtyContainer = shoppingBagItem.querySelector(
'.clayer-shopping-bag-item-qty-container'
)
".clayer-shopping-bag-item-qty-container"
);
if (shoppingBagItemQtyContainer) {
let availabilityMessageContainer = shoppingBagItemQtyContainer.querySelector(
'.clayer-shopping-bag-item-availability-message-container'
)
".clayer-shopping-bag-item-availability-message-container"
);
let qtySelect = document.createElement('select')
qtySelect.dataset.lineItemId = line_item.id
let qtySelect = document.createElement("select");
qtySelect.dataset.lineItemId = line_item.id;
for (qty = 1; qty <= 50; qty++) {
let option = document.createElement('option')
option.value = qty
option.text = qty
let option = document.createElement("option");
option.value = qty;
option.text = qty;
if (qty == line_item.quantity) {
option.selected = true
option.selected = true;
}
qtySelect.appendChild(option)
qtySelect.appendChild(option);
}
qtySelect.addEventListener('change', function(event) {
qtySelect.addEventListener("change", function(event) {
api.updateLineItemQty(

@@ -485,8 +472,8 @@ this.dataset.lineItemId,

availabilityMessageContainer
)
})
);
});
shoppingBagItemQtyContainer.insertBefore(
qtySelect,
shoppingBagItemQtyContainer.firstChild
)
);
}

@@ -496,7 +483,7 @@

let shoppingBagItemUnitAmount = shoppingBagItem.querySelector(
'.clayer-shopping-bag-item-unit-amount'
)
".clayer-shopping-bag-item-unit-amount"
);
if (shoppingBagItemUnitAmount) {
shoppingBagItemUnitAmount.innerHTML =
line_item.formatted_unit_amount
line_item.formatted_unit_amount;
}

@@ -506,7 +493,7 @@

let shoppingBagItemTotalAmount = shoppingBagItem.querySelector(
'.clayer-shopping-bag-item-total-amount'
)
".clayer-shopping-bag-item-total-amount"
);
if (shoppingBagItemTotalAmount) {
shoppingBagItemTotalAmount.innerHTML =
line_item.formatted_total_amount
line_item.formatted_total_amount;
}

@@ -516,20 +503,20 @@

let shoppingBagItemRemove = shoppingBagItem.querySelector(
'.clayer-shopping-bag-item-remove'
)
".clayer-shopping-bag-item-remove"
);
if (shoppingBagItemRemove) {
shoppingBagItemRemove.dataset.lineItemId = line_item.id
shoppingBagItemRemove.addEventListener('click', function(
shoppingBagItemRemove.dataset.lineItemId = line_item.id;
shoppingBagItemRemove.addEventListener("click", function(
event
) {
event.preventDefault()
event.stopPropagation()
event.preventDefault();
event.stopPropagation();
api
.deleteLineItem(this.dataset.lineItemId)
.then(function(lineItem) {
api.getOrder()
})
})
api.getOrder();
});
});
}
shoppingBagItemsContainer.appendChild(shoppingBagItem)
shoppingBagItemsContainer.appendChild(shoppingBagItem);
}

@@ -541,2 +528,2 @@ }

}
}
};

Sorry, the diff of this file is too big to display

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