Skip to content

Commit

Permalink
chore!: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dantio committed Mar 9, 2021
2 parents 2028bc6 + a98293b commit bcb3a5e
Show file tree
Hide file tree
Showing 32 changed files with 1,047 additions and 1,123 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ A Proxy server is required to use the API in the Browser.

For testing purpose you can use: `https://ebay.hendt.workers.dev/`. You can also setup your own Proxy server. We have added a example for cloudfront workers: [https://github.com/hendt/ebay-api/blob/master/proxy/worker.js](https://github.com/hendt/ebay-api/blob/master/proxy/worker.js)

```markup
```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@hendt/ebay-api@latest/lib/ebay-api.min.js"></script>
<script>
const eBay = new eBayApi({
Expand All @@ -60,14 +60,13 @@ For testing purpose you can use: `https://ebay.hendt.workers.dev/`. You can also
sandbox: true,
siteId: 77,
});
interceptors: {
request: (request) => {
// Add Proxy
request.url = 'https://ebay.hendt.workers.dev/' + request.url;
return request;
}
}
// eBay.req.instance is AxiosInstance per default
eBay.req.instance.interceptors.request.use((request) => {
// Add Proxy
request.url = 'https://ebay.hendt.workers.dev/' + request.url;
return request;
});
eBay.buy.browse.getItem('v1|254188828753|0').then(item => {
Expand Down Expand Up @@ -115,8 +114,6 @@ The first parameter in eBayApi:
| endUserCtx | Optional – Conditionally recommended. REST HTTP Header. X-EBAY\_C\_ENDUSERCTX provides various types of information associated with the request. |
| contentLanguage | Conditionally required. REST HTTP Header. Content-Language indicates the locale preferred by the client for the response. |
| acceptLanguage | Optional. REST HTTP Header. Accept-Language indicates the natural language the client prefers for the response. This specifies the language the client wants to use when the field values provided in the request body are displayed to consumers. |
| interceptors | Optional. Intercept request with [Axios interceptors](https://github.com/axios/axios#interceptors). See example in 'Browser' usage above. |
| maxRequests | Max request per day. Default to '5000'. |

**\***: Required

Expand Down Expand Up @@ -235,6 +232,18 @@ const zlib = require('zlib');
};)();
```
## Traditional XML response
The second parameter in the traditional API has the following options:
```ts
export type Options = {
raw?: boolean, // return raw XML
cleanup?: boolean, // remove extraneous tags like '@', 'Ack',
parseOptions?: object, // https://github.com/NaturalIntelligence/fast-xml-parser
useIaf?: boolean // use IAF in header instead of Bearer
};
```
## Examples
### Trading - AddFixedPriceItem \(CDATA\)
Expand Down Expand Up @@ -320,6 +329,7 @@ Check [here](https://github.com/hendt/ebay-api/blob/master/CONTRIBUTING.md)
## Supported By
[hendt.de](https://hendt.de)
[rootle.de](https://rootle.de)
## Similar projects
Expand Down
34 changes: 18 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
</style>
</head>
<body>
<!-- script type="text/javascript" src="./lib/ebay-api.min.js"></script -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@hendt/ebay-api@latest/lib/ebay-api.min.js"></script>
<link rel="stylesheet"
href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.18.1/build/styles/default.min.css">
Expand Down Expand Up @@ -105,23 +106,24 @@ <h1>eBay API Browser example</h1>
<script type="text/javascript">
const form = document.forms[0]
const code = document.getElementById('code')
function createApi () {
code.innerText = 'loading...'
return new eBayApi({
appId: form.appId.value,
certId: form.certId.value,
devId: form.devId.value,

sandbox: form.sandbox.checked,
siteId: form.siteId.value,

interceptors: {
request: (request) => {
request.url = 'https://ebay.hendt.workers.dev/' + request.url;
return request;
}
}

function createApi() {
code.innerText = 'Loading...'
const eBay = new eBayApi({
appId: form.appId.value,
certId: form.certId.value,
devId: form.devId.value,

sandbox: form.sandbox.checked,
siteId: form.siteId.value,
});

eBay.req.instance.interceptors.request.use((request) => {
request.url = 'https://ebay.hendt.workers.dev/' + request.url;
return request;
})

return eBay
}

function handleError(e) {code.innerText = e.message}
Expand Down
13 changes: 4 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
"types": "./lib/index.d.js",
"dependencies": {
"axios": "^0.21.1",
"axios-rate-limit": "^1.1.2",
"debug": "^2.1.1",
"fast-xml-parser": "^3.13.0",
"fast-xml-parser": "^3.18.0",
"nanoevents": "^2.0.0",
"qs": "^6.8.0"
},
Expand Down Expand Up @@ -41,7 +40,7 @@
"prepare": "npm run build",
"tslint": "tslint -c tslint.json 'src/**/*.ts'",
"test": "mocha -r ts-node/register 'test/**/*.spec.ts' --reporter=dot",
"prerelease": "npm run test && npm run build",
"prerelease": "npm run tslint && npm run test && npm run build",
"release": "standard-version"
},
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions src/api/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Auth from '../auth';
import {createRequest, ILimitedRequest} from '../utils/request';
import {createRequest, IEBayApiRequest} from '../request';
import Api from './restful/';
import {Browse, Buy, Feed, Marketing as BuyMarketing, Offer, Order} from './restful/buy';
import {Catalog, Commerce, Identity, Taxonomy, Translation} from './restful/commerce';
Expand All @@ -24,14 +24,14 @@ import {ClientAlerts, Finding, Shopping, Trading} from '../types/traditonalTypes
*/
export default class Factory {
public readonly auth: Auth;
public readonly req: ILimitedRequest;
public readonly req: IEBayApiRequest;

private _traditional?: Traditional;
private _restful: any = {}

constructor(
auth: Auth,
req: ILimitedRequest = createRequest()
req: IEBayApiRequest = createRequest()
) {
this.auth = auth;
this.req = req;
Expand Down
6 changes: 3 additions & 3 deletions src/api/restful/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
EBayUnauthorizedAfterRefresh,
getEBayError
} from '../../errors';
import {createRequest, ILimitedRequest} from '../../utils/request';
import {createRequest, IEBayApiRequest} from '../../request';

const log = debug('ebay:restful:api');

export default abstract class Api {
public readonly auth: Auth;
public readonly req: ILimitedRequest;
public readonly req: IEBayApiRequest;

constructor(auth: Auth, req = createRequest()) {
this.auth = auth;
Expand Down Expand Up @@ -90,7 +90,7 @@ export default abstract class Api {
return this.doRequest('put', url, config, data);
}

private async doRequest(method: keyof ILimitedRequest, url: string, config: any, data?: any): Promise<any> {
private async doRequest(method: keyof IEBayApiRequest, url: string, config: any, data?: any): Promise<any> {
try {
const args = await this.getArgs(method, url, config, data);
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions src/api/restful/postOrder/return/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Api from '../../';
import {FilePurposeEnum, GetReturnFieldGroupEnum} from '../../../../enums/enums';
import {FilePurpose, GetReturnFieldGroupEnum} from '../../../../enums';
import {
CheckEligibilityRequest,
CloseReturnRequest,
Expand Down Expand Up @@ -344,7 +344,7 @@ export default class Return extends Api {
* about the condition of the item, or intended to provide more information about shipment tracking or about
* the shipping label.
*/
public submitReturnFile(returnId: string, filePurpose?: FilePurposeEnum) {
public submitReturnFile(returnId: string, filePurpose?: FilePurpose) {
const id = encodeURIComponent(returnId);
return this.post(`/${id}/file/submit`, {
filePurpose
Expand Down
4 changes: 2 additions & 2 deletions src/api/restful/sell/fulfillment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export default class Fulfillment extends Api {
*/
public getOrders({
filter, limit, offset, orderIds
}: { filter?: string, limit?: number, offset?: number, orderIds?: string[] } = {}) {
}: { filter?: string, limit?: number, offset?: number, orderIds?: string | string[]} = {}) {
return this.get(`/order`, {
params: {
filter,
limit,
offset,
orderIds
orderIds: Array.isArray(orderIds) ? orderIds.join() : orderIds
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/restful/sell/marketing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ItemPromotion,
UpdateBidPercentageRequest,
UpdateCampaignIdentificationRequest
} from '../../../../types/restfulTypes';
} from '../../../../types';

/**
* <p>The <i>Marketing API </i> offers two platforms that sellers can use to promote and advertise their products:
Expand Down Expand Up @@ -291,7 +291,7 @@ export default class Marketing extends Api {
}

/**
*This method deletes the campaign specified by the campaign_id query parameter.
* This method deletes the campaign specified by the campaign_id query parameter.
*
* @param campaignId A unique eBay-assigned ID for an ad campaign that's generated when a campaign is created. Get
* a seller's campaign IDs by calling getCampaigns.
Expand Down
Loading

0 comments on commit bcb3a5e

Please sign in to comment.