@plusscommunities/pluss-core-aws 2.0.26-auth.0 → 2.0.26-beta.0

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 (94) hide show
  1. package/aws/getDefaultEmailAddress.js +21 -21
  2. package/aws/getEmailService.js +16 -16
  3. package/aws/getEmailServiceInfo.js +26 -26
  4. package/aws/sendEmail.js +31 -31
  5. package/config.js +1 -1
  6. package/db/activity/publishActivity.js +22 -22
  7. package/db/analytics/checkActivityExists.js +15 -15
  8. package/db/analytics/logAnalyticsActivity.js +69 -37
  9. package/db/analytics/scheduleOldAggregation.js +14 -14
  10. package/db/auth/getSiteSetting.js +12 -12
  11. package/db/auth/getSiteUserTypes.js +16 -16
  12. package/db/auth/getUserAuth.js +13 -13
  13. package/db/automatedactions/getActionBySiteTrigger.js +9 -9
  14. package/db/common/deleteRef.js +21 -21
  15. package/db/common/editRef.js +36 -36
  16. package/db/common/getRef.js +23 -23
  17. package/db/common/getTableCount.js +18 -18
  18. package/db/common/indexQuery.js +17 -17
  19. package/db/common/indexQueryRecursive.js +20 -20
  20. package/db/common/scanRef.js +18 -18
  21. package/db/common/scanRefRecursive.js +20 -20
  22. package/db/common/updateAttribute.js +27 -27
  23. package/db/common/updateRef.js +20 -20
  24. package/db/linkedUsers/getLinkedBy.js +21 -21
  25. package/db/linkedUsers/getLinkedTo.js +21 -21
  26. package/db/notifications/deleteNotificationsByEntity.js +21 -21
  27. package/db/notifications/getNotificationSetting.js +14 -14
  28. package/db/notifications/publishNotifications.js +39 -39
  29. package/db/postgres/getKnex.js +214 -0
  30. package/db/postgres/safeError.js +40 -0
  31. package/db/property/Property.js +128 -0
  32. package/db/property/PropertyRepository.js +86 -0
  33. package/db/scheduledActions/deleteActionQueue.js +1 -1
  34. package/db/scheduledActions/getActionQueueByEntityId.js +10 -10
  35. package/db/scheduledActions/getActionQueueByEntityKey.js +9 -9
  36. package/db/scheduledActions/getActionQueueById.js +9 -9
  37. package/db/scheduledActions/getActionQueueByTriggerAt.js +14 -14
  38. package/db/scheduledActions/updateActionQueue.js +29 -29
  39. package/db/strings/getString.js +20 -20
  40. package/db/strings/logUpdate.js +18 -18
  41. package/db/templates/getTemplateById.js +1 -1
  42. package/db/templates/getTemplatesList.js +10 -10
  43. package/db/templates/updateTemplate.js +9 -9
  44. package/db/users/getRole.js +1 -1
  45. package/db/users/getUser.js +9 -9
  46. package/db/users/getUserByEmail.js +17 -17
  47. package/helper/audience/filterByAudienceType.js +27 -27
  48. package/helper/audience/filterOnAudienceType.js +26 -26
  49. package/helper/audience/getAudience.js +187 -187
  50. package/helper/audience/getMatchingAudienceTypes.js +21 -21
  51. package/helper/audience/getMatchingAudienceTypesFromPreview.js +60 -60
  52. package/helper/audience/getMatchingTags.js +15 -15
  53. package/helper/audience/isValidAudience.js +20 -20
  54. package/helper/auth/checkTokenBlacklist.js +17 -17
  55. package/helper/auth/getApiKeyFromReq.js +2 -2
  56. package/helper/auth/getSessionUser.js +70 -85
  57. package/helper/auth/getSessionUserFromReq.js +2 -2
  58. package/helper/auth/getSessionUserFromReqAuthKey.js +11 -11
  59. package/helper/auth/validateApiKey.js +32 -32
  60. package/helper/auth/validateMasterAuth.js +174 -174
  61. package/helper/auth/validateSiteAccess.js +12 -12
  62. package/helper/auth/validateSiteSetting.js +7 -7
  63. package/helper/auth/validateUserLoggedIn.js +19 -19
  64. package/helper/createGuid.js +5 -5
  65. package/helper/generateJsonResponse.js +27 -27
  66. package/helper/getUserPreview.js +57 -57
  67. package/helper/getUserPreviewFromHeader.js +17 -17
  68. package/helper/getUserPreviewFromReq.js +17 -17
  69. package/helper/hqPublishing.js +465 -0
  70. package/helper/index.js +28 -28
  71. package/helper/notifySiteConfigs.js +67 -52
  72. package/helper/opengraph/getOpenGraph.js +12 -12
  73. package/helper/rates/checkRateLimit.js +38 -38
  74. package/helper/requestToSource.js +10 -10
  75. package/helper/sendEmail.js +120 -120
  76. package/helper/templates/replacePlaceHolders.js +29 -29
  77. package/helper/time/getLocalTimestamp.js +18 -18
  78. package/helper/time/getSiteTimezone.js +11 -11
  79. package/helper/triggerAutomatedAction.js +25 -25
  80. package/helper/userToUserPreview.js +23 -23
  81. package/helper/users/getUserTypesByPermission.js +24 -24
  82. package/helper/users/getUsersByPermission.js +20 -20
  83. package/notification/prepNotification.js +144 -144
  84. package/notification/sendNotifications.js +166 -166
  85. package/package.json +37 -40
  86. package/templates/supportTicketEmails.js +8 -8
  87. package/helper/auth/context/AuthenticationContext.js +0 -50
  88. package/helper/auth/context/AuthenticationStrategy.js +0 -20
  89. package/helper/auth/context/auth0/Strategy.js +0 -12
  90. package/helper/auth/context/auth0/functions/decodeAccessToken.js +0 -102
  91. package/helper/auth/context/auth0/functions/getSessionUser.js +0 -21
  92. package/helper/auth/context/boltonclarke/Strategy.js +0 -10
  93. package/helper/auth/context/cognito/Strategy.js +0 -12
  94. package/helper/auth/context/cognito/functions/getSessionUser.js +0 -76
