@nka212bg/backend-utils 0.1.62 → 0.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/webPush.js +4 -5
package/package.json
CHANGED
package/webPush.js
CHANGED
|
@@ -48,9 +48,8 @@ const removeEndpoint = (endpoint) => {
|
|
|
48
48
|
return change;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
// the subject must be an https: URL or a mailto:, so anything else (http local dev) falls back to
|
|
52
|
-
const
|
|
53
|
-
const vapidSubject = (subject) => (/^(https|mailto):/.test(subject || "") ? subject : `mailto:${smtpUser()}`);
|
|
51
|
+
// the subject must be an https: URL or a mailto:, so anything else (empty, http local dev) falls back to VAPID_SUBJECT=mailto:you@mail.com
|
|
52
|
+
const vapidSubject = (subject) => (/^(https|mailto):/.test(subject || "") ? subject : process.env.VAPID_SUBJECT);
|
|
54
53
|
|
|
55
54
|
// every call creates a separate instance with its own config:
|
|
56
55
|
// const { sendPush, subscriptionState, publicKey } = require(".../webPush")({ subject: () => __baseUrl, options: { TTL: 86400, urgency: "high" } }); // publicKey()
|
|
@@ -61,7 +60,7 @@ const vapidSubject = (subject) => (/^(https|mailto):/.test(subject || "") ? subj
|
|
|
61
60
|
// subject, publicKey, privateKey, options can also be functions, resolved on each send (e.g. subject: () => __baseUrl)
|
|
62
61
|
const createInstance = (opts = {}) => {
|
|
63
62
|
const config = {
|
|
64
|
-
subject: "",
|
|
63
|
+
subject: "", // https: URL or mailto:
|
|
65
64
|
publicKey: "",
|
|
66
65
|
privateKey: "",
|
|
67
66
|
options: {}, // web-push sendNotification options { TTL, urgency, topic… }
|
|
@@ -91,7 +90,7 @@ const createInstance = (opts = {}) => {
|
|
|
91
90
|
if (typeof payload != "string") payload = JSON.stringify(payload);
|
|
92
91
|
|
|
93
92
|
const vapidDetails = {
|
|
94
|
-
subject: vapidSubject(val(config.subject)
|
|
93
|
+
subject: vapidSubject(val(config.subject)),
|
|
95
94
|
publicKey: publicKey(),
|
|
96
95
|
privateKey: val(config.privateKey) || process.env.VAPID_PRIVATE_KEY,
|
|
97
96
|
};
|