Skip to content

Commit b143281

Browse files
authored
Merge pull request #225 from appfeel/dev/remove-ramda
Remove ramda dependency
2 parents 6a984a8 + 511a1a0 commit b143281

File tree

13 files changed

+89
-126
lines changed

13 files changed

+89
-126
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"@babel/preset-env",
55
{
66
"targets": {
7-
"node": "6"
7+
"node": "14"
88
}
99
}
1010
]

.eslintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"extends": ["airbnb-base", "plugin:prettier/recommended"],
33
"env": {
4-
"node": true
4+
"node": true,
5+
"es2020": true
6+
},
7+
"parserOptions": {
8+
"ecmaVersion": 2020,
9+
"sourceType": "module"
510
}
611
}

package-lock.json

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"firebase-admin": "12.1.1",
5656
"node-adm": "0.9.1",
5757
"node-gcm": "1.1.4",
58-
"ramda": "0.32.0",
5958
"web-push": "3.6.7",
6059
"wns": "0.5.4"
6160
},

src/push-notifications.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class PN {
3737
sendWith(method, regIds, data, cb) {
3838
return method(regIds, data, this.settings)
3939
.then((results) => {
40-
(cb || ((noop) => noop))(null, results);
40+
cb?.(null, results);
4141
return results;
4242
})
4343
.catch((error) => {
44-
(cb || ((noop) => noop))(error);
44+
cb?.(error);
4545
return Promise.reject(error);
4646
});
4747
}

src/sendADM.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ const sendADM = (regIds, _data, settings) => {
1010
};
1111
const promises = [];
1212
const admSender = new adm.Sender(settings.adm);
13-
const data = { ..._data };
14-
const { consolidationKey, expiry, timeToLive, custom } = data;
15-
16-
delete data.consolidationKey;
17-
delete data.expiry;
18-
delete data.timeToLive;
19-
delete data.custom;
13+
const { consolidationKey, expiry, timeToLive, custom, ...data } = _data;
2014

2115
const message = {
2216
expiresAfter:

src/sendAPN.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
const apn = require('@parse/node-apn');
2-
const R = require('ramda');
32
const { APN_METHOD } = require('./constants');
43
const { buildApnsMessage } = require('./utils/tools');
54

6-
const getDeviceTokenOrSelf = R.ifElse(
7-
R.has('device'),
8-
R.prop('device'),
9-
R.identity
10-
);
5+
const getDeviceTokenOrSelf = (token) => token?.device ?? token;
116

127
class APN {
138
constructor(settings) {

src/sendFCM.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@ const { FCM_METHOD } = require('./constants');
44
const FcmMessage = require('./utils/fcmMessage');
55
const { containsValidRecipients } = require('./utils/tools');
66

7-
const getRecipientList = (obj) => {
8-
if (obj.tokens) {
9-
return obj.tokens;
10-
}
11-
if (obj.token) {
12-
return [obj.token];
13-
}
14-
if (obj.condition) {
15-
return [obj.condition];
16-
}
17-
if (obj.topic) {
18-
return [obj.topic];
19-
}
20-
return [];
21-
};
7+
const getRecipientList = (obj) =>
8+
obj.tokens ?? [obj.token, obj.condition, obj.topic].filter(Boolean);
229

2310
const sendChunk = (firebaseApp, recipients, message) => {
2411
const firebaseMessage = message.buildWithRecipients(recipients);
@@ -50,12 +37,15 @@ const sendChunk = (firebaseApp, recipients, message) => {
5037
message: response.responses.map((value) => {
5138
const regToken = recipientList[regIndex];
5239
regIndex += 1;
40+
const errorMsg = value.error
41+
? value.error.message || value.error
42+
: null;
5343
return {
5444
messageId: value.message_id,
5545
originalRegId: regToken,
5646
regId: value.registration_id || regToken,
5747
error: value.error ? new Error(value.error) : null,
58-
errorMsg: value.error ? value.error.message || value.error : null,
48+
errorMsg,
5949
};
6050
}),
6151
};

src/sendGCM.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,8 @@ const gcm = require('node-gcm');
22
const { GCM_METHOD } = require('./constants');
33
const { containsValidRecipients, buildGcmMessage } = require('./utils/tools');
44

5-
const getRecipientList = (obj) => {
6-
if (obj.registrationTokens) {
7-
return obj.registrationTokens;
8-
}
9-
if (obj.to) {
10-
return [obj.to];
11-
}
12-
if (obj.condition) {
13-
return [obj.condition];
14-
}
15-
return [];
16-
};
5+
const getRecipientList = (obj) =>
6+
obj.registrationTokens ?? [obj.to, obj.condition].filter(Boolean);
177

188
const sendChunk = (GCMSender, recipients, message, retries) =>
199
new Promise((resolve) => {
@@ -43,12 +33,15 @@ const sendChunk = (GCMSender, recipients, message, retries) =>
4333
message: response.results.map((value) => {
4434
const regToken = recipientList[regIndex];
4535
regIndex += 1;
36+
const errorMsg = value.error
37+
? value.error.message || value.error
38+
: null;
4639
return {
4740
messageId: value.message_id,
4841
originalRegId: regToken,
4942
regId: value.registration_id || regToken,
5043
error: value.error ? new Error(value.error) : null,
51-
errorMsg: value.error ? value.error.message || value.error : null,
44+
errorMsg,
5245
};
5346
}),
5447
});

src/sendWNS.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ const { WNS_METHOD } = require('./constants');
33

44
const parseErrorMessage = (err) => (err instanceof Error ? err.message : err);
55
const parseError = (err) => {
6-
if (err instanceof Error) {
7-
return err;
8-
}
9-
if (err) {
10-
return new Error(err);
11-
}
6+
if (err instanceof Error) return err;
7+
if (err) return new Error(err);
128
return null;
139
};
1410

0 commit comments

Comments
 (0)