@@ -3,35 +3,35 @@ const moment = require("moment");
3
3
  const editRef = require("../common/editRef");
4
4
 
5
5
  module.exports = (rowId, update) => {
6
- return new Promise(async (resolve, reject) => {
7
- try {
8
- const now = moment().valueOf();
9
- const { Created, Updated, TriggerAt, Status, Recipients } = update;
10
- if (!rowId) {
11
- rowId = uuid.v1();
12
- if (!Created) update.Created = now;
13
- if (!Status) update.Status = "READY";
14
- } else {
15
- if (!Updated) update.Updated = now;
16
- }
17
- if (TriggerAt) {
18
- update.TriggerAt =
19
- typeof TriggerAt === "string"
20
- ? moment(TriggerAt).valueOf()
21
- : TriggerAt;
22
- }
23
- if (Recipients) {
24
- update.Recipients =
25
- typeof Recipients === "string" || Recipients instanceof String
26
- ? Recipients.split(",").map((r) => r.trim())
27
- : Recipients;
28
- }
6
+ return new Promise(async (resolve, reject) => {
7
+ try {
8
+ const now = moment().valueOf();
9
+ const { Created, Updated, TriggerAt, Status, Recipients } = update;
10
+ if (!rowId) {
11
+ rowId = uuid.v1();
12
+ if (!Created) update.Created = now;
13
+ if (!Status) update.Status = "READY";
14
+ } else {
15
+ if (!Updated) update.Updated = now;
16
+ }
17
+ if (TriggerAt) {
18
+ update.TriggerAt =
19
+ typeof TriggerAt === "string"
20
+ ? moment(TriggerAt).valueOf()
21
+ : TriggerAt;
22
+ }
23
+ if (Recipients) {
24
+ update.Recipients =
25
+ typeof Recipients === "string" || Recipients instanceof String
26
+ ? Recipients.split(",").map((r) => r.trim())
27
+ : Recipients;
28
+ }
29
29
 
30
- const updated = await editRef("actionqueue", "RowId", rowId, update);
30
+ const updated = await editRef("actionqueue", "RowId", rowId, update);
31
31
 
32
- resolve(updated);
33
- } catch (error) {
34
- reject(error);
35
- }
36
- });
32
+ resolve(updated);
33
+ } catch (error) {
34
+ reject(error);
35
+ }
36
+ });
37
37
  };
@@ -2,24 +2,24 @@ const _ = require("lodash");
2
2
  const getRef = require("../common/getRef");
3
3
 
4
4
  module.exports = async (id, defaultSite) => {
5
- return new Promise((resolve) => {
6
- getRef("strings", "RowId", id)
7
- .then((ev) => {
8
- return resolve(ev.Value);
9
- })
10
- .catch(() => {
11
- if (defaultSite) {
12
- const defaultId = `${defaultSite}_${id.split("_")[1]}`;
13
- getRef("strings", "RowId", defaultId)
14
- .then((ev) => {
15
- return resolve(ev.Value);
16
- })
17
- .catch(() => {
18
- return resolve(null);
19
- });
20
- } else {
21
- return resolve(null);
22
- }
23
- });
24
- });
5
+ return new Promise((resolve) => {
6
+ getRef("strings", "RowId", id)
7
+ .then((ev) => {
8
+ return resolve(ev.Value);
9
+ })
10
+ .catch(() => {
11
+ if (defaultSite) {
12
+ const defaultId = `${defaultSite}_${id.split("_")[1]}`;
13
+ getRef("strings", "RowId", defaultId)
14
+ .then((ev) => {
15
+ return resolve(ev.Value);
16
+ })
17
+ .catch(() => {
18
+ return resolve(null);
19
+ });
20
+ } else {
21
+ return resolve(null);
22
+ }
23
+ });
24
+ });
25
25
  };
@@ -3,22 +3,22 @@ const { getRowId, log } = require("../../helper");
3
3
  const updateRef = require("../common/updateRef");
4
4
 
5
5
  module.exports = (site, entity) => {
6
- return new Promise((resolve, reject) => {
7
- const key = `update-${entity}`;
8
- const entry = {
9
- Site: site,
10
- StringId: key,
11
- Value: moment().valueOf(),
12
- RowId: getRowId(site, key),
13
- };
14
- updateRef("strings", entry)
15
- .then((data) => {
16
- log("logUpdate", "Logged", data);
17
- return resolve(data);
18
- })
19
- .catch((error) => {
20
- log("logUpdate", "Error", error);
21
- return reject(error);
22
- });
23
- });
6
+ return new Promise((resolve, reject) => {
7
+ const key = `update-${entity}`;
8
+ const entry = {
9
+ Site: site,
10
+ StringId: key,
11
+ Value: moment().valueOf(),
12
+ RowId: getRowId(site, key),
13
+ };
14
+ updateRef("strings", entry)
15
+ .then((data) => {
16
+ log("logUpdate", "Logged", data);
17
+ return resolve(data);
18
+ })
19
+ .catch((error) => {
20
+ log("logUpdate", "Error", error);
21
+ return reject(error);
22
+ });
23
+ });
24
24
  };
@@ -1,5 +1,5 @@
1
1
  const getRef = require("../common/getRef");
2
2
 
3
3
  module.exports = async (rowId) => {
4
- return await getRef("templates", "RowId", rowId);
4
+ return await getRef("templates", "RowId", rowId);
5
5
  };
@@ -1,15 +1,15 @@
1
1
  const indexQuery = require("../common/indexQuery");
2
2
 
