woocommerce-api
Advanced tools
Comparing version
17
index.js
@@ -5,2 +5,3 @@ 'use strict'; | ||
var OAuth = require('oauth-1.0a'); | ||
var crypto = require('crypto'); | ||
var promise = require('bluebird'); | ||
@@ -85,3 +86,4 @@ var _url = require('url'); | ||
queryString += encodeURIComponent(params[i]).replace('%5B', '[').replace('%5D', ']'); | ||
queryString += encodeURIComponent(params[i]).replace('%5B', '[') | ||
.replace('%5D', ']'); | ||
queryString += '='; | ||
@@ -128,6 +130,10 @@ queryString += encodeURIComponent(query[params[i]]); | ||
consumer: { | ||
public: this.consumerKey, | ||
key: this.consumerKey, | ||
secret: this.consumerSecret | ||
}, | ||
signature_method: 'HMAC-SHA256' | ||
signature_method: 'HMAC-SHA256', | ||
hash_function: function(base_string, key) { | ||
return crypto.createHmac('sha256', key).update(base_string) | ||
.digest('base64'); | ||
} | ||
}; | ||
@@ -264,4 +270,5 @@ | ||
/** | ||
* Promifying all requests exposing new methods named [method]Async like in getAsync() | ||
* Promifying all requests exposing new methods | ||
* named [method]Async like in getAsync() | ||
*/ | ||
promise.promisifyAll(Object.getPrototypeOf(WooCommerceAPI)); | ||
promise.promisifyAll(WooCommerceAPI.prototype); |
{ | ||
"name": "woocommerce-api", | ||
"description": "A Node.js wrapper for the WooCommerce REST API", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"scripts": { | ||
@@ -23,12 +23,12 @@ "lint": "jshint .", | ||
"dependencies": { | ||
"bluebird": "^3.4.1", | ||
"oauth-1.0a": "^1.0.1", | ||
"request": "^2.67.0" | ||
"bluebird": "^3.4.6", | ||
"oauth-1.0a": "^2.0.0", | ||
"request": "^2.75.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"istanbul": "^0.4.1", | ||
"jscs": "^3.0.3", | ||
"jshint": "^2.9.1-rc1", | ||
"mocha": "^2.3.4", | ||
"chai": "^3.5.0", | ||
"istanbul": "^0.4.5", | ||
"jscs": "^3.0.7", | ||
"jshint": "^2.9.3", | ||
"mocha": "^3.1.0", | ||
"nock": "^8.0.0" | ||
@@ -38,4 +38,4 @@ }, | ||
"type": "git", | ||
"url": "git@github.com:woothemes/wc-api-node.git" | ||
"url": "git@github.com:woocommerce/wc-api-node.git" | ||
} | ||
} |
@@ -5,4 +5,4 @@ # WooCommerce API - Node.js Client | ||
[](http://travis-ci.org/woothemes/wc-api-node) | ||
[](https://david-dm.org/woothemes/wc-api-node) | ||
[](http://travis-ci.org/woocommerce/wc-api-node) | ||
[](https://david-dm.org/woocommerce/wc-api-node) | ||
[](https://www.npmjs.com/package/woocommerce-api) | ||
@@ -18,6 +18,6 @@ | ||
Generate API credentials (Consumer Key & Consumer Secret) following this instructions <http://docs.woothemes.com/document/woocommerce-rest-api/> | ||
Generate API credentials (Consumer Key & Consumer Secret) following this instructions <http://docs.woocommerce.com/document/woocommerce-rest-api/> | ||
. | ||
Check out the WooCommerce API endpoints and data that can be manipulated in <http://woothemes.github.io/woocommerce-rest-api-docs/>. | ||
Check out the WooCommerce API endpoints and data that can be manipulated in <http://woocommerce.github.io/woocommerce-rest-api-docs/>. | ||
@@ -114,3 +114,4 @@ ## Setup | ||
- 2016-06-39 - v1.4.0 - Added `wpAPIPrefix` option to allow custom WP REST API Url prefix and support for promified methods. | ||
- 2016-09-28 - v1.4.1 - Updated dependencies and updated/fixed oAuth1.0a. | ||
- 2016-06-30 - v1.4.0 - Added `wpAPIPrefix` option to allow custom WP REST API Url prefix and support for promified methods. | ||
- 2016-06-09 - v1.3.2 - Fixed oAuth signature for WP REST API. | ||
@@ -117,0 +118,0 @@ - 2016-06-08 - v1.3.1 - Fixed README.md. |
86
test.js
@@ -16,6 +16,8 @@ var WooCommerce = require('./index.js'); | ||
consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | ||
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
wpAPI: true, | ||
version: 'wc/v1' | ||
}); | ||
chai.expect(api.version).to.equal('v3'); | ||
chai.expect(api.version).to.equal('wc/v1'); | ||
chai.expect(api.isSsl).to.be.false; | ||
@@ -35,3 +37,5 @@ chai.expect(api.verifySsl).to.be.true; | ||
consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | ||
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
wpAPI: true, | ||
version: 'wc/v1' | ||
}); | ||
@@ -41,3 +45,3 @@ | ||
var endpoint = 'products'; | ||
var expected = 'https://test.dev/wc-api/v3/products'; | ||
var expected = 'https://test.dev/wp-json/wc/v1/products'; | ||
var url = api._getUrl(endpoint); | ||
@@ -66,4 +70,4 @@ | ||
it('should return sorted by name query string', function() { | ||
var url = 'http://test.dev/wc-api/v3/products?filter[q]=Woo+Album&fields=id&filter[limit]=1'; | ||
var expected = 'http://test.dev/wc-api/v3/products?fields=id&filter[limit]=1&filter[q]=Woo%20Album'; | ||
var url = 'http://test.dev/wp-json/wc/v1/products?filter[q]=Woo+Album&fields=id&filter[limit]=1'; | ||
var expected = 'http://test.dev/wp-json/wc/v1/products?fields=id&filter[limit]=1&filter[q]=Woo%20Album'; | ||
var normalized = api._normalizeQueryString(url); | ||
@@ -75,3 +79,3 @@ | ||
it('should return content for basic auth', function(done) { | ||
nock('https://test.dev/wc-api/v3').post('/orders', {}).reply(200, { | ||
nock('https://test.dev/wp-json/wc/v1').post('/orders', {}).reply(200, { | ||
ok: true | ||
@@ -88,3 +92,3 @@ }); | ||
it('should return content for get requests', function(done) { | ||
nock('https://test.dev/wc-api/v3').get('/orders').reply(200, { | ||
nock('https://test.dev/wp-json/wc/v1').get('/orders').reply(200, { | ||
ok: true | ||
@@ -101,3 +105,3 @@ }); | ||
it('should return content for put requests', function(done) { | ||
nock('https://test.dev/wc-api/v3').put('/orders', {}).reply(200, { | ||
nock('https://test.dev/wp-json/wc/v1').put('/orders', {}).reply(200, { | ||
ok: true | ||
@@ -114,3 +118,3 @@ }); | ||
it('should return content for delete requests', function(done) { | ||
nock('https://test.dev/wc-api/v3').delete('/orders').reply(200, { | ||
nock('https://test.dev/wp-json/wc/v1').delete('/orders').reply(200, { | ||
ok: true | ||
@@ -127,3 +131,3 @@ }); | ||
it('should return content for options requests', function(done) { | ||
nock('https://test.dev/wc-api/v3').intercept('/orders', 'OPTIONS').reply(400); | ||
nock('https://test.dev/wp-json/wc/v1').intercept('/orders', 'OPTIONS').reply(400); | ||
@@ -137,2 +141,55 @@ api.options('orders', function(err, data) { | ||
it('should return a promise for getAsync requests', function(done) { | ||
nock('https://test.dev/wp-json/wc/v1').get('/orders').reply(200, { | ||
ok: true | ||
}); | ||
api.getAsync('orders').finally(function(data) { | ||
chai.expect(data).be.a.string; | ||
done(); | ||
}); | ||
}); | ||
it('should return a promise for postAsync requests', function(done) { | ||
nock('https://test.dev/wp-json/wc/v1').post('/orders', {}).reply(200, { | ||
ok: true | ||
}); | ||
api.postAsync('orders', {}).finally(function(data) { | ||
chai.expect(data).be.a.string; | ||
done(); | ||
}); | ||
}); | ||
it('should return a promise for putAsync requests', function(done) { | ||
nock('https://test.dev/wp-json/wc/v1').put('/orders', {}).reply(200, { | ||
ok: true | ||
}); | ||
api.putAsync('orders', {}).finally(function(data) { | ||
chai.expect(data).be.a.string; | ||
done(); | ||
}); | ||
}); | ||
it('should return a promise for deleteAsync requests', function(done) { | ||
nock('https://test.dev/wp-json/wc/v1').delete('/orders').reply(200, { | ||
ok: true | ||
}); | ||
api.deleteAsync('orders').finally(function(data) { | ||
chai.expect(data).be.a.string; | ||
done(); | ||
}); | ||
}); | ||
it('should return a promise for optionsAsync requests', function(done) { | ||
nock('https://test.dev/wp-json/wc/v1').intercept('/orders', 'OPTIONS').reply(400); | ||
api.optionsAsync('orders').finally(function(data) { | ||
chai.expect(data).be.a.string; | ||
done(); | ||
}); | ||
}); | ||
it('should return content for OAuth', function(done) { | ||
@@ -142,6 +199,8 @@ var oAuth = new WooCommerce({ | ||
consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | ||
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
wpAPI: true, | ||
version: 'wc/v1' | ||
}); | ||
nock('http://test.dev/wc-api/v3').filteringPath(/\?.*/, '?params').get('/orders?params').reply(200, { | ||
nock('http://test.dev/wp-json/wc/v1').filteringPath(/\?.*/, '?params').get('/orders?params').reply(200, { | ||
ok: true | ||
@@ -156,3 +215,2 @@ }); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
22897
8.59%440
14.58%125
0.81%+ Added
- Removed
- Removed
Updated
Updated
Updated