Skip to main content

AccessRuleClient

AccessRuleClient = object

Service client for managing access rules that control permissions for specific roles or members on channels and channel groups.

Access rules allow fine-grained permission control by overriding the default permissions for specific roles or members on specific channels or channel groups.

Access this client via rootServer.community.accessRules.

Methods​

bulkCreateEditDelete()​

bulkCreateEditDelete(request: AccessRuleBulkCreateEditDeleteRequest, eventHandlers?: object): Promise<void>

Performs batch create, edit, and delete operations on access rules in a single call.

Parameters​

ParameterTypeDescription
requestAccessRuleBulkCreateEditDeleteRequestContains arrays of access rules to create, edit, and delete.
eventHandlers?{ channel.created: ChannelCreatedHandler; channel.deleted: ChannelDeletedHandler; channel.edited: ChannelEditedHandler; channelGroup.created: ChannelGroupCreatedHandler; channelGroup.deleted: ChannelGroupDeletedHandler; channelGroup.edited: ChannelGroupEditedHandler; community.permission.edited: CommunityPermissionEditedHandler; }Optional handlers for permission update events. Supported event keys: channel.created, channel.edited, channel.deleted, channelGroup.created, channelGroup.edited, channelGroup.deleted, community.permission.edited.
eventHandlers.channel.created?ChannelCreatedHandler-
eventHandlers.channel.deleted?ChannelDeletedHandler-
eventHandlers.channel.edited?ChannelEditedHandler-
eventHandlers.channelGroup.created?ChannelGroupCreatedHandler-
eventHandlers.channelGroup.deleted?ChannelGroupDeletedHandler-
eventHandlers.channelGroup.edited?ChannelGroupEditedHandler-
eventHandlers.community.permission.edited?CommunityPermissionEditedHandler-

Returns​

Promise<void>

A promise that resolves when all operations complete.

Throws​

RootApiException with errorCode indicating the first failed operation.

Example​

import {
ChannelOrChannelGroupGuid,
RoleOrMemberGuid,
AccessRuleBulkCreateEditDeleteRequest,
rootServer,
} from "@rootsdk/server-app";

export async function bulkCreateEditDeleteExample(
channelOrChannelGroupId: ChannelOrChannelGroupGuid,
roleOrMemberId: RoleOrMemberGuid,
): Promise<void> {
try {
// Set up the request
// 'undefined' values will not modify existing permissions, you can omit them if desired, they're included here for clarity
const request: AccessRuleBulkCreateEditDeleteRequest = {
creates: [
{
channelOrChannelGroupId: channelOrChannelGroupId,
roleOrMemberId: roleOrMemberId,
overlay: {
channelFullControl: undefined,
channelView: true,
channelUseExternalEmoji: undefined,
channelCreateMessage: true,
channelDeleteMessageOther: undefined,
channelManagePinnedMessages: undefined,
channelViewMessageHistory: undefined,
channelCreateMessageAttachment: undefined,
channelCreateMessageMention: undefined,
channelCreateMessageReaction: undefined,
channelMakeMessagePublic: undefined,
channelMoveUserOther: undefined,
channelVoiceTalk: undefined,
channelVoiceMuteOther: undefined,
channelVoiceDeafenOther: undefined,
channelVoiceKick: undefined,
channelVideoStreamMedia: undefined,
channelCreateFile: undefined,
channelManageFiles: undefined,
channelViewFile: undefined,
channelAppKick: undefined,
},
},
],
edits: [],
deletes: [],
};

// Call the API
await rootServer.community.accessRules.bulkCreateEditDelete(request);
} catch (error) {
// Detect error
throw error;
}
}

create()​

create(request: AccessRuleCreateRequest, eventHandlers?: object): Promise<void>

Creates a new access rule for a role or member on a channel or channel group.

Parameters​