3
3
  module.exports = async (site, featureKey) => {
4
- const query = {
5
- IndexName: "SiteFeatureKeyIndex",
6
- KeyConditionExpression: "Site = :site AND FeatureKey = :featureKey",
7
- ExpressionAttributeValues: {
8
- ":site": site,
9
- ":featureKey": featureKey,
10
- },
11
- };
4
+ const query = {
5
+ IndexName: "SiteFeatureKeyIndex",
6
+ KeyConditionExpression: "Site = :site AND FeatureKey = :featureKey",
7
+ ExpressionAttributeValues: {
8
+ ":site": site,
9
+ ":featureKey": featureKey,
10
+ },
11
+ };
12
12
 
13
- const { Items } = await indexQuery("templates", query);
14
- return Items;
13
+ const { Items } = await indexQuery("templates", query);
14
+ return Items;
15
15
  };
@@ -3,14 +3,14 @@ const moment = require("moment");
3
3
  const editRef = require("../common/editRef");
4
4
 
5
5
  module.exports = async (rowId, update) => {
6
- const now = moment().valueOf();
7
- const { Updated } = update;
8
- if (!rowId) {
9
- rowId = uuid.v1();
10
- if (!update.Created) update.Created = now;
11
- } else {
12
- if (!Updated) update.Updated = now;
13
- }
6
+ const now = moment().valueOf();
7
+ const { Updated } = update;
8
+ if (!rowId) {
9
+ rowId = uuid.v1();
10
+ if (!update.Created) update.Created = now;
11
+ } else {
12
+ if (!Updated) update.Updated = now;
13
+ }
14
14
 
15
- return await editRef("templates", "RowId", rowId, update);
15
+ return await editRef("templates", "RowId", rowId, update);
16
16
  };
@@ -2,5 +2,5 @@ const { getRowId } = require("../../helper");
2
2
  const getRef = require("../common/getRef");
3
3
 
4
4
  module.exports = async (site, id) => {
5
- return await getRef("roles", "RowId", getRowId(site, id));
5
+ return await getRef("roles", "RowId", getRowId(site, id));
6
6
  };
@@ -1,13 +1,13 @@
1
1
  const getRef = require("../common/getRef");
2
2
 
3
3
  module.exports = (key) => {
4
- return new Promise((resolve, reject) => {
5
- getRef("users", "Id", key)
6
- .then((user) => {
7
- resolve(user);
8
- })
9
- .catch((error) => {
10
- reject(error);
11
- });
12
- });
4
+ return new Promise((resolve, reject) => {
5
+ getRef("users", "Id", key)
6
+ .then((user) => {
7
+ resolve(user);
8
+ })
9
+ .catch((error) => {
10
+ reject(error);
11
+ });
12
+ });
13
13
  };
@@ -3,21 +3,21 @@ const { log } = require("../../helper");
3
3
  const indexQuery = require("../common/indexQuery");
4
4
 
5
5
  module.exports = async (email) => {
6
- return new Promise(async (resolve, reject) => {
7
- const logId = log("getUserByEmail", "email", email);
8
- const query = {
9
- IndexName: "UserValidateIndexEmail",
10
- KeyConditionExpression: "email = :email",
11
- ExpressionAttributeValues: {
12
- ":email": email.toLowerCase(),
13
- },
14
- };
15
- const qResult = await indexQuery("users", query);
16
- if (_.isEmpty(qResult.Items)) {
17
- log("getUserByEmail", "result", null, logId);
18
- return resolve(null);
19
- }
20
- log("getUserByEmail", "result", qResult.Items[0], logId);
21
- return resolve(qResult.Items[0]);
22
- });
6
+ return new Promise(async (resolve, reject) => {
7
+ const logId = log("getUserByEmail", "email", email);
8
+ const query = {
9
+ IndexName: "UserValidateIndexEmail",
10
+ KeyConditionExpression: "email = :email",
11
+ ExpressionAttributeValues: {
12
+ ":email": email.toLowerCase(),
13
+ },
14
+ };
15
+ const qResult = await indexQuery("users", query);
16
+ if (_.isEmpty(qResult.Items)) {
17
+ log("getUserByEmail", "result", null, logId);
18
+ return resolve(null);
19
+ }
20
+ log("getUserByEmail", "result", qResult.Items[0], logId);
21
+ return resolve(qResult.Items[0]);
22
+ });
23
23
  };
@@ -5,34 +5,34 @@ const getMatchingTags = require("./getMatchingTags");
5
5
  const isValidAudience = require("./isValidAudience");
6
6
 
7
7
  module.exports = async (items, authkey, site) => {
8
- const validTypes = await getMatchingAudienceTypes(authkey);
9
- let validTags = [];
10
- if (site) {
11
- const userId = await getSessionUser(authkey);
12
- validTags = await getMatchingTags(userId, site);
13
- }
8
+ const validTypes = await getMatchingAudienceTypes(authkey);
9
+ let validTags = [];
10
+ if (site) {
11
+ const userId = await getSessionUser(authkey);
12
+ validTags = await getMatchingTags(userId, site);
13
+ }
14
14
 
15
- return _.filter(items, (item) => {
16
- if (!item.AudienceType) return true;
15
+ return _.filter(items, (item) => {
16
+ if (!item.AudienceType) return true;
17
17
 
18
- if (item.AudienceType === "Custom") {
19
- return _.some(item.AudienceTypeSelection, (at) =>
20
- isValidAudience(
21
- site,
22
- at.AudienceType,
23
- at.AudienceTypeSelection,
24
- validTypes,
25
- validTags
26
- )
27
- );
28
- }
18
+ if (item.AudienceType === "Custom") {
19
+ return _.some(item.AudienceTypeSelection, (at) =>
20
+ isValidAudience(
21
+ site,
22
+ at.AudienceType,
23
+ at.AudienceTypeSelection,
24
+ validTypes,
25
+ validTags,
26
+ ),
27
+ );
28
+ }
29
29
 
30
- return isValidAudience(
31
- site,
32
- item.AudienceType,
33
- item.AudienceTypeSelection,
34
- validTypes,
35
- validTags
36
- );
37
- });
30
+ return isValidAudience(
31
+ site,
32
+ item.AudienceType,
33
+ item.AudienceTypeSelection,
34
+ validTypes,
35
+ validTags,
36
+ );
37
+ });
38
38
  };
@@ -4,33 +4,33 @@ const getMatchingTags = require("./getMatchingTags");
4
4
  const isValidAudience = require("./isValidAudience");
5
5
 
6
6
  module.exports = async (items, validTypes, authkey, site) => {
7
- let validTags = [];
8
- if (authkey) {
9
- const userId = await getSessionUser(authkey);
10
- validTags = await getMatchingTags(userId, site);
11
- }
7
+ let validTags = [];
8
+ if (authkey) {
9
+ const userId = await getSessionUser(authkey);
10
+ validTags = await getMatchingTags(userId, site);
11
+ }
12
12
 
13
- return _.filter(items, (item) => {
14
- if (!item.AudienceType) return true;
13
+ return _.filter(items, (item) => {
14
+ if (!item.AudienceType) return true;
15
15
 
16
- if (item.AudienceType === "Custom") {
17
- return _.some(item.AudienceTypeSelection, (at) =>
18
- isValidAudience(
19
- site,
20
- at.AudienceType,
21
- at.AudienceTypeSelection,
22
- validTypes,
23
- validTags
24
- )
25
- );
26
- }
16
+ if (item.AudienceType === "Custom") {
17
+ return _.some(item.AudienceTypeSelection, (at) =>
18
+ isValidAudience(
19
+ site,
20
+ at.AudienceType,
21
+ at.AudienceTypeSelection,
22
+ validTypes,
23
+ validTags,
24
+ ),
25
+ );
26
+ }
27
27
 
28
- return isValidAudience(
29
- site,
30
- item.AudienceType,
31
- item.AudienceTypeSelection,
32
- validTypes,
33
- validTags
34
- );
35
- });
28
+ return isValidAudience(
29
+ site,
30
+ item.AudienceType,
31
+ item.AudienceTypeSelection,
32
+ validTypes,
33
+ validTags,
34
+ );
35
+ });
36
36
  };