Skip to content

Commit f661920

Browse files
authored
Merge pull request strongloop#188 from strongloop/update-eslint
update eslint dependency and drop support for Node.js 6
2 parents 87fffc3 + 9d47960 commit f661920

21 files changed

+302
-296
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: node_js
22
node_js:
3-
- "6"
43
- "8"
54
- "10"

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
'use strict';
77

8-
var SG = require('strong-globalize');
8+
const SG = require('strong-globalize');
99
SG.SetRootDir(__dirname);
1010

1111
/**
1212
* Export the connector
1313
*/
14-
var loopback = require('loopback');
15-
var PushConnector = require('./lib/push-connector');
14+
const loopback = require('loopback');
15+
const PushConnector = require('./lib/push-connector');
1616
exports = module.exports = PushConnector;
1717

1818
/**
@@ -24,7 +24,7 @@ exports.Notification = require('./models').Notification;
2424
exports.createPushModel = function(options) {
2525
options = options || {};
2626

27-
var pushDataSource = loopback.createDataSource({
27+
const pushDataSource = loopback.createDataSource({
2828
connector: PushConnector,
2929
installation: options.installation,
3030
application: options.application,
@@ -33,7 +33,7 @@ exports.createPushModel = function(options) {
3333
checkPeriodInSeconds: options.checkPeriodInSeconds,
3434
});
3535

36-
var PushModel = pushDataSource.createModel(options.name || 'Push', {},
36+
const PushModel = pushDataSource.createModel(options.name || 'Push', {},
3737
{plural: options.plural || 'push'});
3838
return PushModel;
3939
};

lib/payload.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
'use strict';
77

8-
var g = require('strong-globalize')();
8+
const g = require('strong-globalize')();
99

10-
var serial = 0;
11-
var __hasProp = {}.hasOwnProperty;
10+
let serial = 0;
11+
const __hasProp = {}.hasOwnProperty;
1212

1313
// eslint-disable-next-line camelcase
1414
Payload.prototype.locale_format = /^[a-z]{2}_[A-Z]{2}$/;
1515

1616
function Payload(data) {
17-
var key, prefix, subkey, sum, type, value, _i, _len, _ref, _ref1;
17+
let key, prefix, subkey, sum, type, value, _i, _len, _ref;
1818
if (typeof data !== 'object') {
1919
throw new Error(g.f('Invalid payload'));
2020
}
@@ -55,13 +55,12 @@ function Payload(data) {
5555
}
5656
}
5757
sum = 0;
58-
_ref1 = ['title', 'msg', 'data'];
58+
const _ref1 = ['title', 'msg', 'data'];
5959
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
6060
type = _ref1[_i];
6161
sum += ((function() {
62-
var _ref2, _results;
63-
_ref2 = this[type];
64-
_results = [];
62+
const _ref2 = this[type];
63+
const _results = [];
6564
for (key in _ref2) {
6665
if (!__hasProp.call(_ref2, key)) continue;
6766
_results.push(key);
@@ -97,8 +96,8 @@ Payload.prototype.localized = function(type, lang) {
9796
};
9897

9998
Payload.prototype.compile = function() {
100-
var lang, msg, type, _i, _len, _ref, _ref1;
101-
_ref = ['title', 'msg'];
99+
let lang, msg, type, _i, _len, _ref1;
100+
const _ref = ['title', 'msg'];
102101
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
103102
type = _ref[_i];
104103
_ref1 = this[type];
@@ -112,24 +111,24 @@ Payload.prototype.compile = function() {
112111
};
113112

114113
Payload.prototype.compileTemplate = function(tmpl) {
115-
var _this = this;
114+
const _this = this;
116115
return tmpl.replace(/\$\{(.*?)\}/g, function(match, keyPath) {
117116
return _this.variable(keyPath);
118117
});
119118
};
120119

121120
Payload.prototype.variable = function(keyPath) {
122-
var key, prefix, _ref, _ref1, _ref2;
121+
let _ref, _ref1;
123122
if (keyPath === 'event.name') {
124123
if ((_ref = this.event) != null ? _ref.name : undefined) {
125124
return (_ref1 = this.event) != null ? _ref1.name : undefined;
126125
} else {
127126
throw new Error(g.f('The ${%s} does not exist', keyPath));
128127
}
129128
}
130-
_ref2 = keyPath.split('.', 2);
131-
prefix = _ref2[0];
132-
key = _ref2[1];
129+
const _ref2 = keyPath.split('.', 2);
130+
const prefix = _ref2[0];
131+
const key = _ref2[1];
133132
if (prefix !== 'var' && prefix !== 'data') {
134133
throw new Error(g.f('Invalid variable type for ${%s}', keyPath));
135134
}

lib/providers/apns.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
'use strict';
77

8-
var g = require('strong-globalize')();
8+
const g = require('strong-globalize')();
99

10-
var inherits = require('util').inherits;
11-
var assert = require('assert');
12-
var EventEmitter = require('events').EventEmitter;
13-
var debug = require('debug')('loopback:component:push:provider:apns');
14-
var apn = require('apn');
10+
const inherits = require('util').inherits;
11+
const assert = require('assert');
12+
const EventEmitter = require('events').EventEmitter;
13+
const debug = require('debug')('loopback:component:push:provider:apns');
14+
const apn = require('apn');
1515

1616
/**
1717
* Provider used to distribute push notifications through Apple Push Notification Service.
@@ -21,8 +21,8 @@ var apn = require('apn');
2121
function ApnsProvider(pushSettings) {
2222
pushSettings = pushSettings || {};
2323

24-
var settings = pushSettings.apns || {};
25-
var pushOptions = settings.pushOptions || {};
24+
const settings = pushSettings.apns || {};
25+
const pushOptions = settings.pushOptions || {};
2626

2727
// is running sandbox / production
2828
if (typeof settings.production === 'undefined') {
@@ -32,7 +32,7 @@ function ApnsProvider(pushSettings) {
3232
}
3333

3434
// validate required properties
35-
var errors = {
35+
const errors = {
3636
token: 'JWT Token must be defined, property "token" is undefined.',
3737
bundle: 'Bundle should contain the bundle identifier of the app',
3838

@@ -41,7 +41,7 @@ function ApnsProvider(pushSettings) {
4141
teamId: 'Tokens property "teamId" must be set.',
4242
};
4343

44-
var u = 'undefined';
44+
const u = 'undefined';
4545

4646
assert.notStrictEqual(typeof settings.token, u, errors.token);
4747
assert.notStrictEqual(typeof settings.bundle, u, errors.bundle);
@@ -62,7 +62,7 @@ function ApnsProvider(pushSettings) {
6262
* @type {null}
6363
* @private
6464
*/
65-
var _connection = null;
65+
let _connection = null;
6666

