@plusscommunities/pluss-newsletter-aws 2.0.8-beta.1 → 2.0.8-beta.2
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/newsletterChanged.js +27 -48
- package/package-lock.json +4 -4
- package/package.json +2 -2
- package/watchNewsletter.js +46 -28
package/newsletterChanged.js
CHANGED
|
@@ -65,14 +65,17 @@ const setUnsentNotification = (update) => {
|
|
|
65
65
|
return;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
const checkSendNotifications =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
const checkSendNotifications = (update) => {
|
|
69
|
+
return new Promise(() => {
|
|
70
|
+
if (!update.Notification) return; // no notification
|
|
71
|
+
if (update.UnsentNotification !== "X") return; // already sent notification
|
|
72
|
+
if (update.UnixTimestamp > moment.utc().valueOf()) return; // publish date is later
|
|
72
73
|
|
|
73
|
-
try {
|
|
74
74
|
if (update.Private) {
|
|
75
|
-
|
|
75
|
+
update.Tagged.map((user) => {
|
|
76
|
+
return user.userId;
|
|
77
|
+
});
|
|
78
|
+
publishNotifications(
|
|
76
79
|
update.Tagged.map((user) => {
|
|
77
80
|
return user.userId;
|
|
78
81
|
}),
|
|
@@ -86,34 +89,24 @@ const checkSendNotifications = async (update) => {
|
|
|
86
89
|
return;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
|
|
92
|
+
getAudience(
|
|
90
93
|
update.Site,
|
|
91
94
|
update.AudienceType,
|
|
92
95
|
update.AudienceTypeSelection
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
setUnsentNotification(update);
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.error("checkSendNotifications error:", {
|
|
109
|
-
newsletterId: update.RowId,
|
|
110
|
-
site: update.Site,
|
|
111
|
-
error: error.message,
|
|
112
|
-
stack: error.stack,
|
|
96
|
+
).then((audience) => {
|
|
97
|
+
publishNotifications(
|
|
98
|
+
audience.map((u) => {
|
|
99
|
+
return u.id;
|
|
100
|
+
}),
|
|
101
|
+
values.notificationNewsletterPublished,
|
|
102
|
+
update.Site,
|
|
103
|
+
update.RowId,
|
|
104
|
+
update,
|
|
105
|
+
true
|
|
106
|
+
);
|
|
107
|
+
setUnsentNotification(update);
|
|
113
108
|
});
|
|
114
|
-
|
|
115
|
-
throw error;
|
|
116
|
-
}
|
|
109
|
+
});
|
|
117
110
|
};
|
|
118
111
|
|
|
119
112
|
const logAnalytics = (post) => {
|
|
@@ -126,11 +119,10 @@ const logAnalytics = (post) => {
|
|
|
126
119
|
);
|
|
127
120
|
};
|
|
128
121
|
|
|
129
|
-
module.exports.newsletterChanged =
|
|
122
|
+
module.exports.newsletterChanged = (event, context, callback) => {
|
|
130
123
|
console.log("newsletter changed");
|
|
131
124
|
|
|
132
|
-
|
|
133
|
-
for (const record of event.Records) {
|
|
125
|
+
event.Records.forEach((record) => {
|
|
134
126
|
console.log("Stream record: ", JSON.stringify(record));
|
|
135
127
|
|
|
136
128
|
let site;
|
|
@@ -153,20 +145,7 @@ module.exports.newsletterChanged = async (event, context, callback) => {
|
|
|
153
145
|
}
|
|
154
146
|
|
|
155
147
|
site = data.Site;
|
|
156
|
-
|
|
157
|
-
// Stream-level deduplication: Skip if notification already sent
|
|
158
|
-
if (data.UnsentNotification !== "X") {
|
|
159
|
-
console.log({
|
|
160
|
-
action: "newsletterChanged",
|
|
161
|
-
message: "Notification already sent, skipping duplicate stream event",
|
|
162
|
-
newsletterId: data.RowId,
|
|
163
|
-
unsentFlag: data.UnsentNotification,
|
|
164
|
-
});
|
|
165
|
-
} else {
|
|
166
|
-
// Await notification sending to ensure Lambda doesn't exit prematurely
|
|
167
|
-
await checkSendNotifications(data);
|
|
168
|
-
}
|
|
169
|
-
|
|
148
|
+
checkSendNotifications(data);
|
|
170
149
|
logAnalytics(data);
|
|
171
150
|
} else if (record.eventName == "MODIFY") {
|
|
172
151
|
console.log("MODIFY");
|
|
@@ -214,5 +193,5 @@ module.exports.newsletterChanged = async (event, context, callback) => {
|
|
|
214
193
|
}
|
|
215
194
|
|
|
216
195
|
logUpdate(site, values.updateKey);
|
|
217
|
-
}
|
|
196
|
+
});
|
|
218
197
|
};
|
package/package-lock.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-newsletter-aws",
|
|
3
|
-
"version": "2.0.8-beta.
|
|
3
|
+
"version": "2.0.8-beta.2",
|
|
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.
|
|
1510
|
-
"resolved": "https://registry.npmjs.org/@plusscommunities/pluss-core-aws/-/pluss-core-aws-2.0.23-beta.
|
|
1511
|
-
"integrity": "sha512-
|
|
1509
|
+
"version": "2.0.23-beta.3",
|
|
1510
|
+
"resolved": "https://registry.npmjs.org/@plusscommunities/pluss-core-aws/-/pluss-core-aws-2.0.23-beta.3.tgz",
|
|
1511
|
+
"integrity": "sha512-oBdo29f2w34LXzMa3I0rZJ9TxuSzshRd4Ky7AU/Rnx5jTkSMvd3p0EHsJNUEX5HEukdXItiZmor3tbFxxAilGg==",
|
|
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.8-beta.
|
|
3
|
+
"version": "2.0.8-beta.2",
|
|
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.
|
|
27
|
+
"@plusscommunities/pluss-core-aws": "2.0.23-beta.3",
|
|
28
28
|
"amazon-cognito-identity-js": "^2.0.19",
|
|
29
29
|
"axios": "^1.6.8",
|
|
30
30
|
"aws-sdk": "^2.1591.0",
|
package/watchNewsletter.js
CHANGED
|
@@ -27,13 +27,13 @@ const setUnsentNotification = (update) => {
|
|
|
27
27
|
return;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const sendNotifications = (update) => {
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
};
|