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

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 (90) 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/scheduledActions/deleteActionQueue.js +1 -1
  30. package/db/scheduledActions/getActionQueueByEntityId.js +10 -10
  31. package/db/scheduledActions/getActionQueueByEntityKey.js +9 -9
  32. package/db/scheduledActions/getActionQueueById.js +9 -9
  33. package/db/scheduledActions/getActionQueueByTriggerAt.js +14 -14
  34. package/db/scheduledActions/updateActionQueue.js +29 -29
  35. package/db/strings/getString.js +20 -20
  36. package/db/strings/logUpdate.js +18 -18
  37. package/db/templates/getTemplateById.js +1 -1
  38. package/db/templates/getTemplatesList.js +10 -10
  39. package/db/templates/updateTemplate.js +9 -9
  40. package/db/users/getRole.js +1 -1
  41. package/db/users/getUser.js +9 -9
  42. package/db/users/getUserByEmail.js +17 -17
  43. package/helper/audience/filterByAudienceType.js +27 -27
  44. package/helper/audience/filterOnAudienceType.js +26 -26
  45. package/helper/audience/getAudience.js +187 -187
  46. package/helper/audience/getMatchingAudienceTypes.js +21 -21
  47. package/helper/audience/getMatchingAudienceTypesFromPreview.js +60 -60
  48. package/helper/audience/getMatchingTags.js +15 -15
  49. package/helper/audience/isValidAudience.js +20 -20
  50. package/helper/auth/checkTokenBlacklist.js +17 -17
  51. package/helper/auth/getApiKeyFromReq.js +2 -2
  52. package/helper/auth/getSessionUser.js +70 -85
  53. package/helper/auth/getSessionUserFromReq.js +2 -2
  54. package/helper/auth/getSessionUserFromReqAuthKey.js +11 -11
  55. package/helper/auth/validateApiKey.js +32 -32
  56. package/helper/auth/validateMasterAuth.js +174 -174
  57. package/helper/auth/validateSiteAccess.js +12 -12
  58. package/helper/auth/validateSiteSetting.js +7 -7
  59. package/helper/auth/validateUserLoggedIn.js +19 -19
  60. package/helper/createGuid.js +5 -5
  61. package/helper/generateJsonResponse.js +27 -27
  62. package/helper/getUserPreview.js +57 -57
  63. package/helper/getUserPreviewFromHeader.js +17 -17
  64. package/helper/getUserPreviewFromReq.js +17 -17
  65. package/helper/hqPublishing.js +337 -0
  66. package/helper/index.js +28 -28
  67. package/helper/notifySiteConfigs.js +132 -0
  68. package/helper/opengraph/getOpenGraph.js +12 -12
  69. package/helper/rates/checkRateLimit.js +38 -38
  70. package/helper/requestToSource.js +10 -10
  71. package/helper/sendEmail.js +120 -120
  72. package/helper/templates/replacePlaceHolders.js +29 -29
  73. package/helper/time/getLocalTimestamp.js +18 -18
  74. package/helper/time/getSiteTimezone.js +11 -11
  75. package/helper/triggerAutomatedAction.js +25 -25
  76. package/helper/userToUserPreview.js +23 -23
  77. package/helper/users/getUserTypesByPermission.js +24 -24
  78. package/helper/users/getUsersByPermission.js +20 -20
  79. package/notification/prepNotification.js +144 -144
  80. package/notification/sendNotifications.js +166 -166
  81. package/package.json +35 -40
  82. package/templates/supportTicketEmails.js +8 -8
  83. package/helper/auth/context/AuthenticationContext.js +0 -50
  84. package/helper/auth/context/AuthenticationStrategy.js +0 -20
  85. package/helper/auth/context/auth0/Strategy.js +0 -12
  86. package/helper/auth/context/auth0/functions/decodeAccessToken.js +0 -102
  87. package/helper/auth/context/auth0/functions/getSessionUser.js +0 -21
  88. package/helper/auth/context/boltonclarke/Strategy.js +0 -10
  89. package/helper/auth/context/cognito/Strategy.js +0 -12
  90. package/helper/auth/context/cognito/functions/getSessionUser.js +0 -76
@@ -2,24 +2,24 @@ const crypto = require("crypto");
2
2
  const { getRef } = require("../../db/common/getRef");
3
3
 
4
4
  module.exports = async (token) => {
5
- if (!token) return false;
5
+ if (!token) return false;
6
6
 
7
- try {
8
- // Create hash of token for TokenId lookup
9
- const tokenHash = crypto.createHash("sha256").update(token).digest("hex");
7
+ try {
8
+ // Create hash of token for TokenId lookup
9
+ const tokenHash = crypto.createHash("sha256").update(token).digest("hex");
10
10
 
11
- // Check if token exists in blacklist
12
- const blacklistedToken = await getRef(
13
- "invalidTokens",
14
- "TokenId",
15
- tokenHash
16
- );
11
+ // Check if token exists in blacklist
12
+ const blacklistedToken = await getRef(
13
+ "invalidTokens",
14
+ "TokenId",
15
+ tokenHash,
16
+ );
17
17
 
18
- // Return true if found (blacklisted), false if not found
19
- return !!blacklistedToken;
20
- } catch (error) {
21
- // If error occurs during lookup, assume token is not blacklisted
22
- // This ensures authentication doesn't fail due to blacklist issues
23
- return false;
24
- }
18
+ // Return true if found (blacklisted), false if not found
19
+ return !!blacklistedToken;
20
+ } catch (error) {
21
+ // If error occurs during lookup, assume token is not blacklisted
22
+ // This ensures authentication doesn't fail due to blacklist issues
23
+ return false;
24
+ }
25
25
  };
@@ -1,6 +1,6 @@
1
1
  const getRef = require("../../db/common/getRef");
2
2
 
3
3
  module.exports = async (event) => {
4
- if (!event?.headers?.apikey) return null;
5
- return await getRef("accesskeys", "Key", event.headers.apikey);
4
+ if (!event?.headers?.apikey) return null;
5
+ return await getRef("accesskeys", "Key", event.headers.apikey);
6
6
  };
@@ -1,90 +1,75 @@
1
- // const https = require("https");
2
- // const jose = require("node-jose");
3
- // const { app_client_id, keys_url } = require("../../../config");
4
- // const isUserDisabled = require("./isUserDisabled");
5
- const { log } = require("..");
6
- const AuthenticationContext = require("./context/AuthenticationContext");
1
+ const https = require("https");
2
+ const jose = require("node-jose");
3
+ const { getConfig } = require("../../config");
4
+ const checkTokenBlacklist = require("./checkTokenBlacklist");
7
5
 
8
6
  module.exports = async (token) => {
9
- const logId = log("getSessionUser", "Start", true);
10
- const userId = await AuthenticationContext.getSessionUser(token);
11
- log("getSessionUser", "Result", userId, logId);
12
- return userId;
13
- // return new Promise((resolve, reject) => {
14
- // if (!token) {
15
- // return resolve(null);
16
- // }
17
- // var sections = token.split(".");
18
- // // get the kid from the headers prior to verification
19
- // var header = jose.util.base64url.decode(sections[0]);
20
- // header = JSON.parse(header);
21
- // var kid = header.kid;
22
- // // download the public keys
23
- // https.get(keys_url, async (response) => {
24
- // if (response.statusCode == 200) {
25
- // response.on("data", async (body) => {
26
- // var keys = JSON.parse(body)["keys"];
27
- // // search for the kid in the downloaded public keys
28
- // var key_index = -1;
29
- // for (var i = 0; i < keys.length; i++) {
30
- // if (kid == keys[i].kid) {
31
- // key_index = i;
32
- // break;
33
- // }
34
- // }
35
- // if (key_index == -1) {
36
- // reject();
37
- // return;
38
- // }
39
- // // construct the public key
40
- // jose.JWK.asKey(keys[key_index])
41
- // .then(async (result) => {
42
- // // verify the signature
43
- // jose.JWS.createVerify(result)
44
- // .verify(token)
45
- // .then(async (result2) => {
46
- // // now we can use the claims
47
- // var claims = JSON.parse(result2.payload);
48
- // // additionally we can verify the token expiration
49
- // var current_ts = Math.floor(new Date() / 1000);
50
- // if (current_ts > claims.exp) {
51
- // console.log("Token is expired");
52
- // reject("Token is expired");
53
- // return;
54
- // }
7
+ return new Promise(async (resolve, reject) => {
8
+ if (!token) {
9
+ return resolve(null);
10
+ }
55
11
 
56
- // /* --=- Optional audience stuff we dont use.
57
- // // and the Audience (use claims.client_id if verifying an access token)
58
- // if (claims.aud != app_client_id) {
59
- // console.log('Token was not issued for this audience')
60
- // return;
61
- // }
62
- // */
12
+ // Check if token is blacklisted before expensive verification
13
+ const isBlacklisted = await checkTokenBlacklist(token);
14
+ if (isBlacklisted) {
15
+ reject("Token has been invalidated");
16
+ return;
17
+ }
63
18
 
64
- // const isDisabled = await isUserDisabled(claims.username);
65
-
66
- // if (isDisabled) {
67
- // console.log("User is disabled");
68
- // reject("User is disabled");
69
- // return;
70
- // }
71
-
72
- // resolve(claims.username);
73
- // })
74
- // .catch(async (error) => {
75
- // console.log("Signature verification failed", error);
76
- // reject("Signature verification failed");
77
- // });
78
- // })
79
- // .catch(async (error) => {
80
- // console.log("failed JWK.asKey", error);
81
- // reject(error);
82
- // });
83
- // });
84
- // } else {
85
- // console.log("failed on response", response);
86
- // reject(response);
87
- // }
88
- // });
89
- // });
19
+ var sections = token.split(".");
20
+ // get the kid from the headers prior to verification
21
+ var header = jose.util.base64url.decode(sections[0]);
22
+ header = JSON.parse(header);
23
+ var kid = header.kid;
24
+ // download the public keys
25
+ https.get(getConfig().keys_url, function (response) {
26
+ if (response.statusCode == 200) {
27
+ response.on("data", function (body) {
28
+ var keys = JSON.parse(body)["keys"];
29
+ // search for the kid in the downloaded public keys
30
+ var key_index = -1;
31
+ for (var i = 0; i < keys.length; i++) {
32
+ if (kid == keys[i].kid) {
33
+ key_index = i;
34
+ break;
35
+ }
36
+ }
37
+ if (key_index == -1) {
38
+ reject();
39
+ return;
40
+ }
41
+ // construct the public key
42
+ jose.JWK.asKey(keys[key_index])
43
+ .then(function (result) {
44
+ // verify the signature
45
+ jose.JWS.createVerify(result)
46
+ .verify(token)
47
+ .then(function (result2) {
48
+ // now we can use the claims
49
+ var claims = JSON.parse(result2.payload);
50
+ // additionally we can verify the token expiration
51
+ var current_ts = Math.floor(new Date() / 1000);
52
+ if (current_ts > claims.exp) {
53
+ console.log("Token is expired");
54
+ reject("Token is expired");
55
+ return;
56
+ }
57
+ resolve(claims.username);
58
+ })
59
+ .catch(function (error) {
60
+ console.log("Signature verification failed", error);
61
+ reject("Signature verification failed");
62
+ });
63
+ })
64
+ .catch(function (error) {
65
+ console.log("failed JWK.asKey", error);
66
+ reject(error);
67
+ });
68
+ });
69
+ } else {
70
+ console.log("failed on response", response);
71
+ reject(response);
72
+ }
73
+ });
74
+ });
90
75
  };
@@ -1,6 +1,6 @@
1
1
  const getSessionUser = require("./getSessionUser");
2
2
 
3
3
  module.exports = (event) => {
4
- const idToken = event.headers.Authorization.split("Bearer ")[1];
5
- return getSessionUser(idToken);
4
+ const idToken = event.headers.Authorization.split("Bearer ")[1];
5
+ return getSessionUser(idToken);
6
6
  };
@@ -2,15 +2,15 @@ const getSessionUser = require("./getSessionUser");
2
2
  const getApiKeyFromReq = require("./getApiKeyFromReq");
3
3
 
4
4
  module.exports = async (event) => {
5
- if (!event.headers) {
6
- return null;
7
- }
8
- if (event.headers.apikey) {
9
- const key = await getApiKeyFromReq(event);
10
- return key?.UserId;
11
- }
12
- if (!event.headers.authkey) {
13
- return null;
14
- }
15
- return getSessionUser(event.headers.authkey);
5
+ if (!event.headers) {
6
+ return null;
7
+ }
8
+ if (event.headers.apikey) {
9
+ const key = await getApiKeyFromReq(event);
10
+ return key?.UserId;
11
+ }
12
+ if (!event.headers.authkey) {
13
+ return null;
14
+ }
15
+ return getSessionUser(event.headers.authkey);
16
16
  };
@@ -3,41 +3,41 @@ const { log, generateLogId } = require("../");
3
3
  const getApiKeyFromReq = require("./getApiKeyFromReq");
4
4
 
5
5
  module.exports = async (req, actionType, site) => {
6
- const logId = generateLogId();
7
- try {
8
- log("ApiKey", "Input", req.headers.apikey, logId);
9
- const key = await getApiKeyFromReq(req);
10
- log("ApiKey", "Key", key, logId);
6
+ const logId = generateLogId();
7
+ try {
8
+ log("ApiKey", "Input", req.headers.apikey, logId);
9
+ const key = await getApiKeyFromReq(req);
10
+ log("ApiKey", "Key", key, logId);
11
11
 
12
- if (key.UserId) {
13
- const validateMasterAuth = require("./validateMasterAuth");
14
- return await validateMasterAuth(undefined, actionType, site, undefined, {
15
- userId: key.UserId,
16
- });
17
- }
12
+ if (key.UserId) {
13
+ const validateMasterAuth = require("./validateMasterAuth");
14
+ return await validateMasterAuth(undefined, actionType, site, undefined, {
15
+ userId: key.UserId,
16
+ });
17
+ }
18
18
 
19
- const validSite = key.Site === site;
20
- const isHQKey = key.Site === "hq";
21
- log("ApiKey", "validSite", validSite, logId);
22
- log("ApiKey", "isHQKey", isHQKey, logId);
19
+ const validSite = key.Site === site;
20
+ const isHQKey = key.Site === "hq";
21
+ log("ApiKey", "validSite", validSite, logId);
22
+ log("ApiKey", "isHQKey", isHQKey, logId);
23
23
 
24
- if (!validSite && !isHQKey) {
25
- log("ApiKey", "Result", false, logId);
26
- return false;
27
- }
24
+ if (!validSite && !isHQKey) {
25
+ log("ApiKey", "Result", false, logId);
26
+ return false;
27
+ }
28
28
 
29
- const isAny = actionType === "any";
30
- const isMaster = _.includes(key.Permissions, "master");
31
- const hasPermission = _.includes(key.Permissions, actionType);
32
- const result = isAny || isMaster || hasPermission;
29
+ const isAny = actionType === "any";
30
+ const isMaster = _.includes(key.Permissions, "master");
31
+ const hasPermission = _.includes(key.Permissions, actionType);
32
+ const result = isAny || isMaster || hasPermission;
33
33
 
34
- log("ApiKey", "isAny", isAny, logId);
35
- log("ApiKey", "isMaster", isMaster, logId);
36
- log("ApiKey", "hasPermission", hasPermission, logId);
37
- log("ApiKey", "Result", result, logId);
38
- return result;
39
- } catch (e) {
40
- log("ApiKey", "Error", e, logId);
41
- return false;
42
- }
34
+ log("ApiKey", "isAny", isAny, logId);
35
+ log("ApiKey", "isMaster", isMaster, logId);
36
+ log("ApiKey", "hasPermission", hasPermission, logId);
37
+ log("ApiKey", "Result", result, logId);
38
+ return result;
39
+ } catch (e) {
40
+ log("ApiKey", "Error", e, logId);
41
+ return false;
42
+ }
43
43
  };