6767
/**
6868
* Sets the stored connection
@@ -102,7 +102,7 @@ exports = module.exports = ApnsProvider;
102102
* @private
103103
*/
104104
ApnsProvider.prototype._ensurePushConnection = function(options) {
105-
var self = this;
105+
const self = this;
106106

107107
debug('Check whether connected', self.getConnected());
108108

@@ -130,7 +130,7 @@ ApnsProvider.prototype._ensurePushConnection = function(options) {
130130
* @param recipient
131131
*/
132132
function transmissionErrorHandler(code, notification, recipient) {
133-
var err = new Error(g.f('Cannot send {{APNS}} notification: %s', code));
133+
const err = new Error(g.f('Cannot send {{APNS}} notification: %s', code));
134134
self.emit(err, notification, recipient);
135135
}
136136

@@ -157,8 +157,8 @@ ApnsProvider.prototype._ensurePushConnection = function(options) {
157157
* @param deviceToken
158158
*/
159159
ApnsProvider.prototype.pushNotification = function(notification, deviceToken) {
160-
var self = this;
161-
var pushOptions = self._pushOptions;
160+
const self = this;
161+
const pushOptions = self._pushOptions;
162162

163163
// node-apn has a bug rightnow.. after sending the first
164164
// batch of notifications, the connection goes away
@@ -167,7 +167,7 @@ ApnsProvider.prototype.pushNotification = function(notification, deviceToken) {
167167

168168
// Note parameters are described here:
169169
// http://bit.ly/apns-notification-payload
170-
var note = _createNotification(notification, pushOptions);
170+
const note = _createNotification(notification, pushOptions);
171171

172172
debug('Pushing notification to %j:', deviceToken, note);
173173

@@ -192,7 +192,7 @@ ApnsProvider.prototype.pushNotification = function(notification, deviceToken) {
192192
* @private
193193
*/
194194
function _createNotification(notification, pushOptions) {
195-
var note = new apn.Notification();
195+
const note = new apn.Notification();
196196

197197
note.expiry = notification.getTimeToLiveInSecondsFromNow() || note.expiry;
198198
note.badge = notification.badge;
@@ -221,10 +221,10 @@ function _createNotification(notification, pushOptions) {
221221
* @private
222222
*/
223223
function _extractDeviceTokens(failed) {
224-
var tokens = [];
224+
const tokens = [];
225225

226226
failed.forEach(function(device) {
227-
var token = device.device;
227+
const token = device.device;
228228

229229
tokens.push(token);
230230
});

lib/providers/gcm.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
'use strict';
77

8-
var g = require('strong-globalize')();
8+
const g = require('strong-globalize')();
99

10-
var inherits = require('util').inherits;
11-
var extend = require('util')._extend;
12-
var EventEmitter = require('events').EventEmitter;
13-
var gcm = require('node-gcm');
14-
var debug = require('debug')('loopback:component:push:provider:gcm');
10+
const inherits = require('util').inherits;
11+
const extend = require('util')._extend;
12+
const EventEmitter = require('events').EventEmitter;
13+
const gcm = require('node-gcm');
14+
const debug = require('debug')('loopback:component:push:provider:gcm');
1515

1616
function GcmProvider(pushSettings) {
17-
var settings = pushSettings.gcm || {};
17+
const settings = pushSettings.gcm || {};
1818
this._setupPushConnection(settings);
1919
}
2020

@@ -28,18 +28,18 @@ GcmProvider.prototype._setupPushConnection = function(options) {
2828
};
2929

3030
GcmProvider.prototype.pushNotification = function(notification, deviceToken) {
31-
var self = this;
31+
const self = this;
3232

33-
var registrationIds = (typeof deviceToken == 'string') ?
33+
const registrationIds = (typeof deviceToken == 'string') ?
3434
[deviceToken] : deviceToken;
35-
var message = this._createMessage(notification);
35+
const message = this._createMessage(notification);
3636

3737
debug('Sending message to %j: %j', registrationIds, message);
3838
this._connection.send(message, registrationIds, 3, function(err, result) {
3939
if (!err && result && result.failure) {
40-
var devicesGoneRegistrationIds = [];
41-
var errors = [];
42-
var code;
40+
const devicesGoneRegistrationIds = [];
41+
const errors = [];
42+
let code;
4343
result.results.forEach(function(value, index) {
4444
code = value && value.error;
4545
if (code === 'NotRegistered' || code === 'InvalidRegistration') {
@@ -73,13 +73,13 @@ GcmProvider.prototype.pushNotification = function(notification, deviceToken) {
7373
GcmProvider.prototype._createMessage = function(notification) {
7474
// Message parameters are documented here:
7575
// https://developers.google.com/cloud-messaging/server-ref
76-
var message = new gcm.Message({
76+
const message = new gcm.Message({
7777
timeToLive: notification.getTimeToLiveInSecondsFromNow(),
7878
collapseKey: notification.collapseKey,
7979
delayWhileIdle: notification.delayWhileIdle,
8080
});
8181

82-
var propNames = Object.keys(notification);
82+
const propNames = Object.keys(notification);
8383
// GCM does not have reserved message parameters for alert or badge, adding them as data.
8484
propNames.push('alert', 'badge');
8585

lib/push-connector.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55

66
'use strict';
77

8-
var loopback = require('loopback');
9-
var PushManager = require('./push-manager');
8+
const loopback = require('loopback');
9+
const PushManager = require('./push-manager');
1010
/**
1111
* Export the initialize method to Loopback DataSource
1212
* @param {Object} dataSource Loopback dataSource (Memory, etc).
1313
* @param {Function} callback (unused)
1414
*/
1515
exports.initialize = function(dataSource, callback) {
16-
var settings = dataSource.settings || {};
16+
const settings = dataSource.settings || {};
1717

1818
// Create an instance of the APNSManager
19-
var connector = new PushManager(settings);
19+
const connector = new PushManager(settings);
2020
dataSource.connector = connector;
2121
dataSource.connector.dataSource = dataSource;
2222

2323
connector.DataAccessObject = function() {};
24-
for (var m in PushManager.prototype) {
25-
var method = PushManager.prototype[m];
24+
for (const m in PushManager.prototype) {
25+
const method = PushManager.prototype[m];
2626
if ('function' === typeof method) {
2727
connector.DataAccessObject[m] = method.bind(connector);
28-
for (var k in method) {
28+
for (const k in method) {
2929
connector.DataAccessObject[m][k] = method[k];
3030
}
3131
}

0 commit comments

Comments
 (0)