Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
fix: eliminate MWSSimple.d.ts as dependent packages couldn't access it
Browse files Browse the repository at this point in the history
- oops
- also let's see if semantic-release will start releasing the right thing now
  • Loading branch information
ericblade committed Jan 15, 2020
1 parent 50e488c commit d9d5e9c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[![codebeat badge](https://codebeat.co/badges/8645439c-2be6-4c45-acca-aaf6ac449531)](https://codebeat.co/projects/github-com-ericblade-mws-simple-master)
# mws-simple

**[![codebeat badge](https://codebeat.co/badges/8645439c-2be6-4c45-acca-aaf6ac449531)](https://codebeat.co/projects/github-com-ericblade-mws-simple-master)**

[![Join the chat at https://gitter.im/mws-advanced/Lobby](https://badges.gitter.im/mws-advanced/Lobby.svg)](https://gitter.im/mws-advanced/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

nodejs Amazon MWS API in (about) 250 lines of code

Which means that you will have to do more work in order to make api calls but gives you the most control. Response uses xml2js or csv-parse for conversion.

If you are looking to do something with MWS, but not involve yourself in all the raw data handling,
you may want to have a look at mws-advanced: http://www.github.com/ericblade/mws-advanced
you may want to have a look at [mws-advanced](http://www.github.com/ericblade/mws-advanced)

Defaults to US marketplace settings, but can code to override default

Expand All @@ -21,7 +22,7 @@ npm install @ericblade/mws-simple

## Usage

###### Initialize
### Initialize

``` javascript
let mws = require('mws-simple')({
Expand All @@ -31,7 +32,7 @@ let mws = require('mws-simple')({
});
```

###### Build a request object containing `query` and optionally `path`, `headers`, and `feedContent`
### Build a request object containing `query` and optionally `path`, `headers`, and `feedContent`

Of the [required parameters](http://docs.developer.amazonservices.com/en_US/dev_guide/DG_RequiredRequestParameters.html), `AWSAccessKeyId`, `SellerId`, `Signature`, `SignatureMethod`, `SignatureVersion`, and `Timestamp` will be taken care of but most can be overridden. This leaves `Action`, `MWSAuthToken` (for web applications and third-party developer authorizations only), and `Version` required to be populated.

Expand All @@ -41,16 +42,17 @@ If the API has an endpoint as specified in the documentation, put the endpoint i

For uploading data to MWS, populate `feedContent` with a `buffer` of data.

###### Invoke `request` with your request object
###### [Callback]
#### Invoke `request` with your request object

##### [Callback]

````
mws.request(requestObj, function (err, {res, headers}) {
....
});
````

###### [Promise]
##### [Promise]
````
mws.request(requestObj)
.then(({result, headers}) => {
Expand All @@ -61,7 +63,7 @@ mws.request(requestObj)
});
````

###### Check your error, response, and headers
##### Check your error, response, and headers

Note that there are two arguments that should be used for the callback:

Expand All @@ -81,7 +83,8 @@ the names to all lower-case, so x-mws-quota-resetsOn is actually x-mws-quota-res

## Examples

### List Orders (open and created in last 24 hours):
### List Orders (open and created in last 24 hours)

``` javascript
let date = new Date();
date.setDate(date.getDate() - 1);
Expand Down Expand Up @@ -113,7 +116,8 @@ mws.request(listOrders)
});
```

### Submit Shipments File:
### Submit Shipments File

``` javascript
let submitFeed = {
feedContent: require('fs').readFileSync('amazon-shipments.tab'),
Expand Down
2 changes: 1 addition & 1 deletion src/makeRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import request, {
UrlOptions,
} from 'request';
import { IncomingHttpHeaders } from 'http';
import { DebugOptions } from './types/MWSSimple.d';
import { DebugOptions } from './mws-simple';

import syncWriteToFile from './syncWriteToFile';
import ServerError from './ServerError';
Expand Down
17 changes: 16 additions & 1 deletion src/mws-simple.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { IncomingHttpHeaders } from 'http';
import crypto from 'crypto';
import { ConstructorParams, DebugOptions } from './types/MWSSimple.d';
import ServerError from './ServerError';
import makeRequest from './makeRequest';
import makeSignature from './makeSignature';
import getContentType from './getContentType';

const { name: pkgAppId, version: pkgAppVersionId } = require('../package.json');

export interface ConstructorParams {
appId?: string,
appVersionId?: string,
host?: string,
port?: number,
accessKeyId?: string,
secretAccessKey?: string,
merchantId?: string,
authToken?: string,
}

export interface DebugOptions {
rawFile?: string,
parsedFile?: string,
}

class MWSSimple {
accessKeyId: string = '';

Expand Down
6 changes: 5 additions & 1 deletion src/processRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { parseString as xmlParser } from 'xml2js';
import tabParser from 'csv-parse';
import { ResultsObj } from './types/MWSSimple.d';

export interface ResultsObj {
contentType: string,
body: string,
}

const processXmlRequest = (
body: string,
Expand Down
21 changes: 0 additions & 21 deletions src/types/MWSSimple.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
import { IncomingHttpHeaders } from 'http';

export interface ConstructorParams {
appId?: string,
appVersionId?: string,
host?: string,
port?: number,
accessKeyId?: string,
secretAccessKey?: string,
merchantId?: string,
authToken?: string,
}

export interface DebugOptions {
rawFile?: string,
parsedFile?: string,
}

export interface ResultsObj {
contentType: string,
body: string,
}

0 comments on commit d9d5e9c

Please sign in to comment.