Skip to content

Commit 2d840ac

Browse files
committed
Update .prettierrc and run formatting
1 parent 7fda348 commit 2d840ac

24 files changed

+1489
-1919
lines changed

.prettierrc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{
2-
"singleQuote": true,
3-
"trailingComma": "es5"
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"printWidth": 100,
5+
"tabWidth": 2,
6+
"useTabs": false,
7+
"arrowParens": "always",
8+
"bracketSpacing": true,
9+
"endOfLine": "lf"
410
}

README.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ You can send to multiple devices, independently of platform, creating an array w
118118

119119
```js
120120
// Single destination
121-
const registrationIds = 'INSERT_YOUR_DEVICE_ID';
121+
const registrationIds = "INSERT_YOUR_DEVICE_ID";
122122

123123
// Multiple destinations
124124
const registrationIds = [];
125-
registrationIds.push('INSERT_YOUR_DEVICE_ID');
126-
registrationIds.push('INSERT_OTHER_DEVICE_ID');
125+
registrationIds.push("INSERT_YOUR_DEVICE_ID");
126+
registrationIds.push("INSERT_OTHER_DEVICE_ID");
127127
```
128128

129129
The `PN.send()` method later detects device type and therefore used push method, based on the id stucture. Check out the method `PN.getPushMethodByRegId` how this detection works.
@@ -146,10 +146,10 @@ It can be of 2 types:
146146
Where type can be one of: 'apn', 'gcm', 'adm', 'wns', 'webPush'. The types are available as constants:
147147

148148
```js
149-
import { WEB, WNS, ADM, GCM, APN } from 'node-pushnotifications';
149+
import { WEB, WNS, ADM, GCM, APN } from "node-pushnotifications";
150150

151151
const regId = {
152-
id: 'INSERT_YOUR_DEVICE_ID',
152+
id: "INSERT_YOUR_DEVICE_ID",
153153
type: APN,
154154
};
155155
```
@@ -457,7 +457,7 @@ you can use the `phonegap` setting in order to adapt to the recommended behaviou
457457
```js
458458
const settings = {
459459
gcm: {
460-
id: '<yourId>',
460+
id: "<yourId>",
461461
phonegap: true,
462462
},
463463
};
@@ -542,16 +542,14 @@ Settings:
542542
Note: one of `serviceAccountKey`, `credential` fcm options is required
543543
544544
```js
545-
const tokens = [
546-
'e..Gwso:APA91.......7r910HljzGUVS_f...kbyIFk2sK6......D2s6XZWn2E21x',
547-
];
545+
const tokens = ["e..Gwso:APA91.......7r910HljzGUVS_f...kbyIFk2sK6......D2s6XZWn2E21x"];
548546

