Upgrade octokit to v4.1.2

This commit is contained in:
Angela P Wen 2025-02-19 11:13:12 -08:00
parent dbbcbe019d
commit c1745a9831
1214 changed files with 160765 additions and 0 deletions

View file

@ -0,0 +1,29 @@
import { request as defaultRequest } from "@octokit/request";
async function checkToken(options) {
const request = options.request || defaultRequest;
const response = await request("POST /applications/{client_id}/token", {
headers: {
authorization: `basic ${btoa(
`${options.clientId}:${options.clientSecret}`
)}`
},
client_id: options.clientId,
access_token: options.token
});
const authentication = {
clientType: options.clientType,
clientId: options.clientId,
clientSecret: options.clientSecret,
token: options.token,
scopes: response.data.scopes
};
if (response.data.expires_at)
authentication.expiresAt = response.data.expires_at;
if (options.clientType === "github-app") {
delete authentication.scopes;
}
return { ...response, authentication };
}
export {
checkToken
};

View file

@ -0,0 +1,15 @@
import { request as defaultRequest } from "@octokit/request";
import { oauthRequest } from "./utils.js";
async function createDeviceCode(options) {
const request = options.request || defaultRequest;
const parameters = {
client_id: options.clientId
};
if ("scopes" in options && Array.isArray(options.scopes)) {
parameters.scope = options.scopes.join(" ");
}
return oauthRequest(request, "POST /login/device/code", parameters);
}
export {
createDeviceCode
};

View file

@ -0,0 +1,18 @@
import { request as defaultRequest } from "@octokit/request";
async function deleteAuthorization(options) {
const request = options.request || defaultRequest;
const auth = btoa(`${options.clientId}:${options.clientSecret}`);
return request(
"DELETE /applications/{client_id}/grant",
{
headers: {
authorization: `basic ${auth}`
},
client_id: options.clientId,
access_token: options.token
}
);
}
export {
deleteAuthorization
};

View file

@ -0,0 +1,18 @@
import { request as defaultRequest } from "@octokit/request";
async function deleteToken(options) {
const request = options.request || defaultRequest;
const auth = btoa(`${options.clientId}:${options.clientSecret}`);
return request(
"DELETE /applications/{client_id}/token",
{
headers: {
authorization: `basic ${auth}`
},
client_id: options.clientId,
access_token: options.token
}
);
}
export {
deleteToken
};

View file

@ -0,0 +1,43 @@
import { request as defaultRequest } from "@octokit/request";
import { oauthRequest } from "./utils.js";
async function exchangeDeviceCode(options) {
const request = options.request || defaultRequest;
const response = await oauthRequest(
request,
"POST /login/oauth/access_token",
{
client_id: options.clientId,
device_code: options.code,
grant_type: "urn:ietf:params:oauth:grant-type:device_code"
}
);
const authentication = {
clientType: options.clientType,
clientId: options.clientId,
token: response.data.access_token,
scopes: response.data.scope.split(/\s+/).filter(Boolean)
};
if ("clientSecret" in options) {
authentication.clientSecret = options.clientSecret;
}
if (options.clientType === "github-app") {
if ("refresh_token" in response.data) {
const apiTimeInMs = new Date(response.headers.date).getTime();
authentication.refreshToken = response.data.refresh_token, authentication.expiresAt = toTimestamp(
apiTimeInMs,
response.data.expires_in
), authentication.refreshTokenExpiresAt = toTimestamp(
apiTimeInMs,
response.data.refresh_token_expires_in
);
}
delete authentication.scopes;
}
return { ...response, authentication };
}
function toTimestamp(apiTimeInMs, expirationInSeconds) {
return new Date(apiTimeInMs + expirationInSeconds * 1e3).toISOString();
}
export {
exchangeDeviceCode
};

View file

@ -0,0 +1,42 @@
import { request as defaultRequest } from "@octokit/request";
import { oauthRequest } from "./utils.js";
async function exchangeWebFlowCode(options) {
const request = options.request || defaultRequest;
const response = await oauthRequest(
request,
"POST /login/oauth/access_token",
{
client_id: options.clientId,
client_secret: options.clientSecret,
code: options.code,
redirect_uri: options.redirectUrl
}
);
const authentication = {
clientType: options.clientType,
clientId: options.clientId,
clientSecret: options.clientSecret,
token: response.data.access_token,
scopes: response.data.scope.split(/\s+/).filter(Boolean)
};
if (options.clientType === "github-app") {
if ("refresh_token" in response.data) {
const apiTimeInMs = new Date(response.headers.date).getTime();
authentication.refreshToken = response.data.refresh_token, authentication.expiresAt = toTimestamp(
apiTimeInMs,
response.data.expires_in
), authentication.refreshTokenExpiresAt = toTimestamp(
apiTimeInMs,
response.data.refresh_token_expires_in
);
}
delete authentication.scopes;
}
return { ...response, authentication };
}
function toTimestamp(apiTimeInMs, expirationInSeconds) {
return new Date(apiTimeInMs + expirationInSeconds * 1e3).toISOString();
}
export {
exchangeWebFlowCode
};

