Socket
Socket
Sign inDemoInstall

@esri/hub-discussions

Package Overview
Dependencies
Maintainers
0
Versions
284
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esri/hub-discussions - npm Package Compare versions

Comparing version 28.0.0 to 28.1.0

dist/esm/utils/channels/can-delete-channel.js

27

dist/esm/utils/channel-permission.js
import { AclCategory, AclSubCategory, Role, } from "../types";
import { CANNOT_DISCUSS } from "./constants";
import { isOrgAdmin } from "./platform";
import { isOrgAdmin, userHasPrivilege } from "./platform";
var ChannelAction;

@@ -10,9 +10,17 @@ (function (ChannelAction) {

})(ChannelAction || (ChannelAction = {}));
/**
* @internal
* @hidden
*/
export class ChannelPermission {
constructor(channelAcl, creator) {
constructor(channel) {
this.ALLOWED_GROUP_MEMBER_TYPES = ["owner", "admin", "member"];
this.isChannelAclEmpty = channelAcl.length === 0;
if (channel.channelAcl === undefined) {
throw new Error("channel.channelAcl is required for ChannelPermission checks");
}
this.isChannelAclEmpty = channel.channelAcl.length === 0;
this.permissionsByCategory = {};
this.channelCreator = creator;
channelAcl.forEach((permission) => {
this.channelCreator = channel.creator;
this.channelOrgId = channel.orgId;
channel.channelAcl.forEach((permission) => {
var _a;

@@ -117,5 +125,2 @@ const { category } = permission;

}
/**
* canCreateChannelHelpers
*/
userCanAddAnonymousToAcl(user) {

@@ -125,3 +130,3 @@ if (!this.permissionsByCategory[AclCategory.ANONYMOUS_USER]) {

}
return isOrgAdmin(user);
return (isOrgAdmin(user) || userHasPrivilege(user, "portal:admin:shareToPublic"));
}

@@ -132,3 +137,3 @@ userCanAddUnauthenticatedToAcl(user) {

}
return isOrgAdmin(user);
return (isOrgAdmin(user) || userHasPrivilege(user, "portal:admin:shareToPublic"));
}

@@ -153,3 +158,3 @@ userCanAddAllGroupsToAcl(user) {

}
return (isOrgAdmin(user) &&
return ((isOrgAdmin(user) || userHasPrivilege(user, "portal:admin:shareToOrg")) &&
this.isEveryPermissionForUserOrg(user.orgId, orgPermissions));

@@ -156,0 +161,0 @@ }

@@ -12,5 +12,5 @@ import { SharingAccess } from "../../types";

export function canCreateChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl, creator);
const { access, groups, orgs } = channel;
if (channel.channelAcl) {
const channelPermission = new ChannelPermission(channel);
return channelPermission.canCreateChannel(user);

@@ -37,3 +37,3 @@ }

return (canAllowGroupsLegacy(userGroups, channelGroupIds) &&
isChannelOrgAdmin(user, channelOrgs));
isLegacyChannelOrgAdmin(user, channelOrgs));
}

@@ -56,5 +56,5 @@ function canAllowGroupsLegacy(userGroups, channelGroupIds) {

}
function isChannelOrgAdmin(user, channelOrgs) {
function isLegacyChannelOrgAdmin(user, channelOrgs) {
return isOrgAdmin(user) && channelOrgs.includes(user.orgId);
}
//# sourceMappingURL=can-create-channel.js.map

@@ -1,7 +0,7 @@

import { SharingAccess } from "../../types";
import { ChannelPermission } from "../channel-permission";
import { isOrgAdmin } from "../platform";
const ADMIN_GROUP_ROLES = Object.freeze(["owner", "admin"]);
import { isOrgAdminInOrg } from "../platform";
import { isAuthorizedToModifyChannelByLegacyPermissions } from "./is-authorized-to-modify-channel-by-legacy-permissions";
/**
* Utility to determine if User has privileges to modify a channel
* @deprecated use `canEditChannel` or `canDeleteChannel` instead
* @param channel

@@ -12,5 +12,7 @@ * @param user

export function canModifyChannel(channel, user = {}) {
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl, creator);
if (isOrgAdminInOrg(user, channel.orgId)) {
return true;
}
if (channel.channelAcl) {
const channelPermission = new ChannelPermission(channel);
return channelPermission.canModerateChannel(user);

@@ -20,34 +22,2 @@ }

}
function isAuthorizedToModifyChannelByLegacyPermissions(user, channel) {
const { username, groups: userGroups = [] } = user;
const { access, groups: channelGroups = [], orgs: channelOrgs = [], creator: channelCreator, } = channel;
// ensure authenticated
if (!username) {
return false;
}
if (username === channelCreator) {
return true;
}
if (access === SharingAccess.PRIVATE) {
return isAuthorizedToModifyChannelByLegacyGroup(channelGroups, userGroups);
}
// public or org access
return (isAuthorizedToModifyChannelByLegacyGroup(channelGroups, userGroups) ||
isChannelOrgAdmin(channelOrgs, user));
}
/**
* Ensure the user is an owner/admin of one of the channel groups
*/
function isAuthorizedToModifyChannelByLegacyGroup(channelGroups, userGroups) {
return channelGroups.some((channelGroupId) => {
return userGroups.some((group) => {
const { id: userGroupId, userMembership: { memberType: userMemberType }, } = group;
return (channelGroupId === userGroupId &&
ADMIN_GROUP_ROLES.includes(userMemberType));
});
});
}
function isChannelOrgAdmin(channelOrgs, user) {
return isOrgAdmin(user) && channelOrgs.includes(user.orgId);
}
//# sourceMappingURL=can-modify-channel.js.map

@@ -1,12 +0,6 @@

import { Role, SharingAccess } from "../../types";
import { SharingAccess } from "../../types";
import { ChannelPermission } from "../channel-permission";
import { CANNOT_DISCUSS } from "../constants";
import { hasOrgAdminUpdateRights } from "../portal-privilege";
const ALLOWED_GROUP_ROLES = Object.freeze(["owner", "admin", "member"]);
const ALLOWED_ROLES_FOR_POSTING = Object.freeze([
Role.WRITE,
Role.READWRITE,
Role.MANAGE,
Role.MODERATE,
Role.OWNER,
]);
/**

@@ -19,5 +13,8 @@ * Utility to determine if User has privileges to create a post in a channel

export function canPostToChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs, allowAnonymous, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl, creator);
const { access, groups, orgs, allowAnonymous } = channel;
if (hasOrgAdminUpdateRights(user, channel.orgId)) {
return true;
}
if (channel.channelAcl) {
const channelPermission = new ChannelPermission(channel);
return channelPermission.canPostToChannel(user);

@@ -24,0 +21,0 @@ }

import { reduceByGroupMembership } from "../platform";
import { ChannelPermission } from "../channel-permission";
import { hasOrgAdminViewRights } from "../portal-privilege";
/**
* Utility to determine whether User can view channel posts and channel attributes
* Utility to determine if User can view channel posts and channel attributes
*

@@ -12,5 +13,7 @@ * @export

export function canReadChannel(channel, user = {}) {
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new ChannelPermission(channelAcl, creator);
if (hasOrgAdminViewRights(user, channel.orgId)) {
return true;
}
if (channel.channelAcl) {
const channelPermission = new ChannelPermission(channel);
return channelPermission.canReadChannel(user);

@@ -24,3 +27,3 @@ }

return (intersectGroups(["member", "owner", "admin"])(user, channel) ||
isChannelOrgMember(channel, user));
isLegacyChannelOrgMember(channel, user));
}

@@ -50,3 +53,3 @@ // public channel

}
function isChannelOrgMember(channel, user) {
function isLegacyChannelOrgMember(channel, user) {
// orgs.length = 1 until collaboration/discussion between many orgs is ideated

@@ -53,0 +56,0 @@ return channel.orgs.length === 1 && channel.orgs.indexOf(user.orgId) > -1;

@@ -1,5 +0,7 @@

export { canPostToChannel } from "./can-post-to-channel";
export { canCreateChannel } from "./can-create-channel";
export { canDeleteChannel } from "./can-delete-channel";
export { canEditChannel } from "./can-edit-channel";
export { canModifyChannel } from "./can-modify-channel";
export { canPostToChannel } from "./can-post-to-channel";
export { canReadChannel, canReadFromChannel } from "./can-read-channel";
//# sourceMappingURL=index.js.map

@@ -31,2 +31,15 @@ /**

}
export function isUserInOrg(user = {}, orgId) {
return user.orgId === orgId;
}
export function isOrgAdminInOrg(user, orgId) {
return isOrgAdmin(user) && isUserInOrg(user, orgId);
}
export function userHasPrivilege(user = {}, privilege) {
var _a;
return !!((_a = user.privileges) === null || _a === void 0 ? void 0 : _a.includes(privilege));
}
export function userHasPrivileges(user = {}, privileges) {
return privileges.every((privilege) => userHasPrivilege(user, privilege));
}
//# sourceMappingURL=platform.js.map
import { ChannelPermission } from "../channel-permission";
import { hasOrgAdminUpdateRights } from "../portal-privilege";
/**

@@ -16,9 +17,11 @@ * Utility to determine if User has privileges to delete a post

function isChannelModerator(channel, user) {
const { channelAcl, creator } = channel;
if (!channelAcl) {
if (hasOrgAdminUpdateRights(user, channel.orgId)) {
return true;
}
if (!channel.channelAcl) {
return false;
}
const channelPermission = new ChannelPermission(channelAcl, creator);
const channelPermission = new ChannelPermission(channel);
return channelPermission.canModerateChannel(user);
}
//# sourceMappingURL=can-delete-post.js.map

@@ -1,60 +0,7 @@

import { parseDatasetId } from "@esri/hub-common";
import { MENTION_ATTRIBUTE } from "../constants";
export { canModifyPost } from "./can-modify-post";
export { canDeletePost } from "./can-delete-post";
export { canModifyPostStatus } from "./can-modify-post-status";
export { canModifyPostStatus, canEditPostStatus } from "./can-edit-post-status";
export { canModifyPost, canEditPost } from "./can-edit-post";
export { isDiscussable } from "@esri/hub-common";
/**
* Utility that parses a discussion URI string into its component parts
*
* @export
* @param {string} discussion A discussion URI
* @return {string}
*/
export function parseDiscussionURI(discussion) {
let url;
try {
url = new URL(discussion);
}
catch (e) {
throw new Error(`Invalid URI: ${discussion}`);
}
const source = url.protocol.replace(":", "");
const [, pathname] = discussion.split("://");
const [type, identifier] = pathname.split("/");
let id;
let layer;
if (identifier) {
const { itemId, layerId } = parseDatasetId(identifier);
[id, layer] = [itemId, layerId];
}
const searchParams = new URLSearchParams(url.search.replace("?", ""));
const features = (searchParams.has("id") && searchParams.get("id").split(",")) || null;
const attribute = (searchParams.has("attribute") && searchParams.get("attribute")) || null;
return {
source,
type,
id: id || null,
layer: layer || null,
features,
attribute,
};
}
const MENTION_ATTRIBUTE_AND_VALUE_PATTERN = new RegExp(`${MENTION_ATTRIBUTE}=('|")[\\w@\\.-]+('|")`, "g");
const MENTION_ATTRIBUTE_PATTERN = new RegExp(`${MENTION_ATTRIBUTE}=`, "g");
const NON_WORDS_PATTERN = new RegExp("[^\\w@\\.-]", "g");
/**
* Parses mentioned users
* @param text A string to parse mentioned users from
* @returns A unique collection of usernames parsed from the provided text
*/
export function parseMentionedUsers(text = "") {
const toReplaced = (input, pattern) => input.replace(pattern, "");
const toMentionedUsers = (acc, match) => {
const username = [MENTION_ATTRIBUTE_PATTERN, NON_WORDS_PATTERN].reduce(toReplaced, match);
return acc.indexOf(username) < 0 ? [...acc, username] : acc;
};
const matches = text.match(MENTION_ATTRIBUTE_AND_VALUE_PATTERN) || [];
return matches.reduce(toMentionedUsers, []);
}
export { parseDiscussionURI } from "./parse-discussion-uri";
export { parseMentionedUsers } from "./parse-mentioned-users";
//# sourceMappingURL=index.js.map

@@ -13,9 +13,17 @@ "use strict";

})(ChannelAction || (ChannelAction = {}));
/**
* @internal
* @hidden
*/
class ChannelPermission {
constructor(channelAcl, creator) {
constructor(channel) {
this.ALLOWED_GROUP_MEMBER_TYPES = ["owner", "admin", "member"];
this.isChannelAclEmpty = channelAcl.length === 0;
if (channel.channelAcl === undefined) {
throw new Error("channel.channelAcl is required for ChannelPermission checks");
}
this.isChannelAclEmpty = channel.channelAcl.length === 0;
this.permissionsByCategory = {};
this.channelCreator = creator;
channelAcl.forEach((permission) => {
this.channelCreator = channel.creator;
this.channelOrgId = channel.orgId;
channel.channelAcl.forEach((permission) => {
var _a;

@@ -120,5 +128,2 @@ const { category } = permission;

}
/**
* canCreateChannelHelpers
*/
userCanAddAnonymousToAcl(user) {

@@ -128,3 +133,3 @@ if (!this.permissionsByCategory[types_1.AclCategory.ANONYMOUS_USER]) {

}
return platform_1.isOrgAdmin(user);
return (platform_1.isOrgAdmin(user) || platform_1.userHasPrivilege(user, "portal:admin:shareToPublic"));
}

@@ -135,3 +140,3 @@ userCanAddUnauthenticatedToAcl(user) {

}
return platform_1.isOrgAdmin(user);
return (platform_1.isOrgAdmin(user) || platform_1.userHasPrivilege(user, "portal:admin:shareToPublic"));
}

@@ -156,3 +161,3 @@ userCanAddAllGroupsToAcl(user) {

}
return (platform_1.isOrgAdmin(user) &&
return ((platform_1.isOrgAdmin(user) || platform_1.userHasPrivilege(user, "portal:admin:shareToOrg")) &&
this.isEveryPermissionForUserOrg(user.orgId, orgPermissions));

@@ -159,0 +164,0 @@ }

@@ -15,5 +15,5 @@ "use strict";

function canCreateChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
const { access, groups, orgs } = channel;
if (channel.channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channel);
return channelPermission.canCreateChannel(user);

@@ -41,3 +41,3 @@ }

return (canAllowGroupsLegacy(userGroups, channelGroupIds) &&
isChannelOrgAdmin(user, channelOrgs));
isLegacyChannelOrgAdmin(user, channelOrgs));
}

@@ -60,5 +60,5 @@ function canAllowGroupsLegacy(userGroups, channelGroupIds) {

}
function isChannelOrgAdmin(user, channelOrgs) {
function isLegacyChannelOrgAdmin(user, channelOrgs) {
return platform_1.isOrgAdmin(user) && channelOrgs.includes(user.orgId);
}
//# sourceMappingURL=can-create-channel.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.canModifyChannel = void 0;
const types_1 = require("../../types");
const channel_permission_1 = require("../channel-permission");
const platform_1 = require("../platform");
const ADMIN_GROUP_ROLES = Object.freeze(["owner", "admin"]);
const is_authorized_to_modify_channel_by_legacy_permissions_1 = require("./is-authorized-to-modify-channel-by-legacy-permissions");
/**
* Utility to determine if User has privileges to modify a channel
* @deprecated use `canEditChannel` or `canDeleteChannel` instead
* @param channel

@@ -15,42 +15,12 @@ * @param user

function canModifyChannel(channel, user = {}) {
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
if (platform_1.isOrgAdminInOrg(user, channel.orgId)) {
return true;
}
if (channel.channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channel);
return channelPermission.canModerateChannel(user);
}
return isAuthorizedToModifyChannelByLegacyPermissions(user, channel);
return is_authorized_to_modify_channel_by_legacy_permissions_1.isAuthorizedToModifyChannelByLegacyPermissions(user, channel);
}
exports.canModifyChannel = canModifyChannel;
function isAuthorizedToModifyChannelByLegacyPermissions(user, channel) {
const { username, groups: userGroups = [] } = user;
const { access, groups: channelGroups = [], orgs: channelOrgs = [], creator: channelCreator, } = channel;
// ensure authenticated
if (!username) {
return false;
}
if (username === channelCreator) {
return true;
}
if (access === types_1.SharingAccess.PRIVATE) {
return isAuthorizedToModifyChannelByLegacyGroup(channelGroups, userGroups);
}
// public or org access
return (isAuthorizedToModifyChannelByLegacyGroup(channelGroups, userGroups) ||
isChannelOrgAdmin(channelOrgs, user));
}
/**
* Ensure the user is an owner/admin of one of the channel groups
*/
function isAuthorizedToModifyChannelByLegacyGroup(channelGroups, userGroups) {
return channelGroups.some((channelGroupId) => {
return userGroups.some((group) => {
const { id: userGroupId, userMembership: { memberType: userMemberType }, } = group;
return (channelGroupId === userGroupId &&
ADMIN_GROUP_ROLES.includes(userMemberType));
});
});
}
function isChannelOrgAdmin(channelOrgs, user) {
return platform_1.isOrgAdmin(user) && channelOrgs.includes(user.orgId);
}
//# sourceMappingURL=can-modify-channel.js.map

@@ -7,10 +7,4 @@ "use strict";

const constants_1 = require("../constants");
const portal_privilege_1 = require("../portal-privilege");
const ALLOWED_GROUP_ROLES = Object.freeze(["owner", "admin", "member"]);
const ALLOWED_ROLES_FOR_POSTING = Object.freeze([
types_1.Role.WRITE,
types_1.Role.READWRITE,
types_1.Role.MANAGE,
types_1.Role.MODERATE,
types_1.Role.OWNER,
]);
/**

@@ -23,5 +17,8 @@ * Utility to determine if User has privileges to create a post in a channel

function canPostToChannel(channel, user = {}) {
const { channelAcl, access, groups, orgs, allowAnonymous, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
const { access, groups, orgs, allowAnonymous } = channel;
if (portal_privilege_1.hasOrgAdminUpdateRights(user, channel.orgId)) {
return true;
}
if (channel.channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channel);
return channelPermission.canPostToChannel(user);

@@ -28,0 +25,0 @@ }

@@ -6,4 +6,5 @@ "use strict";

const channel_permission_1 = require("../channel-permission");
const portal_privilege_1 = require("../portal-privilege");
/**
* Utility to determine whether User can view channel posts and channel attributes
* Utility to determine if User can view channel posts and channel attributes
*

@@ -16,5 +17,7 @@ * @export

function canReadChannel(channel, user = {}) {
const { channelAcl, creator } = channel;
if (channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
if (portal_privilege_1.hasOrgAdminViewRights(user, channel.orgId)) {
return true;
}
if (channel.channelAcl) {
const channelPermission = new channel_permission_1.ChannelPermission(channel);
return channelPermission.canReadChannel(user);

@@ -28,3 +31,3 @@ }

return (intersectGroups(["member", "owner", "admin"])(user, channel) ||
isChannelOrgMember(channel, user));
isLegacyChannelOrgMember(channel, user));
}

@@ -56,3 +59,3 @@ // public channel

}
function isChannelOrgMember(channel, user) {
function isLegacyChannelOrgMember(channel, user) {
// orgs.length = 1 until collaboration/discussion between many orgs is ideated

@@ -59,0 +62,0 @@ return channel.orgs.length === 1 && channel.orgs.indexOf(user.orgId) > -1;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var can_post_to_channel_1 = require("./can-post-to-channel");
Object.defineProperty(exports, "canPostToChannel", { enumerable: true, get: function () { return can_post_to_channel_1.canPostToChannel; } });
var can_create_channel_1 = require("./can-create-channel");
Object.defineProperty(exports, "canCreateChannel", { enumerable: true, get: function () { return can_create_channel_1.canCreateChannel; } });
var can_delete_channel_1 = require("./can-delete-channel");
Object.defineProperty(exports, "canDeleteChannel", { enumerable: true, get: function () { return can_delete_channel_1.canDeleteChannel; } });
var can_edit_channel_1 = require("./can-edit-channel");
Object.defineProperty(exports, "canEditChannel", { enumerable: true, get: function () { return can_edit_channel_1.canEditChannel; } });
var can_modify_channel_1 = require("./can-modify-channel");
Object.defineProperty(exports, "canModifyChannel", { enumerable: true, get: function () { return can_modify_channel_1.canModifyChannel; } });
var can_post_to_channel_1 = require("./can-post-to-channel");
Object.defineProperty(exports, "canPostToChannel", { enumerable: true, get: function () { return can_post_to_channel_1.canPostToChannel; } });
var can_read_channel_1 = require("./can-read-channel");

@@ -10,0 +14,0 @@ Object.defineProperty(exports, "canReadChannel", { enumerable: true, get: function () { return can_read_channel_1.canReadChannel; } });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isOrgAdmin = exports.reduceByGroupMembership = void 0;
exports.userHasPrivileges = exports.userHasPrivilege = exports.isOrgAdminInOrg = exports.isUserInOrg = exports.isOrgAdmin = exports.reduceByGroupMembership = void 0;
/**

@@ -36,2 +36,19 @@ * Utility that returns reducer function that filters a user's groups

exports.isOrgAdmin = isOrgAdmin;
function isUserInOrg(user = {}, orgId) {
return user.orgId === orgId;
}
exports.isUserInOrg = isUserInOrg;
function isOrgAdminInOrg(user, orgId) {
return isOrgAdmin(user) && isUserInOrg(user, orgId);
}
exports.isOrgAdminInOrg = isOrgAdminInOrg;
function userHasPrivilege(user = {}, privilege) {
var _a;
return !!((_a = user.privileges) === null || _a === void 0 ? void 0 : _a.includes(privilege));
}
exports.userHasPrivilege = userHasPrivilege;
function userHasPrivileges(user = {}, privileges) {
return privileges.every((privilege) => userHasPrivilege(user, privilege));
}
exports.userHasPrivileges = userHasPrivileges;
//# sourceMappingURL=platform.js.map

@@ -5,2 +5,3 @@ "use strict";

const channel_permission_1 = require("../channel-permission");
const portal_privilege_1 = require("../portal-privilege");
/**

@@ -21,9 +22,11 @@ * Utility to determine if User has privileges to delete a post

function isChannelModerator(channel, user) {
const { channelAcl, creator } = channel;
if (!channelAcl) {
if (portal_privilege_1.hasOrgAdminUpdateRights(user, channel.orgId)) {
return true;
}
if (!channel.channelAcl) {
return false;
}
const channelPermission = new channel_permission_1.ChannelPermission(channelAcl, creator);
const channelPermission = new channel_permission_1.ChannelPermission(channel);
return channelPermission.canModerateChannel(user);
}
//# sourceMappingURL=can-delete-post.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMentionedUsers = exports.parseDiscussionURI = void 0;
const hub_common_1 = require("@esri/hub-common");
const constants_1 = require("../constants");
var can_modify_post_1 = require("./can-modify-post");
Object.defineProperty(exports, "canModifyPost", { enumerable: true, get: function () { return can_modify_post_1.canModifyPost; } });
var can_delete_post_1 = require("./can-delete-post");
Object.defineProperty(exports, "canDeletePost", { enumerable: true, get: function () { return can_delete_post_1.canDeletePost; } });
var can_modify_post_status_1 = require("./can-modify-post-status");
Object.defineProperty(exports, "canModifyPostStatus", { enumerable: true, get: function () { return can_modify_post_status_1.canModifyPostStatus; } });
var hub_common_2 = require("@esri/hub-common");
Object.defineProperty(exports, "isDiscussable", { enumerable: true, get: function () { return hub_common_2.isDiscussable; } });
/**
* Utility that parses a discussion URI string into its component parts
*
* @export
* @param {string} discussion A discussion URI
* @return {string}
*/
function parseDiscussionURI(discussion) {
let url;
try {
url = new URL(discussion);
}
catch (e) {
throw new Error(`Invalid URI: ${discussion}`);
}
const source = url.protocol.replace(":", "");
const [, pathname] = discussion.split("://");
const [type, identifier] = pathname.split("/");
let id;
let layer;
if (identifier) {
const { itemId, layerId } = hub_common_1.parseDatasetId(identifier);
[id, layer] = [itemId, layerId];
}
const searchParams = new URLSearchParams(url.search.replace("?", ""));
const features = (searchParams.has("id") && searchParams.get("id").split(",")) || null;
const attribute = (searchParams.has("attribute") && searchParams.get("attribute")) || null;
return {
source,
type,
id: id || null,
layer: layer || null,
features,
attribute,
};
}
exports.parseDiscussionURI = parseDiscussionURI;
const MENTION_ATTRIBUTE_AND_VALUE_PATTERN = new RegExp(`${constants_1.MENTION_ATTRIBUTE}=('|")[\\w@\\.-]+('|")`, "g");
const MENTION_ATTRIBUTE_PATTERN = new RegExp(`${constants_1.MENTION_ATTRIBUTE}=`, "g");
const NON_WORDS_PATTERN = new RegExp("[^\\w@\\.-]", "g");
/**
* Parses mentioned users
* @param text A string to parse mentioned users from
* @returns A unique collection of usernames parsed from the provided text
*/
function parseMentionedUsers(text = "") {
const toReplaced = (input, pattern) => input.replace(pattern, "");
const toMentionedUsers = (acc, match) => {
const username = [MENTION_ATTRIBUTE_PATTERN, NON_WORDS_PATTERN].reduce(toReplaced, match);
return acc.indexOf(username) < 0 ? [...acc, username] : acc;
};
const matches = text.match(MENTION_ATTRIBUTE_AND_VALUE_PATTERN) || [];
return matches.reduce(toMentionedUsers, []);
}
exports.parseMentionedUsers = parseMentionedUsers;
var can_edit_post_status_1 = require("./can-edit-post-status");
Object.defineProperty(exports, "canModifyPostStatus", { enumerable: true, get: function () { return can_edit_post_status_1.canModifyPostStatus; } });
Object.defineProperty(exports, "canEditPostStatus", { enumerable: true, get: function () { return can_edit_post_status_1.canEditPostStatus; } });
var can_edit_post_1 = require("./can-edit-post");
Object.defineProperty(exports, "canModifyPost", { enumerable: true, get: function () { return can_edit_post_1.canModifyPost; } });
Object.defineProperty(exports, "canEditPost", { enumerable: true, get: function () { return can_edit_post_1.canEditPost; } });
var hub_common_1 = require("@esri/hub-common");
Object.defineProperty(exports, "isDiscussable", { enumerable: true, get: function () { return hub_common_1.isDiscussable; } });
var parse_discussion_uri_1 = require("./parse-discussion-uri");
Object.defineProperty(exports, "parseDiscussionURI", { enumerable: true, get: function () { return parse_discussion_uri_1.parseDiscussionURI; } });
var parse_mentioned_users_1 = require("./parse-mentioned-users");
Object.defineProperty(exports, "parseMentionedUsers", { enumerable: true, get: function () { return parse_mentioned_users_1.parseMentionedUsers; } });
//# sourceMappingURL=index.js.map

@@ -1,2 +0,6 @@

import { IChannelAclPermission, IDiscussionsUser } from "../types";
import { IChannel, IDiscussionsUser } from "../types";
/**
* @internal
* @hidden
*/
export declare class ChannelPermission {

@@ -7,3 +11,4 @@ private readonly ALLOWED_GROUP_MEMBER_TYPES;

private channelCreator;
constructor(channelAcl: IChannelAclPermission[], creator: string);
private channelOrgId;
constructor(channel: IChannel);
canPostToChannel(user: IDiscussionsUser): boolean;

@@ -18,5 +23,2 @@ canCreateChannel(user: IDiscussionsUser): boolean;

private canSomeUserOrg;
/**
* canCreateChannelHelpers
*/
private userCanAddAnonymousToAcl;

@@ -23,0 +25,0 @@ private userCanAddUnauthenticatedToAcl;

@@ -5,2 +5,3 @@ import { IUser } from "@esri/arcgis-rest-types";

* Utility to determine if User has privileges to modify a channel
* @deprecated use `canEditChannel` or `canDeleteChannel` instead
* @param channel

@@ -7,0 +8,0 @@ * @param user

import { IUser } from "@esri/arcgis-rest-auth";
import { IChannel, IDiscussionsUser } from "../../types";
/**
* Utility to determine whether User can view channel posts and channel attributes
* Utility to determine if User can view channel posts and channel attributes
*

@@ -6,0 +6,0 @@ * @export

@@ -1,4 +0,6 @@

export { canPostToChannel } from "./can-post-to-channel";
export { canCreateChannel } from "./can-create-channel";
export { canDeleteChannel } from "./can-delete-channel";
export { canEditChannel } from "./can-edit-channel";
export { canModifyChannel } from "./can-modify-channel";
export { canPostToChannel } from "./can-post-to-channel";
export { canReadChannel, canReadFromChannel } from "./can-read-channel";
import { GroupMembership, IGroup, IUser } from "@esri/arcgis-rest-portal";
import { IDiscussionsUser } from "@esri/hub-common";
declare type Privilege = "portal:user:createItem" | "portal:user:shareToGroup" | "portal:user:viewOrgItems" | "portal:admin:shareToOrg" | "portal:admin:shareToPublic" | "portal:admin:viewItems" | "portal:admin:updateItems" | "portal:admin:deleteItems";
/**

@@ -20,1 +22,6 @@ * Utility that returns reducer function that filters a user's groups

export declare function isOrgAdmin(user: IUser): boolean;
export declare function isUserInOrg(user: IUser | IDiscussionsUser, orgId: string): boolean;
export declare function isOrgAdminInOrg(user: IUser, orgId: string): boolean;
export declare function userHasPrivilege(user: IUser | IDiscussionsUser, privilege: Privilege): boolean;
export declare function userHasPrivileges(user: IUser | IDiscussionsUser, privileges: Privilege[]): boolean;
export {};

@@ -1,19 +0,6 @@

import { IDiscussionParams } from "../../types";
export { canModifyPost } from "./can-modify-post";
export { canDeletePost } from "./can-delete-post";
export { canModifyPostStatus } from "./can-modify-post-status";
export { canModifyPostStatus, canEditPostStatus } from "./can-edit-post-status";
export { canModifyPost, canEditPost } from "./can-edit-post";
export { isDiscussable } from "@esri/hub-common";
/**
* Utility that parses a discussion URI string into its component parts
*
* @export
* @param {string} discussion A discussion URI
* @return {string}
*/
export declare function parseDiscussionURI(discussion: string): IDiscussionParams;
/**
* Parses mentioned users
* @param text A string to parse mentioned users from
* @returns A unique collection of usernames parsed from the provided text
*/
export declare function parseMentionedUsers(text?: string): string[];
export { parseDiscussionURI } from "./parse-discussion-uri";
export { parseMentionedUsers } from "./parse-mentioned-users";
{
"name": "@esri/hub-discussions",
"version": "28.0.0",
"version": "28.1.0",
"description": "Module to interact with ArcGIS Hub Discussions API in Node.js and modern browsers.",

@@ -5,0 +5,0 @@ "main": "dist/node/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc