Skip to content

Commit 0f4ef0b

Browse files
rvaggmhdawson
authored andcommitted
update deps & add linting (#149)
PR-URL: #149 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 3d270da commit 0f4ef0b

File tree

5 files changed

+51
-65
lines changed

5 files changed

+51
-65
lines changed

update/add-route.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
const hyperquest = require('hyperquest')
2-
, bl = require('bl')
3-
, qs = require('querystring')
4-
5-
, url = `https://api.mailgun.net/v3/routes`
2+
const bl = require('bl')
3+
const qs = require('querystring')
64

5+
const url = 'https://api.mailgun.net/v3/routes'
76

87
function addRoute (domain, creds, description, expression, actions, callback) {
9-
var params = {
10-
description
11-
, expression
12-
, action : actions
13-
}
14-
, data = qs.stringify(params)
15-
, options = {
16-
auth : `api:${creds["api-key"]}`
17-
, headers : {
18-
'content-type': 'application/x-www-form-urlencoded'
19-
, 'content-length': Buffer.byteLength(data)
20-
}
21-
}
8+
const params = {
9+
description,
10+
expression,
11+
action: actions
12+
}
13+
const data = qs.stringify(params)
14+
const options = {
15+
auth: `api:${creds['api-key']}`,
16+
headers: {
17+
'content-type': 'application/x-www-form-urlencoded',
18+
'content-length': Buffer.byteLength(data)
19+
}
20+
}
2221

23-
var req = hyperquest.post(url, options)
22+
const req = hyperquest.post(url, options)
2423

2524
req.pipe(bl(callback))
2625
req.end(data)
2726
}
2827

29-
30-
module.exports = addRoute
28+
module.exports = addRoute

update/delete-route.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
const hyperquest = require('hyperquest')
2-
, bl = require('bl')
3-
4-
, url = 'https://api.mailgun.net/v3/routes'
1+
const jsonist = require('jsonist')
52

3+
const url = 'https://api.mailgun.net/v3/routes'
64

75
function deleteRoute (domain, creds, id, callback) {
8-
var options = { auth: `api:${creds["api-key"]}` }
9-
10-
hyperquest.delete(`${url}/${id}`, options).pipe(bl(callback))
6+
const options = { auth: `api:${creds['api-key']}` }
7+
jsonist.delete(`${url}/${id}`, options, callback)
118
}
129

13-
14-
module.exports = deleteRoute
10+
module.exports = deleteRoute

update/list-routes.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
const jsonist = require('jsonist')
22

3-
, url = `https://api.mailgun.net/v3/routes`
4-
3+
const url = 'https://api.mailgun.net/v3/routes'
54

65
function listRoutes (domain, creds, callback) {
7-
var options = { auth: `api:${creds["api-key"]}` }
6+
const options = { auth: `api:${creds['api-key']}` }
87
jsonist.get(url, options, callback)
98
}
109

11-
12-
module.exports = listRoutes
10+
module.exports = listRoutes

update/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"description": "",
55
"main": "update.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"lint": "npx standard",
8+
"test": "npm run lint"
89
},
910
"author": "Rod <[email protected]> (http://r.va.gg/)",
1011
"license": "MIT",
1112
"dependencies": {
12-
"after": "~0.8.1",
13-
"bl": "~0.9.4",
14-
"deep-equal": "~1.0.0",
15-
"hyperquest": "~1.2.0",
16-
"jsonist": "~1.0.2",
17-
"xtend": "~4.0.0"
13+
"after": "^0.8.2",
14+
"bl": "^4.0.0",
15+
"deep-equal": "^2.0.1",
16+
"hyperquest": "^2.1.3",
17+
"jsonist": "^3.0.1",
18+
"xtend": "^4.0.2"
1819
}
1920
}

update/update-aliases.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,58 @@
22
// and adjust them to match the list of provided aliases; removing ones that
33
// don't belong and adding ones that are new
44

5-
const equal = require('deep-equal')
6-
, after = require('after')
7-
, xtend = require('xtend')
8-
, listRoutes = require('./list-routes')
9-
, addRoute = require('./add-route')
10-
, deleteRoute = require('./delete-route')
11-
5+
const equal = require('deep-equal')
6+
const after = require('after')
7+
const xtend = require('xtend')
8+
const listRoutes = require('./list-routes')
9+
const addRoute = require('./add-route')
10+
const deleteRoute = require('./delete-route')
1211

1312
function toExpression (domain, alias) {
1413
return `match_recipient("${alias.from}@${domain}")`
1514
}
1615

17-
1816
function toActions (alias) {
19-
var to = Array.isArray(alias.to) ? alias.to : [ alias.to ]
17+
const to = Array.isArray(alias.to) ? alias.to : [alias.to]
2018
return to.map(function (to) {
2119
return `forward("${to}")`
22-
}).concat([ `stop()` ])
20+
}).concat(['stop()'])
2321
}
2422

25-
2623
function diff (domain, a1, a2) {
2724
a2 = a2.slice()
2825

2926
return a1.filter(function (alias1) {
3027
return !a2.some(function (alias2, i) {
31-
if (alias2.expression == alias1.expression && equal(alias2.actions, alias1.actions)) {
28+
if (alias2.expression === alias1.expression && equal(alias2.actions, alias1.actions)) {
3229
a2.splice(i, 1) // remove it so we don't match duplicates
3330
return true
3431
}
3532
})
3633
})
3734
}
3835

39-
4036
function updateAliases (domain, creds, aliases, dryRun, callback) {
4137
function adjustRoutes (routes) {
42-
43-
var current = routes.items
38+
const current = routes.items
4439

4540
// adjust the incoming aliases to have .expression and .actions properties
4641
aliases = aliases.map(function (alias) {
4742
return xtend(alias, {
48-
expression : toExpression(domain, alias)
49-
, actions : toActions(alias)
43+
expression: toExpression(domain, alias),
44+
actions: toActions(alias)
5045
})
5146
})
5247

53-
var toAdd = diff(domain, aliases, current) // this diff gives us new additions
54-
, toRemove = diff(domain, current, aliases) // this diff gives us stale routes
55-
, done = after(toAdd.length + toRemove.length, callback)
48+
const toAdd = diff(domain, aliases, current) // this diff gives us new additions
49+
const toRemove = diff(domain, current, aliases) // this diff gives us stale routes
50+
const done = after(toAdd.length + toRemove.length, callback)
5651

5752
console.log(`${toAdd.length} route(s) to add`)
5853
console.log(`${toRemove.length} route(s) to remove`)
5954

6055
toAdd.forEach(function (alias) {
61-
var to = Array.isArray(alias.to) ? alias.to : [ alias.to ]
56+
const to = Array.isArray(alias.to) ? alias.to : [alias.to]
6257
console.log(`Adding ${alias.from} -> ${to.join(', ')}...`)
6358
if (!dryRun) {
6459
addRoute(domain, creds, alias.from, alias.expression, alias.actions, done)
@@ -74,11 +69,9 @@ function updateAliases (domain, creds, aliases, dryRun, callback) {
7469
}
7570

7671
listRoutes(domain, creds, function (err, routes) {
77-
if (err)
78-
throw err
72+
if (err) { throw err }
7973
adjustRoutes(routes)
8074
})
8175
}
8276

83-
8477
module.exports = updateAliases

0 commit comments

Comments
 (0)