@plusscommunities/pluss-core-aws 2.0.24 → 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.
- package/aws/getDefaultEmailAddress.js +21 -21
- package/aws/getEmailService.js +16 -16
- package/aws/getEmailServiceInfo.js +26 -26
- package/aws/sendEmail.js +31 -31
- package/config.js +1 -1
- package/db/activity/publishActivity.js +22 -22
- package/db/analytics/checkActivityExists.js +15 -15
- package/db/analytics/logAnalyticsActivity.js +69 -37
- package/db/analytics/scheduleOldAggregation.js +14 -14
- package/db/auth/getSiteSetting.js +12 -12
- package/db/auth/getSiteUserTypes.js +16 -16
- package/db/auth/getUserAuth.js +13 -13
- package/db/automatedactions/getActionBySiteTrigger.js +9 -9
- package/db/common/deleteRef.js +21 -21
- package/db/common/editRef.js +36 -36
- package/db/common/getRef.js +23 -23
- package/db/common/getTableCount.js +18 -18
- package/db/common/indexQuery.js +17 -17
- package/db/common/indexQueryRecursive.js +20 -20
- package/db/common/scanRef.js +18 -18
- package/db/common/scanRefRecursive.js +20 -20
- package/db/common/updateAttribute.js +27 -27
- package/db/common/updateRef.js +20 -20
- package/db/linkedUsers/getLinkedBy.js +21 -21
- package/db/linkedUsers/getLinkedTo.js +21 -21
- package/db/notifications/deleteNotificationsByEntity.js +21 -21
- package/db/notifications/getNotificationSetting.js +14 -14
- package/db/notifications/publishNotifications.js +39 -39
- package/db/scheduledActions/deleteActionQueue.js +1 -1
- package/db/scheduledActions/getActionQueueByEntityId.js +10 -10
- package/db/scheduledActions/getActionQueueByEntityKey.js +9 -9
- package/db/scheduledActions/getActionQueueById.js +9 -9
- package/db/scheduledActions/getActionQueueByTriggerAt.js +14 -14
- package/db/scheduledActions/updateActionQueue.js +29 -29
- package/db/strings/getString.js +20 -20
- package/db/strings/logUpdate.js +18 -18
- package/db/templates/getTemplateById.js +1 -1
- package/db/templates/getTemplatesList.js +10 -10
- package/db/templates/updateTemplate.js +9 -9
- package/db/users/getRole.js +1 -1
- package/db/users/getUser.js +9 -9
- package/db/users/getUserByEmail.js +17 -17
- package/helper/audience/filterByAudienceType.js +27 -27
- package/helper/audience/filterOnAudienceType.js +26 -26
- package/helper/audience/getAudience.js +187 -187
- package/helper/audience/getMatchingAudienceTypes.js +21 -21
- package/helper/audience/getMatchingAudienceTypesFromPreview.js +60 -60
- package/helper/audience/getMatchingTags.js +15 -15
- package/helper/audience/isValidAudience.js +20 -20
- package/helper/auth/checkTokenBlacklist.js +17 -17
- package/helper/auth/getApiKeyFromReq.js +2 -2
- package/helper/auth/getSessionUser.js +66 -66
- package/helper/auth/getSessionUserFromReq.js +2 -2
- package/helper/auth/getSessionUserFromReqAuthKey.js +11 -11
- package/helper/auth/validateApiKey.js +32 -32
- package/helper/auth/validateMasterAuth.js +174 -174
- package/helper/auth/validateSiteAccess.js +12 -12
- package/helper/auth/validateSiteSetting.js +7 -7
- package/helper/auth/validateUserLoggedIn.js +19 -19
- package/helper/createGuid.js +5 -5
- package/helper/generateJsonResponse.js +27 -27
- package/helper/getUserPreview.js +57 -57
- package/helper/getUserPreviewFromHeader.js +17 -17
- package/helper/getUserPreviewFromReq.js +17 -17
- package/helper/hqPublishing.js +45 -0
- package/helper/index.js +28 -28
- package/helper/notifySiteConfigs.js +67 -52
- package/helper/opengraph/getOpenGraph.js +12 -12
- package/helper/rates/checkRateLimit.js +38 -38
- package/helper/requestToSource.js +10 -10
- package/helper/sendEmail.js +120 -120
- package/helper/templates/replacePlaceHolders.js +29 -29
- package/helper/time/getLocalTimestamp.js +18 -18
- package/helper/time/getSiteTimezone.js +11 -11
- package/helper/triggerAutomatedAction.js +25 -25
- package/helper/userToUserPreview.js +23 -23
- package/helper/users/getUserTypesByPermission.js +24 -24
- package/helper/users/getUsersByPermission.js +20 -20
- package/notification/prepNotification.js +144 -144
- package/notification/sendNotifications.js +166 -166
- package/package.json +35 -35
- package/templates/supportTicketEmails.js +8 -8
|
@@ -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
|
-
|
|
5
|
+
if (!token) return false;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
try {
|
|
8
|
+
// Create hash of token for TokenId lookup
|
|
9
|
+
const tokenHash = crypto.createHash("sha256").update(token).digest("hex");
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
// Check if token exists in blacklist
|
|
12
|
+
const blacklistedToken = await getRef(
|
|
13
|
+
"invalidTokens",
|
|
14
|
+
"TokenId",
|
|
15
|
+
tokenHash,
|
|
16
|
+
);
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
5
|
-
|
|
4
|
+
if (!event?.headers?.apikey) return null;
|
|
5
|
+
return await getRef("accesskeys", "Key", event.headers.apikey);
|
|
6
6
|
};
|
|
@@ -4,72 +4,72 @@ const { getConfig } = require("../../config");
|
|
|
4
4
|
const checkTokenBlacklist = require("./checkTokenBlacklist");
|
|
5
5
|
|
|
6
6
|
module.exports = async (token) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
return new Promise(async (resolve, reject) => {
|
|
8
|
+
if (!token) {
|
|
9
|
+
return resolve(null);
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
});
|
|
75
75
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const getSessionUser = require("./getSessionUser");
|
|
2
2
|
|
|
3
3
|
module.exports = (event) => {
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
if (!validSite && !isHQKey) {
|
|
25
|
+
log("ApiKey", "Result", false, logId);
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
};
|