UNPKG

eightsleep

Version:
31 lines 1.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const baseerr_1 = __importDefault(require("baseerr")); class InvalidOauthError extends baseerr_1.default { } function validateOauth(oauth) { if (typeof oauth != 'object') { throw new InvalidOauthError('invalid oauth', { oauth }); } let { access_token: accessToken, token_type: tokenType, expires_in: expiresIn, refresh_token: refreshToken, } = oauth; if (typeof accessToken !== 'string') throw new InvalidOauthError('invalid accessToken', { oauth }); if (typeof tokenType !== 'string') throw new InvalidOauthError('invalid tokenType', { oauth }); expiresIn = new Date(expiresIn).valueOf(); if (typeof expiresIn !== 'number' || isNaN(expiresIn)) throw new InvalidOauthError('invalid expiresIn', { oauth }); if (typeof refreshToken !== 'string') throw new InvalidOauthError('invalid refreshToken', { oauth }); return { accessToken, tokenType, expiresIn: new Date(expiresIn), refreshToken, }; } exports.default = validateOauth; //# sourceMappingURL=validateOauth.js.map