ParameterTypeDescription
requestAccessRuleCreateRequestThe access rule configuration including target, subject, and permission overlay.
eventHandlers?{ channel.created: ChannelCreatedHandler; channel.deleted: ChannelDeletedHandler; channel.edited: ChannelEditedHandler; channelGroup.created: ChannelGroupCreatedHandler; channelGroup.deleted: ChannelGroupDeletedHandler; channelGroup.edited: ChannelGroupEditedHandler; community.permission.edited: CommunityPermissionEditedHandler; }Optional handlers for permission update events. Supported event keys: channel.created, channel.edited, channel.deleted, channelGroup.created, channelGroup.edited, channelGroup.deleted, community.permission.edited.
eventHandlers.channel.created?ChannelCreatedHandler-
eventHandlers.channel.deleted?ChannelDeletedHandler-
eventHandlers.channel.edited?ChannelEditedHandler-
eventHandlers.channelGroup.created?ChannelGroupCreatedHandler-
eventHandlers.channelGroup.deleted?ChannelGroupDeletedHandler-
eventHandlers.channelGroup.edited?ChannelGroupEditedHandler-
eventHandlers.community.permission.edited?CommunityPermissionEditedHandler-

Returns​

Promise<void>

A promise that resolves when the access rule is created.

Throws​

RootApiException with errorCode set to NoPermissionToCreate if missing required permissions, AlreadyExists if the rule already exists, or RequestValidationFailed if the request is invalid.

Example​

import {
ChannelOrChannelGroupGuid,
RoleOrMemberGuid,
AccessRuleCreateRequest,
rootServer,
} from "@rootsdk/server-app";

export async function createExample(
channelOrChannelGroupId: ChannelOrChannelGroupGuid,
roleOrMemberId: RoleOrMemberGuid,
): Promise<void> {
try {
// Set up the request
// 'undefined' values will not modify existing permissions, you can omit them if desired, they're included here for clarity
const request: AccessRuleCreateRequest = {
channelOrChannelGroupId: channelOrChannelGroupId,
roleOrMemberId: roleOrMemberId,
overlay: {
channelFullControl: undefined,
channelView: true,
channelUseExternalEmoji: undefined,
channelCreateMessage: true,
channelDeleteMessageOther: undefined,
channelManagePinnedMessages: undefined,
channelViewMessageHistory: undefined,
channelCreateMessageAttachment: undefined,
channelCreateMessageMention: undefined,
channelCreateMessageReaction: undefined,
channelMakeMessagePublic: undefined,
channelMoveUserOther: undefined,
channelVoiceTalk: undefined,
channelVoiceMuteOther: undefined,
channelVoiceDeafenOther: undefined,
channelVoiceKick: undefined,
channelVideoStreamMedia: undefined,
channelCreateFile: undefined,
channelManageFiles: undefined,
channelViewFile: undefined,
channelAppKick: undefined,
},
};

// Call the API
await rootServer.community.accessRules.create(request);
} catch (error) {
// Detect error
throw error;
}
}

Authorization​

Declare the following permissions in your manifest:

"permissions": {
"channel": {
"fullControl": true
}
}

The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:

  • fullControl on the target channel or channel group

delete()​

delete(request: AccessRuleDeleteRequest, eventHandlers?: object): Promise<void>

Deletes an access rule.

Parameters​

ParameterTypeDescription
requestAccessRuleDeleteRequestIdentifies the access rule to delete.
eventHandlers?{ channel.created: ChannelCreatedHandler; channel.deleted: ChannelDeletedHandler; channel.edited: ChannelEditedHandler; channelGroup.created: ChannelGroupCreatedHandler; channelGroup.deleted: ChannelGroupDeletedHandler; channelGroup.edited: ChannelGroupEditedHandler; community.permission.edited: CommunityPermissionEditedHandler; }Optional handlers for permission update events. Supported event keys: channel.created, channel.edited, channel.deleted, channelGroup.created, channelGroup.edited, channelGroup.deleted, community.permission.edited.
eventHandlers.channel.created?ChannelCreatedHandler-
eventHandlers.channel.deleted?ChannelDeletedHandler-
eventHandlers.channel.edited?ChannelEditedHandler-
eventHandlers.channelGroup.created?ChannelGroupCreatedHandler-
eventHandlers.channelGroup.deleted?ChannelGroupDeletedHandler-
eventHandlers.channelGroup.edited?ChannelGroupEditedHandler-
eventHandlers.community.permission.edited?CommunityPermissionEditedHandler-

