@owlnext/heimdall-js-native
Version:
Heimdall API client & utils for react native technologies
93 lines (92 loc) • 4.11 kB
TypeScript
import HeimdallApi from "./api/heimdall-api";
/**
* Heimdall Client
*/
export default class Heimdall {
private _api;
private readonly _cipher;
static readonly SERVER_ENVIRONMENT_PRODUCTION: string;
static readonly SERVER_ENVIRONMENT_INTEGRATION: string;
/**
* Heimdall constructor.
*/
constructor();
/**
* Authenticate the Heimdall client against the Heimdall API.
* @param props AuthenticationPayload values to authenticate the user on the API.
* @return Promise<AuthenticationTokenObject> A promise with the result of the authentication.
* @throws HeimdallError if an error occurs during API transaction.
*/
authenticate: (props: AuthenticationPayload) => Promise<AuthenticationTokenObject | void>;
/**
* Reconnects the Heimdall client to the API with JWT refresh data.
* @param props RefreshPayload values to reconnect the client.
* @return Promise<AuthenticationTokenObject | void> JWT data if reconnected, or void on error.
* @throws HeimdallError if an error occurs during API transaction.
*/
reconnect: (props: RefreshAuthPayload) => Promise<AuthenticationTokenObject | void>;
/**
* Checks either if the Heimdall client is authenticated against the API.
* @return boolean true if the client is authenticated, false otherwise.
*/
isAuthenticated: () => boolean;
/**
* Removes all authentication stored credentials to avoid further use of the API.
*/
disconnect: () => void;
/**
* Refreshes authentication against Heimdall API
* @return Promise<AuthenticationTokenObject> A promise with the result of the authentication refresh.
* @throws HeimdallError if an error occurs during API transaction.
*/
refreshAuthentication: () => Promise<AuthenticationTokenObject | void>;
/**
* Creates a user.
* @param props CreateUserPayload properties to create the user.
* @return Promise<UserDetailObject | null> A promise with the details of the user created, or null on error.
* @throws HeimdallError if an error occurs during API transaction.
*/
createUser: (props: CreateUserPayload) => Promise<UserDetailObject>;
/**
* Creates a key for given groups of users.
* @param name string the name of the group.
* @param members Array<string> An array with users IRIs.
* @return Promise<KeychainDetailObject | null> a promise with the key details, or null on error.
* @throws HeimdallError if an error occurs during API transaction.
*/
createGroup: (name: string, members: Array<string>) => Promise<GroupDetailObject>;
/**
* Creates a key for given groups of users.
* @param groups Array<string> An array with group IRIs.
* @return Promise<KeychainCreationDetailObject | null> a promise with the key details, or null on error.
* @throws HeimdallError if an error occurs during API transaction.
*/
createKey: (groups: Array<string>) => Promise<KeychainCreationDetailObject>;
/**
* Gets a cipher key.
* @param id string the ID of the keychain to get the cipher key on.
* @return Promise<string> A promise with the cipher key, or null on error.
* @throws HeimdallError if an error occurs during API transaction.
*/
getCipherKey: (id: string) => Promise<KeychainCipherKey>;
/**
* Encrypts a message with a cipher key.
* @param message string the message to encrypt.
* @param cipherKey string the cipher key for encryption.
* @return string the encrypted message.
*/
encrypt: (message: string, cipherKey: string) => string;
/**
* Decrypts a message with a cipher key.
* @param message string the message to decrypt.
* @param cipherKey string the cipher key for decrypt.
* @return string the decrypted message.
*/
decrypt: (message: string, cipherKey: string) => string | null;
/**
* Gets the Heimdall API client.
* @return HeimdallApi the Heimdall API client.
*/
get api(): HeimdallApi;
private validateServerEnvironment;
}