Skip to content

Commit

Permalink
feat!: output esm and cjs
Browse files Browse the repository at this point in the history
 * upgrade fast-xml-parser to version 4
  • Loading branch information
dantio committed Dec 8, 2022
1 parent 1e34c48 commit b37d96e
Show file tree
Hide file tree
Showing 100 changed files with 2,313 additions and 7,164 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
lib
dist
*.sublime*
*.log
*.iml
Expand Down
7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extension": [
"ts"
],
"spec": "test/**/*.spec.ts",
"loader": "ts-node/esm"
}
10 changes: 9 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
*.log
*.enc
src
Expand All @@ -13,4 +14,11 @@ proxy
.github
index.html
.travis.yml
rollup.config.js
rollup.config.js
.babelrc
.mocharc.json
.versionrc.json
tsconfig.cjs.json
CHANGELOG.md
SUMMARY.md
CONTRIBUTING.md
110 changes: 58 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ console.log(JSON.stringify(item, null, 2));
```

#### Detailed configuration example

```javascript
import eBayApi from 'ebay-api';

Expand All @@ -85,15 +86,15 @@ const eBay = new eBayApi({
sandbox: false,

siteId: eBayApi.SiteId.EBAY_US, // required for traditional APIs, see https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html
marketplaceId: eBayApi.MarketplaceId.EBAY_US, // defautl. required for RESTful APIs

marketplaceId: eBayApi.MarketplaceId.EBAY_US, // defautl. required for RESTful APIs
acceptLanguage: eBayApi.Locale.en_US, // defautl
contentLanguage: eBayApi.ContentLanguage.en_US, // defautl.

// optional parameters, should be omitted if not used
devId: '-- devId --', // required for traditional Trading API
ruName: '-- eBay Redirect URL name --', // 'RuName' (eBay Redirect URL name) required for authorization code grant

authToken: '-- Auth\'n\'Auth for traditional API (used by trading) --', // can be set to use traditional API without code grant
});
```
Expand All @@ -106,28 +107,28 @@ For testing purpose you can use `https://ebay.hendt.workers.dev/` url as proxy.

Or use [https://github.com/Rob--W/cors-anywhere](CORS Anywhere is a NodeJS proxy) (works very well with heroku.com).


```html

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ebay-api@latest/lib/ebay-api.min.js"></script>
<script>
const eBay = new eBayApi({
appId: 'appId',
certId: 'certId',
sandbox: false
});
appId: 'appId',
certId: 'certId',
sandbox: false
});
// 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.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 => {
console.log(JSON.stringify(item, null, 2));
}).catch(e => {
console.error(e);
});
eBay.buy.browse.getItem('v1|254188828753|0').then(item => {
console.log(JSON.stringify(item, null, 2));
}).catch(e => {
console.error(e);
});
</script>
```

Expand Down Expand Up @@ -237,7 +238,7 @@ app.get('/success', async function(req, res) {
// 5. Start using the API
const orders = await eBay.sell.fulfillment.getOrders()
res.send(orders);
} catch(e) {
} catch (e) {
console.error(e)
res.sendStatus(400)
}
Expand All @@ -258,17 +259,17 @@ app.get('/orders/:id', async function(req, res) {
}

eBay.OAuth2.setCredentials(token);

// If token get's refreshed
eBay.OAuth2.on('refreshAuthToken', (token) => {
req.session.token = token;
});

try {
// 5. Start using the API
const order = await eBay.sell.fulfillment.getOrder(id);
res.send(order);
} catch(e) {
} catch (e) {
console.error(e)
res.sendStatus(400)
}
Expand Down Expand Up @@ -342,14 +343,17 @@ You have multiple options to do this.


### RESTful API headers

```javascript
const eBay = new eBayApi();

eBay.buy.browse.api({headers: {
'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
}}).getItem('v1|382282567190|651094235351').then((item) => {
console.log(item)
})
eBay.buy.browse.api({
headers: {
'X-EBAY-SOA-GLOBAL-ID': 'EBAY-DE'
}
}).getItem('v1|382282567190|651094235351').then((item) => {
console.log(item)
})
```

### Traditional API headers
Expand All @@ -370,15 +374,17 @@ eBay.trading.AddFixedPriceItem({
```

### Low level: use the Axios interceptor to manipulate the request

```javascript
import eBayApi from 'ebay-api';
const eBay = new eBayApi(/* { your config here } */);

eBay.req.instance.interceptors.request.use((request) => {
// Add Header
request.headers['X-EBAY-SOA-GLOBAL-ID'] = 'EBAY-DE';
return request;
})
import eBayApi from 'ebay-api';

const eBay = new eBayApi(/* { your config here } */);

eBay.req.instance.interceptors.request.use((request) => {
// Add Header
request.headers['X-EBAY-SOA-GLOBAL-ID'] = 'EBAY-DE';
return request;
})
```

### Handle JSON GZIP response e.g fetchItemAspects
Expand All @@ -389,26 +395,26 @@ npm install zlib # or yarn add zlib
```

```javascript
import eBayApi from 'ebay-api';
import zlib from 'zlib';
import eBayApi from 'ebay-api';
import zlib from 'zlib';

const toString = (data) => new Promise((resolve) => {
zlib.gunzip(data, (err, output) => {
if (err) throw err;
resolve(output.toString());
});
const toString = (data) => new Promise((resolve) => {
zlib.gunzip(data, (err, output) => {
if (err) throw err;
resolve(output.toString());
});
});

const eBay = new eBayApi(/* { your config here } */);
const eBay = new eBayApi(/* { your config here } */);

try {
const data = await eBay.commerce.taxonomy.fetchItemAspects(/* categoryTreeId */);
const result = await toString(data);
console.log(result)
} catch (e) {
console.error(e);
}
try {
const data = await eBay.commerce.taxonomy.fetchItemAspects(/* categoryTreeId */);
const result = await toString(data);

console.log(result)
} catch (e) {
console.error(e);
}
```

## Controlling Traditional XML request and response
Expand Down
2 changes: 1 addition & 1 deletion examples/restful/authFlow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable:no-console
import readline from 'readline';
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();
eBay.OAuth2.setScope([
Expand Down
2 changes: 1 addition & 1 deletion examples/restful/buy/browse.getShoppingCart.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/buy/browse.search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/buy/items.getItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/buy/marketing.getAlsoBoughtProducts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/postOrder/inquiry.getInquiry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/postOrder/return.getReturn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/sell/account.getPrivileges.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/sell/fullfillment.getOrder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/restful/sell/getOrders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../../src';
import eBayApi from '../../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/authNAuth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable:no-console
// @ts-ignore
import readline from 'readline';
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();
// DOCS: https://developer.ebay.com/devzone/xml/docs/howto/tokens/gettingtokens.html
Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/clientAlerts.GetPublicAlerts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

import {EventType} from '../../src/api/traditional/clientAlerts';

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/finding.findItemsAdvanced.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable:no-console
// @ts-ignore
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/merchandising.getMostWatchedItems.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/shopping.GetUserProfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable:no-console
// @ts-ignore
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/trading.GetMyMessages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/trading.GetMyeBaySelling.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/trading.GetSingleItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/trading.GeteBayOfficialTime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';

const eBay = eBayApi.fromEnv();

Expand Down
2 changes: 1 addition & 1 deletion examples/traditional/trading.UploadSiteHostedPictures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable:no-console
import eBayApi from '../../src';
import eBayApi from '../../src/eBayApi.js';
import * as fs from 'fs';
import * as path from 'path';
import FormData from 'form-data';
Expand Down

0 comments on commit b37d96e

Please sign in to comment.