Skip to content

Commit 0216b0e

Browse files
authored
Merge pull request #189 from SparkPost/wip-2.0.0
Releasing version 2.0.0
2 parents 8d8ef7d + 039c9f9 commit 0216b0e

File tree

167 files changed

+4033
-4271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+4033
-4271
lines changed

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "sparkpost/api",
3+
"globals": {
4+
"Promise": true
5+
}
6+
}

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"node" : true,
33
"es3" : false,
4+
"esnext" : true,
45
"strict" : true,
56
"curly" : true,
67
"eqeqeq" : true,

.travis.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
language: node_js
22
node_js:
3-
- '4.1'
4-
- '4.0'
5-
- '0.12'
6-
- '0.10'
7-
before_install: npm install -g grunt-cli
8-
install: npm install
9-
script: "npm run-script ci"
3+
- '4'
4+
- '5'
5+
- '6'
6+
after_success:
7+
- npm run coveralls
108
notifications:
119
slack:
1210
secure: dsz+D/TuylEi+6zqdB5dVqyMlpbpafaBBcAwYIijTK6LuG8KdIdGNSFVX1ro6o3bJFwMvtfxNeK1eFrMy8l6VHZQL0dkXWRmCl/pxLhEntUiYTDwDOtiqy1QLZtv5AqtsdSr1qLiOJtgF6gXk66xipnV2UzjLVVoxzSrdOSnX4U=

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [Unreleased][unreleased]
66

