slim-stencil-tools
Advanced tools
Comparing version 0.2.0 to 0.4.0
{ | ||
"name": "slim-stencil-tools", | ||
"version": "0.2.0", | ||
"description": "Lightweight, jQuery-free utility library for BigCommerce Stencil themes", | ||
"version": "0.4.0", | ||
"description": "A lightweight and modern alternative utility library for Bigcommerce Stencil themes", | ||
"main": "dist/slim-stencil-tools.js", | ||
@@ -18,3 +18,7 @@ "scripts": { | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"bigcommerce", | ||
"stencil-utils", | ||
"stencil" | ||
], | ||
"author": "Donny West <donnywest@gmail.com>", | ||
@@ -21,0 +25,0 @@ "license": "MIT", |
@@ -107,6 +107,18 @@ # slim-stencil-tools | ||
###### getShippingEstimate(opts) | ||
Retrieve a shipping estimate for items in the cart. Example coming soon. | ||
Retrieve a shipping estimate for items in the cart. Accepts an object containing the ship-to information. | ||
```javascript | ||
const shipTo = { | ||
country_id: 226, | ||
state_id: 18, | ||
city: 'Gainesville', | ||
zip_code: '32653', | ||
}; | ||
const shippingQuotes = CartApi.getShippingEstimate(shipTo); | ||
``` | ||
###### submitShippingEstimate(params) | ||
Submit selected shipping estimate. Example coming soon. | ||
Submit selected shipping estimate. Accepts the selected shipping method id. | ||
```javascript | ||
CartApi.submitShippingEstimate(3); | ||
``` | ||
@@ -113,0 +125,0 @@ ##### Page |
import fetchStatus from '../lib/fetch-status'; | ||
import buildParams from '../lib/build-params'; | ||
import dataTemplate from '../lib/data-template'; | ||
@@ -34,16 +36,2 @@ /** | ||
* @description | ||
* Simple function to convert object to url params if FormData isn't being used | ||
* @param {Object} obj | ||
*/ | ||
const buildParams = (obj) => { | ||
const str = Object.keys(obj).map( | ||
key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}` | ||
).join('&'); | ||
return str; | ||
}; | ||
/** | ||
* @description | ||
* Base BigCommerce API client function | ||
@@ -58,2 +46,5 @@ * @param {Object} opts | ||
const reqUrl = options.reqUrl ? `${url}?${data}` : url; | ||
const template = options.component | ||
? dataTemplate(options.componentPath, options.component, options.componentSuffix) | ||
: null; | ||
@@ -65,7 +56,8 @@ return new Promise((resolve, reject) => { | ||
...options.headers, | ||
'stencil-config': options.config ? JSON.stringify(options.config) : '{}', | ||
'stencil-options': options.component ? JSON.stringify({ | ||
// eslint-disable-next-line max-len | ||
render_with: `${options.componentPath}/${options.component.toLowerCase()}-${options.componentSuffix}`, | ||
}) : '{}', | ||
'stencil-config': options.config | ||
? JSON.stringify(options.config) | ||
: '{}', | ||
'stencil-options': options.component | ||
? JSON.stringify({ render_with: template }) | ||
: '{}', | ||
}, | ||
@@ -72,0 +64,0 @@ body: options.method === 'GET' ? null : data, |
@@ -7,3 +7,3 @@ import { bcClient } from './Base'; | ||
* @param {String} component | ||
* @param {Object} component | ||
* @param {Object} opts | ||
*/ | ||
@@ -112,3 +112,3 @@ export const getCartContent = (component = 'cart', opts = {}) => new Promise((resolve, reject) => { | ||
*/ | ||
export const submitShippingEstimate = (params) => new Promise((resolve, reject) => { | ||
export const submitShippingEstimate = (methodId) => new Promise((resolve, reject) => { | ||
bcClient({ | ||
@@ -121,3 +121,5 @@ url: '/shipping-quote', | ||
}, | ||
params, | ||
params: { | ||
shipping_method: methodId, | ||
}, | ||
}).then(response => { | ||
@@ -124,0 +126,0 @@ if (response.status !== 'failed') { |
@@ -1,2 +0,2 @@ | ||
import fetchStatus from '../lib/fetch-status'; | ||
import { bcClient } from './Base'; | ||
@@ -7,16 +7,13 @@ /** | ||
* @param {String} url | ||
* @param {String} template | ||
* @param {String} component | ||
* @param {Object} opts | ||
*/ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const getPage = (url, template) => new Promise((resolve, reject) => { | ||
fetch(url, { | ||
headers: { | ||
'stencil-config': '{}', | ||
'stencil-options': JSON.stringify({ render_with: template }), | ||
}, | ||
credentials: 'include', | ||
}).then(fetchStatus) | ||
.then(response => response.json()) | ||
.then(res => resolve(JSON.parse(res))) | ||
export const getPage = (url, component, opts = {}) => new Promise((resolve, reject) => { | ||
bcClient({ | ||
url, | ||
component, | ||
...opts, | ||
}).then(response => resolve(response)) | ||
.catch(error => reject(new Error(error))); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
243569
31
904
165
5