ebay-api
Advanced tools
Comparing version 8.3.0 to 8.4.0
@@ -5,2 +5,3 @@ import Auth from '../auth/index.js'; | ||
import Base from './base.js'; | ||
import { SignatureComponents } from './digitalSignature.js'; | ||
/** | ||
@@ -12,2 +13,3 @@ * Superclass with Auth container. | ||
constructor(config: AppConfig, req?: IEBayApiRequest, auth?: Auth); | ||
getDigitalSignatureHeaders(signatureComponents: SignatureComponents, payload: any): {}; | ||
} |
import Auth from '../auth/index.js'; | ||
import Base from './base.js'; | ||
import { generateContentDigestValue, generateSignature, generateSignatureInput } from './digitalSignature.js'; | ||
/** | ||
@@ -11,2 +12,19 @@ * Superclass with Auth container. | ||
} | ||
getDigitalSignatureHeaders(signatureComponents, payload) { | ||
if (!this.config.signature) { | ||
return {}; | ||
} | ||
const digitalSignatureHeaders = { | ||
'x-ebay-enforce-signature': true, | ||
'x-ebay-signature-key': this.config.signature.jwe, | ||
...payload ? { | ||
'content-digest': generateContentDigestValue(payload, this.config.signature.cipher ?? 'sha256') | ||
} : {}, | ||
'signature-input': generateSignatureInput(payload) | ||
}; | ||
return { | ||
...digitalSignatureHeaders, | ||
'signature': generateSignature(digitalSignatureHeaders, this.config.signature.privateKey, signatureComponents, payload) | ||
}; | ||
} | ||
} |
@@ -15,7 +15,5 @@ import Restful from '../../index.js'; | ||
/** | ||
* his method creates keypairs. | ||
* This method creates keypairs. | ||
*/ | ||
createSigningKey(data: { | ||
signingKeyCipher: string; | ||
}): Promise<any>; | ||
createSigningKey(signingKeyCipher: 'ED25519' | 'RSA'): Promise<any>; | ||
/** | ||
@@ -22,0 +20,0 @@ * This method returns the <b>Public Key</b>, <b>Public Key as JWE</b>, |
@@ -20,6 +20,8 @@ import Restful from '../../index.js'; | ||
/** | ||
* his method creates keypairs. | ||
* This method creates keypairs. | ||
*/ | ||
createSigningKey(data) { | ||
return this.post(`/signing_key`, data); | ||
createSigningKey(signingKeyCipher) { | ||
return this.post(`/signing_key`, { | ||
signingKeyCipher | ||
}); | ||
} | ||
@@ -26,0 +28,0 @@ /** |
@@ -1,5 +0,5 @@ | ||
import Api from '../index.js'; | ||
import Auth from '../../auth/index.js'; | ||
import { IEBayApiRequest } from '../../request.js'; | ||
import { ApiRequestConfig, AppConfig } from '../../types/index.js'; | ||
import Api from '../index.js'; | ||
export declare const defaultApiHeaders: Record<string, string>; | ||
@@ -9,2 +9,3 @@ export type RestfulApiConfig = { | ||
useIaf?: boolean; | ||
sign?: boolean; | ||
apiVersion?: string; | ||
@@ -18,3 +19,3 @@ basePath?: string; | ||
method: keyof IEBayApiRequest; | ||
url: string; | ||
path: string; | ||
config?: any; | ||
@@ -55,8 +56,12 @@ data?: any; | ||
get apiz(): this; | ||
get(url: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
delete(url: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
post(url: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
put(url: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
/** | ||
* Sign request | ||
*/ | ||
get sign(): this; | ||
get(path: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
delete(path: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
post(path: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
put(path: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
get additionalHeaders(): any; | ||
enrichRequestConfig(config?: any, apiConfig?: Required<RestfulApiConfig>): Promise<any>; | ||
enrichRequestConfig(apiRequest: ApiRequest, payload?: any, apiConfig?: Required<RestfulApiConfig>): Promise<any>; | ||
private doRequest; | ||
@@ -63,0 +68,0 @@ private shouldRefreshToken; |
@@ -0,3 +1,3 @@ | ||
import { EBayInvalidAccessToken, handleEBayError } from '../../errors/index.js'; | ||
import Api from '../index.js'; | ||
import { EBayInvalidAccessToken, handleEBayError } from '../../errors/index.js'; | ||
export const defaultApiHeaders = { | ||
@@ -56,3 +56,4 @@ 'Content-Type': 'application/json', | ||
headers: {}, | ||
returnResponse: false | ||
returnResponse: false, | ||
sign: false | ||
}; | ||
@@ -83,14 +84,20 @@ } | ||
} | ||
async get(url, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'get', url, config }, apiConfig); | ||
/** | ||
* Sign request | ||
*/ | ||
get sign() { | ||
return this.api({ sign: true }); | ||
} | ||
async delete(url, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'delete', url, config }, apiConfig); | ||
async get(path, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'get', path, config }, apiConfig); | ||
} | ||
async post(url, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'post', url, data, config }, apiConfig); | ||
async delete(path, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'delete', path, config }, apiConfig); | ||
} | ||
async put(url, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'put', url, data, config }, apiConfig); | ||
async post(path, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'post', path, data, config }, apiConfig); | ||
} | ||
async put(path, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'put', path, data, config }, apiConfig); | ||
} | ||
get additionalHeaders() { | ||
@@ -106,4 +113,9 @@ return Object.keys(additionalHeaders) | ||
} | ||
async enrichRequestConfig(config = {}, apiConfig = this.apiConfig) { | ||
async enrichRequestConfig(apiRequest, payload = null, apiConfig = this.apiConfig) { | ||
const authHeader = await this.auth.getHeaderAuthorization(apiConfig.useIaf); | ||
const signatureHeaders = apiConfig.sign ? this.getDigitalSignatureHeaders({ | ||
method: apiRequest.method.toUpperCase(), | ||
authority: Restful.buildServerUrl('', apiConfig.subdomain, apiConfig.sandbox, apiConfig.tld), | ||
path: apiConfig.apiVersion + apiConfig.basePath + apiRequest.path | ||
}, payload) : {}; | ||
const headers = { | ||
@@ -113,8 +125,9 @@ ...defaultApiHeaders, | ||
...authHeader, | ||
...apiConfig.headers | ||
...apiConfig.headers, | ||
...signatureHeaders | ||
}; | ||
return { | ||
...config, | ||
...apiRequest.config, | ||
headers: { | ||
...(config.headers || {}), | ||
...(apiRequest.config.headers || {}), | ||
...headers | ||
@@ -146,5 +159,5 @@ } | ||
async request(apiRequest, apiConfig = this.apiConfig, refreshToken = false) { | ||
const { url, method, data, config } = apiRequest; | ||
const { path, method, data } = apiRequest; | ||
const apiCfg = { ...this.apiConfig, ...apiConfig }; | ||
const endpoint = this.getServerUrl(apiCfg) + url; | ||
const endpoint = this.getServerUrl(apiCfg) + path; | ||
try { | ||
@@ -154,3 +167,3 @@ if (refreshToken) { | ||
} | ||
const enrichedConfig = await this.enrichRequestConfig(config, apiCfg); | ||
const enrichedConfig = await this.enrichRequestConfig(apiRequest, data, apiCfg); | ||
const args = ['get', 'delete'].includes(method) ? [enrichedConfig] : [data, enrichedConfig]; | ||
@@ -157,0 +170,0 @@ // @ts-ignore |
@@ -0,3 +1,3 @@ | ||
import { ClientAlerts, Finding, Merchandising, Shopping, Trading } from '../../types/index.js'; | ||
import Api from '../index.js'; | ||
import { ClientAlerts, Finding, Merchandising, Shopping, Trading } from '../../types/index.js'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Traditional eBay API. |
import { stringify } from 'qs'; | ||
import { EBayIAFTokenExpired, EBayIAFTokenInvalid, handleEBayError } from '../../errors/index.js'; | ||
import Api from '../index.js'; | ||
import { EBayIAFTokenExpired, EBayIAFTokenInvalid, handleEBayError } from '../../errors/index.js'; | ||
import ClientAlertsCalls from './clientAlerts/index.js'; | ||
@@ -31,5 +31,2 @@ import FindingCalls from './finding/index.js'; | ||
createTradingApi() { | ||
if (!this.config.devId) { | ||
throw new Error('devId is required for trading API.'); | ||
} | ||
if (typeof this.config.siteId !== 'number') { | ||
@@ -40,5 +37,6 @@ throw new Error('siteId is required for trading API.'); | ||
endpoint: { | ||
production: 'https://api.ebay.com/ws/api.dll', | ||
sandbox: 'https://api.sandbox.ebay.com/ws/api.dll' | ||
production: 'api.ebay.com', | ||
sandbox: 'api.sandbox.ebay.com' | ||
}, | ||
path: '/ws/api.dll', | ||
calls: TradingCalls, | ||
@@ -63,5 +61,6 @@ xmlns: 'urn:ebay:apis:eBLBaseComponents', | ||
endpoint: { | ||
production: 'https://open.api.ebay.com/shopping', | ||
sandbox: 'https://open.api.sandbox.ebay.com/shopping' | ||
production: 'open.api.ebay.com', | ||
sandbox: 'open.api.sandbox.ebay.com' | ||
}, | ||
path: '/shopping', | ||
xmlns: 'urn:ebay:apis:eBLBaseComponents', | ||
@@ -82,5 +81,6 @@ calls: ShoppingCalls, | ||
endpoint: { | ||
production: 'https://svcs.ebay.com/services/search/FindingService/v1', | ||
sandbox: 'https://svcs.sandbox.ebay.com/services/search/FindingService/v1' | ||
production: 'svcs.ebay.com', | ||
sandbox: 'svcs.sandbox.ebay.com' | ||
}, | ||
path: '/services/search/FindingService/v1', | ||
xmlns: 'http://www.ebay.com/marketplace/search/v1/services', | ||
@@ -100,5 +100,6 @@ calls: FindingCalls, | ||
endpoint: { | ||
production: 'https://clientalerts.ebay.com/ws/ecasvc/ClientAlerts', | ||
sandbox: 'https://clientalerts.sandbox.ebay.com/ws/ecasvc/ClientAlerts' | ||
production: 'clientalerts.ebay.com', | ||
sandbox: 'clientalerts.sandbox.ebay.com' | ||
}, | ||
path: '/ws/ecasvc/ClientAlerts', | ||
calls: ClientAlertsCalls | ||
@@ -137,5 +138,6 @@ }; | ||
endpoint: { | ||
production: 'https://svcs.ebay.com/MerchandisingService', | ||
sandbox: 'https://svcs.sandbox.ebay.com/MerchandisingService' | ||
production: 'svcs.ebay.com', | ||
sandbox: 'svcs.sandbox.ebay.com' | ||
}, | ||
path: '/MerchandisingService', | ||
xmlns: 'http://www.ebay.com/marketplace/services', | ||
@@ -169,6 +171,7 @@ calls: MerchandisingCalls, | ||
const useIaf = !eBayAuthToken && accessToken; | ||
const host = this.config.sandbox ? api.endpoint.sandbox : api.endpoint.production; | ||
return { | ||
...apiConfig, | ||
xmlns: api.xmlns, | ||
endpoint: api.endpoint[this.config.sandbox ? 'sandbox' : 'production'], | ||
endpoint: `https://${host}${api.path}`, | ||
headers: { | ||
@@ -178,2 +181,9 @@ ...api.headers(callName, useIaf ? accessToken : null), | ||
}, | ||
digitalSignatureHeaders: payload => { | ||
return apiConfig.sign ? this.getDigitalSignatureHeaders({ | ||
method: 'POST', | ||
authority: host, | ||
path: api.path | ||
}, payload) : {}; | ||
}, | ||
...(!useIaf ? { eBayAuthToken } : {}) | ||
@@ -180,0 +190,0 @@ }; |
@@ -37,2 +37,3 @@ import { XMLBuilder } from 'fast-xml-parser'; | ||
useIaf?: boolean; | ||
sign?: boolean; | ||
hook?: (xml: string) => BodyHeaders; | ||
@@ -44,2 +45,3 @@ } & ApiRequestConfig; | ||
eBayAuthToken?: string | null; | ||
digitalSignatureHeaders?: (payload: any) => Headers; | ||
}; | ||
@@ -68,3 +70,3 @@ export declare const defaultApiConfig: Required<Omit<TraditionalApiConfig, 'hook'>>; | ||
*/ | ||
constructor(callName: string, fields: Fields, config: XMLReqConfig, req: IEBayApiRequest); | ||
constructor(callName: string, fields: Fields | null, config: XMLReqConfig, req: IEBayApiRequest); | ||
/** | ||
@@ -71,0 +73,0 @@ * returns the expected name of XML node of a Request |
import debug from 'debug'; | ||
import { XMLParser, XMLBuilder } from 'fast-xml-parser'; | ||
import { XMLBuilder, XMLParser } from 'fast-xml-parser'; | ||
import { checkEBayResponse, EbayNoCallError } from '../../errors/index.js'; | ||
@@ -35,2 +35,3 @@ const log = debug('ebay:xml:request'); | ||
useIaf: true, | ||
sign: false, | ||
headers: {}, | ||
@@ -141,2 +142,3 @@ returnResponse: false | ||
...this.getHeaders(), | ||
...this.config.digitalSignatureHeaders ? this.config.digitalSignatureHeaders(body) : {}, | ||
...(headers ? headers : {}) | ||
@@ -143,0 +145,0 @@ } |
@@ -14,3 +14,3 @@ import Api from './api/index.js'; | ||
import * as types from './types/index.js'; | ||
import { AppConfig, ClientAlerts, Finding, Merchandising, Shopping, Trading } from './types/index.js'; | ||
import { AppConfig, ClientAlerts, Finding, Merchandising, Shopping, Signature, Trading } from './types/index.js'; | ||
export default class eBayApi extends Api { | ||
@@ -58,3 +58,4 @@ static readonly SiteId: typeof enums.SiteId; | ||
get clientAlerts(): ClientAlerts; | ||
setSignature(signature: Signature): void; | ||
} | ||
export { eBayApi, SiteId, MarketplaceId, ContentLanguage, Locale, enums, errors, types }; |
@@ -32,2 +32,9 @@ import ApiFactory from './api/apiFactory.js'; | ||
} | ||
let signature = null; | ||
if (process.env.EBAY_JWE && process.env.EBAY_PRIVATE_KEY) { | ||
signature = { | ||
jwe: process.env.EBAY_JWE, | ||
privateKey: process.env.EBAY_PRIVATE_KEY | ||
}; | ||
} | ||
return new eBayApi({ | ||
@@ -43,3 +50,4 @@ appId: process.env.EBAY_APP_ID, | ||
ruName: process.env.EBAY_RU_NAME, | ||
sandbox: (process.env.EBAY_SANDBOX === 'true') | ||
sandbox: (process.env.EBAY_SANDBOX === 'true'), | ||
signature | ||
}, req); | ||
@@ -90,2 +98,5 @@ } | ||
} | ||
setSignature(signature) { | ||
this.config.signature = signature; | ||
} | ||
} | ||
@@ -92,0 +103,0 @@ eBayApi.SiteId = SiteId; |
@@ -111,2 +111,7 @@ // tslint:disable:max-classes-per-file | ||
} | ||
else if (typeof data === 'string') { | ||
eBayError = { | ||
message: data | ||
}; | ||
} | ||
else { | ||
@@ -113,0 +118,0 @@ eBayError = data; |
@@ -19,2 +19,8 @@ import { AxiosRequestConfig } from 'axios'; | ||
}; | ||
export type Cipher = 'sha256' | 'sha512'; | ||
export type Signature = { | ||
cipher?: Cipher; | ||
jwe: string; | ||
privateKey: string; | ||
}; | ||
export type eBayConfig = Keyset & { | ||
@@ -24,2 +30,3 @@ sandbox: boolean; | ||
scope?: Scope; | ||
signature?: Signature | null; | ||
} & TraditionalConfig & RestConfig; | ||
@@ -26,0 +33,0 @@ export type ApiConfig = { |
@@ -8,3 +8,3 @@ import ClientAlertsCalls from '../api/traditional/clientAlerts/index.js'; | ||
import { TraditionalApiConfig } from '../api/traditional/XMLRequest.js'; | ||
export type XMLApiCall = (fields?: Fields, apiConfig?: TraditionalApiConfig) => Promise<any>; | ||
export type XMLApiCall = (fields?: Fields | null, apiConfig?: TraditionalApiConfig) => Promise<any>; | ||
export type Trading = { | ||
@@ -32,2 +32,3 @@ [key in typeof TradingCalls[number]]: XMLApiCall; | ||
xmlns: string; | ||
path: string; | ||
calls: typeof TradingCalls | typeof ShoppingCalls | typeof FindingCalls | typeof ClientAlertsCalls | typeof MerchandisingCalls; | ||
@@ -34,0 +35,0 @@ headers: (callName: string, accessToken?: string | null) => object; |
@@ -5,2 +5,3 @@ import Auth from '../auth/index.js'; | ||
import Base from './base.js'; | ||
import { SignatureComponents } from './digitalSignature.js'; | ||
/** | ||
@@ -12,2 +13,3 @@ * Superclass with Auth container. | ||
constructor(config: AppConfig, req?: IEBayApiRequest, auth?: Auth); | ||
getDigitalSignatureHeaders(signatureComponents: SignatureComponents, payload: any): {}; | ||
} |
@@ -8,2 +8,3 @@ "use strict"; | ||
const base_js_1 = __importDefault(require("./base.js")); | ||
const digitalSignature_js_1 = require("./digitalSignature.js"); | ||
/** | ||
@@ -17,3 +18,20 @@ * Superclass with Auth container. | ||
} | ||
getDigitalSignatureHeaders(signatureComponents, payload) { | ||
if (!this.config.signature) { | ||
return {}; | ||
} | ||
const digitalSignatureHeaders = { | ||
'x-ebay-enforce-signature': true, | ||
'x-ebay-signature-key': this.config.signature.jwe, | ||
...payload ? { | ||
'content-digest': (0, digitalSignature_js_1.generateContentDigestValue)(payload, this.config.signature.cipher ?? 'sha256') | ||
} : {}, | ||
'signature-input': (0, digitalSignature_js_1.generateSignatureInput)(payload) | ||
}; | ||
return { | ||
...digitalSignatureHeaders, | ||
'signature': (0, digitalSignature_js_1.generateSignature)(digitalSignatureHeaders, this.config.signature.privateKey, signatureComponents, payload) | ||
}; | ||
} | ||
} | ||
exports.default = Api; |
@@ -15,7 +15,5 @@ import Restful from '../../index.js'; | ||
/** | ||
* his method creates keypairs. | ||
* This method creates keypairs. | ||
*/ | ||
createSigningKey(data: { | ||
signingKeyCipher: string; | ||
}): Promise<any>; | ||
createSigningKey(signingKeyCipher: 'ED25519' | 'RSA'): Promise<any>; | ||
/** | ||
@@ -22,0 +20,0 @@ * This method returns the <b>Public Key</b>, <b>Public Key as JWE</b>, |
@@ -25,6 +25,8 @@ "use strict"; | ||
/** | ||
* his method creates keypairs. | ||
* This method creates keypairs. | ||
*/ | ||
createSigningKey(data) { | ||
return this.post(`/signing_key`, data); | ||
createSigningKey(signingKeyCipher) { | ||
return this.post(`/signing_key`, { | ||
signingKeyCipher | ||
}); | ||
} | ||
@@ -31,0 +33,0 @@ /** |
@@ -1,5 +0,5 @@ | ||
import Api from '../index.js'; | ||
import Auth from '../../auth/index.js'; | ||
import { IEBayApiRequest } from '../../request.js'; | ||
import { ApiRequestConfig, AppConfig } from '../../types/index.js'; | ||
import Api from '../index.js'; | ||
export declare const defaultApiHeaders: Record<string, string>; | ||
@@ -9,2 +9,3 @@ export type RestfulApiConfig = { | ||
useIaf?: boolean; | ||
sign?: boolean; | ||
apiVersion?: string; | ||
@@ -18,3 +19,3 @@ basePath?: string; | ||
method: keyof IEBayApiRequest; | ||
url: string; | ||
path: string; | ||
config?: any; | ||
@@ -55,8 +56,12 @@ data?: any; | ||
get apiz(): this; | ||
get(url: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
delete(url: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
post(url: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
put(url: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
/** | ||
* Sign request | ||
*/ | ||
get sign(): this; | ||
get(path: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
delete(path: string, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
post(path: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
put(path: string, data?: any, config?: any, apiConfig?: RestfulApiConfig): Promise<any>; | ||
get additionalHeaders(): any; | ||
enrichRequestConfig(config?: any, apiConfig?: Required<RestfulApiConfig>): Promise<any>; | ||
enrichRequestConfig(apiRequest: ApiRequest, payload?: any, apiConfig?: Required<RestfulApiConfig>): Promise<any>; | ||
private doRequest; | ||
@@ -63,0 +68,0 @@ private shouldRefreshToken; |
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.defaultApiHeaders = void 0; | ||
const index_js_1 = __importDefault(require("../index.js")); | ||
const index_js_2 = require("../../errors/index.js"); | ||
const index_js_1 = require("../../errors/index.js"); | ||
const index_js_2 = __importDefault(require("../index.js")); | ||
exports.defaultApiHeaders = { | ||
@@ -24,3 +24,3 @@ 'Content-Type': 'application/json', | ||
}; | ||
class Restful extends index_js_1.default { | ||
class Restful extends index_js_2.default { | ||
constructor(config, req, auth, apiConfig = {}) { | ||
@@ -64,3 +64,4 @@ super(config, req, auth); | ||
headers: {}, | ||
returnResponse: false | ||
returnResponse: false, | ||
sign: false | ||
}; | ||
@@ -91,14 +92,20 @@ } | ||
} | ||
async get(url, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'get', url, config }, apiConfig); | ||
/** | ||
* Sign request | ||
*/ | ||
get sign() { | ||
return this.api({ sign: true }); | ||
} | ||
async delete(url, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'delete', url, config }, apiConfig); | ||
async get(path, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'get', path, config }, apiConfig); | ||
} | ||
async post(url, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'post', url, data, config }, apiConfig); | ||
async delete(path, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'delete', path, config }, apiConfig); | ||
} | ||
async put(url, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'put', url, data, config }, apiConfig); | ||
async post(path, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'post', path, data, config }, apiConfig); | ||
} | ||
async put(path, data, config = {}, apiConfig) { | ||
return this.doRequest({ method: 'put', path, data, config }, apiConfig); | ||
} | ||
get additionalHeaders() { | ||
@@ -114,4 +121,9 @@ return Object.keys(additionalHeaders) | ||
} | ||
async enrichRequestConfig(config = {}, apiConfig = this.apiConfig) { | ||
async enrichRequestConfig(apiRequest, payload = null, apiConfig = this.apiConfig) { | ||
const authHeader = await this.auth.getHeaderAuthorization(apiConfig.useIaf); | ||
const signatureHeaders = apiConfig.sign ? this.getDigitalSignatureHeaders({ | ||
method: apiRequest.method.toUpperCase(), | ||
authority: Restful.buildServerUrl('', apiConfig.subdomain, apiConfig.sandbox, apiConfig.tld), | ||
path: apiConfig.apiVersion + apiConfig.basePath + apiRequest.path | ||
}, payload) : {}; | ||
const headers = { | ||
@@ -121,8 +133,9 @@ ...exports.defaultApiHeaders, | ||
...authHeader, | ||
...apiConfig.headers | ||
...apiConfig.headers, | ||
...signatureHeaders | ||
}; | ||
return { | ||
...config, | ||
...apiRequest.config, | ||
headers: { | ||
...(config.headers || {}), | ||
...(apiRequest.config.headers || {}), | ||
...headers | ||
@@ -148,3 +161,3 @@ } | ||
} | ||
if (error.name === index_js_2.EBayInvalidAccessToken.name) { | ||
if (error.name === index_js_1.EBayInvalidAccessToken.name) { | ||
return true; | ||
@@ -155,5 +168,5 @@ } | ||
async request(apiRequest, apiConfig = this.apiConfig, refreshToken = false) { | ||
const { url, method, data, config } = apiRequest; | ||
const { path, method, data } = apiRequest; | ||
const apiCfg = { ...this.apiConfig, ...apiConfig }; | ||
const endpoint = this.getServerUrl(apiCfg) + url; | ||
const endpoint = this.getServerUrl(apiCfg) + path; | ||
try { | ||
@@ -163,3 +176,3 @@ if (refreshToken) { | ||
} | ||
const enrichedConfig = await this.enrichRequestConfig(config, apiCfg); | ||
const enrichedConfig = await this.enrichRequestConfig(apiRequest, data, apiCfg); | ||
const args = ['get', 'delete'].includes(method) ? [enrichedConfig] : [data, enrichedConfig]; | ||
@@ -176,3 +189,3 @@ // @ts-ignore | ||
catch (ex) { | ||
(0, index_js_2.handleEBayError)(ex); | ||
(0, index_js_1.handleEBayError)(ex); | ||
} | ||
@@ -179,0 +192,0 @@ } |
@@ -0,3 +1,3 @@ | ||
import { ClientAlerts, Finding, Merchandising, Shopping, Trading } from '../../types/index.js'; | ||
import Api from '../index.js'; | ||
import { ClientAlerts, Finding, Merchandising, Shopping, Trading } from '../../types/index.js'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Traditional eBay API. |
@@ -30,4 +30,4 @@ "use strict"; | ||
const qs_1 = require("qs"); | ||
const index_js_1 = __importDefault(require("../index.js")); | ||
const index_js_2 = require("../../errors/index.js"); | ||
const index_js_1 = require("../../errors/index.js"); | ||
const index_js_2 = __importDefault(require("../index.js")); | ||
const index_js_3 = __importDefault(require("./clientAlerts/index.js")); | ||
@@ -42,3 +42,3 @@ const index_js_4 = __importDefault(require("./finding/index.js")); | ||
*/ | ||
class Traditional extends index_js_1.default { | ||
class Traditional extends index_js_2.default { | ||
constructor() { | ||
@@ -53,3 +53,3 @@ super(...arguments); | ||
// Try to refresh the token. | ||
if (this.config.autoRefreshToken && (error.name === index_js_2.EBayIAFTokenExpired.name || error.name === index_js_2.EBayIAFTokenInvalid.name)) { | ||
if (this.config.autoRefreshToken && (error.name === index_js_1.EBayIAFTokenExpired.name || error.name === index_js_1.EBayIAFTokenInvalid.name)) { | ||
return await this.request(apiConfig, api, callName, fields, true); | ||
@@ -62,5 +62,2 @@ } | ||
createTradingApi() { | ||
if (!this.config.devId) { | ||
throw new Error('devId is required for trading API.'); | ||
} | ||
if (typeof this.config.siteId !== 'number') { | ||
@@ -71,5 +68,6 @@ throw new Error('siteId is required for trading API.'); | ||
endpoint: { | ||
production: 'https://api.ebay.com/ws/api.dll', | ||
sandbox: 'https://api.sandbox.ebay.com/ws/api.dll' | ||
production: 'api.ebay.com', | ||
sandbox: 'api.sandbox.ebay.com' | ||
}, | ||
path: '/ws/api.dll', | ||
calls: index_js_7.default, | ||
@@ -94,5 +92,6 @@ xmlns: 'urn:ebay:apis:eBLBaseComponents', | ||
endpoint: { | ||
production: 'https://open.api.ebay.com/shopping', | ||
sandbox: 'https://open.api.sandbox.ebay.com/shopping' | ||
production: 'open.api.ebay.com', | ||
sandbox: 'open.api.sandbox.ebay.com' | ||
}, | ||
path: '/shopping', | ||
xmlns: 'urn:ebay:apis:eBLBaseComponents', | ||
@@ -113,5 +112,6 @@ calls: index_js_6.default, | ||
endpoint: { | ||
production: 'https://svcs.ebay.com/services/search/FindingService/v1', | ||
sandbox: 'https://svcs.sandbox.ebay.com/services/search/FindingService/v1' | ||
production: 'svcs.ebay.com', | ||
sandbox: 'svcs.sandbox.ebay.com' | ||
}, | ||
path: '/services/search/FindingService/v1', | ||
xmlns: 'http://www.ebay.com/marketplace/search/v1/services', | ||
@@ -131,5 +131,6 @@ calls: index_js_4.default, | ||
endpoint: { | ||
production: 'https://clientalerts.ebay.com/ws/ecasvc/ClientAlerts', | ||
sandbox: 'https://clientalerts.sandbox.ebay.com/ws/ecasvc/ClientAlerts' | ||
production: 'clientalerts.ebay.com', | ||
sandbox: 'clientalerts.sandbox.ebay.com' | ||
}, | ||
path: '/ws/ecasvc/ClientAlerts', | ||
calls: index_js_3.default | ||
@@ -168,5 +169,6 @@ }; | ||
endpoint: { | ||
production: 'https://svcs.ebay.com/MerchandisingService', | ||
sandbox: 'https://svcs.sandbox.ebay.com/MerchandisingService' | ||
production: 'svcs.ebay.com', | ||
sandbox: 'svcs.sandbox.ebay.com' | ||
}, | ||
path: '/MerchandisingService', | ||
xmlns: 'http://www.ebay.com/marketplace/services', | ||
@@ -193,3 +195,3 @@ calls: index_js_5.default, | ||
catch (e) { | ||
(0, index_js_2.handleEBayError)(e); | ||
(0, index_js_1.handleEBayError)(e); | ||
} | ||
@@ -201,6 +203,7 @@ } | ||
const useIaf = !eBayAuthToken && accessToken; | ||
const host = this.config.sandbox ? api.endpoint.sandbox : api.endpoint.production; | ||
return { | ||
...apiConfig, | ||
xmlns: api.xmlns, | ||
endpoint: api.endpoint[this.config.sandbox ? 'sandbox' : 'production'], | ||
endpoint: `https://${host}${api.path}`, | ||
headers: { | ||
@@ -210,2 +213,9 @@ ...api.headers(callName, useIaf ? accessToken : null), | ||
}, | ||
digitalSignatureHeaders: payload => { | ||
return apiConfig.sign ? this.getDigitalSignatureHeaders({ | ||
method: 'POST', | ||
authority: host, | ||
path: api.path | ||
}, payload) : {}; | ||
}, | ||
...(!useIaf ? { eBayAuthToken } : {}) | ||
@@ -212,0 +222,0 @@ }; |
@@ -37,2 +37,3 @@ import { XMLBuilder } from 'fast-xml-parser'; | ||
useIaf?: boolean; | ||
sign?: boolean; | ||
hook?: (xml: string) => BodyHeaders; | ||
@@ -44,2 +45,3 @@ } & ApiRequestConfig; | ||
eBayAuthToken?: string | null; | ||
digitalSignatureHeaders?: (payload: any) => Headers; | ||
}; | ||
@@ -68,3 +70,3 @@ export declare const defaultApiConfig: Required<Omit<TraditionalApiConfig, 'hook'>>; | ||
*/ | ||
constructor(callName: string, fields: Fields, config: XMLReqConfig, req: IEBayApiRequest); | ||
constructor(callName: string, fields: Fields | null, config: XMLReqConfig, req: IEBayApiRequest); | ||
/** | ||
@@ -71,0 +73,0 @@ * returns the expected name of XML node of a Request |
@@ -41,2 +41,3 @@ "use strict"; | ||
useIaf: true, | ||
sign: false, | ||
headers: {}, | ||
@@ -147,2 +148,3 @@ returnResponse: false | ||
...this.getHeaders(), | ||
...this.config.digitalSignatureHeaders ? this.config.digitalSignatureHeaders(body) : {}, | ||
...(headers ? headers : {}) | ||
@@ -149,0 +151,0 @@ } |
@@ -14,3 +14,3 @@ import Api from './api/index.js'; | ||
import * as types from './types/index.js'; | ||
import { AppConfig, ClientAlerts, Finding, Merchandising, Shopping, Trading } from './types/index.js'; | ||
import { AppConfig, ClientAlerts, Finding, Merchandising, Shopping, Signature, Trading } from './types/index.js'; | ||
export default class eBayApi extends Api { | ||
@@ -58,3 +58,4 @@ static readonly SiteId: typeof enums.SiteId; | ||
get clientAlerts(): ClientAlerts; | ||
setSignature(signature: Signature): void; | ||
} | ||
export { eBayApi, SiteId, MarketplaceId, ContentLanguage, Locale, enums, errors, types }; |
@@ -68,2 +68,9 @@ "use strict"; | ||
} | ||
let signature = null; | ||
if (process.env.EBAY_JWE && process.env.EBAY_PRIVATE_KEY) { | ||
signature = { | ||
jwe: process.env.EBAY_JWE, | ||
privateKey: process.env.EBAY_PRIVATE_KEY | ||
}; | ||
} | ||
return new eBayApi({ | ||
@@ -79,3 +86,4 @@ appId: process.env.EBAY_APP_ID, | ||
ruName: process.env.EBAY_RU_NAME, | ||
sandbox: (process.env.EBAY_SANDBOX === 'true') | ||
sandbox: (process.env.EBAY_SANDBOX === 'true'), | ||
signature | ||
}, req); | ||
@@ -126,2 +134,5 @@ } | ||
} | ||
setSignature(signature) { | ||
this.config.signature = signature; | ||
} | ||
} | ||
@@ -128,0 +139,0 @@ exports.default = eBayApi; |
@@ -131,2 +131,7 @@ "use strict"; | ||
} | ||
else if (typeof data === 'string') { | ||
eBayError = { | ||
message: data | ||
}; | ||
} | ||
else { | ||
@@ -133,0 +138,0 @@ eBayError = data; |
@@ -19,2 +19,8 @@ import { AxiosRequestConfig } from 'axios'; | ||
}; | ||
export type Cipher = 'sha256' | 'sha512'; | ||
export type Signature = { | ||
cipher?: Cipher; | ||
jwe: string; | ||
privateKey: string; | ||
}; | ||
export type eBayConfig = Keyset & { | ||
@@ -24,2 +30,3 @@ sandbox: boolean; | ||
scope?: Scope; | ||
signature?: Signature | null; | ||
} & TraditionalConfig & RestConfig; | ||
@@ -26,0 +33,0 @@ export type ApiConfig = { |
@@ -8,3 +8,3 @@ import ClientAlertsCalls from '../api/traditional/clientAlerts/index.js'; | ||
import { TraditionalApiConfig } from '../api/traditional/XMLRequest.js'; | ||
export type XMLApiCall = (fields?: Fields, apiConfig?: TraditionalApiConfig) => Promise<any>; | ||
export type XMLApiCall = (fields?: Fields | null, apiConfig?: TraditionalApiConfig) => Promise<any>; | ||
export type Trading = { | ||
@@ -32,2 +32,3 @@ [key in typeof TradingCalls[number]]: XMLApiCall; | ||
xmlns: string; | ||
path: string; | ||
calls: typeof TradingCalls | typeof ShoppingCalls | typeof FindingCalls | typeof ClientAlertsCalls | typeof MerchandisingCalls; | ||
@@ -34,0 +35,0 @@ headers: (callName: string, accessToken?: string | null) => object; |
{ | ||
"name": "ebay-api", | ||
"author": "Daniil Tomilow", | ||
"version": "8.3.0", | ||
"version": "8.4.0", | ||
"description": "eBay API for Node and Browser", | ||
@@ -98,2 +98,3 @@ "type": "module", | ||
"@rollup/plugin-terser": "^0.2.0", | ||
"@rollup/plugin-virtual": "^3.0.1", | ||
"@types/chai": "^4.3.4", | ||
@@ -100,0 +101,0 @@ "@types/debug": "^4.1.7", |
@@ -24,3 +24,3 @@ # eBay Node API in TypeScript with Browser support | ||
* `v8.3.0` is the latest release. | ||
* `v8.4.0` is the latest release. | ||
* See [here](https://github.com/hendt/ebay-api/blob/master/CHANGELOG.md) for the full changelog. | ||
@@ -310,2 +310,37 @@ | ||
## Digital Signature | ||
Signatures are required when the call is made for EU- or UK-domiciled sellers, and only for the following APIs/methods: | ||
* All methods in the Finances API | ||
* issueRefund in the Fulfillment API | ||
* GetAccount in the Trading API | ||
* The following methods in the Post-Order API: | ||
- Issue Inquiry Refund | ||
- Issue case refund | ||
- Issue return refund | ||
- Process Return Request | ||
- Create Cancellation Request | ||
- Approve Cancellation Request | ||
### How to use Digital Signature | ||
```js | ||
// 1. Create singning key and save it appropriatly | ||
const signingKey = await eBay.developer.keyManagement.createSigningKey('ED25519'); | ||
// 2. Set the signature | ||
eBay.setSignature(signingKey) | ||
// or in constructor | ||
eBay = new eBayApi({ | ||
appId: '...', | ||
certId: '...', | ||
signature: { | ||
jwe: signingKey.jwe, | ||
privateKey: signingKey.privateKey | ||
} | ||
}); | ||
// 3. Use the 'sign' keyword in Restful API | ||
const summary = await eBay.sell.finances.sign.getSellerFundsSummary(); | ||
// 3. Or the 'sign' parameter in traditional API | ||
const account = await eBay.trading.GetAccount(null, {sign: true}); | ||
``` | ||
## RESTful API | ||
@@ -312,0 +347,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 8 instances in 1 package
1988835
268
37447
648
24
68