Returns​

Promise<void>

A promise that resolves when the deletion completes.

Throws​

RootApiException with errorCode set to NotFound if the access rule does not exist, or NoPermissionToDelete if missing required permissions.

Example​

import {
ChannelOrChannelGroupGuid,
RoleOrMemberGuid,
AccessRuleDeleteRequest,
rootServer,
} from "@rootsdk/server-app";

export async function deleteExample(
channelOrChannelGroupId: ChannelOrChannelGroupGuid,
roleOrMemberId: RoleOrMemberGuid,
): Promise<void> {
try {
// Set up the request
const request: AccessRuleDeleteRequest = {
channelOrChannelGroupId: channelOrChannelGroupId,
roleOrMemberId: roleOrMemberId,
};

// Call the API
await rootServer.community.accessRules.delete(request);
} catch (error) {
// Detect error
throw error;
}
}

Authorization​

Declare the following permissions in your manifest:

"permissions": {
"channel": {
"fullControl": true
}
}

The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:

  • fullControl on the target channel or channel group

edit()​

edit(request: AccessRuleEditRequest, eventHandlers?: object): Promise<void>

Modifies an existing access rule's permission overlay.

Parameters​

ParameterTypeDescription
requestAccessRuleEditRequestIdentifies the access rule and the new overlay.
eventHandlers?{ channel.created: ChannelCreatedHandler; channel.deleted: ChannelDeletedHandler; channel.edited: ChannelEditedHandler; channelGroup.created: ChannelGroupCreatedHandler; channelGroup.deleted: ChannelGroupDeletedHandler; channelGroup.edited: ChannelGroupEditedHandler; community.permission.edited: CommunityPermissionEditedHandler; }Optional handlers for permission update events. Supported event keys: channel.created, channel.edited, channel.deleted, channelGroup.created, channelGroup.edited, channelGroup.deleted, community.permission.edited.
eventHandlers.channel.created?ChannelCreatedHandler-
eventHandlers.channel.deleted?ChannelDeletedHandler-
eventHandlers.channel.edited?ChannelEditedHandler-
eventHandlers.channelGroup.created?ChannelGroupCreatedHandler-
eventHandlers.channelGroup.deleted?ChannelGroupDeletedHandler-
eventHandlers.channelGroup.edited?ChannelGroupEditedHandler-
eventHandlers.community.permission.edited?CommunityPermissionEditedHandler-

Returns​

Promise<void>

A promise that resolves when the edit completes.

Throws​

RootApiException with errorCode set to NotFound if the access rule does not exist, or NoPermissionToEdit if missing required permissions.

Example​

import {
ChannelOrChannelGroupGuid,
RoleOrMemberGuid,
AccessRuleEditRequest,
rootServer,
} from "@rootsdk/server-app";

export async function editExample(
channelOrChannelGroupId: ChannelOrChannelGroupGuid,
roleOrMemberId: RoleOrMemberGuid,
): Promise<void> {
try {
// Set up the request
// 'undefined' values will not modify existing permissions, you can omit them if desired, they're included here for clarity
const request: AccessRuleEditRequest = {
channelOrChannelGroupId: channelOrChannelGroupId,
roleOrMemberId: roleOrMemberId,
overlay: {
channelFullControl: undefined,
channelView: true,
channelUseExternalEmoji: undefined,
channelCreateMessage: true,
channelDeleteMessageOther: undefined,
channelManagePinnedMessages: undefined,
channelViewMessageHistory: undefined,
channelCreateMessageAttachment: undefined,
channelCreateMessageMention: undefined,
channelCreateMessageReaction: undefined,
channelMakeMessagePublic: undefined,
channelMoveUserOther: undefined,
channelVoiceTalk: undefined,
channelVoiceMuteOther: undefined,
channelVoiceDeafenOther: undefined,
channelVoiceKick: undefined,
channelVideoStreamMedia: undefined,
channelCreateFile: undefined,
channelManageFiles: undefined,
channelViewFile: undefined,
channelAppKick: undefined,
},
};

// Call the API
await rootServer.community.accessRules.edit(request);
} catch (error) {
// Detect error
throw error;
}
}

Authorization​

Declare the following permissions in your manifest:

"permissions": {
"channel": {
"fullControl": true
}
}

The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:

  • fullControl on the target channel or channel group

get()​

get(request: AccessRuleGetRequest): Promise<AccessRule>

Retrieves a single access rule.

Parameters​

ParameterTypeDescription
requestAccessRuleGetRequestIdentifies the access rule to retrieve.

Returns​

Promise<AccessRule>

A promise that resolves to the AccessRule object.

Throws​

RootApiException with errorCode set to NotFound if the access rule does not exist, or NoPermissionToRead if missing required permissions.

Example​

import {
ChannelOrChannelGroupGuid,
RoleOrMemberGuid,
AccessRule,
AccessRuleGetRequest,
rootServer,
} from "@rootsdk/server-app";

export async function getExample(
channelOrChannelGroupId: ChannelOrChannelGroupGuid,
roleOrMemberId: RoleOrMemberGuid,
): Promise<AccessRule> {
try {
// Set up the request
const request: AccessRuleGetRequest = {
channelOrChannelGroupId: channelOrChannelGroupId,
roleOrMemberId: roleOrMemberId,
};

// Call the API
const accessRule: AccessRule =
await rootServer.community.accessRules.get(request);

return accessRule;
} catch (error) {
// Detect error
throw error;
}
}

listByChannelOrChannelGroup()​

listByChannelOrChannelGroup(request: AccessRuleListByChannelOrChannelGroupRequest): Promise<AccessRule[]>

Lists all access rules for a specific channel or channel group.

Parameters​

ParameterTypeDescription
requestAccessRuleListByChannelOrChannelGroupRequestIdentifies the channel or channel group.

Returns​

Promise<AccessRule[]>

A promise that resolves to an array of AccessRule objects.

Throws​

RootApiException with errorCode set to NotFound if the target does not exist, or NoPermissionToRead if missing required permissions.

Example​

import {
ChannelOrChannelGroupGuid,
AccessRule,
AccessRuleListByChannelOrChannelGroupRequest,
rootServer,
} from "@rootsdk/server-app";

export async function listByChannelOrChannelGroupExample(
channelOrChannelGroupId: ChannelOrChannelGroupGuid,
): Promise<AccessRule[]> {
try {
// Set up the request
const request: AccessRuleListByChannelOrChannelGroupRequest = {
channelOrChannelGroupId: channelOrChannelGroupId,
};

// Call the API
const accessRules: AccessRule[] =
await rootServer.community.accessRules.listByChannelOrChannelGroup(
request,
);

return accessRules;
} catch (error) {
// Detect error
throw error;
}
}

listByRoleOrMember()​

listByRoleOrMember(request: AccessRuleListByRoleOrMemberRequest): Promise<AccessRule[]>

Lists all access rules for a specific role or member.

Parameters​

ParameterTypeDescription
requestAccessRuleListByRoleOrMemberRequestIdentifies the role or member.

Returns​

Promise<AccessRule[]>

A promise that resolves to an array of AccessRule objects.

Throws​

RootApiException with errorCode set to NotFound if the target does not exist, or NoPermissionToRead if missing required permissions.

Example​

import {
RoleOrMemberGuid,
AccessRuleListByRoleOrMemberRequest,
AccessRule,
rootServer,
} from "@rootsdk/server-app";

export async function listByRoleOrMemberExample(
roleOrMemberId: RoleOrMemberGuid,
): Promise<AccessRule[]> {
try {
// Set up the request
const request: AccessRuleListByRoleOrMemberRequest = {
roleOrMemberId: roleOrMemberId,
};

// Call the API
const accessRules: AccessRule[] =
await rootServer.community.accessRules.listByRoleOrMember(request);

return accessRules;
} catch (error) {
// Detect error
throw error;
}
}