@plusscommunities/pluss-newsletter-aws 2.0.9-beta.0 → 2.0.9

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-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-newsletter-aws",
3
- "version": "2.0.9-beta.0",
3
+ "version": "2.0.9",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -1506,9 +1506,9 @@
1506
1506
  }
1507
1507
  },
1508
1508
  "@plusscommunities/pluss-core-aws": {
1509
- "version": "2.0.23-beta.2",
1510
- "resolved": "https://registry.npmjs.org/@plusscommunities/pluss-core-aws/-/pluss-core-aws-2.0.23-beta.2.tgz",
1511
- "integrity": "sha512-ZCWDvQirCZ6PDq8j27hgm8rjAwpDZupix5c50709SGHG10Melv4uMHM1o0q4KbYBysBvCHMubWtUhDBtDdakow==",
1509
+ "version": "2.0.23",
1510
+ "resolved": "https://registry.npmjs.org/@plusscommunities/pluss-core-aws/-/pluss-core-aws-2.0.23.tgz",
1511
+ "integrity": "sha512-pqZvjIvhkrMS37oazUmkXsItI4h1OcEQTikCBp4/zkzlsOY4GYJT91MGgROVficIeFKzlEI97PqswD2UiR+8Hg==",
1512
1512
  "requires": {
1513
1513
  "@aws/dynamodb-auto-marshaller": "^0.7.1",
1514
1514
  "amazon-cognito-identity-js": "^2.0.19",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-newsletter-aws",
3
- "version": "2.0.9-beta.0",
3
+ "version": "2.0.9",
4
4
  "description": "Extension package to enable newsletter on Pluss Communities Platform",
5
5
  "scripts": {
6
6
  "gc": "node ../../tools/gc ./",
@@ -24,7 +24,7 @@
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
26
  "@aws/dynamodb-auto-marshaller": "^0.7.1",
27
- "@plusscommunities/pluss-core-aws": "2.0.23-beta.2",
27
+ "@plusscommunities/pluss-core-aws": "2.0.23",
28
28
  "amazon-cognito-identity-js": "^2.0.19",
29
29
  "axios": "^1.6.8",
30
30
  "aws-sdk": "^2.1591.0",
@@ -27,13 +27,13 @@ const setUnsentNotification = (update) => {
27
27
  return;
28
28
  };
29
29
 
30
- const sendNotifications = (update) => {
31
- return new Promise(() => {
30
+ const sendNotifications = async (update) => {
31
+ if (!update.Notification) return; // no notification
32
+ if (update.UnsentNotification !== "X") return; // already sent notification
33
+
34
+ try {
32
35
  if (update.Private) {
33
- update.Tagged.map((user) => {
34
- return user.userId;
35
- });
36
- publishNotifications(
36
+ await publishNotifications(
37
37
  update.Tagged.map((user) => {
38
38
  return user.userId;
39
39
  }),
@@ -47,24 +47,35 @@ const sendNotifications = (update) => {
47
47
  return;
48
48
  }
49
49
 
50
- getAudience(
50
+ const audience = await getAudience(
51
51
  update.Site,
52
52
  update.AudienceType,
53
53
  update.AudienceTypeSelection
54
- ).then((audience) => {
55
- publishNotifications(
56
- audience.map((u) => {
57
- return u.id;
58
- }),
59
- values.notificationNewsletterPublished,
60
- update.Site,
61
- update.RowId,
62
- update,
63
- true
64
- );
65
- setUnsentNotification(update);
54
+ );
55
+
56
+ await publishNotifications(
57
+ audience.map((u) => {
58
+ return u.id;
59
+ }),
60
+ values.notificationNewsletterPublished,
61
+ update.Site,
62
+ update.RowId,
63
+ update,
64
+ true
65
+ );
66
+
67
+ setUnsentNotification(update);
68
+ } catch (error) {
69
+ console.error("sendNotifications error:", {
70
+ newsletterId: update.RowId,
71
+ site: update.Site,
72
+ title: update.Title,
73
+ error: error.message,
74
+ stack: error.stack,
66
75
  });
67
- });
76
+ // Don't re-throw - allow other newsletters to process
77
+ // But log the failure so we can investigate
78
+ }
68
79
  };
69
80
 
70
81
  const fixActivityLog = async (post, startTime) => {
@@ -197,14 +208,21 @@ module.exports.watchNewsletter = async (event, context, callback) => {
197
208
  };
198
209
  console.log("running query");
199
210
  console.log(query);
200
- indexQuery(values.tableNameNewsletterEntries, query).then((res) => {
201
- res.Items.forEach((update) => {
202
- console.log(
203
- `sending notifications for ${update.RowId} - ${update.Title}`
204
- );
205
- sendNotifications(update);
206
- });
207
- });
211
+
212
+ // Wait for query to complete
213
+ const res = await indexQuery(values.tableNameNewsletterEntries, query);
214
+
215
+ console.log(`Found ${res.Items.length} newsletters to send notifications for`);
216
+
217
+ // Process newsletters sequentially to ensure each completes before next starts
218
+ for (const update of res.Items) {
219
+ console.log(
220
+ `sending notifications for ${update.RowId} - ${update.Title}`
221
+ );
222
+
223
+ // Wait for each newsletter's notifications to complete
224
+ await sendNotifications(update);
225
+ }
208
226
 
209
227
  await checkFixLog(startTime);
210
228
  };