@point-api/js-sdk
Version:
Javascript SDK for Point API
55 lines (54 loc) • 1.95 kB
TypeScript
export interface AuthManager {
setCredentials: (emailAddress: string, apiKey: string) => void;
getJwt: () => Promise<string>;
onJwtChange: (listener: (jwt: string | undefined) => void) => void;
offJwtChange: (listener: (jwt: string | undefined) => void) => void;
isUserActive: () => boolean | undefined;
}
export default class AuthManagerImpl implements AuthManager {
private emailAddress;
private apiKey;
/** Point API URL */
private readonly ApiUrl;
/** Point API version */
private readonly ApiVersionAccept;
private userActive;
private jwt;
private jwtRenewTimeoutId;
private jwtChangedEmitter;
/**
* Creates AuthManager instance
*
* @param emailAddress Email address of Point user account
* @param apiKey User's API Key
* @param apiUrl Point API URL
*/
constructor(emailAddress: string, apiKey: string, apiUrl: string | undefined, apiVersion: string);
setCredentials: (emailAddress: string, apiKey: string) => void;
/**
* Returns JWT token.
*
* If the token hasn't been fetched yet the method will fetch it from
* the server by caliing /auth endpoint.
*
* @returns JWT string
*/
getJwt: () => Promise<string>;
/**
* Adds a listener that will be called upon JWT change.
* @param listener: <Function> The callback function
*/
onJwtChange: (listener: (jwt: string | undefined) => void) => void;
/**
* Removes a listener that will be called upon JWT change.
* @param listener: <Function> The callback function
*/
offJwtChange: (listener: (jwt: string | undefined) => void) => void;
isUserActive: () => boolean | undefined;
private refreshJwtToken;
/**
* Calls /init endpoint which is used to speed up session initialization
* for autocomplete. Can be called right after successfull authorization.
*/
private initSession;
}