[pubnub] Add grant method

This commit is contained in:
Christian Boehlke 2019-02-05 12:54:56 +01:00
parent c807902931
commit 971d40fedc
2 changed files with 39 additions and 1 deletions

View File

@ -4,7 +4,8 @@
// rollymaduk <https://github.com/rollymaduk>,
// vitosamson <https://github.com/vitosamson>,
// FlorianDr <https://github.com/FlorianDr>,
// danduh <https://github.com/danduh>
// danduh <https://github.com/danduh>,
// ChristianBoehlke <https://github.com/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<Pubnub.SetStateResponse>;
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;

View File

@ -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);