ebay-api 1.13.4 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/LICENSE +18 -19
  2. package/README.md +512 -118
  3. package/lib/api/apiFactory.d.ts +27 -0
  4. package/lib/api/apiFactory.js +100 -0
  5. package/lib/api/apiFactory.js.map +1 -0
  6. package/lib/api/base.d.ts +13 -0
  7. package/lib/api/base.js +25 -0
  8. package/lib/api/base.js.map +1 -0
  9. package/lib/api/index.d.ts +11 -0
  10. package/lib/api/index.js +18 -0
  11. package/lib/api/index.js.map +1 -0
  12. package/lib/api/restful/buy/browse/index.d.ts +84 -0
  13. package/lib/api/restful/buy/browse/index.js +142 -0
  14. package/lib/api/restful/buy/browse/index.js.map +1 -0
  15. package/lib/api/restful/buy/deal/index.d.ts +55 -0
  16. package/lib/api/restful/buy/deal/index.js +80 -0
  17. package/lib/api/restful/buy/deal/index.js.map +1 -0
  18. package/lib/api/restful/buy/feed/index.d.ts +43 -0
  19. package/lib/api/restful/buy/feed/index.js +85 -0
  20. package/lib/api/restful/buy/feed/index.js.map +1 -0
  21. package/lib/api/restful/buy/index.d.ts +17 -0
  22. package/lib/api/restful/buy/index.js +21 -0
  23. package/lib/api/restful/buy/index.js.map +1 -0
  24. package/lib/api/restful/buy/marketing/index.d.ts +27 -0
  25. package/lib/api/restful/buy/marketing/index.js +51 -0
  26. package/lib/api/restful/buy/marketing/index.js.map +1 -0
  27. package/lib/api/restful/buy/marketplaceInsights/index.d.ts +28 -0
  28. package/lib/api/restful/buy/marketplaceInsights/index.js +51 -0
  29. package/lib/api/restful/buy/marketplaceInsights/index.js.map +1 -0
  30. package/lib/api/restful/buy/offer/index.d.ts +23 -0
  31. package/lib/api/restful/buy/offer/index.js +37 -0
  32. package/lib/api/restful/buy/offer/index.js.map +1 -0
  33. package/lib/api/restful/buy/order/index.d.ts +264 -0
  34. package/lib/api/restful/buy/order/index.js +369 -0
  35. package/lib/api/restful/buy/order/index.js.map +1 -0
  36. package/lib/api/restful/commerce/catalog/index.d.ts +73 -0
  37. package/lib/api/restful/commerce/catalog/index.js +108 -0
  38. package/lib/api/restful/commerce/catalog/index.js.map +1 -0
  39. package/lib/api/restful/commerce/charity/index.d.ts +34 -0
  40. package/lib/api/restful/commerce/charity/index.js +56 -0
  41. package/lib/api/restful/commerce/charity/index.js.map +1 -0
  42. package/lib/api/restful/commerce/identity/index.d.ts +14 -0
  43. package/lib/api/restful/commerce/identity/index.js +27 -0
  44. package/lib/api/restful/commerce/identity/index.js.map +1 -0
  45. package/lib/api/restful/commerce/index.d.ts +15 -0
  46. package/lib/api/restful/commerce/index.js +19 -0
  47. package/lib/api/restful/commerce/index.js.map +1 -0
  48. package/lib/api/restful/commerce/notification/index.d.ts +117 -0
  49. package/lib/api/restful/commerce/notification/index.js +187 -0
  50. package/lib/api/restful/commerce/notification/index.js.map +1 -0
  51. package/lib/api/restful/commerce/taxonomy/index.d.ts +78 -0
  52. package/lib/api/restful/commerce/taxonomy/index.js +135 -0
  53. package/lib/api/restful/commerce/taxonomy/index.js.map +1 -0
  54. package/lib/api/restful/commerce/translation/index.d.ts +15 -0
  55. package/lib/api/restful/commerce/translation/index.js +25 -0
  56. package/lib/api/restful/commerce/translation/index.js.map +1 -0
  57. package/lib/api/restful/developer/analytics/index.d.ts +22 -0
  58. package/lib/api/restful/developer/analytics/index.js +45 -0
  59. package/lib/api/restful/developer/analytics/index.js.map +1 -0
  60. package/lib/api/restful/developer/index.d.ts +5 -0
  61. package/lib/api/restful/developer/index.js +9 -0
  62. package/lib/api/restful/developer/index.js.map +1 -0
  63. package/lib/api/restful/index.d.ts +63 -0
  64. package/lib/api/restful/index.js +165 -0
  65. package/lib/api/restful/index.js.map +1 -0
  66. package/lib/api/restful/postOrder/cancellation/index.d.ts +57 -0
  67. package/lib/api/restful/postOrder/cancellation/index.js +95 -0
  68. package/lib/api/restful/postOrder/cancellation/index.js.map +1 -0
  69. package/lib/api/restful/postOrder/case/index.d.ts +63 -0
  70. package/lib/api/restful/postOrder/case/index.js +97 -0
  71. package/lib/api/restful/postOrder/case/index.js.map +1 -0
  72. package/lib/api/restful/postOrder/index.d.ts +11 -0
  73. package/lib/api/restful/postOrder/index.js +15 -0
  74. package/lib/api/restful/postOrder/index.js.map +1 -0
  75. package/lib/api/restful/postOrder/inquiry/index.d.ts +82 -0
  76. package/lib/api/restful/postOrder/inquiry/index.js +131 -0
  77. package/lib/api/restful/postOrder/inquiry/index.js.map +1 -0
  78. package/lib/api/restful/postOrder/return/index.d.ts +231 -0
  79. package/lib/api/restful/postOrder/return/index.js +361 -0
  80. package/lib/api/restful/postOrder/return/index.js.map +1 -0
  81. package/lib/api/restful/sell/account/index.d.ts +217 -0
  82. package/lib/api/restful/sell/account/index.js +337 -0
  83. package/lib/api/restful/sell/account/index.js.map +1 -0
  84. package/lib/api/restful/sell/analytics/index.d.ts +41 -0
  85. package/lib/api/restful/sell/analytics/index.js +61 -0
  86. package/lib/api/restful/sell/analytics/index.js.map +1 -0
  87. package/lib/api/restful/sell/compliance/index.d.ts +37 -0
  88. package/lib/api/restful/sell/compliance/index.js +57 -0
  89. package/lib/api/restful/sell/compliance/index.js.map +1 -0
  90. package/lib/api/restful/sell/feed/index.d.ts +151 -0
  91. package/lib/api/restful/sell/feed/index.js +255 -0
  92. package/lib/api/restful/sell/feed/index.js.map +1 -0
  93. package/lib/api/restful/sell/finances/index.d.ts +74 -0
  94. package/lib/api/restful/sell/finances/index.js +105 -0
  95. package/lib/api/restful/sell/finances/index.js.map +1 -0
  96. package/lib/api/restful/sell/fulfillment/index.d.ts +137 -0
  97. package/lib/api/restful/sell/fulfillment/index.js +199 -0
  98. package/lib/api/restful/sell/fulfillment/index.js.map +1 -0
  99. package/lib/api/restful/sell/index.d.ts +29 -0
  100. package/lib/api/restful/sell/index.js +33 -0
  101. package/lib/api/restful/sell/index.js.map +1 -0
  102. package/lib/api/restful/sell/inventory/index.d.ts +248 -0
  103. package/lib/api/restful/sell/inventory/index.js +346 -0
  104. package/lib/api/restful/sell/inventory/index.js.map +1 -0
  105. package/lib/api/restful/sell/listing/index.d.ts +14 -0
  106. package/lib/api/restful/sell/listing/index.js +25 -0
  107. package/lib/api/restful/sell/listing/index.js.map +1 -0
  108. package/lib/api/restful/sell/logistics/index.d.ts +44 -0
  109. package/lib/api/restful/sell/logistics/index.js +66 -0
  110. package/lib/api/restful/sell/logistics/index.js.map +1 -0
  111. package/lib/api/restful/sell/marketing/index.d.ts +443 -0
  112. package/lib/api/restful/sell/marketing/index.js +609 -0
  113. package/lib/api/restful/sell/marketing/index.js.map +1 -0
  114. package/lib/api/restful/sell/metadata/index.d.ts +77 -0
  115. package/lib/api/restful/sell/metadata/index.js +131 -0
  116. package/lib/api/restful/sell/metadata/index.js.map +1 -0
  117. package/lib/api/restful/sell/negotiation/index.d.ts +24 -0
  118. package/lib/api/restful/sell/negotiation/index.js +39 -0
  119. package/lib/api/restful/sell/negotiation/index.js.map +1 -0
  120. package/lib/api/restful/sell/recommendation/index.d.ts +26 -0
  121. package/lib/api/restful/sell/recommendation/index.js +39 -0
  122. package/lib/api/restful/sell/recommendation/index.js.map +1 -0
  123. package/lib/api/traditional/XMLRequest.d.ts +98 -0
  124. package/lib/api/traditional/XMLRequest.js +191 -0
  125. package/lib/api/traditional/XMLRequest.js.map +1 -0
  126. package/lib/api/traditional/clientAlerts/index.d.ts +9 -0
  127. package/lib/api/traditional/clientAlerts/index.js +15 -0
  128. package/lib/api/traditional/clientAlerts/index.js.map +1 -0
  129. package/lib/api/traditional/clientAlerts/types.d.ts +31 -0
  130. package/lib/api/traditional/clientAlerts/types.js +36 -0
  131. package/lib/api/traditional/clientAlerts/types.js.map +1 -0
  132. package/lib/api/traditional/fields.d.ts +1948 -0
  133. package/lib/api/traditional/fields.js +1949 -0
  134. package/lib/api/traditional/fields.js.map +1 -0
  135. package/lib/api/traditional/finding/index.d.ts +12 -0
  136. package/lib/api/traditional/finding/index.js +16 -0
  137. package/lib/api/traditional/finding/index.js.map +1 -0
  138. package/lib/api/traditional/index.d.ts +17 -0
  139. package/lib/api/traditional/index.js +207 -0
  140. package/lib/api/traditional/index.js.map +1 -0
  141. package/lib/api/traditional/merchandising/index.d.ts +7 -0
  142. package/lib/api/traditional/merchandising/index.js +11 -0
  143. package/lib/api/traditional/merchandising/index.js.map +1 -0
  144. package/lib/api/traditional/shopping/index.d.ts +11 -0
  145. package/lib/api/traditional/shopping/index.js +16 -0
  146. package/lib/api/traditional/shopping/index.js.map +1 -0
  147. package/lib/api/traditional/trading/index.d.ts +142 -0
  148. package/lib/api/traditional/trading/index.js +146 -0
  149. package/lib/api/traditional/trading/index.js.map +1 -0
  150. package/lib/auth/authNAuth.d.ts +49 -0
  151. package/lib/auth/authNAuth.js +122 -0
  152. package/lib/auth/authNAuth.js.map +1 -0
  153. package/lib/auth/index.d.ts +17 -0
  154. package/lib/auth/index.js +32 -0
  155. package/lib/auth/index.js.map +1 -0
  156. package/lib/auth/oAuth2.d.ts +90 -0
  157. package/lib/auth/oAuth2.js +258 -0
  158. package/lib/auth/oAuth2.js.map +1 -0
  159. package/lib/ebay-api.min.js +2 -0
  160. package/lib/ebay-api.min.js.map +1 -0
  161. package/lib/enums/apiEnums.d.ts +49 -0
  162. package/lib/enums/apiEnums.js +55 -0
  163. package/lib/enums/apiEnums.js.map +1 -0
  164. package/lib/enums/index.d.ts +2 -0
  165. package/lib/enums/index.js +15 -0
  166. package/lib/enums/index.js.map +1 -0
  167. package/lib/enums/restfulEnums.d.ts +672 -0
  168. package/lib/enums/restfulEnums.js +714 -0
  169. package/lib/enums/restfulEnums.js.map +1 -0
  170. package/lib/errors/index.d.ts +66 -0
  171. package/lib/errors/index.js +208 -0
  172. package/lib/errors/index.js.map +1 -0
  173. package/lib/index.d.ts +55 -0
  174. package/lib/index.js +98 -0
  175. package/lib/index.js.map +1 -0
  176. package/lib/request.d.ts +26 -0
  177. package/lib/request.js +51 -0
  178. package/lib/request.js.map +1 -0
  179. package/lib/types/apiTypes.d.ts +28 -0
  180. package/lib/types/apiTypes.js +3 -0
  181. package/lib/types/apiTypes.js.map +1 -0
  182. package/lib/types/index.d.ts +3 -0
  183. package/lib/types/index.js +16 -0
  184. package/lib/types/index.js.map +1 -0
  185. package/lib/types/restfulTypes.d.ts +1067 -0
  186. package/lib/types/restfulTypes.js +3 -0
  187. package/lib/types/restfulTypes.js.map +1 -0
  188. package/lib/types/traditonalTypes.d.ts +34 -0
  189. package/lib/types/traditonalTypes.js +3 -0
  190. package/lib/types/traditonalTypes.js.map +1 -0
  191. package/package.json +115 -21
  192. package/.npmignore +0 -17
  193. package/.travis.yml +0 -7
  194. package/examples/Finding-FindItemsByKeywords.js +0 -46
  195. package/examples/Merchandising-GetMostWatchedItemsRequest.js +0 -16
  196. package/examples/Shopping-GetSingleItem.js +0 -18
  197. package/examples/Trading-GetOrders.js +0 -26
  198. package/index.js +0 -10
  199. package/lib/deep-to-array.js +0 -42
  200. package/lib/defaults.js +0 -69
  201. package/lib/errors.js +0 -44
  202. package/lib/json-parser.js +0 -336
  203. package/lib/key-lists.js +0 -64
  204. package/lib/urls.js +0 -64
  205. package/lib/versions.js +0 -35
  206. package/lib/xml-converter.js +0 -21
  207. package/lib/xml-request.js +0 -207
  208. package/scripts/parse-input-xml.js +0 -41
  209. package/test/deep-to-array.test.js +0 -100
  210. package/test/errors.test.js +0 -75
  211. package/test/helpers.js +0 -22
  212. package/test/mocha.opts +0 -1
  213. package/test/mocks/GetMultipleItems.xml +0 -115
  214. package/test/mocks/GetOrders-empty.xml +0 -17
  215. package/test/mocks/GetOrders.xml +0 -463
  216. package/test/pagination.test.js +0 -5
  217. package/test/parsing.test.js +0 -248
  218. package/test/xml-request.test.js +0 -447