7+
## [2.0.0] - 2016-11-04 - *breaking*
8+
- [#188](https://github.com/SparkPost/node-sparkpost/pull/188) Added setting debug in initialization (@aydrian)
9+
- [#186](https://github.com/SparkPost/node-sparkpost/pull/186) Return full body for sparkpost requests (@aydrian)
10+
- [#184](https://github.com/SparkPost/node-sparkpost/pull/184) Standardized action verbs on remaining libraries (@aydrian)
11+
- [#183](https://github.com/SparkPost/node-sparkpost/pull/183) Standardized action verbs for Webhooks (@aydrian)
12+
- [#181](https://github.com/SparkPost/node-sparkpost/pull/181) Removed toApiFormat (@aydrian)
13+
- [#177](https://github.com/SparkPost/node-sparkpost/pull/177) Refactored inbound domains library (@aydrian)
14+
- [#173](https://github.com/SparkPost/node-sparkpost/pull/173) Updated tests and examples for transmissions (@aydrian)
15+
- [#172](https://github.com/SparkPost/node-sparkpost/pull/172) Refactored subaccounts library (@aydrian)
16+
- [#171](https://github.com/SparkPost/node-sparkpost/pull/171) Refactored relay webhooks library (@aydrian)
17+
- [#170](https://github.com/SparkPost/node-sparkpost/pull/170) Refactored webhooks library (@aydrian)
18+
- [#169](https://github.com/SparkPost/node-sparkpost/pull/169) Refactored templates library (@aydrian)
19+
- [#168](https://github.com/SparkPost/node-sparkpost/pull/168) Refactored suppression list library (@aydrian)
20+
- [#167](https://github.com/SparkPost/node-sparkpost/pull/167) Refactored sending domains library (@aydrian)
21+
- [#166](https://github.com/SparkPost/node-sparkpost/pull/166) Refactored recipient lists library (@aydrian)
22+
- [#163](https://github.com/SparkPost/node-sparkpost/pull/163) Set options.json=true for GET requests (@aydrian)
23+
- [#162](https://github.com/SparkPost/node-sparkpost/pull/162) Removed SendGrid Compatibility (@aydrian)
24+
- [#160](https://github.com/SparkPost/node-sparkpost/pull/160) Switch to using npm scripts instead of grunt (@aydrian)
25+
- [#159](https://github.com/SparkPost/node-sparkpost/pull/159) Switched JSHint for ESLint with SparkPost config (@aydrian)
26+
- [#158](https://github.com/SparkPost/node-sparkpost/pull/158) Refactored transmissions library (@aydrian)
27+
- [#157](https://github.com/SparkPost/node-sparkpost/pull/157) Removed support for nodejs versions .10 & .12 (@aydrian)
28+
- [#154](https://github.com/SparkPost/node-sparkpost/pull/154) Implement promise support (@aydrian)
29+
- [#123](https://github.com/SparkPost/node-sparkpost/pull/123) Added json flag to base request and tests to check for JSON response (@aydrian)
30+
- [#112](https://github.com/SparkPost/node-sparkpost/pull/112) Returns body.results or body as a response. Added debug support. (@aydrian)
31+
732
## [1.3.8] - 2016-08-26
833
- [#165](https://github.com/SparkPost/node-sparkpost/pull/165) Updated webhook update method to not send id in request (@aydrian)
934

@@ -110,7 +135,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
110135
## 0.1.0 - 2014-11-10
111136
- First Release!
112137

113-
[unreleased]: https://github.com/sparkpost/node-sparkpost/compare/1.3.8...HEAD
138+
[unreleased]: https://github.com/sparkpost/node-sparkpost/compare/2.0.0...HEAD
139+
[2.0.0]: https://github.com/sparkpost/node-sparkpost/compare/1.3.8...2.0.0
114140
[1.3.8]: https://github.com/sparkpost/node-sparkpost/compare/1.3.7...1.3.8
115141
[1.3.7]: https://github.com/sparkpost/node-sparkpost/compare/1.3.6...1.3.7
116142
[1.3.6]: https://github.com/sparkpost/node-sparkpost/compare/1.3.5...1.3.6

CONTRIBUTING.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ Current milestone Pull Requests will receive priority review for merging.
1313
3. Write corresponding tests and code (only what is needed to satisfy the issue and tests please)
1414
* Include your tests in the 'test' directory in an appropriate test file
1515
* Write code to satisfy the tests
16-
* Run tests using ```grunt test```
16+
* Run tests using ```npm test```
1717
5. Ensure automated tests pass
18-
6. Submit a new Pull Request applying your feature/fix branch to the develop branch of the SparkPost SDK
18+
6. Submit a new Pull Request applying your feature/fix branch to the develop branch of the SparkPost client library
19+
20+
## Releases
21+
If you are a collaborator, when you want release a new version, follow these steps.
22+
23+
1. Make sure all the changes are merged into master
24+
2. Make sure all changes have passed [Travis CI build][1]
25+
3. Determine type of release. We use [Semantic Versioning](http://semver.org/).
26+
4. Update [CHANGELOG.md](CHANGELOG.md) with release notes and commit
27+
5. Run `npm version` command to increment `package.json` version, commit changes, tag changes, and push to upstream.
28+
- Patch -> `npm version patch`
29+
- Minor -> `npm version minor`
30+
- Major -> `npm version major`
31+
6. Once [Travis CI build][1] (from tag) has completed, make sure you're working directory is clean and run `npm publish`
32+
while in the project root.
33+
7. Create a new [Github Release](https://github.com/SparkPost/node-sparkpost/releases) using the new tag. Copy release
34+
notes from the [CHANGELOG.md](CHANGELOG.md).
35+
36+
[1]: https://travis-ci.org/SparkPost/node-sparkpost

Gruntfile.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

README.md

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<a href="https://www.sparkpost.com"><img src="https://www.sparkpost.com/sites/default/files/attachments/SparkPost_Logo_2-Color_Gray-Orange_RGB.svg" width="200px"/></a>
22

3-
[Sign up](https://app.sparkpost.com/sign-up?src=Dev-Website&sfdcid=70160000000pqBb) for a SparkPost account and visit our [Developer Hub](https://developers.sparkpost.com) for even more content.
3+
[Sign up][sparkpost sign up] for a SparkPost account and visit our [Developer Hub](https://developers.sparkpost.com) for even more content.
44

55
# Node.js Client Library
66

@@ -12,7 +12,7 @@ The official Node.js binding for your favorite [SparkPost APIs](https://develope
1212

1313
Before using this library, you must have:
1414

15-
* A shiny new SparkPost Account, [sign up for a new account](https://app.sparkpost.com/#/sign-up) or [login to SparkPost](https://app.sparkpost.com/)
15+
* A shiny new SparkPost Account, [sign up for a new account][sparkpost sign up] or [login to SparkPost](https://app.sparkpost.com/)
1616
* A valid SparkPost API Key. Check out our [Support Center](https://support.sparkpost.com/) for information on how to [create API keys](https://support.sparkpost.com/customer/portal/articles/1933377-create-api-keys)
1717

1818
## Installation
@@ -21,8 +21,10 @@ Before using this library, you must have:
2121
npm install sparkpost
2222
```
2323

24+
*Note: Node.js versions 0.10 and 0.12 are no longer supported. For versions < 4, please continue using [sparkpost v1.3.8](https://github.com/SparkPost/node-sparkpost/tree/1.3.8)*
25+
2426
## Initialization
25-
**new SparkPost(apiKey, options)** - Initialization
27+
**new SparkPost(apiKey[, options])** - Initialization
2628

2729
* `apiKey`
2830
* Required: yes (unless key is stored in `SPARKPOST_API_KEY` environment variable)
@@ -40,19 +42,23 @@ npm install sparkpost
4042
* Required: no
4143
* Type: `Object`
4244
* set headers that apply to all requests
45+
* `options.debug`
46+
* Required: no
47+
* Type: `Boolean`
48+
* Default: `false`
49+
* appends full response from request client as `debug` when `true` for debugging purposes<br/>
50+
*Note: This will expose your api key to the client-side. Do not use in production.*
4351

4452
## Methods
45-
* **request(options, callback)**
53+
54+
*Note: All methods return promises and accept an optional last argument callback. [Read about how we handle callbacks and promises](/docs/async.md).*
55+
56+
* **request(options[, callback])**
4657
* `options` - [see request modules options](https://github.com/mikeal/request#requestoptions-callback)
4758
* `options.uri` - can either be a full url or a path that is appended to `options.origin` used at initialization ([url.resolve](http://nodejs.org/api/url.html#url_url_resolve_from_to))
48-
* `callback` - executed after task is completed. **required**
49-
* standard `callback(err, data)`
50-
* `err` - any error that occurred
51-
* `data.res` - full response from request client
52-
* `data.body` - payload from response
53-
* **get | post | put | delete(options, callback)**
59+
* `options.debug` - setting to `true` includes full response from request client for debugging purposes
60+
* **get | post | put | delete(options[, callback])**
5461
* `options` - see request options
55-
* `callback` - see request options
5662
* Request method will be overwritten and set to the same value as the name of these methods.
5763

5864
## Creating a SparkPost Client
@@ -91,25 +97,27 @@ var options = {
9197
uri: 'metrics/domains'
9298
};
9399

94-
client.get(options, function(err, data) {
95-
if(err) {
100+
client.get(options)
101+
.then(data => {
102+
console.log(data);
103+
})
104+
.catch(err => {
96105
console.log(err);
97-
return;
98-
}
99-
100-
console.log(data.body);
101-
});
106+
});
102107
```
103108

104109
## Send An Email "Hello World" Example
105-
Below is an example of how to send a simple email. Sending an email is known as a *transmission*. By using the send method on the transmissions service that's available from the SparkPost object you instatiate you can pass in a *transmissionBody* object with all the information relevant to the email being sent. The send method also takes a callback method that will let you know if the email was sent successful and if not information about the error that ocurred.
110+
Below is an example of how to send a simple email. Sending an email is known as a *transmission*. By using the send
111+
method on the transmissions service that's available from the SparkPost object you instantiate, you can pass in an
112+
object with all the [transmission attributes](https://developers.sparkpost.com/api/transmissions#header-transmission-attributes)
113+
relevant to the email being sent. The send method will return a promise that will let you know if the email was sent
114+
successful and if not information about the error that occurred. If a callback is passed, it will be executed.
106115

107116
```javascript
108117
var SparkPost = require('sparkpost');
109-
var sp = new SparkPost('<YOUR API KEY>');
118+
var client = new SparkPost('<YOUR API KEY>');
110119

111-
sp.transmissions.send({
112-
transmissionBody: {
120+
client.transmissions.send({
113121
content: {
114122
from: 'testing@sparkpostbox.com',
115123
subject: 'Hello, World!',
@@ -118,15 +126,15 @@ sp.transmissions.send({
118126
recipients: [
119127
{address: '<YOUR EMAIL ADDRESS>'}
120128
]
121-
}
122-
}, function(err, res) {
123-
if (err) {
129+
})
130+
.then(data => {
131+
console.log('Woohoo! You just sent your first mailing!');
132+
console.log(data);
133+
})
134+
.catch(err => {
124135
console.log('Whoops! Something went wrong');
125136
console.log(err);
126-
} else {
127-
console.log('Woohoo! You just sent your first mailing!');
128-
}
129-
});
137+
});
130138
```
131139

132140
## SparkPost API Resources Supported in Node Client Library
@@ -147,20 +155,20 @@ Click on the desired API to see usage and more information
147155
## Development
148156

149157
### Setup
150-
We use [Grunt](http://gruntjs.com/) for our task runner, so you will also have to install Grunt globally `npm install -g grunt-cli`
151-
152158
Run `npm install` inside the repository to install all the dev dependencies.
153159

154160
### Testing
155-
Once all the dependencies are installed, you can execute the unit tests using `grunt test`
161+
Once all the dependencies are installed, you can execute the unit tests using `npm test`
156162

157163
### Contributing
158-
[Guidelines for adding issues](docs/ADDING_ISSUES.markdown)
164+
[Guidelines for adding issues](docs/ADDING_ISSUES.md)
159165

160-
[Our coding standards](docs/CODE_STYLE_GUIDE.markdown)
166+
[Our coding standards](docs/CODE_STYLE_GUIDE.md)
161167

162168
[Submitting pull requests](CONTRIBUTING.md)
163169

164170
### ChangeLog
165171

166172
[See ChangeLog here](CHANGELOG.md)
173+
174+
[sparkpost sign up]: https://app.sparkpost.com/sign-up?src=Dev-Website&sfdcid=701600000011daf
File renamed without changes.
File renamed without changes.

docs/async.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Async Handling
2+
3+
Callbacks and promises living together... MASS HYSTERIA. Or not! This library handles both of your favorite async strategies.
4+
5+
### Promises
6+
7+
All our library methods return promises, so if you're a promise-fan, just do what you normally do.
8+
9+
```javascript
10+
let client = new SparkPost(key);
11+
12+
client.templates.get(id)
13+
.then((data) => {
14+
// this the full API response body
15+
})
16+
.catch((err) => {
17+
// handle the sad error
18+
});
19+
```
20+
21+
### Callbacks
22+
23+
If you're more of a callbacker, that works too. Pass a callback as the last argument and it'll be handled like a regular, error-first callback.
24+
25+
```javascript
26+
let client = new SparkPost(key);
27+
28+
client.templates.get(id, (err, data) => {
29+
if (err) {
30+
// handle the sad error
31+
return;
32+
}
33+
34+
// this is the full API response body
35+
});
36+
```

0 commit comments

Comments
 (0)