homebridge-nest-cam-ft
Version:
Nest cam plugin for homebridge: https://homebridge.io/
71 lines • 3.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestEndpoints = exports.handleError = void 0;
const axios_1 = __importDefault(require("axios"));
const API_TIMEOUT_SECONDS = 10;
function handleError(log, error, message, debug = false) {
const addendum = 'Troubleshoot here: https://git.io/Jtxww';
if (error.response) {
const status = parseInt(error.response.status);
const errMsg = `${message}: ${status}`;
if (status >= 500 || status === 404) {
log === null || log === void 0 ? void 0 : log.debug(`${errMsg}\n${addendum}`);
}
else {
debug ? log === null || log === void 0 ? void 0 : log.debug(`${errMsg}\n${addendum}`) : log === null || log === void 0 ? void 0 : log.error(`${errMsg}\n${addendum}`);
}
}
else if (error.code) {
const errMsg = `${message}: ${error.code}`;
if (error.code === 'ECONNRESET' || error.code === 'EAI_AGAIN') {
log === null || log === void 0 ? void 0 : log.debug(`${errMsg}\n${addendum}`);
}
else {
debug ? log === null || log === void 0 ? void 0 : log.debug(`${errMsg}\n${addendum}`) : log === null || log === void 0 ? void 0 : log.error(`${errMsg}\n${addendum}`);
}
}
else {
log === null || log === void 0 ? void 0 : log.error(error);
}
}
exports.handleError = handleError;
class NestEndpoints {
constructor(fieldTestMode) {
this.NEST_API_HOSTNAME = 'https://home.nest.com';
this.CAMERA_API_HOSTNAME = 'https://webapi.camera.home.nest.com';
this.CAMERA_AUTH_COOKIE = 'website_2';
if (fieldTestMode) {
this.NEST_API_HOSTNAME = 'https://home.ft.nest.com';
this.CAMERA_API_HOSTNAME = 'https://webapi.camera.home.ft.nest.com';
this.CAMERA_AUTH_COOKIE = 'website_ft';
}
}
async sendRequest(accessToken, hostname, endpoint, method, type = 'json', contentType = '', timeout = true, data) {
const headers = {
'User-Agent': NestEndpoints.USER_AGENT_STRING,
Referer: this.NEST_API_HOSTNAME,
};
if (contentType) {
headers['Content-Type'] = contentType;
}
if (accessToken) {
headers.Authorization = `Basic ${accessToken}`;
}
const url = hostname + endpoint;
const req = {
method,
url,
data,
headers,
responseType: type,
timeout: timeout ? API_TIMEOUT_SECONDS * 1000 : undefined,
};
return (await (0, axios_1.default)(req)).data;
}
}
exports.NestEndpoints = NestEndpoints;
NestEndpoints.USER_AGENT_STRING = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36';
//# sourceMappingURL=endpoints.js.map