@@ -1,336 +0,0 @@
1
- /**
2
- * default response parser, for JSON.
3
- * (and supporting helpers)
4
- * for XML responses, should be run through `./xml-converter` first.
5
- */
6
-
7
- var
8
- _ = require('lodash'),
9
- util = require('util'),
10
- debug = require('debug')('ebay:parser'),
11
-
12
- _errors = require('./errors'),
13
- EbaySystemError = _errors.EbaySystemError,
14
- EbayRequestError = _errors.EbayRequestError,
15
- EbayClientError = _errors.EbayClientError,
16
-
17
- knownArrayKeysByApiEndpoint = require('./key-lists').knownArrayKeysByApiEndpoint;
18
-
19
-
20
- /*
21
- helper: find an array containing only special key-value pairs
22
- e.g. 'galleryURL' (makes it easier to handle in DB)
23
- */
24
- function _isArrayOfValuePairs(el) {
25
- if (_.isArray(el)) {
26
- if (_.all(el, _isValuePair)) return true;
27
- }
28
- return false;
29
- }
30
-
31
- /*
32
- helper: identify a structure returned from the API:
33
- { @key:KEY, __value__:VALUE } => want to turn into { KEY: VALUE }
34
- (and array of these into single obj)
35
- */
36
- function _isValuePair(el) {
37
- if (_.isObject(el) && _.size(el) === 2) {
38
- var keys = _.keys(el);
39
- if (new RegExp(/^@/).test(keys[0]) && keys[1] === '__value__') {
40
- return true;
41
- }
42
- }
43
- return false;
44
- }
45
-
46
-
47
- /*
48
- helper to filter the keys that get flattened.
49
- */
50
- function _canFlattenKey(key, requestContext) {
51
- //debug('_canFlattenKey?', key, requestContext);
52
-
53
- // assume that '*Array' and '*List' elements are arrays.
54
- if (/Array$/.test(key) || /List$/.test(key)) return false;
55
-
56
- // per-endpoint blacklist of known array keys.
57
- if (requestContext != null && requestContext.serviceName && requestContext.opType &&
58
- knownArrayKeysByApiEndpoint[requestContext.serviceName] != null &&
59
- knownArrayKeysByApiEndpoint[requestContext.serviceName][requestContext.opType] != null &&
60
- _.contains(knownArrayKeysByApiEndpoint[requestContext.serviceName][requestContext.opType], key)) {
61
- return false;
62
- }
63
-
64
- // otherwise assume it can be flattened if there's a single value.
65
- return true;
66
- }
67
-
68
-
69
- /*
70
- convert `OrderArray: [ Order: [...] ]` structure to `Orders: []`.
71
- @param parentObj: the obj *containing* the key to be restructured.
72
- @param key: the key within the object to fix.
73
- modifies byref.
74
- @return new key.
75
- */
76
- function _flattenSillyArray(parentObj, key, requestContext) {
77
- //debug('_flattenSillyArray', key, parentObj[key]);
78
-
79
- var subKey = key.replace(/Array$/, ''); // e.g. 'Order' from 'OrderArray'
80
- var newKey = subKey + 's'; // e.g. 'Orders'
81
-
82
- // `compact` avoids creating an array of `[undefined]`,
83
- // from input `['']` when xml "array" element was empty.
84
- parentObj[newKey] = _.compact(parentObj[key][0][subKey]);
85
- delete parentObj[key];
86
-
87
- // might have already been flattened...
88
- if (!_.isArray(parentObj[newKey])) parentObj[newKey] = [ parentObj[newKey] ];
89
-
90
- parentObj[newKey] = parentObj[newKey].map(function(subObj) {
91
- return exports.flatten(subObj, -1, requestContext);
92
- });
93
-
94
- return newKey;
95
- }
96
-
97
-
98
- function _convertAmountStructure(el, requestContext) {
99
- if (_.isArray(el)) {
100
- return el.map(function(subEl) {
101
- return _convertAmountStructure(subEl);
102
- });
103
- }
104
-
105
- if (el.hasOwnProperty('_') && el.hasOwnProperty('$')) {
106
- el.amount = +el._;
107
- delete el._;
108
- _.extend(el, el['$']); // {currencyID}
109
- delete el['$'];
110
- }
111
- return el;
112
- }
113
-
114
-
115
- function _castTypes(el) {
116
- if (_.isString(el)) {
117
- if (!isNaN(el)) el = +el; // numeric string to number
118
- else if (el === 'true') el = true;
119
- else if (el === 'false') el = false;
120
- }
121
- return el;
122
- }
123
-
124
-
125
- /*
126
- recursively turn 1-element arrays/objects into flat values/objects.
127
- intended to handle flaw of XML->JSON conversion, that everything becomes an array.
128
- NOTE this is risky/complicated, because it has to make assumptions
129
- about what *should* remain an array,
130
- so some items might be structured differently depending on number of values.
131
- helpers like `canFlattenKey()` try to mitigate this risk.
132
-
133
- also transforms numbers and booleans from strings to types.
134
-
135
- `maxDepth` of -1 equals infinity.
136
- */
137
- exports.flatten = function flatten(el, maxDepth, requestContext, _depth) {
138
- if (_depth == null) _depth = 1;
139
- if (maxDepth == null) maxDepth = 10; // default
140
-
141
- if (_depth === 1) debug('flattening', el, {maxDepth: maxDepth, requestContext: requestContext});
142
-
143
- if (maxDepth >= 0 && _depth > maxDepth) {
144
- return el;
145
- }
146
-
147
- // flatten 1-item arrays.
148
- // note: this is dangerous, means responses w/ single value can look different from multiple values.
149
- // trying to mitigate with `canFlattenKey()` check below.
150
- if (_.isArray(el) && el.length === 1) {
151
- el = _.first(el);
152
- }
153
-
154
- // weird value-pair structure:
155
- // turn `{ @key:KEY, __value__:VALUE }` into `{ KEY: VALUE }`
156
- if (_isValuePair(el)) {
157
- var values = _.values(el);
158
- debug('converting key-value pair', el);
159
- el = {};
160
- el[ values[0] ] = values[1];
161
- }
162
-
163
- //// previous fix just creates an array of these. we want a clean key:val obj.
164
- //// so, is this an array of special value-pairs?
165
- //// TODO - disabled this b/c old and inefficient - understand where it was needed, and try to optimize.
166
- //if (_isArrayOfValuePairs(el)) {
167
- // var fixEl = {};
168
- // _(el).each(function(pair) {
169
- // _.extend(fixEl, flatten(pair, maxDepth, requestContext, _depth + 1)); // fix each, combine
170
- // });
171
- // el = fixEl;
172
- //}
173
-
174
- // flatten sub-elements
175
- if (_.isObject(el) && !_.isArray(el)) {
176
- _.forOwn(el, function(childEl, childKey) {
177
- // special cases
178
- if (/Array$/.test(childKey)) {
179
- childKey = _flattenSillyArray(el, childKey, requestContext); // on parent, byref; childKey changes!
180
- childEl = el[childKey]; // ref to new element
181
- }
182
- else if (/(Amount|Cost|Price|Subtotal)/.test(childKey)) {
183
- el[childKey] = _convertAmountStructure(childEl, requestContext);
184
- }
185
-
186
- if (_canFlattenKey(childKey, requestContext)) {
187
- el[childKey] = flatten(childEl, maxDepth, requestContext, _depth + 1);
188
- }
189
- // can't flatten [presumed] array itself, but can still flatten its children.
190
- // @REVIEW: this causes weird skipping behavior, where grandchildren are flattened before higher levels,
191
- // so can't assume that lower levels haven't been flattened yet!
192
- else if (_.isArray(childEl)) {
193
- el[childKey] = childEl.map(function(grandChildEl) {
194
- return flatten(grandChildEl, maxDepth, requestContext, _depth + 1);
195
- });
196
- }
197
- });
198
- }
199
-
200
- if (_.isArray(el)) {
201
- el = el.map(function(childEl) {
202
- return flatten(childEl, maxDepth, requestContext, _depth + 1);
203
- });
204
- }
205
-
206
- // DISABLE - also casting IDs - fix.
207
- //el = _castTypes(el);
208
-
209
- debug('flattened to', el);
210
- return el;
211
- };
212
-
213
-
214
- /*
215
- parse API responses. differs by query type.
216
- @param data: response, converted to (or originally in) JSON.
217
- @param requestContext: context on the request.
218
- - same as `options` in `xmlRequest()`, see docs there.
219
- @param callback: gets `null, data` in success case, and `error, data` on error case.
220
- - error can be from response or parsing failure. (see error types.)
221
- - callback is actually called immediately/synchronously - just using to have 2 return values in error case.
222
- */
223
- exports.parseResponseJson = function(data, requestContext, callback) {
224
- debug('parsing response json', data, requestContext);
225
-
226
- var flatten = exports.flatten;
227
-
228
- requestContext = requestContext || {};
229
-
230
- // flattening can be slow with big responses;
231
- // don't necessarily want to flatten all the way up front.
232
- // (maybe better to let app pick the keys it wants and flatten only them.)
233
- data = flatten(data, requestContext.parseDepth, requestContext);
234
-
235
- // find the response key.
236
- // (is probably `{requestContext.opType}Response`)
237
- var responseKey = _(data).keys().find(function(key) {
238
- return /[a-zA-Z]+Response$/.test(key);
239
- }) || requestContext.opType + 'Response';
240
-
241
- debug('looking for response key', responseKey);
242
-
243
- data = data[responseKey];
244
-
245
- if (_.isUndefined(data)) {
246
- // assume this is a failure of the client to parse the response properly.
247
- throw new EbayClientError("Response missing " + responseKey + " element");
248
- }
249
-
250
- //
251
- // 'Ack', 'Errors', (and maybe 'errorMessage'?) indicate errors.
252
- // see http://developer.ebay.com/devzone/xml/docs/Reference/ebay/Errors/ErrorMessages.htm
253
- //
254
- var
255
- ack,
256
- errorMessage, // build a string
257
- errorClassification = 'RequestError', // 'RequestError' or 'SystemError'
258
- errorSeverityCode = 'Warning', // 'Warning' or 'Error'
259
- errors, // error object(s) in response.
260
- extraErrorProps,
261
- error = null; // final Error instance
262
-
263
- if (!_.isUndefined(data.Ack)) ack = data.Ack;
264
- else if (!_.isUndefined(data.ack)) ack = data.ack;
265
-
266
- if (ack != null) ack = flatten(ack, -1, requestContext);
267
-
268
- // note: docs say,
269
- // "Both Success and Warning indicate that the request was successful.
270
- // However, a value of Warning means that something occurred
271
- // that may affect your application or the user."
272
- // treating Warning as an error,
273
- // but caller still gets the data, and the 'SeverityCode', so it can choose to ignore.
274
- //
275
- if (_.isUndefined(ack) || ack !== 'Success') {
276
- //
277
- // handle all different ways errors can be represented
278
- //
279
-
280
- // Trading, Shopping, Finding(?)
281
- if (!_.isUndefined(data.Errors)) {
282
- errors = _.isArray(data.Errors) ? data.Errors : [data.Errors];
283
-
284
- // build composite message.
285
- errorMessage = errors.map(function(errorObj) {
286
- errorObj = flatten(errorObj, -1, requestContext);
287
- if (errorObj.ErrorClassification === 'SystemError') {
288
- errorClassification = errorObj.ErrorClassification; // SystemError trumps RequestError
289
- }
290
- if (errorObj.SeverityCode === 'Error') {
291
- errorSeverityCode = errorObj.SeverityCode; // Error trumps Warning
292
- }
293
- return (errorObj.SeverityCode || 'Error') + ': ' + errorObj.LongMessage + (errorObj.ErrorCode ? ' (' + errorObj.ErrorCode + ')' : '');
294
- }).join(', ');
295
- }
296
-
297
- // @review which API is this for?
298
- // (maybe a relic of JSON response, no longer relevant?)
299
- else if (!_.isUndefined(data.errorMessage)) {
300
- errorMessage = flatten(data.errorMessage, -1, requestContext);
301
- if (_.isObject(errorMessage)) errorMessage = util.inspect(errorMessage, true, 3);
302
- // TODO error code and classification in this format?
303
- }
304
-
305
- debug('response error', errorClassification, errorSeverityCode, ack, errorMessage);
306
-
307
- // fallback
308
- if (errorMessage == null) {
309
- errorMessage = util.format("Bad ack code: ", ack);
310
- errorSeverityCode = 'Error';
311
- }
312
-
313
- // more context for programatically interpreting the error
314
- extraErrorProps = {
315
- severityCode: errorSeverityCode,
316
- classification: errorClassification,
317
- errors: errors,
318
- details: _.clone(ack)
319
- };
320
-
321
- // still pass back the data! so client can ignore the warning/error if it chooses.
322
- if (errorClassification === 'SystemError') {
323
- error = new EbaySystemError("eBay API system " + errorSeverityCode.toLowerCase() + ": " + errorMessage, extraErrorProps);
324
- }
325
- else {
326
- error = new EbayRequestError("eBay API request " + errorSeverityCode.toLowerCase() + ": " + errorMessage, extraErrorProps);
327
- }
328
- }
329
-
330
- //
331
- // PER-OP PARSING
332
- //
333
- // ...?
334
-
335
- callback(error, data);
336
- };
package/lib/key-lists.js DELETED
@@ -1,64 +0,0 @@
1
- /**
2
- * lists of known keys for parsing.
3
- *
4
- * TODO fill this out more -- PR's welcome!
5
- */
6
-
7
- exports.knownArrayKeysByApiEndpoint = {
8
-
9
- /*
10
- e.g.
11
- {
12
- serviceName1: {
13
- opType1: [...] // known array keys
14
- opType2: [...]
15
- ...
16
- },
17
- serviceName2: {...}
18
- }
19
- */
20
-
21
- 'Trading': {
22
-
23
- // see http://developer.ebay.com/devzone/xml/docs/reference/ebay/GetOrders.html#Response.OrderArray.Order.PaidTime
24
- 'GetOrders': [
25
- 'AddressAttribute',
26
- 'Attribute',
27
- 'BuyerPackageEnclosure',
28
- 'BuyerPackageEnclosure',
29
- 'BuyerTaxIdentifier',
30
- 'CancelDetail',
31
- 'ErrorParameters',
32
- 'Errors',
33
- 'ExternalTransaction',
34
- 'InternationalShippingServiceOption',
35
- 'NameValueList',
36
- 'Orders',
37
- 'Payment',
38
- 'PaymentReferenceID',
39
- 'PickupOptions',
40
- 'Refund',
41
- 'RequiredSellerAction',
42
- 'ShipToLocation',
43
- 'ShipmentTrackingDetails',
44
- 'ShippingPackageInfo',
45
- 'ShippingPackageInfo',
46
- 'ShippingServiceOptions',
47
- 'TaxDetails',
48
- 'TaxJurisdiction',
49
- 'Transactions',
50
- 'Value',
51
- 'VariationSpecifics'
52
- ]
53
- },
54
-
55
- 'Shopping': {
56
-
57
- 'GetMultipleItems': [
58
- 'Item',
59
- // ...
60
- ]
61
- }
62
-
63
- // TODO others...
64
- };
package/lib/urls.js DELETED
@@ -1,64 +0,0 @@
1
- var
2
- _ = require('lodash'),
3
- debug = require('debug')('ebay:urls');
4
-
5
-
6
- /*
7
- build URL to API endpoints.
8
- @param options: request context (see
9
- */
10
- exports.buildRequestUrl = function(options) {
11
- var url;
12
-
13
- options = options || {};
14
-
15
- var serviceName = options.serviceName.replace(/Service$/, '');
16
-
17
- // note: sandboxes do not all support SSL.
18
-
19
- switch (serviceName) {
20
- case 'Finding':
21
- if (options.sandbox) url = 'http://svcs.sandbox.ebay.com/services/search/FindingService/v1';
22
- else url = 'http://svcs.ebay.com/services/search/FindingService/v1'; // no HTTPS support, really?!
23
- break;
24
-
25
- case 'Product':
26
- if (options.sandbox) url = 'http://svcs.sandbox.ebay.com/services/marketplacecatalog/' + serviceName + '/v1';
27
- else url = 'http://svcs.ebay.com/services/marketplacecatalog/' + serviceName + '/v1'; // no HTTPS support, really?!
28
- break;
29
-
30
- case 'Shopping':
31
- if (options.sandbox) url = 'http://open.api.sandbox.ebay.com/shopping';
32
- else url = "http://open.api.ebay.com/shopping"; // no HTTPS support, really?!
33
- break;
34
-
35
- case 'Trading':
36
- if (options.sandbox) url = 'https://api.sandbox.ebay.com/ws/api.dll';
37
- else url = 'https://api.ebay.com/ws/api.dll';
38
- break;
39
-
40
- case 'Merchandising':
41
- if (options.sandbox) url = 'http://svcs.sandbox.ebay.com/MerchandisingService';
42
- else url = "https://svcs.ebay.com/MerchandisingService";
43
- break;
44
-
45
- // this is not a real service, it's more of a meta-service. the name is made up here.
46
- // it's also not really an API - it's used for HTML consent pages -
47
- // but other URLs for eBay's systems are here, so including this here too.
48
- // @see http://developer.ebay.com/devzone/guides/ebayfeatures/Basics/Tokens-MultipleUsers.html
49
- case 'Signin':
50
- if (options.sandbox) url = 'https://signin.sandbox.ebay.com/ws/eBayISAPI.dll';
51
- else url = 'https://signin.ebay.com/ws/eBayISAPI.dll';
52
- break;
53
-
54
- default:
55
- if (options.sandbox) {
56
- throw new Error("Sandbox endpoint for " + serviceName + " service not yet implemented. Please add.");
57
- }
58
- else url = "https://svcs.ebay.com/" + serviceName + 'Service?';
59
- }
60
-
61
- // [removed URL params - all XML based now. if need to bring back, look in git history.]
62
-
63
- return url;
64
- };
package/lib/versions.js DELETED
@@ -1,35 +0,0 @@
1
- var
2
- _ = require('lodash'),
3
- debug = require('debug')('ebay:versions');
4
- //getRequest = require('./get-request').getRequest;
5
-
6
-
7
- // check the latest API versions (to update the code accordingly)
8
- // callback gets hash of APIs:versions
9
- exports.getLatestApiVersions = function(options, callback) {
10
- throw new Error("TODO re-implement/refactor me!");
11
-
12
- //var checkVersion = function(serviceName, next) {
13
- // debug('checkVersion for', serviceName);
14
- //
15
- // getRequest({
16
- // serviceName: serviceName,
17
- // opType: 'getVersion',
18
- // appId: options.appId,
19
- // parser: function versionParser(data, callback) {
20
- // callback(null, data.version);
21
- // }
22
- // },
23
- // next);
24
- //};
25
- //
26
- //async.series({
27
- // 'finding': async.apply(checkVersion, 'Finding'),
28
- // 'merchandising': async.apply(checkVersion, 'Merchandising'),
29
- // // 'shopping': async.apply(checkVersion, 'Shopping'), // doesn't have this call!
30
- // // 'trading': async.apply(checkVersion, 'Trading') // doesn't have this call!
31
- //
32
- // // ... which others have it?
33
- // },
34
- // callback);
35
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * convert XML from responses to JSON,
3
- * to be parsed as JSON.
4
- */
5
-
6
- var
7
- debug = require('debug')('ebay:xml-converter'),
8
- xml2js = require('xml2js'),
9
- EbayClientError = require('./errors').EbayClientError;
10
-
11
-
12
- exports.convertXmlToJson = function(xmlBody, options, callback) {
13
- var xmlParser = new xml2js.Parser();
14
- xmlParser.parseString(xmlBody, function(error, data) {
15
- if (error) {
16
- debug(error);
17
- return callback(new EbayClientError("Error parsing XML: " + error.message));
18
- }
19
- callback(null, data);
20
- });
21
- };