@plusscommunities/pluss-core-aws 1.4.18-beta.0 → 1.4.20

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.
@@ -21,14 +21,14 @@ const saveNotification = (receiver, notification) => {
21
21
  });
22
22
  };
23
23
 
24
- module.exports = (
24
+ module.exports = async (
25
25
  receivers,
26
26
  type,
27
27
  site,
28
28
  id,
29
29
  data,
30
30
  sendPush,
31
- config = { type: "app", id: null, ignoreMute: false }
31
+ config = { type: "app", id: null, ignoreMute: false, raiseError: false }
32
32
  ) => {
33
33
  const notification = {};
34
34
  notification.Timestamp = moment.utc().valueOf();
@@ -42,6 +42,13 @@ module.exports = (
42
42
  });
43
43
  if (sendPush) {
44
44
  const notiData = prepNotification(notification);
45
- sendNotifications(receivers, notiData.Text, type, id, notiData, config);
45
+ await sendNotifications(
46
+ receivers,
47
+ notiData.Text,
48
+ type,
49
+ id,
50
+ notiData,
51
+ config
52
+ );
46
53
  }
47
54
  };
@@ -13,7 +13,7 @@ module.exports = async (
13
13
  excludeClientBranding = false,
14
14
  brandingImage = null,
15
15
  bcc = null,
16
- }
16
+ } = {}
17
17
  ) => {
18
18
  const { communityConfig, serverlessConfig } = getConfig();
19
19
 
@@ -5,7 +5,7 @@ const getUser = require("../db/users/getUser");
5
5
  const getNotificationSetting = require("../db/notifications/getNotificationSetting");
6
6
  const { log } = require("../helper");
7
7
 
8
- const SendNotification = (tokens, message, type, key, params, config) => {
8
+ const SendNotification = async (tokens, message, type, key, params, config) => {
9
9
  const logId = log("SendNotification", "input", {
10
10
  tokens,
11
11
  message,
@@ -43,39 +43,37 @@ const SendNotification = (tokens, message, type, key, params, config) => {
43
43
  }
44
44
  messages.push(msg);
45
45
  } else {
46
- log(
47
- "SendNotification",
48
- "IsTokenError",
49
- `Push token ${token} is not a valid Expo push token`,
50
- logId
51
- );
46
+ const message = `Push token ${token} is not a valid Expo push token`;
47
+ log("SendNotification", "IsTokenError", message, logId);
48
+ if (config.raiseError) throw new Error(message);
52
49
  }
53
50
  }
54
51
 
55
52
  log("SendNotification", "messages", messages);
56
53
  const chunks = expo.chunkPushNotifications(messages);
57
54
  for (const chunk of chunks) {
58
- expo
59
- .sendPushNotificationsAsync(chunk)
60
- .then((receipts) => {
61
- log("SendNotification", "Receipts", receipts, logId);
62
- })
63
- .catch((error) => {
64
- if (error.code && error.code === "PUSH_TOO_MANY_EXPERIENCE_IDS") {
65
- log(
66
- "SendNotification",
67
- "CaughtError",
68
- "PUSH_TOO_MANY_EXPERIENCE_IDS",
69
- logId
70
- );
71
- // send separately
72
- _.values(error.details).forEach((appTokens) => {
73
- SendNotification(appTokens, message, type, key, params, config);
74
- });
75
- } else {
76
- log("SendNotification", "SendError", error, logId);
77
- }
78
- });
55
+ try {
56
+ const receipts = await expo.sendPushNotificationsAsync(chunk);
57
+ log("SendNotification", "Receipts", receipts, logId);
58
+ } catch (error) {
59
+ if (error.code && error.code === "PUSH_TOO_MANY_EXPERIENCE_IDS") {
60
+ log(
61
+ "SendNotification",
62
+ "CaughtError",
63
+ "PUSH_TOO_MANY_EXPERIENCE_IDS",
64
+ logId
65
+ );
66
+ // send separately
67
+ await Promise.all(
68
+ _.values(error.details).map((appTokens) =>
69
+ SendNotification(appTokens, message, type, key, params, config)
70
+ )
71
+ );
72
+ } else {
73
+ log("SendNotification", "SendError", error, logId);
74
+ if (config.raiseError) throw error;
75
+ }
76
+ }
79
77
  }
80
78
  };
81
79
 
@@ -104,13 +102,13 @@ const checkMuted = async (userId, config) => {
104
102
  return false;
105
103
  };
106
104
 
107
- module.exports = (
105
+ module.exports = async (
108
106
  receiverKeys,
109
107
  message,
110
108
  type,
111
109
  key,
112
110
  value,
113
- config = { type: "app", id: null, ignoreMute: false }
111
+ config = { type: "app", id: null, ignoreMute: false, raiseError: false }
114
112
  ) => {
115
113
  const logId = log("sendNotifications", "input", {
116
114
  receiverKeys,
@@ -142,6 +140,7 @@ module.exports = (
142
140
  }
143
141
  } catch (error) {
144
142
  log("sendNotifications", "error", error.toString());
143
+ if (config.raiseError) reject(error);
145
144
  }
146
145
  resolve();
147
146
  })
@@ -151,7 +150,6 @@ module.exports = (
151
150
  })
152
151
  );
153
152
  });
154
- Promise.all(promises).then((res) => {
155
- SendNotification(tokens, message, type, key, value, config);
156
- });
153
+ await Promise.all(promises);
154
+ await SendNotification(tokens, message, type, key, value, config);
157
155
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.4.18-beta.0",
3
+ "version": "1.4.20",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",
7
7
  "patch": "npm version patch",
8
- "betaupload": "npm publish --access public --tag beta",
8
+ "betaupload": "npm i && npm i && npm publish --access public --tag beta",
9
9
  "betaupload:p": "npm run betapatch && npm run betaupload",
10
- "upload": "npm publish --access public",
10
+ "upload": "npm i && npm i && npm publish --access public",
11
11
  "upload:p": "npm run patch && npm run upload"
12
12
  },
13
13
  "author": "Phillip Suh",