549547
const notifications = {
550-
collapseKey: Math.random().toString().replace('0.', ''),
551-
priority: 'high',
552-
sound: 'default',
553-
title: 'Title 1',
554-
body: 'Body 2',
548+
collapseKey: Math.random().toString().replace("0.", ""),
549+
priority: "high",
550+
sound: "default",
551+
title: "Title 1",
552+
body: "Body 2",
555553
// titleLocKey: 'GREETING',
556554
// titleLocArgs: ['Smith', 'M'],
557555
// fcm_notification: {
@@ -566,16 +564,16 @@ const notifications = {
566564
// },
567565
custom: {
568566
friend_id: 54657,
569-
list_id: 'N7jSif1INyZkA7r910HljzGUVS',
567+
list_id: "N7jSif1INyZkA7r910HljzGUVS",
570568
},
571569
};
572570

573571
pushNotifications.send(tokens, notifications, (error, result) => {
574572
if (error) {
575-
console.log('[error]', error);
573+
console.log("[error]", error);
576574
throw error;
577575
} else {
578-
console.log('[result]', result, result.at(0));
576+
console.log("[result]", result, result.at(0));
579577
}
580578
});
581579
```
@@ -619,9 +617,7 @@ Fcm object that will be sent to provider ([Fcm message format](https://firebase.
619617
}
620618
}
621619
},
622-
"tokens": [
623-
"e..Gwso:APA91.......7r910HljzGUVS_f...kbyIFk2sK6......D2s6XZWn2E21x"
624-
]
620+
"tokens": ["e..Gwso:APA91.......7r910HljzGUVS_f...kbyIFk2sK6......D2s6XZWn2E21x"]
625621
}
626622
```
627623
@@ -666,8 +662,7 @@ delete data.expiry;
666662
delete data.timeToLive;
667663

668664
const ADMmesssage = {
669-
expiresAfter:
670-
expiry - Math.floor(Date.now() / 1000) || timeToLive || 28 * 86400,
665+
expiresAfter: expiry - Math.floor(Date.now() / 1000) || timeToLive || 28 * 86400,
671666
consolidationKey,
672667
data,
673668
};
@@ -683,7 +678,7 @@ Data can be passed as a simple string payload. If you do not pass a string, the
683678
Settings are directly forwarded to `webPush.sendNotification`.
684679
685680
```js
686-
const payload = typeof data === 'string' ? data : JSON.stringify(data);
681+
const payload = typeof data === "string" ? data : JSON.stringify(data);
687682
webPush.sendNotification(regId, payload, settings.web);
688683
```
689684

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./lib/push-notifications');
1+
module.exports = require("./lib/push-notifications");

src/constants.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module.exports = {
22
DEFAULT_TTL: 28 * 86400,
33
GCM_MAX_TTL: 2419200, // 4 weeks in seconds (https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json)
4-
APN_METHOD: 'apn',
5-
GCM_METHOD: 'gcm',
6-
FCM_METHOD: 'fcm',
7-
ADM_METHOD: 'adm',
8-
WNS_METHOD: 'wns',
9-
WEB_METHOD: 'webPush',
10-
UNKNOWN_METHOD: 'unknown',
4+
APN_METHOD: "apn",
5+
GCM_METHOD: "gcm",
6+
FCM_METHOD: "fcm",
7+
ADM_METHOD: "adm",
8+
WNS_METHOD: "wns",
9+
WEB_METHOD: "webPush",
10+
UNKNOWN_METHOD: "unknown",
1111
DEFAULT_SETTINGS: {
1212
gcm: {
1313
id: null, // PUT YOUR GCM SERVER API KEY,
@@ -25,12 +25,12 @@ module.exports = {
2525
// keyId: '',
2626
// teamId: '',
2727
// },
28-
cert: 'cert.pem',
29-
key: 'key.pem',
28+
cert: "cert.pem",
29+
key: "key.pem",
3030
ca: null,
3131
pfx: null,
3232
passphrase: null,
33-
production: process.env.NODE_ENV === 'production',
33+
production: process.env.NODE_ENV === "production",
3434
voip: false,
3535
address: null,
3636
port: 443,
@@ -57,13 +57,13 @@ module.exports = {
5757
client_secret: null, // PUT YOUR WNS CLIENT SECRET,
5858
accessToken: null,
5959
headers: null,
60-
notificationMethod: 'sendTileSquareBlock',
60+
notificationMethod: "sendTileSquareBlock",
6161
},
6262
web: {
6363
vapidDetails: {
6464
subject: "< 'mailto' Address or URL >",
65-
publicKey: '< URL Safe Base64 Encoded Public Key >',
66-
privateKey: '< URL Safe Base64 Encoded Private Key >',
65+
publicKey: "< URL Safe Base64 Encoded Public Key >",
66+
privateKey: "< URL Safe Base64 Encoded Private Key >",
6767
},
6868
// gcmAPIKey: '< GCM API Key >',
6969
// TTL: 2419200

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./push-notifications');
1+
module.exports = require("./push-notifications");

src/push-notifications.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const sendGCM = require('./sendGCM');
2-
const sendFCM = require('./sendFCM');
3-
const APN = require('./sendAPN');
4-
const sendADM = require('./sendADM');
5-
const sendWNS = require('./sendWNS');
6-
const sendWebPush = require('./sendWeb');
1+
const sendGCM = require("./sendGCM");
2+
const sendFCM = require("./sendFCM");
3+
const APN = require("./sendAPN");
4+
const sendADM = require("./sendADM");
5+
const sendWNS = require("./sendWNS");
6+
const sendWebPush = require("./sendWeb");
77

88
const {
99
DEFAULT_SETTINGS,
@@ -14,7 +14,7 @@ const {
1414
GCM_METHOD,
1515
FCM_METHOD,
1616
APN_METHOD,
17-
} = require('./constants');
17+
} = require("./constants");
1818

1919
class PN {
2020
constructor(options) {
@@ -27,9 +27,7 @@ class PN {
2727
this.apn.shutdown();
2828
}
2929
this.apn = new APN(this.settings.apn);
30-
this.useFcmOrGcmMethod = this.settings.isLegacyGCM
31-
? GCM_METHOD
32-
: FCM_METHOD;
30+
this.useFcmOrGcmMethod = this.settings.isLegacyGCM ? GCM_METHOD : FCM_METHOD;
3331
}
3432

3533
sendWith(method, regIds, data, cb) {
@@ -45,16 +43,14 @@ class PN {
4543
}
4644

4745
getPushMethodByRegId(regId) {
48-
if (typeof regId === 'object' && (!regId.type || !regId.id)) {
46+
if (typeof regId === "object" && (!regId.type || !regId.id)) {
4947
return { regId, pushMethod: WEB_METHOD };
5048
}
5149

52-
if (typeof regId === 'object' && regId.id && regId.type) {
50+
if (typeof regId === "object" && regId.id && regId.type) {
5351
return {
5452
regId: regId.id,
55-
pushMethod: this.settings.isAlwaysUseFCM
56-
? this.useFcmOrGcmMethod
57-
: regId.type,
53+
pushMethod: this.settings.isAlwaysUseFCM ? this.useFcmOrGcmMethod : regId.type,
5854
};
5955
}
6056

@@ -64,18 +60,15 @@ class PN {
6460
return { regId, pushMethod: this.useFcmOrGcmMethod };
6561
}
6662

67-
if (regId.substring(0, 4) === 'http') {
63+
if (regId.substring(0, 4) === "http") {
6864
return { regId, pushMethod: WNS_METHOD };
6965
}
7066

7167
if (/^(amzn[0-9]*.adm)/i.test(regId)) {
7268
return { regId, pushMethod: ADM_METHOD };
7369
}
7470

75-
if (
76-
(regId.length === 64 || regId.length === 160) &&
77-
/^[a-fA-F0-9]+$/.test(regId)
78-
) {
71+
if ((regId.length === 64 || regId.length === 160) && /^[a-fA-F0-9]+$/.test(regId)) {
7972
return { regId, pushMethod: APN_METHOD };
8073
}
8174

@@ -131,9 +124,7 @@ class PN {
131124

132125
// iOS APN
133126
if (regIdsAPN.length > 0) {
134-
promises.push(
135-
this.sendWith(this.apn.sendAPN.bind(this.apn), regIdsAPN, data)
136-
);
127+
promises.push(this.sendWith(this.apn.sendAPN.bind(this.apn), regIdsAPN, data));
137128
}
138129

139130
// Microsoft WNS
@@ -157,15 +148,15 @@ class PN {
157148
// Unknown
158149
if (regIdsUnk.length > 0) {
159150
const results = {
160-
method: 'unknown',
151+
method: "unknown",
161152
success: 0,
162153
failure: regIdsUnk.length,
163154
message: [],
164155
};
165156
regIdsUnk.forEach((regId) => {
166157
results.message.push({
167158
regId,
168-
error: new Error('Unknown registration id'),
159+
error: new Error("Unknown registration id"),
169160
});
170161
});
171162
promises.push(Promise.resolve(results));
@@ -175,7 +166,7 @@ class PN {
175166
if (promises.length === 0) {
176167
promises.push(
177168
Promise.resolve({
178-
method: 'none',
169+
method: "none",
179170
success: 0,
180171
failure: 0,
181172
message: [],

src/sendADM.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const adm = require('node-adm');
2-
const { ADM_METHOD } = require('./constants');
1+
const adm = require("node-adm");
2+
const { ADM_METHOD } = require("./constants");
33

44
const sendADM = (regIds, _data, settings) => {
55
const resumed = {
@@ -13,8 +13,7 @@ const sendADM = (regIds, _data, settings) => {
1313
const { consolidationKey, expiry, timeToLive, custom, ...data } = _data;
1414

1515
const message = {
16-
expiresAfter:
17-
expiry - Math.floor(Date.now() / 1000) || timeToLive || 28 * 86400,
16+
expiresAfter: expiry - Math.floor(Date.now() / 1000) || timeToLive || 28 * 86400,
1817
consolidationKey,
1918
data: { ...data, ...custom },
2019
};
@@ -24,8 +23,7 @@ const sendADM = (regIds, _data, settings) => {
2423
new Promise((resolve) => {
2524
admSender.send(message, regId, (err, response) => {
2625
const errorMsg = err instanceof Error ? err.message : response.error;
27-
const error =
28-
err || (response.error ? new Error(response.error) : null);
26+
const error = err || (response.error ? new Error(response.error) : null);
2927
resumed.success += error ? 0 : 1;
3028
resumed.failure += error ? 1 : 0;
3129
resumed.message.push({

src/sendAPN.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const apn = require('@parse/node-apn');
2-
const { APN_METHOD } = require('./constants');
3-
const { buildApnsMessage } = require('./utils/tools');
1+
const apn = require("@parse/node-apn");
2+
const { APN_METHOD } = require("./constants");
3+
const { buildApnsMessage } = require("./utils/tools");
44

55
const getDeviceTokenOrSelf = (token) => token?.device ?? token;
66

@@ -25,8 +25,7 @@ class APN {
2525

2626
if (!this.connection) {
2727
return Promise.reject(
28-
this.connectionError ||
29-
new Error('Unknown error: APN connection not configured properly')
28+
this.connectionError || new Error("Unknown error: APN connection not configured properly")
3029
);
3130
}
3231

0 commit comments

Comments
 (0)