node-hue-api
Version:
Philips Hue API Library for Node.js
79 lines (78 loc) • 2.69 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OAuthTokens = void 0;
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);
}
}
exports.OAuthTokens = OAuthTokens;