Skip to content

Commit

Permalink
Refactor: Status PAT info endpoint: Resolve jsdoc eslint errors (anur…
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty541 authored Aug 6, 2023
1 parent 8780cc2 commit ed84840
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions api/status/pat-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
import { logger, request, dateDiff } from "../../src/common/utils.js";
export const RATE_LIMIT_SECONDS = 60 * 5; // 1 request per 5 minutes

/**
* @typedef {import('axios').AxiosRequestHeaders} AxiosRequestHeaders Axios request headers.
* @typedef {import('axios').AxiosResponse} AxiosResponse Axios response.
*/

/**
* Simple uptime check fetcher for the PATs.
*
* @param {import('axios').AxiosRequestHeaders} variables
* @param {string} token
* @param {AxiosRequestHeaders} variables Fetcher variables.
* @param {string} token GitHub token.
* @returns {Promise<AxiosResponse>} The response.
*/
const uptimeFetcher = (variables, token) => {
return request(
Expand All @@ -36,8 +42,17 @@ const getAllPATs = () => {
return Object.keys(process.env).filter((key) => /PAT_\d*$/.exec(key));
};

/**
* @typedef {(variables: AxiosRequestHeaders, token: string) => Promise<AxiosResponse>} Fetcher The fetcher function.
* @typedef {{validPATs: string[], expiredPATs: string[], exhaustedPATs: string[], suspendedPATs: string[], errorPATs: string[], details: any}} PATInfo The PAT info.
*/

/**
* Check whether any of the PATs is expired.
*
* @param {Fetcher} fetcher The fetcher function.
* @param {AxiosRequestHeaders} variables Fetcher variables.
* @returns {Promise<PATInfo>} The response.
*/
const getPATInfo = async (fetcher, variables) => {
const details = {};
Expand Down Expand Up @@ -117,6 +132,10 @@ const getPATInfo = async (fetcher, variables) => {

/**
* Cloud function that returns information about the used PATs.
*
* @param {any} _ The request.
* @param {any} res The response.
* @returns {Promise<void>} The response.
*/
export default async (_, res) => {
res.setHeader("Content-Type", "application/json");
Expand Down

1 comment on commit ed84840

@vercel
Copy link

@vercel vercel bot commented on ed84840 Aug 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.