diff --git a/CHANGELOG.md b/CHANGELOG.md index 11ab457..1d577a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +0.0.3 September 19, 2018 + - Add TypeScript example + - Correct typo in README.md + - Configure mocha test case + - Add types for the application, buy, commerce and sell APIs + 0.0.2 September 19, 2018 - Add Support for browse API : search - Add SANDBOX usage using environment variable diff --git a/README.md b/README.md index 1458189..e6bf00b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ You can find [examples of JavaScript and TypeScript here](https://github.com/bhu ## Installation ```bash -npm install eBay-node-client --save +npm install ebay-node-client --save ``` ## Test Cases @@ -35,7 +35,7 @@ export EBAY_CLIENT_ID=KEY export EBAY_CLIENT_SECRET=SECRET ``` -## To Enable Sanbox Purpose +## To Enable Sandbox Purpose ```bash export EBAY_CLIENT_SANDBOX='true' ``` diff --git a/examples/javaScript/buy/browse/getItem.js b/examples/javaScript/buy/browse/getItem.js index 0513b7b..be0ad5d 100644 --- a/examples/javaScript/buy/browse/getItem.js +++ b/examples/javaScript/buy/browse/getItem.js @@ -13,7 +13,8 @@ var browseRequest = async function () { }); eBay.setToken(token.access_token); } catch (error) { - + console.log('error ', error); + return; } var itemId = 'v1|110329773707|410089528845'; diff --git a/examples/javaScript/buy/browse/search.js b/examples/javaScript/buy/browse/search.js index a974f26..d8bd412 100644 --- a/examples/javaScript/buy/browse/search.js +++ b/examples/javaScript/buy/browse/search.js @@ -13,7 +13,8 @@ var browseRequest = async function () { }); eBay.setToken(token.access_token); } catch (error) { - + console.log('error ', error); + return; } var data = { diff --git a/examples/javaScript/commerce/taxonomy/getCategorySubtree.js b/examples/javaScript/commerce/taxonomy/getCategorySubtree.js index 709460d..4023b4f 100644 --- a/examples/javaScript/commerce/taxonomy/getCategorySubtree.js +++ b/examples/javaScript/commerce/taxonomy/getCategorySubtree.js @@ -13,7 +13,8 @@ var categoryRequest = async function () { }); eBay.setToken(token.access_token); } catch (error) { - + console.log('error ', error); + return; } var categoryTreeId = 203; diff --git a/examples/javaScript/commerce/taxonomy/getCategorySuggestions.js b/examples/javaScript/commerce/taxonomy/getCategorySuggestions.js index e97bf22..d4131af 100644 --- a/examples/javaScript/commerce/taxonomy/getCategorySuggestions.js +++ b/examples/javaScript/commerce/taxonomy/getCategorySuggestions.js @@ -13,7 +13,8 @@ var categoryRequest = async function () { }); eBay.setToken(token.access_token); } catch (error) { - + console.log('error ', error); + return; } var categoryTreeId = 203; diff --git a/examples/javaScript/commerce/taxonomy/getCategoryTree.js b/examples/javaScript/commerce/taxonomy/getCategoryTree.js index 31c5314..815515a 100644 --- a/examples/javaScript/commerce/taxonomy/getCategoryTree.js +++ b/examples/javaScript/commerce/taxonomy/getCategoryTree.js @@ -14,7 +14,8 @@ var categoryRequest = async function () { }); eBay.setToken(token.access_token); } catch (error) { - + console.log('error ', error); + return; } var categoryTreeId = 203; diff --git a/examples/javaScript/commerce/taxonomy/getDefaultCategoryTreeId.js b/examples/javaScript/commerce/taxonomy/getDefaultCategoryTreeId.js index 036cec8..3b1fbbf 100644 --- a/examples/javaScript/commerce/taxonomy/getDefaultCategoryTreeId.js +++ b/examples/javaScript/commerce/taxonomy/getDefaultCategoryTreeId.js @@ -13,7 +13,8 @@ var categoryRequest = async function () { }); eBay.setToken(token.access_token); } catch (error) { - + console.log('error ', error); + return; } var data = { diff --git a/examples/javaScript/commerce/taxonomy/getItemAspectsForCategory.js b/examples/javaScript/commerce/taxonomy/getItemAspectsForCategory.js index a2e6c03..a5b7827 100644 --- a/examples/javaScript/commerce/taxonomy/getItemAspectsForCategory.js +++ b/examples/javaScript/commerce/taxonomy/getItemAspectsForCategory.js @@ -13,7 +13,8 @@ var categoryRequest = async function () { }); eBay.setToken(token.access_token); } catch (error) { - + console.log('error ', error); + return; } var categoryTreeId = 203; diff --git a/examples/javaScript/sell/inventory/createOrReplaceInventoryItem.js b/examples/javaScript/sell/inventory/createOrReplaceInventoryItem.js index 23a1233..fb12530 100644 --- a/examples/javaScript/sell/inventory/createOrReplaceInventoryItem.js +++ b/examples/javaScript/sell/inventory/createOrReplaceInventoryItem.js @@ -5,7 +5,7 @@ var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; var eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret); -var browseRequest = async function () { +var browseRequest = function () { var userToken = 'USER_TOKEN'; eBay.setUserToken(userToken); diff --git a/examples/typeScript/application/oauthToken.ts b/examples/typeScript/application/oauthToken.ts new file mode 100644 index 0000000..712ecb4 --- /dev/null +++ b/examples/typeScript/application/oauthToken.ts @@ -0,0 +1,22 @@ +'use strict'; + +const clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +const clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +const eBay = require('../../../lib/eBay-node-client')(clientId, clientSecret); + +const applicationRequest = async function () { + + try { + const token = await eBay.application.getOAuthToken({ + grant_type: 'client_credentials', + scope: 'https://api.ebay.com/oauth/api_scope' + }); + console.log('token.access_token ', token.access_token); + eBay.setToken(token.access_token); + } catch (error) { + console.log('error ', error); + } +}; + +applicationRequest(); diff --git a/examples/typeScript/buy/browse/getItem.ts b/examples/typeScript/buy/browse/getItem.ts new file mode 100644 index 0000000..19eca89 --- /dev/null +++ b/examples/typeScript/buy/browse/getItem.ts @@ -0,0 +1,30 @@ +'use strict'; + +const clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +const clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +const eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret); + +const browseRequest = async function () { + try { + const token = await eBay.application.getOAuthToken({ + grant_type: 'client_credentials', + scope: 'https://api.ebay.com/oauth/api_scope' + }); + eBay.setToken(token.access_token); + } catch (error) { + console.log('error ', error); + return; + } + + const itemId = 'v1|110329773707|410089528845'; + eBay.browse.getItem(itemId, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +browseRequest(); diff --git a/examples/typeScript/buy/browse/search.ts b/examples/typeScript/buy/browse/search.ts new file mode 100644 index 0000000..d8bd412 --- /dev/null +++ b/examples/typeScript/buy/browse/search.ts @@ -0,0 +1,33 @@ +'use strict'; + +var clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +var eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret); + +var browseRequest = async function () { + try { + var token = await eBay.application.getOAuthToken({ + grant_type: 'client_credentials', + scope: 'https://api.ebay.com/oauth/api_scope' + }); + eBay.setToken(token.access_token); + } catch (error) { + console.log('error ', error); + return; + } + + var data = { + gtin: '010942122258', + limit: '1' + }; + eBay.browse.search(data, function (error, response) { + if (error) { + console.log('error ', error); + return; + } + console.log('response', response); + }); +}; + +browseRequest(); diff --git a/examples/typeScript/package.json b/examples/typeScript/package.json index e08b3ae..27b950f 100644 --- a/examples/typeScript/package.json +++ b/examples/typeScript/package.json @@ -4,11 +4,11 @@ "description": "eBay", "license": "MIT", "dependencies": { - "@types/node": "^8.0.53", "@types/es6-promise": "0.0.33", + "@types/node": "^8.0.53", "babel-eslint": "^8.0.1", "babel-preset-node6": "^11.0.0", - "eBay-node-client": "*" + "ebay-node-client": "*" }, "devDependencies": {} } diff --git a/index.d.ts b/index.d.ts index 418f5e0..61f5d8a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,93 +1,74 @@ -// Type definitions for amazon-mws +// Type definitions for ebay-node-client -declare class BaseAmazonMWS { - - search(params: any): Promise; +declare class BaseeBayNodeClient { } -declare class Feeds extends BaseAmazonMWS { +declare class Application extends BaseeBayNodeClient { - submit(params: any): Promise; + getOAuthToken(params: any): Promise; } -declare class Finances extends BaseAmazonMWS { - -} +declare class Browse extends BaseeBayNodeClient { -declare class FulfillmentInboundShipment extends BaseAmazonMWS { + getItem(itemId: string): Promise; - create(params: any): Promise; + search(params: any): Promise; } -declare class FulfillmentInventory extends BaseAmazonMWS { +declare class Taxonomy extends BaseeBayNodeClient { -} + getCategorySubtree(categoryTreeId: string, params: any): Promise; -declare class FulfillmentOutboundShipment extends BaseAmazonMWS { + getCategorySuggestions(categoryTreeId: string, params: any): Promise; -} + getItemAspectsForCategory(categoryTreeId: string, params: any): Promise; -declare class MerchantFulfillment extends BaseAmazonMWS { + getCategoryTree(categoryTreeId: string): Promise; - create(params: any): Promise; + getDefaultCategoryTreeId(params: any): Promise; } -declare class Orders extends BaseAmazonMWS { - -} +declare class Inventory extends BaseeBayNodeClient { -declare class Products extends BaseAmazonMWS { + createOrReplaceInventoryItem(sku: string, params: any): Promise; - searchFor(params: any): Promise; + getInventoryItem(sku: string): Promise; + getInventoryItems(params: any): Promise; + } -declare class Reports extends BaseAmazonMWS { +declare class eBayNodeClient { -} + application: Application; -declare class Sellers extends BaseAmazonMWS { + browse: Browse; -} + taxonomy: Taxonomy; -declare class AmazonMWS { + inventory: Inventory; constructor() - constructor(key: string, token: string); + constructor(clientId: string, clientSecret: string); - setApiKey(key: string, secret: string): void; + constructor(clientId: string, clientSecret: string, isSandbox: boolean); - setHost(host?: string, port?: string, protocol?: string): void; - - feeds: Feeds; - - finances: Finances; - - fulfillmentInboundShipment: FulfillmentInboundShipment; - - fulfillmentInventory: FulfillmentInventory; + setApiKey(clientId: string, clientSecret: string): void; - fulfillmentOutboundShipment: FulfillmentOutboundShipment; - - merchantFulfillment: MerchantFulfillment; - - orders: Orders; - - products: Products; - - reports: Reports; + setHost(host?: string, port?: string, protocol?: string): void; - sellers: Sellers; + setToken(applicationToken: string): void; + setUserToken(userToken: string): void; } -declare namespace AmazonMWS { +declare namespace eBayNodeClient { } -export = AmazonMWS; \ No newline at end of file +export = eBayNodeClient; \ No newline at end of file diff --git a/test/intialize/config.js b/test/intialize/config.js new file mode 100644 index 0000000..f07403f --- /dev/null +++ b/test/intialize/config.js @@ -0,0 +1,6 @@ +'use strict'; +module.exports = { + clientId: process.env.EBAY_CLIENT_ID, + clientSecret: process.env.EBAY_CLIENT_SECRET, + USER_TOKEN: process.env.EBAY_USER_TOKEN, +}; \ No newline at end of file diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..1fe408e --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,11 @@ +### +### mocha.opts +### + +--bail +--silly +--full-trace +--recursive +--timeout 20000 +--reporter spec +./test/specs/**/*.spec.js diff --git a/test/specs/application/oauth.spec.js b/test/specs/application/oauth.spec.js new file mode 100644 index 0000000..774ed20 --- /dev/null +++ b/test/specs/application/oauth.spec.js @@ -0,0 +1,40 @@ +'use strict'; +var config = require('../../intialize/config'); +var clientId = config.clientId; +var clientSecret = config.clientSecret; + +var chai = require('chai'); +var expect = chai.expect; + +var eBay = require('../../../lib/eBay-node-client')(clientId, clientSecret); + +describe('Application', function () { + + before(function () { + expect(clientId).to.be.a('string'); + expect(clientSecret).to.be.a('string'); + }); + + it('It should get Application OAuth Token ', async function () { + var options = { + grant_type: 'client_credentials', + scope: 'https://api.ebay.com/oauth/api_scope' + }; + + expect(options.grant_type).to.be.a('string'); + expect(options.scope).to.be.a('string'); + + try { + var response = await eBay.application.getOAuthToken(options); + eBay.setToken(response.access_token); + expect(response).to.be.a('object'); + expect(response).to.have.property('access_token').to.be.a('string'); + expect(response).to.have.property('expires_in').to.be.a('number'); + expect(response).to.have.property('token_type').to.be.a('string'); + } catch (error) { + console.log('error ', error); + expect(response).to.be.a(undefined); + } + + }); +}); \ No newline at end of file