diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index c10cd506b9..4a8b497506 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -4,7 +4,8 @@ // rollymaduk , // vitosamson , // FlorianDr , -// danduh +// danduh , +// ChristianBoehlke // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // @see https://www.pubnub.com/docs/web-javascript/api-reference-configuration // TypeScript Version: 2.2 @@ -99,6 +100,15 @@ declare class Pubnub { params: Pubnub.SetStateParameters ): Promise; + grant( + params: Pubnub.GrantParameters, + callback: (status: Pubnub.GrantStatus, response: {}) => void + ): void; + + grant( + params: Pubnub.GrantParameters + ): Promise<{}>; + encrypt( data: string, customCipherKey?: string, @@ -348,6 +358,23 @@ declare namespace Pubnub { }; } + // grant + interface GrantParameters { + channels?: string[]; + channelGroups?: string[]; + authKeys?: string[]; + ttl?: number; + read?: boolean; + write?: boolean; + manage?: boolean; + } + + interface GrantStatus { + error: boolean; + operation: string; + statusCode: number; + } + // encrypt & decrypt interface CryptoParameters { encryptKey?: boolean; diff --git a/types/pubnub/pubnub-tests.ts b/types/pubnub/pubnub-tests.ts index 96dd4202ba..8750919e59 100644 --- a/types/pubnub/pubnub-tests.ts +++ b/types/pubnub/pubnub-tests.ts @@ -87,6 +87,17 @@ pubnub.setState({ channels: [] }).then(res => { console.log(res.state); }); +const grantOptions = { + channels: ['channel-1'], + authKeys: ['auth-key'], + read: true, + write: false, + manage: false +}; +pubnub.grant(grantOptions).then(status => { + console.log(status); +}); + pubnub.history({channel: 'channel-1', count: 2}, (status, res) => { console.log(status); console.log(res);