@plusscommunities/pluss-core-aws 2.0.5 → 2.0.6-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.
@@ -1,6 +1,6 @@
1
1
  const indexQuery = require("../common/indexQuery");
2
2
 
3
- module.exports = (site) => {
3
+ module.exports = async (site) => {
4
4
  return new Promise((resolve, reject) => {
5
5
  const query = {
6
6
  IndexName: "UserTypesSiteIndex",
@@ -11,8 +11,8 @@ module.exports = (site) => {
11
11
  };
12
12
 
13
13
  indexQuery("usertypes", query)
14
- .then((gweg) => {
15
- resolve(gweg.Items);
14
+ .then((res) => {
15
+ resolve(res.Items);
16
16
  })
17
17
  .catch((error) => {
18
18
  reject(error);
@@ -148,6 +148,15 @@ const getEventMatches = async (users, audienceTypeSelection) => {
148
148
  });
149
149
  };
150
150
 
151
+ /**
152
+ * Retrieves the audience based on the specified criteria.
153
+ *
154
+ * @param {string} site - The site to retrieve the audience from.
155
+ * @param {string} audienceType - The type of audience to retrieve.
156
+ * @param {string | Array} audienceTypeSelection - The selection criteria for the audience.
157
+ * @param {boolean} [preview=true] - Indicates whether to retrieve a preview of the users in the audience.
158
+ * @returns {Array} - The audience that matches the specified criteria.
159
+ */
151
160
  module.exports = async (
152
161
  site,
153
162
  audienceType,
@@ -0,0 +1,18 @@
1
+ const getSiteUserTypes = require("../../db/auth/getSiteUserTypes");
2
+
3
+ /**
4
+ * Retrieves user types based on the specified site and permissions.
5
+ *
6
+ * @param {string} site - The site to retrieve user types from.
7
+ * @param {string[]} permissions - The permissions to filter user types by.
8
+ * @returns {Object[]} - An array of filtered user types.
9
+ */
10
+ const getUserTypesByPermission = async (site, permissions) => {
11
+ const siteUserTypes = await getSiteUserTypes(site);
12
+ const filteredUserTypes = siteUserTypes.filter((userType) =>
13
+ userType.Permissions.some((permission) => permissions.includes(permission))
14
+ );
15
+ return filteredUserTypes;
16
+ };
17
+
18
+ module.exports = getUserTypesByPermission;
@@ -0,0 +1,23 @@
1
+ import getUserTypesByPermission from "./getUserTypesByPermission";
2
+ import getAudience from "../audience/getAudience";
3
+
4
+ /**
5
+ * Retrieves users by permission.
6
+ *
7
+ * @param {string} site - The site to retrieve users from.
8
+ * @param {Array<string>} permissions - The permissions to filter users by.
9
+ * @returns {Promise<Array<object>>} - A promise that resolves to an array of users matching the given permissions.
10
+ */
11
+ const getUsersByPermission = async (site, permissions) => {
12
+ const userTypes = await getUserTypesByPermission(site, permissions);
13
+ const audienceMatches = userTypes.map((ut) => {
14
+ return {
15
+ AudienceType: "UserType",
16
+ AudienceTypeSelection: ut.typeName,
17
+ };
18
+ });
19
+ const audience = await getAudience(site, "Custom", audienceMatches);
20
+ return audience;
21
+ };
22
+
23
+ module.exports = getUsersByPermission;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "2.0.5",
3
+ "version": "2.0.6-beta.0",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",