Skip to content

Commit

Permalink
Updating typescript to include permissions constants
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Apr 1, 2020
1 parent bf7310f commit 5b08dec
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"jsonwebtoken": "^8.3.0",
"seamless-immutable": "^7.1.4",
"uuid": "^3.3.2",
"ws": "^6.1.3"
"ws": "^6.1.3",
"@types/seamless-immutable": "7.1.10",
"@types/ws": "^6.0.3"
},
"devDependencies": {
"@babel/cli": "^7.6.0",
Expand All @@ -71,10 +73,8 @@
"@types/rollup-plugin-json": "^3.0.2",
"@types/rollup-plugin-peer-deps-external": "^2.2.0",
"@types/rollup-plugin-url": "^2.2.0",
"@types/seamless-immutable": "7.1.10",
"@types/sinon": "^7.5.1",
"@types/uuid": "^3.4.5",
"@types/ws": "^6.0.3",
"babel-eslint": "^10.0.1",
"bluebird": "^3.5.3",
"chai": "^4.2.0",
Expand Down
14 changes: 14 additions & 0 deletions types/stream-chat/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,25 @@ export class Permission {
owner: boolean,
action: string,
);

name: string;
priority: number;
resources: string[];
roles: string[];
owner: boolean;
action: string;
}

export const AllowAll: Permission;
export const DenyAll: Permission;

export const Allow: 'Allow';
export const Deny: 'Deny';
export const AnyResource: ['*'];
export const AnyRole: ['*'];
export const MaxPriority: 999;
export const MinPriority: 1;

export function JWTUserToken(
apiSecret: string,
userId: string,
Expand Down
55 changes: 53 additions & 2 deletions types/stream-chat/test-stream-chat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { StreamChat, Event } from 'stream-chat';

import {
StreamChat,
Event,
Deny,
AnyRole,
Allow,
AnyResource,
Permission,
MaxPriority,
} from 'stream-chat';
const apiKey = 'apiKey';

// $ExpectType StreamChat
Expand Down Expand Up @@ -101,3 +109,46 @@ channel.on(eventHandler);
channel.off(eventHandler);
channel.on('message.new', eventHandler);
channel.off('message.new', eventHandler);

const permissions = [
new Permission(
'Admin users can perform any action',
MaxPriority,
AnyResource,
AnyRole,
false,
Allow,
),
new Permission(
'Anonymous users are not allowed',
500,
AnyResource,
['anonymous'],
false,
Deny,
),
new Permission(
'Users can modify their own messages',
400,
AnyResource,
['user'],
true,
Allow,
),
new Permission('Users can create channels', 300, AnyResource, ['user'], false, Allow),
new Permission(
'Channel Members',
200,
['ReadChannel', 'CreateMessage'],
['channel_member'],
false,
Allow,
),
new Permission('Discard all', 100, AnyResource, AnyRole, false, Deny),
];

client.updateChannelType('messaging', { permissions }).then(response => {
const permissions = response.permissions;
const permissionName: string = permissions[0].name;
const permissionRoles: string[] = permissions[0].roles;
});

0 comments on commit 5b08dec

Please sign in to comment.