Socket
Socket
Sign inDemoInstall

ebay-promised

Package Overview
Dependencies
59
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.0 to 2.0.0

.babelrc

4

lib/definitions/endpoints.js

@@ -1,2 +0,3 @@

// Generated by CoffeeScript 1.9.0
"use strict";
module.exports = {

@@ -14,1 +15,2 @@ FindingService: {

};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2VzNi9kZWZpbml0aW9ucy9lbmRwb2ludHMuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxPQUFPLE9BQVAsR0FBaUI7QUFDZixrQkFBZ0I7QUFDZCxnQkFBWTtBQURFLEdBREQ7QUFJZixZQUFVO0FBQ1IsZ0JBQVk7QUFESixHQUpLO0FBT2YsV0FBUztBQUNQLGdCQUFZLGlDQURMO0FBRVAsYUFBUztBQUZGO0FBUE0sQ0FBakIiLCJmaWxlIjoiZW5kcG9pbnRzLmpzIiwic291cmNlc0NvbnRlbnQiOlsibW9kdWxlLmV4cG9ydHMgPSB7XG4gIEZpbmRpbmdTZXJ2aWNlOiB7XG4gICAgcHJvZHVjdGlvbjogXCJodHRwczovL3N2Y3MuZWJheS5jb20vc2VydmljZXMvc2VhcmNoL0ZpbmRpbmdTZXJ2aWNlL3YxP1wiXG4gIH0sXG4gIFNob3BwaW5nOiB7XG4gICAgcHJvZHVjdGlvbjogXCJodHRwOi8vb3Blbi5hcGkuZWJheS5jb20vc2hvcHBpbmc/XCJcbiAgfSxcbiAgVHJhZGluZzoge1xuICAgIHByb2R1Y3Rpb246IFwiaHR0cHM6Ly9hcGkuZWJheS5jb20vd3MvYXBpLmRsbFwiLFxuICAgIHNhbmRib3g6ICdodHRwczovL2FwaS5zYW5kYm94LmViYXkuY29tL3dzL2FwaS5kbGwnXG4gIH1cbn07XG4iXX0=

@@ -1,2 +0,4 @@

// Generated by CoffeeScript 1.9.0
'use strict';
module.exports = ['@', 'Timestamp', 'Ack', 'Version', 'Build'];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2VzNi9kZWZpbml0aW9ucy9leHRyYW5lb3VzLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsT0FBTyxPQUFQLEdBQWlCLENBQUMsR0FBRCxFQUFNLFdBQU4sRUFBbUIsS0FBbkIsRUFBMEIsU0FBMUIsRUFBcUMsT0FBckMsQ0FBakIiLCJmaWxlIjoiZXh0cmFuZW91cy5qcyIsInNvdXJjZXNDb250ZW50IjpbIm1vZHVsZS5leHBvcnRzID0gWydAJywgJ1RpbWVzdGFtcCcsICdBY2snLCAnVmVyc2lvbicsICdCdWlsZCddO1xuIl19

@@ -1,2 +0,4 @@

// Generated by CoffeeScript 1.9.0
module.exports = ["authToken", "cert", "devName", 'serviceName', 'appId', "sandbox", "site", "app", "raw", "perPage", "callsPerEpoc", "epoc"];
"use strict";
module.exports = ["authToken", "cert", "devName", "serviceName", "appId", "sandbox", "site", "app", "raw", "perPage"];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL2VzNi9kZWZpbml0aW9ucy9nbG9iYWxzLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsT0FBTyxPQUFQLEdBQWlCLENBQ2IsV0FEYSxFQUViLE1BRmEsRUFHYixTQUhhLEVBSWIsYUFKYSxFQUtiLE9BTGEsRUFNYixTQU5hLEVBT2IsTUFQYSxFQVFiLEtBUmEsRUFTYixLQVRhLEVBVWIsU0FWYSxDQUFqQiIsImZpbGUiOiJnbG9iYWxzLmpzIiwic291cmNlc0NvbnRlbnQiOlsibW9kdWxlLmV4cG9ydHMgPSBbXG4gICAgXCJhdXRoVG9rZW5cIlxuICAsIFwiY2VydFwiXG4gICwgXCJkZXZOYW1lXCJcbiAgLCBcInNlcnZpY2VOYW1lXCJcbiAgLCBcImFwcElkXCJcbiAgLCBcInNhbmRib3hcIlxuICAsIFwic2l0ZVwiXG4gICwgXCJhcHBcIlxuICAsIFwicmF3XCJcbiAgLCBcInBlclBhZ2VcIlxuIF1cbiJdfQ==

@@ -1,246 +0,17 @@

// Generated by CoffeeScript 1.9.0
var Ebay, Lazy, Q, async, debug, defaults, ecjson, endpoints, extraneous, globals, limit, o2x, request, utils, _,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__hasProp = {}.hasOwnProperty;
'use strict';
async = require('async');
var _Ebay = require('./Ebay');
Q = require('q');
var _Ebay2 = _interopRequireDefault(_Ebay);
o2x = require('object-to-xml');
var _errors = require('./errors');
request = require('request-promise');
var errors = _interopRequireWildcard(_errors);
ecjson = require("ecjson");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
_ = require('underscore');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
Lazy = require('lazy.js');
limit = require('simple-rate-limiter');
endpoints = require('./definitions/endpoints');
globals = require('./definitions/globals');
extraneous = require('./definitions/extraneous');
utils = require("./utils");
debug = require('debug')('Ebay');
defaults = JSON.stringify({
__fields__: {},
__globals__: {
serviceName: "Trading",
sandbox: false,
site: 0,
app: 'ebay-promised',
raw: false,
perPage: 100,
callsPerEpoc: 3,
epoc: 1000
}
});
module.exports = Ebay = (function(_super) {
__extends(Ebay, _super);
Ebay.post = limit(request.post.bind(request));
Ebay.get = limit(request.get.bind(request));
Ebay.include(JSON.parse(defaults));
Ebay.methodize(require('./definitions/calls'), function(method) {
return function() {
this.__op__ = method;
return this;
};
});
Ebay.methodize(require('./definitions/fields'), function(field) {
return function(val) {
if (!val) {
return this.__fields__[field];
}
this.__fields__[field] = val;
return this;
};
});
Ebay.methodize(globals, function(setter) {
return function(val) {
if (!val) {
return this.__globals__[setter];
}
this.__globals__[setter] = val;
return this;
};
});
function Ebay(options) {
if (options == null) {
options = {};
}
this.safelyApplyOptions(options);
Ebay.post.to(this.callsPerEpoc()).per(this.epoc());
Ebay.get.to(this.callsPerEpoc()).per(this.epoc());
this;
}
Ebay.prototype.op = function() {
return this.__op__;
};
Ebay.prototype.fields = function() {
return this.__fields__;
};
Ebay.prototype.reset = function() {
this.__fields__ = JSON.parse(defaults).__fields__;
return this;
};
Ebay.prototype.safelyApplyOptions = function(options) {
var setting, _i, _len, _ref, _results;
if (options == null) {
options = {};
}
_ref = Object.keys(options);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
setting = _ref[_i];
if (this.respondsTo(setting)) {
_results.push(this[setting](options[setting]));
}
}
return _results;
};
Ebay.prototype.callImmediately = function(method, options) {};
Ebay.prototype.endpoint = function() {
if (!endpoints[this.serviceName()]) {
throw new Error("unknown endpoint for serviceName " + (this.serviceName()));
}
return endpoints[this.serviceName()][this.sandbox() ? 'sandbox' : 'production'];
};
Ebay.prototype.pagination = function(pageNumber) {
if (pageNumber == null) {
pageNumber = 1;
}
return {
Pagination: {
PageNumber: pageNumber,
EntriesPerPage: this.perPage()
}
};
};
Ebay.prototype.respondsTo = function(method) {
return _(this[method]).isFunction();
};
Ebay.prototype.__inject__ = function(pageNumber) {
var fields, listKey;
fields = this.fields();
listKey = utils.getListKeyName(fields);
if (listKey) {
debug("listKey detected:: " + listKey);
}
if (listKey) {
fields[listKey] = _.extend(fields[listKey], this.pagination(pageNumber));
}
return fields;
};
Ebay.prototype.__build__ = function(pageNumber) {
var body, doc;
if (pageNumber == null) {
pageNumber = 1;
}
body = [];
doc = {};
body.push({
RequesterCredentials: {
eBayAuthToken: this.authToken()
}
});
body.push(this.__inject__(pageNumber));
doc['xml version="1.0" encoding="utf-8"?'] = null;
doc[(this.op()) + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\""] = _.extend.apply(_, body);
return o2x(doc);
};
Ebay.prototype.__headers__ = function() {
return {
'X-EBAY-API-CALL-NAME': this.op(),
'X-EBAY-API-COMPATIBILITY-LEVEL': '775',
'X-EBAY-API-SITEID': this.site(),
'X-EBAY-API-CERT-NAME': this.cert(),
'X-EBAY-API-APP-NAME': this.app()
};
};
Ebay.prototype.__request__ = function(page, cb) {
var options;
if (page == null) {
page = 1;
}
debug("starting request...");
options = {
url: this.endpoint(),
body: this.__build__(page),
headers: this.__headers__()
};
return Ebay.post(options).once('limiter-exec', (function(_this) {
return function(promise) {
return promise["catch"](cb).then(function(res) {
debug("response recieved from eBay");
return ecjson.XmlToJson(res, function(json) {
return cb(null, utils.normalizeResponse.bind(_this)(json));
});
});
};
})(this));
};
Ebay.prototype.invoke = function(page) {
var d;
if (page == null) {
page = 1;
}
d = Q.defer();
this.__request__(page, (function(_this) {
return function(err, pageOne) {
var pages, _i, _ref, _results;
if (err) {
d.reject(err);
}
if (!(pageOne.pagination && pageOne.pagination.pages > 1)) {
return d.resolve(pageOne);
}
pages = (function() {
_results = [];
for (var _i = 2, _ref = pageOne.pagination.pages; 2 <= _ref ? _i <= _ref : _i >= _ref; 2 <= _ref ? _i++ : _i--){ _results.push(_i); }
return _results;
}).apply(this);
debug("Beginning pagination for pages: " + (pages.join(', ')));
return async.mapLimit(pages, 2, _this.__request__.bind(_this), function(err, responses) {
if (err) {
return d.reject(err);
}
pageOne.results = Lazy(pageOne.results).concat(Lazy(responses).pluck('results')).value();
debug(pageOne.pagination.n + " === " + pageOne.results.length + " ?");
return d.resolve(pageOne);
});
};
})(this));
return d.promise;
};
return Ebay;
})(utils.Module);
module.exports = _Ebay2.default;
module.exports.errors = errors;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL2VzNi9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBOzs7O0FBQ0E7O0lBQVksTTs7Ozs7O0FBQ1osT0FBTyxPQUFQO0FBQ0EsT0FBTyxPQUFQLENBQWUsTUFBZixHQUF3QixNQUF4QiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBFYmF5ICAgICAgICBmcm9tICcuL0ViYXknXG5pbXBvcnQgKiBhcyBlcnJvcnMgZnJvbSAnLi9lcnJvcnMnXG5tb2R1bGUuZXhwb3J0cyAgICAgICAgPSBFYmF5XG5tb2R1bGUuZXhwb3J0cy5lcnJvcnMgPSBlcnJvcnMiXX0=
{
"name": "ebay-promised",
"version": "1.5.0",
"version": "2.0.0",
"description": "promise wrapped Ebay requests with sensible response parsers",
"main": "lib/index.js",
"main": "./lib/index.js",
"dependencies": {
"async": "~0.2.10",
"bluebird": "^3.4.0",
"debug": "^2.1.1",
"ecjson": "^0.1.2",
"lazy.js": "^0.3.2",
"object-to-xml": "0.0.2",
"q": "~1.0.1",
"request-promise": "0.4.0",
"simple-rate-limiter": "^0.2.3",
"underscore": "~1.6.0"
"es6-error": "^3.0.0",
"object-to-xml": "1.0.0",
"request-promise": "^3.0.0",
"simple-rate-limiter": "^0.2.3"
},
"devDependencies": {},
"devDependencies": {
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"chai": "^3.5.0",
"mocha": "^2.5.2"
},
"scripts": {
"test": "test.coffee"
"test": "mocha --compilers js:babel-register --check-leaks -t 20000 ./test/*.spec.js",
"watch": "npm run clean && babel --watch --source-maps inline --out-dir=$npm_package_config_out $npm_package_config_in",
"test:watch": "mocha --compilers js:babel-register --check-leaks -t 20000 --watch --growl ./test/*.spec.js",
"compile": "babel --source-maps inline --out-dir=$npm_package_config_out $npm_package_config_in",
"clean": "rm -rf $npm_package_config_out",
"preversion": "npm run clean && npm run compile"
},

@@ -30,3 +38,7 @@ "repository": {

"author": "Benjamin Clos",
"license": "ISC"
"license": "ISC",
"config": {
"out": "lib",
"in": "es6"
}
}

@@ -1,47 +0,56 @@

# A promise based wrapper for the eBay API
# A Promise-based module for working with the eBay API
This module provides a succint, verbose way to build requests with the eBay API.
[![Build Status](https://travis-ci.org/ondreian/ebay-promised.svg?branch=master)](https://travis-ci.org/ondreian/ebay-promised)
[![Documentation](https://doc.esdoc.org/github.com/ondreian/ebay-promised/badge.svg)](https://doc.esdoc.org/github.com/ondreian/ebay-promised/)
`npm install ebay-promised --save`
This module provides a succint, verbose way to build requests with the eBay API.
Currently it works in production applications with the eBay XML POST Trading API, and I have not properly fleshed out the other eBay services.
Most of the other services are GET based and query string driven.
## How to use this module
## Features
```coffeescript
# Basic Setup
- [X] Bluebird Promises
- [X] Transparent pagination
- [X] Transparent eBay compliant rate-limiting
- [X] Reasonable response parsers
- [X] Functionally tested vs the Sandbox API
- [X] ergonomic chaining API with immutability
- [X] transparently can load instance from ENV vars
- [X] proper Error subclassing to enable verbose use of `Promise.catch`
config =
ruName : 'example123'
cert : 'exampleCert123'
devName : 'exampleDevName'
authToken : 'accesstoken123'
sandbox : true
epoc : 1000 # MS
callsPerEpoc : 1 # number of requests per epoc
## How to use this module
Readinging through the [Functional Tests](/test/Ebay.Functional.spec.js) is a great way to familiarize yourself with some common API calls.
Ebay = require 'ebay-promised'
ebay = new Ebay(config) # you can pass in configuration in initializiation
```javascript
# Basic Setup
import Ebay from 'ebay-promised'
import config from './config'
# or call it down the line
ebay = (new Ebay)
.ruName(config.ruName)
.cert(config.cert)
.devName(config.devName)
.sandbox(config.sandbox) # will now use the eBay sandbox site
.authToken(config.authToken) # the user token to authenticate with against the API
.serviceName('Trading') # the service to use
```
const ebay = Ebay.create(config)
const {err} = Ebay.errors
Now let's set up a call
ebay
.GetMyeBaySelling() // Transforms it to a sealed Request, global config can no longer change
.ActiveList({ Include: true }) // Pass in a field,value
.DetailLevel("ReturnAll") // Pass in another field, value
.run() // Run the request against the eBay API
.then(handleSuccess)
.catch(err.Ebay_Api_Error, err => {
// this error is a special case
// it means your HTTP request was successful but eBay did not like it
})
.catch( err = {
// catch all other errors ala:
// Network Errors
})
```coffeescript
// Ebay can also load your credentials from `process.env`
ebay
.getCategories() # a call from the Ebay trading API (http://developer.ebay.com/devzone/xml/docs/reference/ebay/getcategories.html)
.detailLevel('ReturnAll') # an option for the getCategories call
.levelLimit(1) # another option
.invoke() # says you are done building the request, and makes it to ebay returns a Q promise
.fail(handleError) # what to do if your request fails
.then(handleCategories) # what to do when your request succeeds
const envEbay = Ebay.fromEnv()

@@ -52,32 +61,12 @@ ```

All calls that are currently defined live in ebay-promised/definitions/src/calls
if you find a call that is missing, feel free to open an issue so it can be addressed, or make a pull request
All calls, fields, and globals that are currently defined live in `./es6/definitions`
### Rate Limiting
If you find a call that is missing, feel free to open an issue so it can be addressed, or make a pull request.
ebay-promised handles rate-limiting internally, with a default limit of 3 calls per second.
To override these settings you can pass in the config.epoc and a config.callsPerEpoc options
### Pagination
Internally ebay-promised will attempt to detect when a request is paginated and go ahead and grab the subsequent pages for you and concatenate the results
Internally ebay-promised will attempt to detect when a request is paginated and go ahead and grab the subsequent pages for you and concatenate the results.
### Utility methods
Ebay#respondsTo
- this method is to test if a method exists for eBay
Ebay#reset
- this method resets the fields for the api
Ebay#__build__
- this is an internal method usually, but it will return the current state of the XML document to be POSTed to eBay
Pull requests are welcome.
#### TODOs
- Add full support for other Ebay API services
- Add tests
Pull requests are welcome.

Sorry, the diff of this file is not supported yet

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc