@plusscommunities/pluss-core-aws 2.0.25-auth.0 → 2.0.25-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 (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 +45 -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
package/package.json CHANGED
@@ -1,42 +1,37 @@
1
1
  {
2
- "name": "@plusscommunities/pluss-core-aws",
3
- "version": "2.0.25-auth.0",
4
- "description": "Core extension package for Pluss Communities platform",
5
- "scripts": {
6
- "betapatch": "npm version prepatch --preid=beta",
7
- "patch": "npm version patch",
8
- "betaupload": "npm i && npm i && npm publish --access public --tag beta",
9
- "betaupload:p": "npm run betapatch && npm run betaupload",
10
- "authpatch": "npm version prepatch --preid=auth",
11
- "authupload": "npm i && npm i && npm publish --access public --tag auth",
12
- "authupload:p": "npm run authpatch && npm run authupload",
13
- "upload": "npm i && npm i && npm publish --access public",
14
- "upload:p": "npm run patch && npm run upload"
15
- },
16
- "author": "Thorbjorn Kappel Davis",
17
- "license": "ISC",
18
- "dependencies": {
19
- "@aws/dynamodb-auto-marshaller": "^0.7.1",
20
- "amazon-cognito-identity-js": "^2.0.19",
21
- "axios": "^1.6.8",
22
- "aws-sdk": "^2.1591.0",
23
- "expo-server-sdk": "^3.0.1",
24
- "html-entities": "^2.3.2",
25
- "https": "^1.0.0",
26
- "jsonwebtoken": "^9.0.2",
27
- "jwks-rsa": "^3.1.0",
28
- "lodash": "^4.17.10",
29
- "moment": "^2.30.1",
30
- "moment-timezone": "^0.5.41",
31
- "node-fetch": "^2.2.0",
32
- "node-jose": "^1.0.0",
33
- "nodemailer": "^6.9.12",
34
- "twilio": "^3.18.0",
35
- "uuid": "^2.0.3"
36
- },
37
- "devDependencies": {
38
- "eslint-config-rallycoding": "^3.2.0",
39
- "serverless-domain-manager": "^3.3.1",
40
- "serverless-prune-plugin": "^1.4.1"
41
- }
2
+ "name": "@plusscommunities/pluss-core-aws",
3
+ "version": "2.0.25-beta.0",
4
+ "description": "Core extension package for Pluss Communities platform",
5
+ "scripts": {
6
+ "betapatch": "npm version prepatch --preid=beta",
7
+ "patch": "npm version patch",
8
+ "betaupload": "npm i && npm i && npm publish --access public --tag beta",
9
+ "betaupload:p": "npm run betapatch && npm run betaupload",
10
+ "upload": "npm i && npm i && npm publish --access public",
11
+ "upload:p": "npm run patch && npm run upload"
12
+ },
13
+ "author": "Thorbjorn Kappel Davis",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "@aws/dynamodb-auto-marshaller": "^0.7.1",
17
+ "amazon-cognito-identity-js": "^2.0.19",
18
+ "axios": "^1.6.8",
19
+ "aws-sdk": "^2.1591.0",
20
+ "expo-server-sdk": "^3.0.1",
21
+ "html-entities": "^2.3.2",
22
+ "https": "^1.0.0",
23
+ "lodash": "^4.17.10",
24
+ "moment": "^2.30.1",
25
+ "moment-timezone": "^0.5.41",
26
+ "node-fetch": "^2.2.0",
27
+ "node-jose": "^1.0.0",
28
+ "nodemailer": "^6.9.12",
29
+ "twilio": "^3.18.0",
30
+ "uuid": "^2.0.3"
31
+ },
32
+ "devDependencies": {
33
+ "eslint-config-rallycoding": "^3.2.0",
34
+ "serverless-domain-manager": "^3.3.1",
35
+ "serverless-prune-plugin": "^1.4.1"
36
+ }
42
37
  }
@@ -1,6 +1,6 @@
1
1
  module.exports.newTicketEmailTemplate = {
2
- subject: `New Support Ticket: ___TITLE___`,
3
- content: `<div style='margin-bottom: 24px; font-size: 14px; line-height: 23px; color: #3e4245;'>
2
+ subject: `New Support Ticket: ___TITLE___`,
3
+ content: `<div style='margin-bottom: 24px; font-size: 14px; line-height: 23px; color: #3e4245;'>
4
4
  ___NAME___ from ___SITE___ (___CLIENT___) has submitted a new support ticket.
5
5
  </div>
6
6
  <div style='margin-bottom: 16px; font-size: 22px; line-height: 30px; color: #0a2246; font-weight: bold;'>
@@ -12,8 +12,8 @@ module.exports.newTicketEmailTemplate = {
12
12
  };
13
13
 
14
14
  module.exports.statusChangeEmailTemplate = {
15
- subject: `Status Changed on Your Ticket: ___TITLE___`,
16
- content: `<div style='margin-bottom: 24px; font-size: 14px; line-height: 23px; color: #3e4245;'>
15
+ subject: `Status Changed on Your Ticket: ___TITLE___`,
16
+ content: `<div style='margin-bottom: 24px; font-size: 14px; line-height: 23px; color: #3e4245;'>
17
17
  Your ticket has been updated.
18
18
  </div>
19
19
  <div style='margin-bottom: 16px; font-size: 13px; line-height: 28px; height: 28px; width: 300px; border-radius: 4px; background-color: ___LABELCOLOR___; color: #fff; text-align: center;'>
@@ -28,8 +28,8 @@ module.exports.statusChangeEmailTemplate = {
28
28
  };
29
29
 
30
30
  module.exports.ticketCommentEmailTemplate = {
31
- subject: `New Comment on Ticket: ___TITLE___`,
32
- content: `<div style='margin-bottom: 24px; font-size: 14px; line-height: 23px; color: #3e4245;'>
31
+ subject: `New Comment on Ticket: ___TITLE___`,
32
+ content: `<div style='margin-bottom: 24px; font-size: 14px; line-height: 23px; color: #3e4245;'>
33
33
  There is a new comment on an update:
34
34
  </div>
35
35
  <div style='margin-bottom: 24px; font-size: 15px; line-height: 22px; border-radius: 4px; border: solid 1px #ccc; padding: 8px; color: #536280; max-width: 500px; display: inline-block;'>
@@ -44,6 +44,6 @@ module.exports.ticketCommentEmailTemplate = {
44
44
  };
45
45
 
46
46
  module.exports.plussTeamEmails = [
47
- "marty@plusscommunities.com",
48
- "thor@plusscommunities.com",
47
+ "marty@plusscommunities.com",
48
+ "thor@plusscommunities.com",
49
49
  ];
@@ -1,50 +0,0 @@
1
- const Auth0Strategy = require("./auth0/Strategy");
2
- const CognitoStrategy = require("./cognito/Strategy");
3
- const BoltonClarkeStrategy = require("./boltonclarke/Strategy");
4
- const { getConfig } = require("../../../config");
5
-
6
- class AuthenticationContext {
7
- static strategy = null;
8
-
9
- static initialiseStrategy() {
10
- switch (getConfig().authConfig.provider) {
11
- case "auth0":
12
- AuthenticationContext.strategy = new Auth0Strategy();
13
- break;
14
- case "boltonclarke":
15
- AuthenticationContext.strategy = new BoltonClarkeStrategy();
16
- break;
17
- case "cognito":
18
- AuthenticationContext.strategy = new CognitoStrategy();
19
- break;
20
- default:
21
- throw new Error("Invalid authentication provider specified");
22
- }
23
- }
24
-
25
- static getSessionUser = async (token) => {
26
- if (!AuthenticationContext.strategy) {
27
- AuthenticationContext.initialiseStrategy();
28
- }
29
- return AuthenticationContext.strategy.getSessionUser(token);
30
- };
31
-
32
- static populateUser = async (token) => {
33
- if (!AuthenticationContext.strategy) {
34
- AuthenticationContext.initialiseStrategy();
35
- }
36
- return AuthenticationContext.strategy.populateUser(token);
37
- };
38
-
39
- static updateIdentityAttributes = async (input, userId) => {
40
- if (!AuthenticationContext.strategy) {
41
- AuthenticationContext.initialiseStrategy();
42
- }
43
- return AuthenticationContext.strategy.updateIdentityAttributes(
44
- input,
45
- userId
46
- );
47
- };
48
- }
49
-
50
- module.exports = AuthenticationContext;
@@ -1,20 +0,0 @@
1
- // Authentication Strategy Interface
2
- class AuthenticationStrategy {
3
- constructor() {}
4
-
5
- getSessionUser(token) {
6
- throw new Error("Method 'getSessionUser()' must be implemented.");
7
- }
8
-
9
- // optional function to populate user data based on a token
10
- populateUser(token) {
11
- return;
12
- }
13
-
14
- // optional function to save attributes to identity provider
15
- updateIdentityAttributes = async (input, userId) => {
16
- return;
17
- };
18
- }
19
-
20
- module.exports = AuthenticationStrategy;
@@ -1,12 +0,0 @@
1
- // auth0Strategy.js
2
- const AuthenticationStrategy = require("../AuthenticationStrategy");
3
- const getSessionUser = require("./functions/getSessionUser");
4
-
5
- class Auth0Strategy extends AuthenticationStrategy {
6
- constructor() {
7
- super();
8
- this.getSessionUser = getSessionUser;
9
- }
10
- }
11
-
12
- module.exports = Auth0Strategy;
@@ -1,102 +0,0 @@
1
- const jwt = require("jsonwebtoken");
2
- const jwksClient = require("jwks-rsa");
3
-
4
- const { getConfig } = require("../../../../../config");
5
- const { log } = require("../../../../");
6
-
7
- // Function to retrieve the signing key from Auth0 JWKS
8
- const getKey = (header, callback) => {
9
- // Initialize JWKS client
10
- const client = jwksClient({
11
- jwksUri: `https://${getConfig().auth0Config.domain}/.well-known/jwks.json`,
12
- });
13
- const logId = log("getKey", "header", header);
14
- client.getSigningKey(header.kid, (err, key) => {
15
- if (err) {
16
- log("getKey", "Error:client.getSigningKey", err, logId);
17
- callback(err, null);
18
- } else {
19
- const signingKey = key.publicKey || key.rsaPublicKey;
20
- log("getKey", "signingKey", signingKey, logId);
21
- callback(null, signingKey);
22
- }
23
- });
24
- };
25
-
26
- // Function to retrieve the signing key from the secondary Auth0 JWKS
27
- const getSecondaryKey = (header, callback) => {
28
- const logId = log("getSecondaryKey", "header", header);
29
-
30
- // Initialize secondary JWKS client for the secondary domain
31
- const secondaryClient = jwksClient({
32
- jwksUri: `https://${
33
- getConfig().auth0Config.secondaryDomain
34
- }/.well-known/jwks.json`,
35
- });
36
-
37
- secondaryClient.getSigningKey(header.kid, (err, key) => {
38
- if (err) {
39
- log("getSecondaryKey", "Error:secondaryClient.getSigningKey", err, logId);
40
- callback(err, null);
41
- } else {
42
- const signingKey = key.publicKey || key.rsaPublicKey;
43
- log("getSecondaryKey", "signingKey", signingKey, logId);
44
- callback(null, signingKey);
45
- }
46
- });
47
- };
48
-
49
- // Secondary function to verify the access token
50
- const verifySecondaryAccessToken = (token) => {
51
- return new Promise((resolve, reject) => {
52
- jwt.verify(
53
- token,
54
- getSecondaryKey,
55
- {
56
- audience: getConfig().auth0Config.audience,
57
- issuer: `https://${getConfig().auth0Config.secondaryDomain}/`,
58
- algorithms: ["RS256"],
59
- },
60
- (err, decoded) => {
61
- if (err) {
62
- log("verifySecondaryAccessToken", "Error:jwt.verify", err);
63
- reject(err);
64
- } else {
65
- resolve(decoded); // 'sub' contains the user ID
66
- }
67
- }
68
- );
69
- });
70
- };
71
-
72
- // Function to validate the token and extract user information
73
- const decodeAccessToken = async (token) => {
74
- return new Promise((resolve, reject) => {
75
- jwt.verify(
76
- token,
77
- getKey,
78
- {
79
- audience: getConfig().auth0Config.audience,
80
- issuer: `https://${getConfig().auth0Config.domain}/`,
81
- algorithms: ["RS256"],
82
- },
83
- (err, decoded) => {
84
- if (err) {
85
- log("decodeAccessToken", "Error:jwt.verify", err);
86
- // Attempt to verify with the secondary domain
87
- verifySecondaryAccessToken(token)
88
- .then((decodedSecondary) => {
89
- resolve(decodedSecondary);
90
- })
91
- .catch((secondaryErr) => {
92
- reject(secondaryErr);
93
- });
94
- } else {
95
- resolve(decoded); // 'sub' contains the user ID
96
- }
97
- }
98
- );
99
- });
100
- };
101
-
102
- module.exports = decodeAccessToken;
@@ -1,21 +0,0 @@
1
- const decodeAccessToken = require("./decodeAccessToken");
2
- const { getConfig } = require("../../../../../config");
3
-
4
- // Function to validate the token and extract user information
5
- const getSessionUser = async (token) => {
6
- return new Promise((resolve, reject) => {
7
- decodeAccessToken(token)
8
- .then((claims) => {
9
- return resolve(
10
- claims[getConfig().auth0Config.residentIdClaim] ||
11
- claims[getConfig().auth0Config.staffIdClaim] ||
12
- claims[getConfig().auth0Config.userIdClaim]
13
- );
14
- })
15
- .catch((err) => {
16
- reject(err);
17
- });
18
- });
19
- };
20
-
21
- module.exports = getSessionUser;
@@ -1,10 +0,0 @@
1
- // auth0Strategy.js
2
- const Auth0Strategy = require("../auth0/Strategy");
3
-
4
- class BoltonClarkeStrategy extends Auth0Strategy {
5
- constructor() {
6
- super();
7
- }
8
- }
9
-
10
- module.exports = BoltonClarkeStrategy;
@@ -1,12 +0,0 @@
1
- // cognitoStrategy.js
2
- const AuthenticationStrategy = require("../AuthenticationStrategy");
3
- const getSessionUser = require("./functions/getSessionUser");
4
-
5
- class CognitoStrategy extends AuthenticationStrategy {
6
- constructor() {
7
- super();
8
- this.getSessionUser = getSessionUser;
9
- }
10
- }
11
-
12
- module.exports = CognitoStrategy;
@@ -1,76 +0,0 @@
1
- const https = require("https");
2
- const jose = require("node-jose");
3
-
4
- const { getConfig } = require("../../../../../config");
5
-
6
- module.exports = async (token) => {
7
- return new Promise((resolve, reject) => {
8
- if (!token) {
9
- return resolve(null);
10
- }
11
- var sections = token.split(".");
12
- // get the kid from the headers prior to verification
13
- var header = jose.util.base64url.decode(sections[0]);
14
- header = JSON.parse(header);
15
- var kid = header.kid;
16
- // download the public keys
17
- https.get(getConfig().keys_url, async (response) => {
18
- if (response.statusCode == 200) {
19
- response.on("data", async (body) => {
20
- var keys = JSON.parse(body)["keys"];
21
- // search for the kid in the downloaded public keys
22
- var key_index = -1;
23
- for (var i = 0; i < keys.length; i++) {
24
- if (kid == keys[i].kid) {
25
- key_index = i;
26
- break;
27
- }
28
- }
29
- if (key_index == -1) {
30
- reject();
31
- return;
32
- }
33
- // construct the public key
34
- jose.JWK.asKey(keys[key_index])
35
- .then(async (result) => {
36
- // verify the signature
37
- jose.JWS.createVerify(result)
38
- .verify(token)
39
- .then(async (result2) => {
40
- // now we can use the claims
41
- var claims = JSON.parse(result2.payload);
42
- // additionally we can verify the token expiration
43
- var current_ts = Math.floor(new Date() / 1000);
44
- if (current_ts > claims.exp) {
45
- console.log("Token is expired");
46
- reject("Token is expired");
47
- return;
48
- }
49
-
50
- // const isDisabled = await isUserDisabled(claims.username);
51
-
52
- // if (isDisabled) {
53
- // console.log("User is disabled");
54
- // reject("User is disabled");
55
- // return;
56
- // }
57
-
58
- resolve(claims.username);
59
- })
60
- .catch(async (error) => {
61
- console.log("Signature verification failed", error);
62
- reject("Signature verification failed");
63
- });
64
- })
65
- .catch(async (error) => {
66
- console.log("failed JWK.asKey", error);
67
- reject(error);
68
- });
69
- });
70
- } else {
71
- console.log("failed on response", response);
72
- reject(response);
73
- }
74
- });
75
- });
76
- };