UNPKG

node-apple-weatherkit

Version:
52 lines 1.61 kB
"use strict"; /* * Copyright (c) 2022 RainMachine - Green Electronics LLC * Author: Nicu Pavel * License: MIT */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WeatherKit = void 0; const jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); const endpoints_1 = require("./api/endpoints"); class WeatherKit { constructor(options) { this.options = options; this.token = this.encodeJWT(options); } get jwt() { return this.token; } get availability() { return new endpoints_1.AvailabilityEndpoint(this.token); } get weather() { return new endpoints_1.WeatherEndpoint(this.token); } encodeJWT(options) { const now = new Date(); const currentTime = (now.getTime() / 1000) >> 0; if (!options.expireTime) { options.expireTime = now.setFullYear(now.getFullYear() + 1); } const payload = { iss: options.teamId, iat: currentTime, exp: options.expireTime, sub: options.serviceId, }; const headers = { alg: 'ES256', kid: options.keyId, id: options.teamId + '.' + options.serviceId, }; return jsonwebtoken_1.default.sign(payload, options.key, { algorithm: 'ES256', header: { ...headers }, }); } } exports.WeatherKit = WeatherKit; //# sourceMappingURL=WeatherKit.js.map