shopify-api-node
Advanced tools
Comparing version 2.4.0 to 2.5.0
17
index.js
'use strict'; | ||
const camelCase = require('lodash/camelCase'); | ||
const transform = require('lodash/transform'); | ||
const defaults = require('lodash/defaults'); | ||
const assign = require('lodash/assign'); | ||
const valvelet = require('valvelet'); | ||
const EventEmitter = require('events'); | ||
const stopcock = require('stopcock'); | ||
const path = require('path'); | ||
@@ -37,2 +39,3 @@ const got = require('got'); | ||
EventEmitter.call(this); | ||
this.options = defaults(options, { timeout: 60000 }); | ||
@@ -56,7 +59,13 @@ | ||
if (options.autoLimit) { | ||
const conf = assign({ calls: 2, interval: 1000 }, options.autoLimit); | ||
this.request = valvelet(this.request, conf.calls, conf.interval); | ||
const conf = transform(options.autoLimit, (result, value, key) => { | ||
if (key === 'calls') key = 'limit'; | ||
result[key] = value; | ||
}, { bucketSize: 35 }); | ||
this.request = stopcock(this.request, conf); | ||
} | ||
} | ||
Object.setPrototypeOf(Shopify.prototype, EventEmitter.prototype); | ||
/** | ||
@@ -77,2 +86,4 @@ * Updates API call limits. | ||
callLimits.max = limits[1]; | ||
this.emit('callLimits', callLimits); | ||
}; | ||
@@ -79,0 +90,0 @@ |
{ | ||
"name": "shopify-api-node", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Shopify API bindings for Node.js", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"qs": "^6.1.0", | ||
"valvelet": "^1.1.0" | ||
"stopcock": "^1.0.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
@@ -1,2 +0,2 @@ | ||
# shopify-api-node | ||
# Shopify API Node.js (Official module) | ||
@@ -8,3 +8,3 @@ [![Version npm][npm-shopify-api-node-badge]][npm-shopify-api-node] | ||
Shopify API bindings for Node.js. | ||
Official Shopify API bindings for Node.js. | ||
@@ -47,8 +47,9 @@ ## Installation: | ||
- `autoLimit` - Optional - This option allows you to regulate the request rate | ||
in order to avoid hitting the [rate limit][api-call-limit]. It can be a | ||
boolean or a plain JavaScript object. When set to `true` requests are limited | ||
to 2 per second. When using an object, the `calls` property specifies the | ||
maximum number of allowed requests and the `interval` property the timespan | ||
in milliseconds where the limit is calculated. For example | ||
`{ calls: 4, interval: 1000 }` specifies a maximum of 4 requests per second. | ||
in order to avoid hitting the [rate limit][api-call-limit]. Requests are | ||
limited using the token bucket algorithm. Accepted values are a boolean or a | ||
plain JavaScript object. When using an object, the `calls` property and the | ||
`interval` property specify the refill rate and the `bucketSize` property | ||
the bucket size. For example `{ calls: 2, interval: 1000, bucketSize: 35 }` | ||
specifies a limit of 2 requests per second with a burst of 35 requests. When | ||
set to `true` requests are limited as specified in the above example. | ||
Defaults to `false`. | ||
@@ -92,4 +93,10 @@ - `timeout` - Optional - A number that specifies the milliseconds to wait for | ||
Values start at `undefined` and are updated every time a request is made. | ||
Values start at `undefined` and are updated every time a request is made. After | ||
every update the `callLimits` event is emitted with the updated limits as | ||
argument. | ||
```js | ||
shopify.on('callLimits', limits => console.log(limits)); | ||
``` | ||
### Resources | ||
@@ -125,2 +132,6 @@ | ||
- `list([params])` | ||
- applicationCredit | ||
- `create(params)` | ||
- `get(id[, params])` | ||
- `list([params])` | ||
- article | ||
@@ -155,4 +166,9 @@ - `authors()` | ||
- checkout | ||
- `complete(token)` | ||
- `count([params])` | ||
- `create(params)` | ||
- `get(token)` | ||
- `list([params])` | ||
- `shippingRates(token)` | ||
- `update(token, params)` | ||
- collect | ||
@@ -164,2 +180,6 @@ - `count([params])` | ||
- `list([params])` | ||
- collectionListing | ||
- `get(applicationId, id)` | ||
- `list(applicationId[, params])` | ||
- `productIds(applicationId, id)` | ||
- comment | ||
@@ -267,2 +287,10 @@ - `approve(id)` | ||
- `list()` | ||
- marketingEvent | ||
- `count()` | ||
- `create(params)` | ||
- `delete(id)` | ||
- `get(id)` | ||
- `list([params])` | ||
- `update(id, params)` | ||
- `engagements(id, params)` | ||
- metafield | ||
@@ -298,2 +326,7 @@ - `count([params])` | ||
- `update(id, params)` | ||
- payment | ||
- `count(checkoutToken)` | ||
- `create(checkoutToken, params)` | ||
- `get(checkoutToken, id)` | ||
- `list(checkoutToken)` | ||
- policy | ||
@@ -315,2 +348,7 @@ - `list([params])` | ||
- `update(productId, id, params)` | ||
- productListing | ||
- `count(applicationId)` | ||
- `get(applicationId, id)` | ||
- `list(applicationId[, params])` | ||
- `productIds(applicationId[, params])` | ||
- productVariant | ||
@@ -343,2 +381,11 @@ - `count(productId)` | ||
- `get(orderId, id[, params])` | ||
- report | ||
- `create(params)` | ||
- `delete(id)` | ||
- `get(id[, params])` | ||
- `list([params])` | ||
- `update(id, params)` | ||
- resourceFeedback | ||
- `create(params)` | ||
- `list()` | ||
- scriptTag | ||
@@ -401,6 +448,14 @@ - `count([params])` | ||
## Use a frontend framework which mimics the Shopify merchant admin: | ||
## Use Polaris, a React powered Frontend Framework which mimics the Shopify merchant admin: | ||
[Shopify Embedded App Frontend Framework][shopify-embedded-app-frontend-framework] | ||
[Polaris][polaris] | ||
## Shopify Apps already using Shopify API node: | ||
(add yours!) | ||
* [Wholesaler][wholesaler] | ||
* [Wholesaler & Customer Pricing][wholesaler-customer-pricing] | ||
* [Pricing Rules by MONEI][pricing-rules-by-monei] | ||
## Supported by: | ||
@@ -427,11 +482,14 @@ | ||
[shopify-token]: https://github.com/lpinca/shopify-token | ||
[api-call-limit]: https://help.shopify.com/api/guides/api-call-limit | ||
[api-call-limit]: https://help.shopify.com/api/guides/api-call-limit/?ref=microapps | ||
[becoming-a-shopify-app-developer]: https://app.shopify.com/services/partners/signup?ref=microapps | ||
[checking-out-the-roots]: https://help.shopify.com/api/guides?ref=microapps | ||
[talking-to-other-masters]: https://ecommerce.shopify.com/c/shopify-apps?ref=microapps | ||
[reading-api-docs]: https://help.shopify.com/api/reference?ref=microapps | ||
[reading-api-docs]: https://help.shopify.com/api/reference/?ref=microapps | ||
[learning-from-others]: https://stackoverflow.com/questions/tagged/shopify | ||
[shopify-embedded-app-frontend-framework]: http://seaff.microapps.com?utm_source=shopify-api-node-module-repo-readme&utm_medium=click&utm_campaign=github | ||
[polaris]: https://polaris.shopify.com/?ref=microapps | ||
[microapps]: http://microapps.com/?utm_source=shopify-api-node-module-repo-readme&utm_medium=click&utm_campaign=github | ||
[moonmail]: https://moonmail.io/?utm_source=shopify-api-node-module-repo-readme&utm_medium=click&utm_campaign=github | ||
[monei]: https://monei.net/?utm_source=shopify-api-node-module-repo-readme&utm_medium=click&utm_campaign=github | ||
[wholesaler]: https://apps.shopify.com/wholesaler?ref=microapps | ||
[wholesaler-customer-pricing]: https://apps.shopify.com/wholesaler-pro-1?ref=microapps | ||
[pricing-rules-by-monei]: https://apps.shopify.com/pricing-rules-by-monei?ref=microapps |
@@ -38,7 +38,5 @@ 'use strict'; | ||
const url = this.buildUrl(`${id}/activate`); | ||
return this.shopify.request(url, 'POST', undefined, { | ||
[this.key]: params | ||
}); | ||
return this.shopify.request(url, 'POST', this.key, params); | ||
}; | ||
module.exports = ApplicationCharge; |
'use strict'; | ||
const assign = require('lodash/assign'); | ||
const pick = require('lodash/pick'); | ||
const omit = require('lodash/omit'); | ||
@@ -22,4 +22,29 @@ const base = require('../mixins/base'); | ||
assign(Checkout.prototype, pick(base, ['count', 'list', 'buildUrl'])); | ||
assign(Checkout.prototype, omit(base, 'delete')); | ||
/** | ||
* Completes a free checkout. | ||
* | ||
* @param {String} token Checkout token | ||
* @return {Promise} Promise that resolves with the result | ||
* @public | ||
*/ | ||
Checkout.prototype.complete = function complete(token) { | ||
const url = this.buildUrl(`${token}/complete`); | ||
return this.shopify.request(url, 'POST', undefined, {}) | ||
.then(body => body[this.key]); | ||
}; | ||
/** | ||
* Gets a list of available shipping rates for the specified checkout. | ||
* | ||
* @param {String} token Checkout token | ||
* @return {Promise} Promise that resolves with the result | ||
* @public | ||
*/ | ||
Checkout.prototype.shippingRates = function shippingRates(token) { | ||
const url = this.buildUrl(`${token}/shipping_rates`); | ||
return this.shopify.request(url, 'GET', 'shipping_rates'); | ||
}; | ||
module.exports = Checkout; |
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
68363
56
1878
484
+ Addedstopcock@^1.0.0
+ Addedstopcock@1.1.0(transitive)
- Removedvalvelet@^1.1.0
- Removedvalvelet@1.1.1(transitive)