@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/webPush.js +4 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nka212bg/backend-utils",
3
3
  "author": "nka212bg",
4
- "version": "0.1.62",
4
+ "version": "0.1.63",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@maxmind/geoip2-node": "^5.0.0",
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 the smtp user's email
52
- const smtpUser = () => (process.env.SMTP_URL ? decodeURIComponent(new URL(process.env.SMTP_URL).username) : process.env.SMTP_USER);
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) || process.env.VAPID_SUBJECT),
93
+ subject: vapidSubject(val(config.subject)),
95
94
  publicKey: publicKey(),
96
95
  privateKey: val(config.privateKey) || process.env.VAPID_PRIVATE_KEY,
97
96
  };