ebay-api 9.0.2 → 9.1.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.
- package/README.md +76 -2
- package/dist/api/traditional/XMLRequest.d.ts +5 -4
- package/dist/api/traditional/XMLRequest.js +7 -7
- package/dist/ebay-api.min.mjs +1 -1
- package/dist/errors/index.d.ts +5 -4
- package/dist/errors/index.js +19 -18
- package/lib/api/traditional/XMLRequest.d.ts +5 -4
- package/lib/api/traditional/XMLRequest.js +7 -6
- package/lib/ebay-api.min.js +1 -1
- package/lib/errors/index.d.ts +5 -4
- package/lib/errors/index.js +19 -18
- package/package.json +2 -2
package/dist/errors/index.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare class ApiEnvError extends EBayError {
|
|
|
13
13
|
export declare class EbayApiError extends EBayError {
|
|
14
14
|
readonly errorCode: number | undefined;
|
|
15
15
|
readonly meta?: EBayErrorMeta;
|
|
16
|
-
|
|
16
|
+
readonly firstError?: EBayFirstError;
|
|
17
|
+
constructor(message: string, description?: string, meta?: EBayErrorMeta, errorCode?: number, firstError?: EBayFirstError);
|
|
17
18
|
}
|
|
18
19
|
export declare class EBayApiError extends EbayApiError {
|
|
19
20
|
}
|
|
@@ -89,7 +90,7 @@ export type EBayApiErrorResponse = string | EBayPostOrderErrorResponse | EBayRes
|
|
|
89
90
|
export type ApiRequestResult = {
|
|
90
91
|
response: {
|
|
91
92
|
data?: EBayApiErrorResponse;
|
|
92
|
-
status?:
|
|
93
|
+
status?: number;
|
|
93
94
|
statusText?: string;
|
|
94
95
|
headers?: Record<string, string>;
|
|
95
96
|
};
|
|
@@ -103,7 +104,7 @@ export type ApiRequestResult = {
|
|
|
103
104
|
export type ErrorCommonMeta = {
|
|
104
105
|
res?: {
|
|
105
106
|
data: any;
|
|
106
|
-
status?:
|
|
107
|
+
status?: number;
|
|
107
108
|
statusText?: string;
|
|
108
109
|
headers?: Record<string, string>;
|
|
109
110
|
};
|
|
@@ -127,4 +128,4 @@ export type EBayErrorBag = {
|
|
|
127
128
|
};
|
|
128
129
|
export declare const extractEBayError: (result: ApiRequestResult, data?: EBayApiErrorResponse) => EBayErrorBag;
|
|
129
130
|
export declare const handleEBayError: (error: any) => never;
|
|
130
|
-
export declare const checkEBayTraditionalResponse: (
|
|
131
|
+
export declare const checkEBayTraditionalResponse: (apiResponse: any, data: any) => void;
|
package/dist/errors/index.js
CHANGED
|
@@ -21,9 +21,10 @@ export class ApiEnvError extends EBayError {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
export class EbayApiError extends EBayError {
|
|
24
|
-
constructor(message, description, meta, errorCode) {
|
|
24
|
+
constructor(message, description, meta, errorCode, firstError) {
|
|
25
25
|
super(message, description, meta);
|
|
26
26
|
this.errorCode = errorCode;
|
|
27
|
+
this.firstError = firstError;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
export class EBayApiError extends EbayApiError {
|
|
@@ -51,7 +52,7 @@ export class EBayTokenRequired extends EBayApiError {
|
|
|
51
52
|
EBayTokenRequired.code = 930;
|
|
52
53
|
export class EBayInvalidScope extends EBayApiError {
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
+
function getEBayError(data) {
|
|
55
56
|
if (!data) {
|
|
56
57
|
return {
|
|
57
58
|
message: `eBay API Error`,
|
|
@@ -114,7 +115,7 @@ const getErrorCode = (eBayError) => {
|
|
|
114
115
|
return undefined;
|
|
115
116
|
};
|
|
116
117
|
export const extractEBayError = (result, data) => {
|
|
117
|
-
const eBayError =
|
|
118
|
+
const eBayError = getEBayError(data || result.response?.data);
|
|
118
119
|
const meta = {
|
|
119
120
|
...eBayError,
|
|
120
121
|
[rawError]: result
|
|
@@ -154,42 +155,42 @@ export const handleEBayError = (error) => {
|
|
|
154
155
|
else if (typeof error !== 'object') {
|
|
155
156
|
throw new EBayError(error);
|
|
156
157
|
}
|
|
157
|
-
const { message, meta, description, errorCode } = extractEBayError(error);
|
|
158
|
+
const { message, meta, description, errorCode, firstError } = extractEBayError(error);
|
|
158
159
|
if ('domain' in meta && meta.domain === 'ACCESS') {
|
|
159
|
-
throw new EBayAccessDenied(message, description, meta, errorCode);
|
|
160
|
+
throw new EBayAccessDenied(message, description, meta, errorCode, firstError);
|
|
160
161
|
}
|
|
161
162
|
else if ('message' in meta && meta.message === 'invalid_grant') {
|
|
162
|
-
throw new EBayInvalidGrant(message, description, meta, errorCode);
|
|
163
|
+
throw new EBayInvalidGrant(message, description, meta, errorCode, firstError);
|
|
163
164
|
}
|
|
164
165
|
else if ('message' in meta && meta.message === 'invalid_scope') {
|
|
165
|
-
throw new EBayInvalidScope(message, description, meta, errorCode);
|
|
166
|
+
throw new EBayInvalidScope(message, description, meta, errorCode, firstError);
|
|
166
167
|
}
|
|
167
168
|
else if ('message' in meta && meta.message === 'Invalid access token') {
|
|
168
|
-
throw new EBayInvalidAccessToken(message, description, meta, errorCode);
|
|
169
|
+
throw new EBayInvalidAccessToken(message, description, meta, errorCode, firstError);
|
|
169
170
|
}
|
|
170
171
|
else if (errorCode === EBayNotFound.code) {
|
|
171
|
-
throw new EBayNotFound(message, description, meta, errorCode);
|
|
172
|
+
throw new EBayNotFound(message, description, meta, errorCode, firstError);
|
|
172
173
|
}
|
|
173
|
-
throw new EBayApiError(message, description, meta, errorCode);
|
|
174
|
+
throw new EBayApiError(message, description, meta, errorCode, firstError);
|
|
174
175
|
};
|
|
175
|
-
export const checkEBayTraditionalResponse = (
|
|
176
|
+
export const checkEBayTraditionalResponse = (apiResponse, data) => {
|
|
176
177
|
if (!('Errors' in data) && !('errorMessage' in data)) {
|
|
177
178
|
return;
|
|
178
179
|
}
|
|
179
|
-
const { message, meta, description, errorCode } = extractEBayError(
|
|
180
|
+
const { message, meta, description, errorCode, firstError } = extractEBayError(apiResponse, data);
|
|
180
181
|
if (typeof errorCode === 'undefined') {
|
|
181
|
-
throw new EBayApiError(message, description, meta, errorCode);
|
|
182
|
+
throw new EBayApiError(message, description, meta, errorCode, firstError);
|
|
182
183
|
}
|
|
183
184
|
switch (errorCode) {
|
|
184
185
|
case EBayIAFTokenExpired.code:
|
|
185
|
-
throw new EBayIAFTokenExpired(message, description, meta, errorCode);
|
|
186
|
+
throw new EBayIAFTokenExpired(message, description, meta, errorCode, firstError);
|
|
186
187
|
case EBayIAFTokenInvalid.code:
|
|
187
188
|
case 1.32:
|
|
188
|
-
throw new EBayIAFTokenInvalid(message, description, meta, errorCode);
|
|
189
|
+
throw new EBayIAFTokenInvalid(message, description, meta, errorCode, firstError);
|
|
189
190
|
case EBayTokenRequired.code:
|
|
190
|
-
throw new EBayTokenRequired(message, description, meta, errorCode);
|
|
191
|
+
throw new EBayTokenRequired(message, description, meta, errorCode, firstError);
|
|
191
192
|
case EBayAuthTokenIsHardExpired.code:
|
|
192
|
-
throw new EBayAuthTokenIsHardExpired(message, description, meta, errorCode);
|
|
193
|
+
throw new EBayAuthTokenIsHardExpired(message, description, meta, errorCode, firstError);
|
|
193
194
|
}
|
|
194
|
-
throw new EBayApiError(message, description, meta, errorCode);
|
|
195
|
+
throw new EBayApiError(message, description, meta, errorCode, firstError);
|
|
195
196
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { XMLBuilder } from 'fast-xml-parser';
|
|
1
|
+
import { X2jOptions, XMLBuilder, XmlBuilderOptions } from 'fast-xml-parser';
|
|
2
2
|
import { IEBayApiRequest } from '../../request.js';
|
|
3
3
|
import { ApiRequestConfig, Headers } from '../../types/index.js';
|
|
4
4
|
import { Fields } from './fields.js';
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const defaultXmlBuilderOptions: {
|
|
6
6
|
attributeNamePrefix: string;
|
|
7
7
|
textNodeName: string;
|
|
8
8
|
ignoreAttributes: boolean;
|
|
@@ -32,7 +32,8 @@ export type BodyHeaders = {
|
|
|
32
32
|
};
|
|
33
33
|
export type TraditionalApiConfig = {
|
|
34
34
|
raw?: boolean;
|
|
35
|
-
parseOptions?:
|
|
35
|
+
parseOptions?: X2jOptions;
|
|
36
|
+
xmlBuilderOptions?: XmlBuilderOptions;
|
|
36
37
|
useIaf?: boolean;
|
|
37
38
|
sign?: boolean;
|
|
38
39
|
hook?: (xml: string) => BodyHeaders;
|
|
@@ -52,7 +53,7 @@ export default class XMLRequest {
|
|
|
52
53
|
private readonly fields;
|
|
53
54
|
private readonly config;
|
|
54
55
|
private readonly req;
|
|
55
|
-
|
|
56
|
+
readonly j2x: XMLBuilder;
|
|
56
57
|
constructor(callName: string, fields: Fields | null, config: XMLReqConfig, req: IEBayApiRequest);
|
|
57
58
|
private getResponseWrapper;
|
|
58
59
|
private getCredentials;
|
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defaultHeaders = exports.defaultApiConfig = exports.defaultXML2JSONParseOptions = exports.
|
|
6
|
+
exports.defaultHeaders = exports.defaultApiConfig = exports.defaultXML2JSONParseOptions = exports.defaultXmlBuilderOptions = void 0;
|
|
7
7
|
const debug_1 = __importDefault(require("debug"));
|
|
8
8
|
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
9
9
|
const index_js_1 = require("../../errors/index.js");
|
|
10
10
|
const log = (0, debug_1.default)('ebay:xml:request');
|
|
11
|
-
exports.
|
|
11
|
+
exports.defaultXmlBuilderOptions = {
|
|
12
12
|
attributeNamePrefix: '@_',
|
|
13
13
|
textNodeName: '#value',
|
|
14
14
|
ignoreAttributes: false,
|
|
@@ -37,6 +37,7 @@ exports.defaultXML2JSONParseOptions = {
|
|
|
37
37
|
exports.defaultApiConfig = {
|
|
38
38
|
raw: false,
|
|
39
39
|
parseOptions: exports.defaultXML2JSONParseOptions,
|
|
40
|
+
xmlBuilderOptions: exports.defaultXmlBuilderOptions,
|
|
40
41
|
useIaf: true,
|
|
41
42
|
sign: false,
|
|
42
43
|
headers: {},
|
|
@@ -50,9 +51,10 @@ class XMLRequest {
|
|
|
50
51
|
if (!callName) {
|
|
51
52
|
throw new index_js_1.EBayNoCallError();
|
|
52
53
|
}
|
|
54
|
+
this.config = { ...exports.defaultApiConfig, ...config };
|
|
55
|
+
this.j2x = new fast_xml_parser_1.XMLBuilder({ ...exports.defaultXmlBuilderOptions, ...this.config.xmlBuilderOptions });
|
|
53
56
|
this.callName = callName;
|
|
54
57
|
this.fields = fields || {};
|
|
55
|
-
this.config = { ...exports.defaultApiConfig, ...config };
|
|
56
58
|
this.req = req;
|
|
57
59
|
}
|
|
58
60
|
getResponseWrapper() {
|
|
@@ -84,7 +86,7 @@ class XMLRequest {
|
|
|
84
86
|
}
|
|
85
87
|
toXML(fields) {
|
|
86
88
|
const HEADING = '<?xml version="1.0" encoding="utf-8"?>';
|
|
87
|
-
return HEADING +
|
|
89
|
+
return HEADING + this.j2x.build({
|
|
88
90
|
[this.callName + 'Request']: {
|
|
89
91
|
'@_xmlns': this.config.xmlns,
|
|
90
92
|
...this.getCredentials(),
|
|
@@ -122,7 +124,7 @@ class XMLRequest {
|
|
|
122
124
|
log('error', error);
|
|
123
125
|
if (error.response?.data) {
|
|
124
126
|
const json = this.toJSON(error.response.data);
|
|
125
|
-
(0, index_js_1.checkEBayTraditionalResponse)(error
|
|
127
|
+
(0, index_js_1.checkEBayTraditionalResponse)(error, json[this.callName + 'Response']);
|
|
126
128
|
}
|
|
127
129
|
throw error;
|
|
128
130
|
}
|
|
@@ -132,5 +134,4 @@ class XMLRequest {
|
|
|
132
134
|
return json[this.getResponseWrapper()] ?? json;
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
|
-
XMLRequest.j2x = new fast_xml_parser_1.XMLBuilder(exports.defaultJSON2XMLOptions);
|
|
136
137
|
exports.default = XMLRequest;
|