View file

@ -0,0 +1,16 @@
import { oauthAuthorizationUrl } from "@octokit/oauth-authorization-url";
import { request as defaultRequest } from "@octokit/request";
import { requestToOAuthBaseUrl } from "./utils.js";
function getWebFlowAuthorizationUrl({
request = defaultRequest,
...options
}) {
const baseUrl = requestToOAuthBaseUrl(request);
return oauthAuthorizationUrl({
...options,
baseUrl
});
}
export {
getWebFlowAuthorizationUrl
};

14
node_modules/@octokit/oauth-methods/dist-src/index.js generated vendored Normal file
View file

@ -0,0 +1,14 @@
import { VERSION } from "./version.js";
export * from "./get-web-flow-authorization-url.js";
export * from "./exchange-web-flow-code.js";
export * from "./create-device-code.js";
export * from "./exchange-device-code.js";
export * from "./check-token.js";
export * from "./refresh-token.js";
export * from "./scope-token.js";
export * from "./reset-token.js";
export * from "./delete-token.js";
export * from "./delete-authorization.js";
export {
VERSION
};

View file

@ -0,0 +1,35 @@
import { request as defaultRequest } from "@octokit/request";
import { oauthRequest } from "./utils.js";
async function refreshToken(options) {
const request = options.request || defaultRequest;
const response = await oauthRequest(
request,
"POST /login/oauth/access_token",
{
client_id: options.clientId,
client_secret: options.clientSecret,
grant_type: "refresh_token",
refresh_token: options.refreshToken
}
);
const apiTimeInMs = new Date(response.headers.date).getTime();
const authentication = {
clientType: "github-app",
clientId: options.clientId,
clientSecret: options.clientSecret,
token: response.data.access_token,
refreshToken: response.data.refresh_token,
expiresAt: toTimestamp(apiTimeInMs, response.data.expires_in),
refreshTokenExpiresAt: toTimestamp(
apiTimeInMs,
response.data.refresh_token_expires_in
)
};
return { ...response, authentication };
}
function toTimestamp(apiTimeInMs, expirationInSeconds) {
return new Date(apiTimeInMs + expirationInSeconds * 1e3).toISOString();
}
export {
refreshToken
};

View file

@ -0,0 +1,31 @@
import { request as defaultRequest } from "@octokit/request";
async function resetToken(options) {
const request = options.request || defaultRequest;
const auth = btoa(`${options.clientId}:${options.clientSecret}`);
const response = await request(
"PATCH /applications/{client_id}/token",
{
headers: {
authorization: `basic ${auth}`
},
client_id: options.clientId,
access_token: options.token
}
);
const authentication = {
clientType: options.clientType,
clientId: options.clientId,
clientSecret: options.clientSecret,
token: response.data.token,
scopes: response.data.scopes
};
if (response.data.expires_at)
authentication.expiresAt = response.data.expires_at;
if (options.clientType === "github-app") {
delete authentication.scopes;
}
return { ...response, authentication };
}
export {
resetToken
};

View file

@ -0,0 +1,36 @@
import { request as defaultRequest } from "@octokit/request";
async function scopeToken(options) {
const {
request: optionsRequest,
clientType,
clientId,
clientSecret,
token,
...requestOptions
} = options;
const request = options.request || defaultRequest;
const response = await request(
"POST /applications/{client_id}/token/scoped",
{
headers: {
authorization: `basic ${btoa(`${clientId}:${clientSecret}`)}`
},
client_id: clientId,
access_token: token,
...requestOptions
}
);
const authentication = Object.assign(
{
clientType,
clientId,
clientSecret,
token: response.data.token
},
response.data.expires_at ? { expiresAt: response.data.expires_at } : {}
);
return { ...response, authentication };
}
export {
scopeToken
};

34
node_modules/@octokit/oauth-methods/dist-src/utils.js generated vendored Normal file
View file

@ -0,0 +1,34 @@
import { RequestError } from "@octokit/request-error";
function requestToOAuthBaseUrl(request) {
const endpointDefaults = request.endpoint.DEFAULTS;
return /^https:\/\/(api\.)?github\.com$/.test(endpointDefaults.baseUrl) ? "https://github.com" : endpointDefaults.baseUrl.replace("/api/v3", "");
}
async function oauthRequest(request, route, parameters) {
const withOAuthParameters = {
baseUrl: requestToOAuthBaseUrl(request),
headers: {
accept: "application/json"
},
...parameters
};
const response = await request(route, withOAuthParameters);
if ("error" in response.data) {
const error = new RequestError(
`${response.data.error_description} (${response.data.error}, ${response.data.error_uri})`,
400,
{
request: request.endpoint.merge(
route,
withOAuthParameters
)
}
);
error.response = response;
throw error;
}
return response;
}
export {
oauthRequest,
requestToOAuthBaseUrl
};

View file

@ -0,0 +1,4 @@
const VERSION = "5.1.4";
export {
VERSION
};