UNPKG

node-hue-api

Version:
75 lines (74 loc) 2.56 kB
export class OAuthTokens { constructor(other) { this._accessTokenValue = {}; this._refreshTokenValue = {}; if (other) { if (other.accessTokenValue) { this._setAccessToken(other.accessTokenValue, other.accessTokenExpiresAt); } if (other.refreshTokenValue) { this._setRefreshToken(other.refreshTokenValue, other.refreshTokenExpiresAt); } } } _setAccessToken(token, expiresAt) { this._accessTokenValue.value = token; this._accessTokenValue.expiresAt = expiresAt; } _setRefreshToken(token, expiresAt) { this._refreshTokenValue.value = token; this._refreshTokenValue.expiresAt = expiresAt; } get refreshTokenValue() { var _a; return (_a = this._refreshTokenValue) === null || _a === void 0 ? void 0 : _a.value; } get accessTokenValue() { var _a; return (_a = this._accessTokenValue) === null || _a === void 0 ? void 0 : _a.value; } /** * Gets the access token expiry if known * @returns the timestamp value of the expiry of the access token, or -1 os not known */ get accessTokenExpiresAt() { var _a; if (((_a = this._accessTokenValue) === null || _a === void 0 ? void 0 : _a.expiresAt) !== undefined) { return this._accessTokenValue.expiresAt; } return -1; } /** * Gets the refresh token expiry if known * @returns the timestamp value of the expiry of the refresh token, or -1 os not known */ get refreshTokenExpiresAt() { var _a; if (((_a = this._refreshTokenValue) === null || _a === void 0 ? void 0 : _a.expiresAt) !== undefined) { return this._refreshTokenValue.expiresAt; } return -1; } get accessToken() { if (this.accessTokenValue) { return { value: this.accessTokenValue, expiresAt: this.accessTokenExpiresAt }; } return undefined; } get refreshToken() { if (this.refreshTokenValue) { return { value: this.refreshTokenValue, expiresAt: this.refreshTokenExpiresAt }; } return undefined; } toString() { const data = {}, refresh = this.refreshToken, access = this.accessToken; if (access) { data.accessToken = this.accessToken; } if (refresh) { data.refreshToken = this.refreshToken; } return JSON.stringify(data, null, 2); } }