First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

7
node_modules/@octokit/oauth-app/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,7 @@
MIT License Copyright (c) 2020 Octokit contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1176
node_modules/@octokit/oauth-app/README.md generated vendored Normal file

File diff suppressed because it is too large Load Diff

790
node_modules/@octokit/oauth-app/dist-node/index.js generated vendored Normal file
View File

@@ -0,0 +1,790 @@
// pkg/dist-src/index.js
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
// pkg/dist-src/version.js
var VERSION = "8.0.3";
// pkg/dist-src/add-event-handler.js
function addEventHandler(state, eventName, eventHandler) {
if (Array.isArray(eventName)) {
for (const singleEventName of eventName) {
addEventHandler(state, singleEventName, eventHandler);
}
return;
}
if (!state.eventHandlers[eventName]) {
state.eventHandlers[eventName] = [];
}
state.eventHandlers[eventName].push(eventHandler);
}
// pkg/dist-src/oauth-app-octokit.js
import { Octokit } from "@octokit/core";
import { getUserAgent } from "universal-user-agent";
var OAuthAppOctokit = Octokit.defaults({
userAgent: `octokit-oauth-app.js/${VERSION} ${getUserAgent()}`
});
// pkg/dist-src/methods/get-user-octokit.js
import { createOAuthUserAuth } from "@octokit/auth-oauth-user";
// pkg/dist-src/emit-event.js
async function emitEvent(state, context) {
const { name, action } = context;
if (state.eventHandlers[`${name}.${action}`]) {
for (const eventHandler of state.eventHandlers[`${name}.${action}`]) {
await eventHandler(context);
}
}
if (state.eventHandlers[name]) {
for (const eventHandler of state.eventHandlers[name]) {
await eventHandler(context);
}
}
}
// pkg/dist-src/methods/get-user-octokit.js
async function getUserOctokitWithState(state, options) {
return state.octokit.auth({
type: "oauth-user",
...options,
async factory(options2) {
const octokit = new state.Octokit({
authStrategy: createOAuthUserAuth,
auth: options2
});
const authentication = await octokit.auth({
type: "get"
});
await emitEvent(state, {
name: "token",
action: "created",
token: authentication.token,
scopes: authentication.scopes,
authentication,
octokit
});
return octokit;
}
});
}
// pkg/dist-src/methods/get-web-flow-authorization-url.js
import * as OAuthMethods from "@octokit/oauth-methods";
function getWebFlowAuthorizationUrlWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
request: state.octokit.request,
...options,
allowSignup: state.allowSignup ?? options.allowSignup,
redirectUrl: options.redirectUrl ?? state.redirectUrl,
scopes: options.scopes ?? state.defaultScopes
};
return OAuthMethods.getWebFlowAuthorizationUrl({
clientType: state.clientType,
...optionsWithDefaults
});
}
// pkg/dist-src/methods/create-token.js
import * as OAuthAppAuth from "@octokit/auth-oauth-app";
async function createTokenWithState(state, options) {
const authentication = await state.octokit.auth({
type: "oauth-user",
...options
});
await emitEvent(state, {
name: "token",
action: "created",
token: authentication.token,
scopes: authentication.scopes,
authentication,
octokit: new state.Octokit({
authStrategy: OAuthAppAuth.createOAuthUserAuth,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: authentication.token,
scopes: authentication.scopes,
refreshToken: authentication.refreshToken,
expiresAt: authentication.expiresAt,
refreshTokenExpiresAt: authentication.refreshTokenExpiresAt
}
})
});
return { authentication };
}
// pkg/dist-src/methods/check-token.js
import * as OAuthMethods2 from "@octokit/oauth-methods";
async function checkTokenWithState(state, options) {
const result = await OAuthMethods2.checkToken({
// @ts-expect-error not worth the extra code to appease TS
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
});
Object.assign(result.authentication, { type: "token", tokenType: "oauth" });
return result;
}
// pkg/dist-src/methods/reset-token.js
import * as OAuthMethods3 from "@octokit/oauth-methods";
import { createOAuthUserAuth as createOAuthUserAuth3 } from "@octokit/auth-oauth-user";
async function resetTokenWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
};
if (state.clientType === "oauth-app") {
const response2 = await OAuthMethods3.resetToken({
clientType: "oauth-app",
...optionsWithDefaults
});
const authentication2 = Object.assign(response2.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "reset",
token: response2.authentication.token,
scopes: response2.authentication.scopes || void 0,
authentication: authentication2,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth3,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response2.authentication.token,
scopes: response2.authentication.scopes
}
})
});
return { ...response2, authentication: authentication2 };
}
const response = await OAuthMethods3.resetToken({
clientType: "github-app",
...optionsWithDefaults
});
const authentication = Object.assign(response.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "reset",
token: response.authentication.token,
authentication,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth3,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response.authentication.token
}
})
});
return { ...response, authentication };
}
// pkg/dist-src/methods/refresh-token.js
import * as OAuthMethods4 from "@octokit/oauth-methods";
import { createOAuthUserAuth as createOAuthUserAuth4 } from "@octokit/auth-oauth-user";
async function refreshTokenWithState(state, options) {
if (state.clientType === "oauth-app") {
throw new Error(
"[@octokit/oauth-app] app.refreshToken() is not supported for OAuth Apps"
);
}
const response = await OAuthMethods4.refreshToken({
clientType: "github-app",
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
refreshToken: options.refreshToken
});
const authentication = Object.assign(response.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "refreshed",
token: response.authentication.token,
authentication,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth4,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response.authentication.token
}
})
});
return { ...response, authentication };
}
// pkg/dist-src/methods/scope-token.js
import * as OAuthMethods5 from "@octokit/oauth-methods";
import { createOAuthUserAuth as createOAuthUserAuth5 } from "@octokit/auth-oauth-user";
async function scopeTokenWithState(state, options) {
if (state.clientType === "oauth-app") {
throw new Error(
"[@octokit/oauth-app] app.scopeToken() is not supported for OAuth Apps"
);
}
const response = await OAuthMethods5.scopeToken({
clientType: "github-app",
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
});
const authentication = Object.assign(response.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "scoped",
token: response.authentication.token,
authentication,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth5,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response.authentication.token
}
})
});
return { ...response, authentication };
}
// pkg/dist-src/methods/delete-token.js
import * as OAuthMethods6 from "@octokit/oauth-methods";
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
async function deleteTokenWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
};
const response = state.clientType === "oauth-app" ? await OAuthMethods6.deleteToken({
clientType: "oauth-app",
...optionsWithDefaults
}) : (
/* v8 ignore next 4 */
await OAuthMethods6.deleteToken({
clientType: "github-app",
...optionsWithDefaults
})
);
await emitEvent(state, {
name: "token",
action: "deleted",
token: options.token,
octokit: new state.Octokit({
authStrategy: createUnauthenticatedAuth,
auth: {
reason: `Handling "token.deleted" event. The access for the token has been revoked.`
}
})
});
return response;
}
// pkg/dist-src/methods/delete-authorization.js
import * as OAuthMethods7 from "@octokit/oauth-methods";
import { createUnauthenticatedAuth as createUnauthenticatedAuth2 } from "@octokit/auth-unauthenticated";
async function deleteAuthorizationWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
};
const response = state.clientType === "oauth-app" ? await OAuthMethods7.deleteAuthorization({
clientType: "oauth-app",
...optionsWithDefaults
}) : (
/* v8 ignore next 4 */
await OAuthMethods7.deleteAuthorization({
clientType: "github-app",
...optionsWithDefaults
})
);
await emitEvent(state, {
name: "token",
action: "deleted",
token: options.token,
octokit: new state.Octokit({
authStrategy: createUnauthenticatedAuth2,
auth: {
reason: `Handling "token.deleted" event. The access for the token has been revoked.`
}
})
});
await emitEvent(state, {
name: "authorization",
action: "deleted",
token: options.token,
octokit: new state.Octokit({
authStrategy: createUnauthenticatedAuth2,
auth: {
reason: `Handling "authorization.deleted" event. The access for the app has been revoked.`
}
})
});
return response;
}
// pkg/dist-src/middleware/unknown-route-response.js
function unknownRouteResponse(request) {
return {
status: 404,
headers: { "content-type": "application/json" },
text: JSON.stringify({
error: `Unknown route: ${request.method} ${request.url}`
})
};
}
// pkg/dist-src/middleware/handle-request.js
async function handleRequest(app, { pathPrefix = "/api/github/oauth" }, request) {
let { pathname } = new URL(request.url, "http://localhost");
if (!pathname.startsWith(`${pathPrefix}/`)) {
return void 0;
}
if (request.method === "OPTIONS") {
return {
status: 200,
headers: {
"access-control-allow-origin": "*",
"access-control-allow-methods": "*",
"access-control-allow-headers": "Content-Type, User-Agent, Authorization"
}
};
}
pathname = pathname.slice(pathPrefix.length + 1);
const route = [request.method, pathname].join(" ");
const routes = {
getLogin: `GET login`,
getCallback: `GET callback`,
createToken: `POST token`,
getToken: `GET token`,
patchToken: `PATCH token`,
patchRefreshToken: `PATCH refresh-token`,
scopeToken: `POST token/scoped`,
deleteToken: `DELETE token`,
deleteGrant: `DELETE grant`
};
if (!Object.values(routes).includes(route)) {
return unknownRouteResponse(request);
}
let json;
try {
const text = await request.text();
json = text ? JSON.parse(text) : {};
} catch (error) {
return {
status: 400,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify({
error: "[@octokit/oauth-app] request error"
})
};
}
const { searchParams } = new URL(request.url, "http://localhost");
const query = Object.fromEntries(searchParams);
const headers = request.headers;
try {
if (route === routes.getLogin) {
const authOptions = {};
if (query.state) {
Object.assign(authOptions, { state: query.state });
}
if (query.scopes) {
Object.assign(authOptions, { scopes: query.scopes.split(",") });
}
if (query.allowSignup) {
Object.assign(authOptions, {
allowSignup: query.allowSignup === "true"
});
}
if (query.redirectUrl) {
Object.assign(authOptions, { redirectUrl: query.redirectUrl });
}
const { url } = app.getWebFlowAuthorizationUrl(authOptions);
return { status: 302, headers: { location: url } };
}
if (route === routes.getCallback) {
if (query.error) {
throw new Error(
`[@octokit/oauth-app] ${query.error} ${query.error_description}`
);
}
if (!query.code) {
throw new Error('[@octokit/oauth-app] "code" parameter is required');
}
const {
authentication: { token: token2 }
} = await app.createToken({
code: query.code
});
return {
status: 200,
headers: {
"content-type": "text/html"
},
text: `<h1>Token created successfully</h1>
<p>Your token is: <strong>${token2}</strong>. Copy it now as it cannot be shown again.</p>`
};
}
if (route === routes.createToken) {
const { code, redirectUrl } = json;
if (!code) {
throw new Error('[@octokit/oauth-app] "code" parameter is required');
}
const result = await app.createToken({
code,
redirectUrl
});
delete result.authentication.clientSecret;
return {
status: 201,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.getToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const result = await app.checkToken({
token: token2
});
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.patchToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const result = await app.resetToken({ token: token2 });
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.patchRefreshToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const { refreshToken: refreshToken2 } = json;
if (!refreshToken2) {
throw new Error(
"[@octokit/oauth-app] refreshToken must be sent in request body"
);
}
const result = await app.refreshToken({ refreshToken: refreshToken2 });
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.scopeToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const result = await app.scopeToken({
token: token2,
...json
});
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.deleteToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
await app.deleteToken({
token: token2
});
return {
status: 204,
headers: { "access-control-allow-origin": "*" }
};
}
const token = headers.authorization?.substr("token ".length);
if (!token) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
await app.deleteAuthorization({
token
});
return {
status: 204,
headers: { "access-control-allow-origin": "*" }
};
} catch (error) {
return {
status: 400,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify({ error: error.message })
};
}
}
// pkg/dist-src/middleware/node/parse-request.js
function parseRequest(request) {
const { method, url, headers } = request;
async function text() {
const text2 = await new Promise((resolve, reject) => {
let bodyChunks = [];
request.on("error", reject).on("data", (chunk) => bodyChunks.push(chunk)).on("end", () => resolve(Buffer.concat(bodyChunks).toString()));
});
return text2;
}
return { method, url, headers, text };
}
// pkg/dist-src/middleware/node/send-response.js
function sendResponse(octokitResponse, response) {
response.writeHead(octokitResponse.status, octokitResponse.headers);
response.end(octokitResponse.text);
}
// pkg/dist-src/middleware/node/index.js
function createNodeMiddleware(app, options = {}) {
return async function(request, response, next) {
const octokitRequest = await parseRequest(request);
const octokitResponse = await handleRequest(app, options, octokitRequest);
if (octokitResponse) {
sendResponse(octokitResponse, response);
return true;
} else {
next?.();
return false;
}
};
}
// pkg/dist-src/middleware/web-worker/parse-request.js
function parseRequest2(request) {
const headers = Object.fromEntries(request.headers.entries());
return {
method: request.method,
url: request.url,
headers,
text: () => request.text()
};
}
// pkg/dist-src/middleware/web-worker/send-response.js
function sendResponse2(octokitResponse) {
const responseOptions = {
status: octokitResponse.status
};
if (octokitResponse.headers) {
Object.assign(responseOptions, { headers: octokitResponse.headers });
}
return new Response(octokitResponse.text, responseOptions);
}
// pkg/dist-src/middleware/web-worker/index.js
function createWebWorkerHandler(app, options = {}) {
return async function(request) {
const octokitRequest = await parseRequest2(request);
const octokitResponse = await handleRequest(app, options, octokitRequest);
return octokitResponse ? sendResponse2(octokitResponse) : void 0;
};
}
// pkg/dist-src/middleware/aws-lambda/api-gateway-v2-parse-request.js
function parseRequest3(request) {
const { method } = request.requestContext.http;
let url = request.rawPath;
const { stage } = request.requestContext;
if (url.startsWith("/" + stage)) url = url.substring(stage.length + 1);
if (request.rawQueryString) url += "?" + request.rawQueryString;
const headers = request.headers;
const text = async () => request.body || "";
return { method, url, headers, text };
}
// pkg/dist-src/middleware/aws-lambda/api-gateway-v2-send-response.js
function sendResponse3(octokitResponse) {
return {
statusCode: octokitResponse.status,
headers: octokitResponse.headers,
body: octokitResponse.text
};
}
// pkg/dist-src/middleware/aws-lambda/api-gateway-v2.js
function createAWSLambdaAPIGatewayV2Handler(app, options = {}) {
return async function(event) {
const request = parseRequest3(event);
const response = await handleRequest(app, options, request);
return response ? sendResponse3(response) : void 0;
};
}
// pkg/dist-src/index.js
var OAuthApp = class {
static VERSION = VERSION;
static defaults(defaults) {
const OAuthAppWithDefaults = class extends this {
constructor(...args) {
super({
...defaults,
...args[0]
});
}
};
return OAuthAppWithDefaults;
}
constructor(options) {
const Octokit2 = options.Octokit || OAuthAppOctokit;
this.type = options.clientType || "oauth-app";
const octokit = new Octokit2({
authStrategy: createOAuthAppAuth,
auth: {
clientType: this.type,
clientId: options.clientId,
clientSecret: options.clientSecret
}
});
const state = {
clientType: this.type,
clientId: options.clientId,
clientSecret: options.clientSecret,
// @ts-expect-error defaultScopes not permitted for GitHub Apps
defaultScopes: options.defaultScopes || [],
allowSignup: options.allowSignup,
baseUrl: options.baseUrl,
redirectUrl: options.redirectUrl,
log: options.log,
Octokit: Octokit2,
octokit,
eventHandlers: {}
};
this.on = addEventHandler.bind(null, state);
this.octokit = octokit;
this.getUserOctokit = getUserOctokitWithState.bind(
null,
state
);
this.getWebFlowAuthorizationUrl = getWebFlowAuthorizationUrlWithState.bind(
null,
state
);
this.createToken = createTokenWithState.bind(
null,
state
);
this.checkToken = checkTokenWithState.bind(
null,
state
);
this.resetToken = resetTokenWithState.bind(
null,
state
);
this.refreshToken = refreshTokenWithState.bind(
null,
state
);
this.scopeToken = scopeTokenWithState.bind(
null,
state
);
this.deleteToken = deleteTokenWithState.bind(null, state);
this.deleteAuthorization = deleteAuthorizationWithState.bind(null, state);
}
// assigned during constructor
type;
on;
octokit;
getUserOctokit;
getWebFlowAuthorizationUrl;
createToken;
checkToken;
resetToken;
refreshToken;
scopeToken;
deleteToken;
deleteAuthorization;
};
export {
OAuthApp,
createAWSLambdaAPIGatewayV2Handler,
createNodeMiddleware,
createWebWorkerHandler,
handleRequest,
sendResponse as sendNodeResponse,
unknownRouteResponse
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,15 @@
function addEventHandler(state, eventName, eventHandler) {
if (Array.isArray(eventName)) {
for (const singleEventName of eventName) {
addEventHandler(state, singleEventName, eventHandler);
}
return;
}
if (!state.eventHandlers[eventName]) {
state.eventHandlers[eventName] = [];
}
state.eventHandlers[eventName].push(eventHandler);
}
export {
addEventHandler
};

16
node_modules/@octokit/oauth-app/dist-src/emit-event.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
async function emitEvent(state, context) {
const { name, action } = context;
if (state.eventHandlers[`${name}.${action}`]) {
for (const eventHandler of state.eventHandlers[`${name}.${action}`]) {
await eventHandler(context);
}
}
if (state.eventHandlers[name]) {
for (const eventHandler of state.eventHandlers[name]) {
await eventHandler(context);
}
}
}
export {
emitEvent
};

131
node_modules/@octokit/oauth-app/dist-src/index.js generated vendored Normal file
View File

@@ -0,0 +1,131 @@
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
import { VERSION } from "./version.js";
import { addEventHandler } from "./add-event-handler.js";
import { OAuthAppOctokit } from "./oauth-app-octokit.js";
import {
getUserOctokitWithState
} from "./methods/get-user-octokit.js";
import {
getWebFlowAuthorizationUrlWithState
} from "./methods/get-web-flow-authorization-url.js";
import {
createTokenWithState
} from "./methods/create-token.js";
import {
checkTokenWithState
} from "./methods/check-token.js";
import {
resetTokenWithState
} from "./methods/reset-token.js";
import {
refreshTokenWithState
} from "./methods/refresh-token.js";
import {
scopeTokenWithState
} from "./methods/scope-token.js";
import {
deleteTokenWithState
} from "./methods/delete-token.js";
import {
deleteAuthorizationWithState
} from "./methods/delete-authorization.js";
import { handleRequest } from "./middleware/handle-request.js";
import { unknownRouteResponse } from "./middleware/unknown-route-response.js";
import { createNodeMiddleware } from "./middleware/node/index.js";
import { sendResponse } from "./middleware/node/send-response.js";
import { createWebWorkerHandler } from "./middleware/web-worker/index.js";
import { createAWSLambdaAPIGatewayV2Handler } from "./middleware/aws-lambda/api-gateway-v2.js";
class OAuthApp {
static VERSION = VERSION;
static defaults(defaults) {
const OAuthAppWithDefaults = class extends this {
constructor(...args) {
super({
...defaults,
...args[0]
});
}
};
return OAuthAppWithDefaults;
}
constructor(options) {
const Octokit = options.Octokit || OAuthAppOctokit;
this.type = options.clientType || "oauth-app";
const octokit = new Octokit({
authStrategy: createOAuthAppAuth,
auth: {
clientType: this.type,
clientId: options.clientId,
clientSecret: options.clientSecret
}
});
const state = {
clientType: this.type,
clientId: options.clientId,
clientSecret: options.clientSecret,
// @ts-expect-error defaultScopes not permitted for GitHub Apps
defaultScopes: options.defaultScopes || [],
allowSignup: options.allowSignup,
baseUrl: options.baseUrl,
redirectUrl: options.redirectUrl,
log: options.log,
Octokit,
octokit,
eventHandlers: {}
};
this.on = addEventHandler.bind(null, state);
this.octokit = octokit;
this.getUserOctokit = getUserOctokitWithState.bind(
null,
state
);
this.getWebFlowAuthorizationUrl = getWebFlowAuthorizationUrlWithState.bind(
null,
state
);
this.createToken = createTokenWithState.bind(
null,
state
);
this.checkToken = checkTokenWithState.bind(
null,
state
);
this.resetToken = resetTokenWithState.bind(
null,
state
);
this.refreshToken = refreshTokenWithState.bind(
null,
state
);
this.scopeToken = scopeTokenWithState.bind(
null,
state
);
this.deleteToken = deleteTokenWithState.bind(null, state);
this.deleteAuthorization = deleteAuthorizationWithState.bind(null, state);
}
// assigned during constructor
type;
on;
octokit;
getUserOctokit;
getWebFlowAuthorizationUrl;
createToken;
checkToken;
resetToken;
refreshToken;
scopeToken;
deleteToken;
deleteAuthorization;
}
export {
OAuthApp,
createAWSLambdaAPIGatewayV2Handler,
createNodeMiddleware,
createWebWorkerHandler,
handleRequest,
sendResponse as sendNodeResponse,
unknownRouteResponse
};

View File

@@ -0,0 +1,16 @@
import * as OAuthMethods from "@octokit/oauth-methods";
async function checkTokenWithState(state, options) {
const result = await OAuthMethods.checkToken({
// @ts-expect-error not worth the extra code to appease TS
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
});
Object.assign(result.authentication, { type: "token", tokenType: "oauth" });
return result;
}
export {
checkTokenWithState
};

View File

@@ -0,0 +1,32 @@
import * as OAuthAppAuth from "@octokit/auth-oauth-app";
import { emitEvent } from "../emit-event.js";
async function createTokenWithState(state, options) {
const authentication = await state.octokit.auth({
type: "oauth-user",
...options
});
await emitEvent(state, {
name: "token",
action: "created",
token: authentication.token,
scopes: authentication.scopes,
authentication,
octokit: new state.Octokit({
authStrategy: OAuthAppAuth.createOAuthUserAuth,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: authentication.token,
scopes: authentication.scopes,
refreshToken: authentication.refreshToken,
expiresAt: authentication.expiresAt,
refreshTokenExpiresAt: authentication.refreshTokenExpiresAt
}
})
});
return { authentication };
}
export {
createTokenWithState
};

View File

@@ -0,0 +1,47 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
import { emitEvent } from "../emit-event.js";
async function deleteAuthorizationWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
};
const response = state.clientType === "oauth-app" ? await OAuthMethods.deleteAuthorization({
clientType: "oauth-app",
...optionsWithDefaults
}) : (
/* v8 ignore next 4 */
await OAuthMethods.deleteAuthorization({
clientType: "github-app",
...optionsWithDefaults
})
);
await emitEvent(state, {
name: "token",
action: "deleted",
token: options.token,
octokit: new state.Octokit({
authStrategy: createUnauthenticatedAuth,
auth: {
reason: `Handling "token.deleted" event. The access for the token has been revoked.`
}
})
});
await emitEvent(state, {
name: "authorization",
action: "deleted",
token: options.token,
octokit: new state.Octokit({
authStrategy: createUnauthenticatedAuth,
auth: {
reason: `Handling "authorization.deleted" event. The access for the app has been revoked.`
}
})
});
return response;
}
export {
deleteAuthorizationWithState
};

View File

@@ -0,0 +1,36 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import { createUnauthenticatedAuth } from "@octokit/auth-unauthenticated";
import { emitEvent } from "../emit-event.js";
async function deleteTokenWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
};
const response = state.clientType === "oauth-app" ? await OAuthMethods.deleteToken({
clientType: "oauth-app",
...optionsWithDefaults
}) : (
/* v8 ignore next 4 */
await OAuthMethods.deleteToken({
clientType: "github-app",
...optionsWithDefaults
})
);
await emitEvent(state, {
name: "token",
action: "deleted",
token: options.token,
octokit: new state.Octokit({
authStrategy: createUnauthenticatedAuth,
auth: {
reason: `Handling "token.deleted" event. The access for the token has been revoked.`
}
})
});
return response;
}
export {
deleteTokenWithState
};

View File

@@ -0,0 +1,10 @@
function getOAuthClientCode() {
return `import { Octokit: Core } from "https://esm.sh/@octokit/core";
export const Octokit = Core.defaults({
oauth: {}
})`;
}
export {
getOAuthClientCode
};

View File

@@ -0,0 +1,29 @@
import { createOAuthUserAuth } from "@octokit/auth-oauth-user";
import { emitEvent } from "../emit-event.js";
async function getUserOctokitWithState(state, options) {
return state.octokit.auth({
type: "oauth-user",
...options,
async factory(options2) {
const octokit = new state.Octokit({
authStrategy: createOAuthUserAuth,
auth: options2
});
const authentication = await octokit.auth({
type: "get"
});
await emitEvent(state, {
name: "token",
action: "created",
token: authentication.token,
scopes: authentication.scopes,
authentication,
octokit
});
return octokit;
}
});
}
export {
getUserOctokitWithState
};

View File

@@ -0,0 +1,18 @@
import * as OAuthMethods from "@octokit/oauth-methods";
function getWebFlowAuthorizationUrlWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
request: state.octokit.request,
...options,
allowSignup: state.allowSignup ?? options.allowSignup,
redirectUrl: options.redirectUrl ?? state.redirectUrl,
scopes: options.scopes ?? state.defaultScopes
};
return OAuthMethods.getWebFlowAuthorizationUrl({
clientType: state.clientType,
...optionsWithDefaults
});
}
export {
getWebFlowAuthorizationUrlWithState
};

View File

@@ -0,0 +1,40 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import { emitEvent } from "../emit-event.js";
import { createOAuthUserAuth } from "@octokit/auth-oauth-user";
async function refreshTokenWithState(state, options) {
if (state.clientType === "oauth-app") {
throw new Error(
"[@octokit/oauth-app] app.refreshToken() is not supported for OAuth Apps"
);
}
const response = await OAuthMethods.refreshToken({
clientType: "github-app",
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
refreshToken: options.refreshToken
});
const authentication = Object.assign(response.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "refreshed",
token: response.authentication.token,
authentication,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response.authentication.token
}
})
});
return { ...response, authentication };
}
export {
refreshTokenWithState
};

View File

@@ -0,0 +1,66 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import { emitEvent } from "../emit-event.js";
import { createOAuthUserAuth } from "@octokit/auth-oauth-user";
async function resetTokenWithState(state, options) {
const optionsWithDefaults = {
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
};
if (state.clientType === "oauth-app") {
const response2 = await OAuthMethods.resetToken({
clientType: "oauth-app",
...optionsWithDefaults
});
const authentication2 = Object.assign(response2.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "reset",
token: response2.authentication.token,
scopes: response2.authentication.scopes || void 0,
authentication: authentication2,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response2.authentication.token,
scopes: response2.authentication.scopes
}
})
});
return { ...response2, authentication: authentication2 };
}
const response = await OAuthMethods.resetToken({
clientType: "github-app",
...optionsWithDefaults
});
const authentication = Object.assign(response.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "reset",
token: response.authentication.token,
authentication,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response.authentication.token
}
})
});
return { ...response, authentication };
}
export {
resetTokenWithState
};

View File

@@ -0,0 +1,40 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import { createOAuthUserAuth } from "@octokit/auth-oauth-user";
import { emitEvent } from "../emit-event.js";
async function scopeTokenWithState(state, options) {
if (state.clientType === "oauth-app") {
throw new Error(
"[@octokit/oauth-app] app.scopeToken() is not supported for OAuth Apps"
);
}
const response = await OAuthMethods.scopeToken({
clientType: "github-app",
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.octokit.request,
...options
});
const authentication = Object.assign(response.authentication, {
type: "token",
tokenType: "oauth"
});
await emitEvent(state, {
name: "token",
action: "scoped",
token: response.authentication.token,
authentication,
octokit: new state.Octokit({
authStrategy: createOAuthUserAuth,
auth: {
clientType: state.clientType,
clientId: state.clientId,
clientSecret: state.clientSecret,
token: response.authentication.token
}
})
});
return { ...response, authentication };
}
export {
scopeTokenWithState
};

View File

@@ -0,0 +1,13 @@
function parseRequest(request) {
const { method } = request.requestContext.http;
let url = request.rawPath;
const { stage } = request.requestContext;
if (url.startsWith("/" + stage)) url = url.substring(stage.length + 1);
if (request.rawQueryString) url += "?" + request.rawQueryString;
const headers = request.headers;
const text = async () => request.body || "";
return { method, url, headers, text };
}
export {
parseRequest
};

View File

@@ -0,0 +1,10 @@
function sendResponse(octokitResponse) {
return {
statusCode: octokitResponse.status,
headers: octokitResponse.headers,
body: octokitResponse.text
};
}
export {
sendResponse
};

View File

@@ -0,0 +1,13 @@
import { parseRequest } from "./api-gateway-v2-parse-request.js";
import { sendResponse } from "./api-gateway-v2-send-response.js";
import { handleRequest } from "../handle-request.js";
function createAWSLambdaAPIGatewayV2Handler(app, options = {}) {
return async function(event) {
const request = parseRequest(event);
const response = await handleRequest(app, options, request);
return response ? sendResponse(response) : void 0;
};
}
export {
createAWSLambdaAPIGatewayV2Handler
};

View File

@@ -0,0 +1,240 @@
import { OAuthApp } from "../index.js";
import { unknownRouteResponse } from "./unknown-route-response.js";
async function handleRequest(app, { pathPrefix = "/api/github/oauth" }, request) {
let { pathname } = new URL(request.url, "http://localhost");
if (!pathname.startsWith(`${pathPrefix}/`)) {
return void 0;
}
if (request.method === "OPTIONS") {
return {
status: 200,
headers: {
"access-control-allow-origin": "*",
"access-control-allow-methods": "*",
"access-control-allow-headers": "Content-Type, User-Agent, Authorization"
}
};
}
pathname = pathname.slice(pathPrefix.length + 1);
const route = [request.method, pathname].join(" ");
const routes = {
getLogin: `GET login`,
getCallback: `GET callback`,
createToken: `POST token`,
getToken: `GET token`,
patchToken: `PATCH token`,
patchRefreshToken: `PATCH refresh-token`,
scopeToken: `POST token/scoped`,
deleteToken: `DELETE token`,
deleteGrant: `DELETE grant`
};
if (!Object.values(routes).includes(route)) {
return unknownRouteResponse(request);
}
let json;
try {
const text = await request.text();
json = text ? JSON.parse(text) : {};
} catch (error) {
return {
status: 400,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify({
error: "[@octokit/oauth-app] request error"
})
};
}
const { searchParams } = new URL(request.url, "http://localhost");
const query = Object.fromEntries(searchParams);
const headers = request.headers;
try {
if (route === routes.getLogin) {
const authOptions = {};
if (query.state) {
Object.assign(authOptions, { state: query.state });
}
if (query.scopes) {
Object.assign(authOptions, { scopes: query.scopes.split(",") });
}
if (query.allowSignup) {
Object.assign(authOptions, {
allowSignup: query.allowSignup === "true"
});
}
if (query.redirectUrl) {
Object.assign(authOptions, { redirectUrl: query.redirectUrl });
}
const { url } = app.getWebFlowAuthorizationUrl(authOptions);
return { status: 302, headers: { location: url } };
}
if (route === routes.getCallback) {
if (query.error) {
throw new Error(
`[@octokit/oauth-app] ${query.error} ${query.error_description}`
);
}
if (!query.code) {
throw new Error('[@octokit/oauth-app] "code" parameter is required');
}
const {
authentication: { token: token2 }
} = await app.createToken({
code: query.code
});
return {
status: 200,
headers: {
"content-type": "text/html"
},
text: `<h1>Token created successfully</h1>
<p>Your token is: <strong>${token2}</strong>. Copy it now as it cannot be shown again.</p>`
};
}
if (route === routes.createToken) {
const { code, redirectUrl } = json;
if (!code) {
throw new Error('[@octokit/oauth-app] "code" parameter is required');
}
const result = await app.createToken({
code,
redirectUrl
});
delete result.authentication.clientSecret;
return {
status: 201,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.getToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const result = await app.checkToken({
token: token2
});
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.patchToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const result = await app.resetToken({ token: token2 });
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.patchRefreshToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const { refreshToken } = json;
if (!refreshToken) {
throw new Error(
"[@octokit/oauth-app] refreshToken must be sent in request body"
);
}
const result = await app.refreshToken({ refreshToken });
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.scopeToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
const result = await app.scopeToken({
token: token2,
...json
});
delete result.authentication.clientSecret;
return {
status: 200,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify(result)
};
}
if (route === routes.deleteToken) {
const token2 = headers.authorization?.substr("token ".length);
if (!token2) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
await app.deleteToken({
token: token2
});
return {
status: 204,
headers: { "access-control-allow-origin": "*" }
};
}
const token = headers.authorization?.substr("token ".length);
if (!token) {
throw new Error(
'[@octokit/oauth-app] "Authorization" header is required'
);
}
await app.deleteAuthorization({
token
});
return {
status: 204,
headers: { "access-control-allow-origin": "*" }
};
} catch (error) {
return {
status: 400,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
},
text: JSON.stringify({ error: error.message })
};
}
}
export {
handleRequest
};

View File

@@ -0,0 +1,19 @@
import { parseRequest } from "./parse-request.js";
import { sendResponse } from "./send-response.js";
import { handleRequest } from "../handle-request.js";
function createNodeMiddleware(app, options = {}) {
return async function(request, response, next) {
const octokitRequest = await parseRequest(request);
const octokitResponse = await handleRequest(app, options, octokitRequest);
if (octokitResponse) {
sendResponse(octokitResponse, response);
return true;
} else {
next?.();
return false;
}
};
}
export {
createNodeMiddleware
};

View File

@@ -0,0 +1,14 @@
function parseRequest(request) {
const { method, url, headers } = request;
async function text() {
const text2 = await new Promise((resolve, reject) => {
let bodyChunks = [];
request.on("error", reject).on("data", (chunk) => bodyChunks.push(chunk)).on("end", () => resolve(Buffer.concat(bodyChunks).toString()));
});
return text2;
}
return { method, url, headers, text };
}
export {
parseRequest
};

View File

@@ -0,0 +1,7 @@
function sendResponse(octokitResponse, response) {
response.writeHead(octokitResponse.status, octokitResponse.headers);
response.end(octokitResponse.text);
}
export {
sendResponse
};

View File

@@ -0,0 +1,12 @@
function unknownRouteResponse(request) {
return {
status: 404,
headers: { "content-type": "application/json" },
text: JSON.stringify({
error: `Unknown route: ${request.method} ${request.url}`
})
};
}
export {
unknownRouteResponse
};

View File

@@ -0,0 +1,13 @@
import { parseRequest } from "./parse-request.js";
import { sendResponse } from "./send-response.js";
import { handleRequest } from "../handle-request.js";
function createWebWorkerHandler(app, options = {}) {
return async function(request) {
const octokitRequest = await parseRequest(request);
const octokitResponse = await handleRequest(app, options, octokitRequest);
return octokitResponse ? sendResponse(octokitResponse) : void 0;
};
}
export {
createWebWorkerHandler
};

View File

@@ -0,0 +1,12 @@
function parseRequest(request) {
const headers = Object.fromEntries(request.headers.entries());
return {
method: request.method,
url: request.url,
headers,
text: () => request.text()
};
}
export {
parseRequest
};

View File

@@ -0,0 +1,12 @@
function sendResponse(octokitResponse) {
const responseOptions = {
status: octokitResponse.status
};
if (octokitResponse.headers) {
Object.assign(responseOptions, { headers: octokitResponse.headers });
}
return new Response(octokitResponse.text, responseOptions);
}
export {
sendResponse
};

View File

@@ -0,0 +1,9 @@
import { Octokit } from "@octokit/core";
import { getUserAgent } from "universal-user-agent";
import { VERSION } from "./version.js";
const OAuthAppOctokit = Octokit.defaults({
userAgent: `octokit-oauth-app.js/${VERSION} ${getUserAgent()}`
});
export {
OAuthAppOctokit
};

4
node_modules/@octokit/oauth-app/dist-src/version.js generated vendored Normal file
View File

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

View File

@@ -0,0 +1,2 @@
import type { EventHandler, EventAndActionName, State, ClientType, Options } from "./types.js";
export declare function addEventHandler(state: State, eventName: EventAndActionName | EventAndActionName[], eventHandler: EventHandler<Options<ClientType>>): void;

View File

@@ -0,0 +1,2 @@
import type { State, EventHandlerContext, ClientType, Options } from "./types.js";
export declare function emitEvent(state: State, context: EventHandlerContext<Options<ClientType>>): Promise<void>;

60
node_modules/@octokit/oauth-app/dist-types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,60 @@
import { type GetUserOctokitWithStateInterface } from "./methods/get-user-octokit.js";
import { type GetWebFlowAuthorizationUrlInterface } from "./methods/get-web-flow-authorization-url.js";
import { type CreateTokenInterface } from "./methods/create-token.js";
import { type CheckTokenInterface } from "./methods/check-token.js";
import { type ResetTokenInterface } from "./methods/reset-token.js";
import { type RefreshTokenInterface } from "./methods/refresh-token.js";
import { type ScopeTokenInterface } from "./methods/scope-token.js";
import { type DeleteTokenInterface } from "./methods/delete-token.js";
import { type DeleteAuthorizationInterface } from "./methods/delete-authorization.js";
import type { AddEventHandler, ClientType, ClientTypeFromOptions, ConstructorOptions, OctokitTypeFromOptions, Options } from "./types.js";
export type { HandlerOptions, OctokitRequest, OctokitResponse, } from "./middleware/types.js";
export { handleRequest } from "./middleware/handle-request.js";
export { unknownRouteResponse } from "./middleware/unknown-route-response.js";
export { createNodeMiddleware } from "./middleware/node/index.js";
export { sendResponse as sendNodeResponse } from "./middleware/node/send-response.js";
export { createWebWorkerHandler } from "./middleware/web-worker/index.js";
export { createAWSLambdaAPIGatewayV2Handler } from "./middleware/aws-lambda/api-gateway-v2.js";
export type { GetUserOctokitWithStateInterface } from "./methods/get-user-octokit.js";
export type { GetWebFlowAuthorizationUrlInterface } from "./methods/get-web-flow-authorization-url.js";
export type { CreateTokenInterface } from "./methods/create-token.js";
export type { CheckTokenInterface } from "./methods/check-token.js";
export type { ResetTokenInterface } from "./methods/reset-token.js";
export type { RefreshTokenInterface } from "./methods/refresh-token.js";
export type { ScopeTokenInterface } from "./methods/scope-token.js";
export type { DeleteTokenInterface } from "./methods/delete-token.js";
export type { DeleteAuthorizationInterface } from "./methods/delete-authorization.js";
export type { AddEventHandler, ClientType, ClientTypeFromOptions, ConstructorOptions, OctokitTypeFromOptions, Options, } from "./types.js";
type Constructor<T> = new (...args: any[]) => T;
export declare class OAuthApp<TOptions extends Options<ClientType> = Options<"oauth-app">> {
static VERSION: string;
static defaults<TDefaults extends Options<ClientType>, S extends Constructor<OAuthApp<TDefaults>>>(this: S, defaults: TDefaults): ({
new (...args: any[]): {
type: ClientTypeFromOptions<TDefaults>;
on: AddEventHandler<TDefaults>;
octokit: OctokitTypeFromOptions<TDefaults>;
getUserOctokit: GetUserOctokitWithStateInterface<ClientTypeFromOptions<TDefaults>, OctokitTypeFromOptions<TDefaults>>;
getWebFlowAuthorizationUrl: GetWebFlowAuthorizationUrlInterface<ClientTypeFromOptions<TDefaults>>;
createToken: CreateTokenInterface<ClientTypeFromOptions<TDefaults>>;
checkToken: CheckTokenInterface<ClientTypeFromOptions<TDefaults>>;
resetToken: ResetTokenInterface<ClientTypeFromOptions<TDefaults>>;
refreshToken: RefreshTokenInterface;
scopeToken: ScopeTokenInterface;
deleteToken: DeleteTokenInterface;
deleteAuthorization: DeleteAuthorizationInterface;
};
} & S) & typeof this;
constructor(options: ConstructorOptions<TOptions>);
type: ClientTypeFromOptions<TOptions>;
on: AddEventHandler<TOptions>;
octokit: OctokitTypeFromOptions<TOptions>;
getUserOctokit: GetUserOctokitWithStateInterface<ClientTypeFromOptions<TOptions>, OctokitTypeFromOptions<TOptions>>;
getWebFlowAuthorizationUrl: GetWebFlowAuthorizationUrlInterface<ClientTypeFromOptions<TOptions>>;
createToken: CreateTokenInterface<ClientTypeFromOptions<TOptions>>;
checkToken: CheckTokenInterface<ClientTypeFromOptions<TOptions>>;
resetToken: ResetTokenInterface<ClientTypeFromOptions<TOptions>>;
refreshToken: RefreshTokenInterface;
scopeToken: ScopeTokenInterface;
deleteToken: DeleteTokenInterface;
deleteAuthorization: DeleteAuthorizationInterface;
}

View File

@@ -0,0 +1,14 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import type { ClientType, State } from "../types.js";
export type CheckTokenOptions = {
token: string;
};
export declare function checkTokenWithState(state: State, options: CheckTokenOptions): Promise<any>;
export interface CheckTokenInterface<TClientType extends ClientType> {
(options: CheckTokenOptions): (TClientType extends "oauth-app" ? Promise<OAuthMethods.CheckTokenOAuthAppResponse> : Promise<OAuthMethods.CheckTokenGitHubAppResponse>) & {
authentication: {
type: "token";
tokenType: "oauth";
};
};
}

View File

@@ -0,0 +1,20 @@
import * as OAuthAppAuth from "@octokit/auth-oauth-app";
import type { ClientType, GithubAppUserAuthenticationWithOptionalExpiration, State } from "../types.js";
export type CreateTokenWebFlowOptions = Omit<OAuthAppAuth.WebFlowAuthOptions, "type">;
export type CreateTokenOAuthAppDeviceFlowOptions = Omit<OAuthAppAuth.OAuthAppDeviceFlowAuthOptions, "type">;
export type CreateTokenGitHubAppDeviceFlowOptions = Omit<OAuthAppAuth.GitHubAppDeviceFlowAuthOptions, "type">;
export declare function createTokenWithState(state: State, options: CreateTokenWebFlowOptions | CreateTokenOAuthAppDeviceFlowOptions | CreateTokenGitHubAppDeviceFlowOptions): Promise<{
authentication: OAuthAppAuth.OAuthAppUserAuthentication | OAuthAppAuth.GitHubAppUserAuthentication | OAuthAppAuth.GitHubAppUserAuthenticationWithExpiration;
}>;
export interface CreateTokenInterface<TClientType extends ClientType> {
(options: CreateTokenWebFlowOptions): TClientType extends "oauth-app" ? Promise<{
authentication: OAuthAppAuth.OAuthAppUserAuthentication;
}> : Promise<{
authentication: GithubAppUserAuthenticationWithOptionalExpiration;
}>;
(options: TClientType extends "oauth-app" ? CreateTokenOAuthAppDeviceFlowOptions : CreateTokenGitHubAppDeviceFlowOptions): TClientType extends "oauth-app" ? Promise<{
authentication: OAuthAppAuth.OAuthAppUserAuthentication;
}> : Promise<{
authentication: GithubAppUserAuthenticationWithOptionalExpiration;
}>;
}

View File

@@ -0,0 +1,9 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import type { State } from "../types.js";
export type DeleteAuthorizationOptions = {
token: string;
};
export declare function deleteAuthorizationWithState(state: State, options: DeleteAuthorizationOptions): Promise<OAuthMethods.DeleteAuthorizationResponse>;
export interface DeleteAuthorizationInterface {
(options: DeleteAuthorizationOptions): Promise<OAuthMethods.DeleteAuthorizationResponse>;
}

View File

@@ -0,0 +1,9 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import type { State } from "../types.js";
export type DeleteTokenOptions = {
token: string;
};
export declare function deleteTokenWithState(state: State, options: DeleteTokenOptions): Promise<OAuthMethods.DeleteTokenResponse>;
export interface DeleteTokenInterface {
(options: DeleteTokenOptions): Promise<OAuthMethods.DeleteTokenResponse>;
}

View File

@@ -0,0 +1 @@
export declare function getOAuthClientCode(): string;

View File

@@ -0,0 +1,10 @@
import type { OAuthAppStrategyOptionsWebFlow, OAuthAppStrategyOptionsDeviceFlow, OAuthAppStrategyOptionsExistingAuthentication, GitHubAppStrategyOptionsWebFlow, GitHubAppStrategyOptionsDeviceFlow, GitHubAppStrategyOptionsExistingAuthentication, GitHubAppStrategyOptionsExistingAuthenticationWithExpiration } from "@octokit/auth-oauth-user";
import type { State, OctokitInstance, ClientType } from "../types.js";
type StateOptions = "clientType" | "clientId" | "clientSecret" | "request";
export type GetUserOctokitOAuthAppOptions = Omit<OAuthAppStrategyOptionsWebFlow, StateOptions> | Omit<OAuthAppStrategyOptionsDeviceFlow, StateOptions> | Omit<OAuthAppStrategyOptionsExistingAuthentication, StateOptions>;
export type GetUserOctokitGitHubAppOptions = Omit<GitHubAppStrategyOptionsWebFlow, StateOptions> | Omit<GitHubAppStrategyOptionsDeviceFlow, StateOptions> | Omit<GitHubAppStrategyOptionsExistingAuthentication, StateOptions> | Omit<GitHubAppStrategyOptionsExistingAuthenticationWithExpiration, StateOptions>;
export declare function getUserOctokitWithState(state: State, options: GetUserOctokitOAuthAppOptions | GetUserOctokitGitHubAppOptions): Promise<import("@octokit/core").Octokit>;
export interface GetUserOctokitWithStateInterface<TClientType extends ClientType, TOctokitInstance extends OctokitInstance = OctokitInstance> {
(options: TClientType extends "oauth-app" ? GetUserOctokitOAuthAppOptions : GetUserOctokitGitHubAppOptions): Promise<TOctokitInstance>;
}
export {};

View File

@@ -0,0 +1,10 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import type { ClientType, State } from "../types.js";
type StateOptions = "clientType" | "clientId" | "clientSecret" | "request";
export type GetWebFlowAuthorizationUrlOAuthAppOptions = Omit<OAuthMethods.GetWebFlowAuthorizationUrlOAuthAppOptions, StateOptions>;
export type GetWebFlowAuthorizationUrlGitHubAppOptions = Omit<OAuthMethods.GetWebFlowAuthorizationUrlGitHubAppOptions, StateOptions>;
export declare function getWebFlowAuthorizationUrlWithState(state: State, options: any): any;
export interface GetWebFlowAuthorizationUrlInterface<TClientType extends ClientType> {
(options: TClientType extends "oauth-app" ? GetWebFlowAuthorizationUrlOAuthAppOptions : GetWebFlowAuthorizationUrlGitHubAppOptions): TClientType extends "oauth-app" ? OAuthMethods.GetWebFlowAuthorizationUrlOAuthAppResult : OAuthMethods.GetWebFlowAuthorizationUrlGitHubAppResult;
}
export {};

View File

@@ -0,0 +1,19 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import type { State } from "../types.js";
export type RefreshTokenOptions = {
refreshToken: string;
};
export declare function refreshTokenWithState(state: State, options: RefreshTokenOptions): Promise<OAuthMethods.RefreshTokenResponse & {
authentication: {
type: "token";
tokenType: "oauth";
};
}>;
export interface RefreshTokenInterface {
(options: RefreshTokenOptions): Promise<OAuthMethods.RefreshTokenResponse & {
authentication: {
type: "token";
tokenType: "oauth";
};
}>;
}

View File

@@ -0,0 +1,24 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import type { ClientType, State } from "../types.js";
export type ResetTokenOptions = {
token: string;
};
export declare function resetTokenWithState(state: State, options: ResetTokenOptions): Promise<(OAuthMethods.ResetTokenOAuthAppResponse | OAuthMethods.ResetTokenGitHubAppResponse) & {
authentication: {
type: "token";
tokenType: "oauth";
};
}>;
export interface ResetTokenInterface<TClientType extends ClientType> {
(options: ResetTokenOptions): TClientType extends "oauth-app" ? Promise<OAuthMethods.ResetTokenOAuthAppResponse & {
authentication: {
type: "token";
tokenType: "oauth";
};
}> : Promise<OAuthMethods.ResetTokenGitHubAppResponse & {
authentication: {
type: "token";
tokenType: "oauth";
};
}>;
}

View File

@@ -0,0 +1,19 @@
import * as OAuthMethods from "@octokit/oauth-methods";
import type { State } from "../types.js";
type StateOptions = "clientType" | "clientId" | "clientSecret" | "request";
export type ScopeTokenOptions = Omit<OAuthMethods.ScopeTokenOptions, StateOptions>;
export declare function scopeTokenWithState(state: State, options: ScopeTokenOptions): Promise<OAuthMethods.ScopeTokenResponse & {
authentication: {
type: "token";
tokenType: "oauth";
};
}>;
export interface ScopeTokenInterface {
(options: ScopeTokenOptions): Promise<OAuthMethods.ScopeTokenResponse & {
authentication: {
type: "token";
tokenType: "oauth";
};
}>;
}
export {};

View File

@@ -0,0 +1,3 @@
import type { OctokitRequest } from "../types.js";
import type { APIGatewayProxyEventV2 } from "aws-lambda";
export declare function parseRequest(request: APIGatewayProxyEventV2): OctokitRequest;

View File

@@ -0,0 +1,3 @@
import type { OctokitResponse } from "../types.js";
import type { APIGatewayProxyStructuredResultV2 } from "aws-lambda";
export declare function sendResponse(octokitResponse: OctokitResponse): APIGatewayProxyStructuredResultV2;

View File

@@ -0,0 +1,5 @@
import type { HandlerOptions } from "../types.js";
import type { OAuthApp } from "../../index.js";
import type { ClientType, Options } from "../../types.js";
import type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from "aws-lambda";
export declare function createAWSLambdaAPIGatewayV2Handler(app: OAuthApp<Options<ClientType>>, options?: HandlerOptions): (event: APIGatewayProxyEventV2) => Promise<APIGatewayProxyStructuredResultV2 | undefined>;

View File

@@ -0,0 +1,4 @@
import { OAuthApp } from "../index.js";
import type { HandlerOptions, OctokitRequest, OctokitResponse } from "./types.js";
import type { ClientType, Options } from "../types.js";
export declare function handleRequest(app: OAuthApp<Options<ClientType>>, { pathPrefix }: HandlerOptions, request: OctokitRequest): Promise<OctokitResponse | undefined>;

View File

@@ -0,0 +1,7 @@
type IncomingMessage = any;
type ServerResponse = any;
import type { OAuthApp } from "../../index.js";
import type { HandlerOptions } from "../types.js";
import type { ClientType, Options } from "../../types.js";
export declare function createNodeMiddleware(app: OAuthApp<Options<ClientType>>, options?: HandlerOptions): (request: IncomingMessage, response: ServerResponse, next?: Function) => Promise<boolean>;
export {};

View File

@@ -0,0 +1,4 @@
type IncomingMessage = any;
import type { OctokitRequest } from "../types.js";
export declare function parseRequest(request: IncomingMessage): OctokitRequest;
export {};

View File

@@ -0,0 +1,4 @@
type ServerResponse = any;
import type { OctokitResponse } from "../types.js";
export declare function sendResponse(octokitResponse: OctokitResponse, response: ServerResponse): void;
export {};

View File

@@ -0,0 +1,14 @@
export type OctokitRequest = {
method: string;
url: string;
headers: Record<string, string>;
text: () => Promise<string>;
};
export type OctokitResponse = {
status: number;
headers?: Record<string, string>;
text?: string;
};
export type HandlerOptions = {
pathPrefix?: string;
};

View File

@@ -0,0 +1,8 @@
import type { OctokitRequest } from "./types.js";
export declare function unknownRouteResponse(request: OctokitRequest): {
status: number;
headers: {
"content-type": string;
};
text: string;
};

View File

@@ -0,0 +1,4 @@
import type { OAuthApp } from "../../index.js";
import type { HandlerOptions } from "../types.js";
import type { ClientType, Options } from "../../types.js";
export declare function createWebWorkerHandler<T extends Options<ClientType>>(app: OAuthApp<T>, options?: HandlerOptions): (request: Request) => Promise<Response | undefined>;

View File

@@ -0,0 +1,2 @@
import type { OctokitRequest } from "../types.js";
export declare function parseRequest(request: Request): OctokitRequest;

View File

@@ -0,0 +1,2 @@
import type { OctokitResponse } from "../types.js";
export declare function sendResponse(octokitResponse: OctokitResponse): Response;

View File

@@ -0,0 +1,2 @@
import { Octokit } from "@octokit/core";
export declare const OAuthAppOctokit: typeof Octokit;

68
node_modules/@octokit/oauth-app/dist-types/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,68 @@
import type { Octokit } from "@octokit/core";
import type { OAuthAppUserAuthentication, GitHubAppUserAuthentication, GitHubAppUserAuthenticationWithExpiration } from "@octokit/auth-oauth-app";
import type { OAuthAppOctokit } from "./oauth-app-octokit.js";
export type ClientType = "oauth-app" | "github-app";
export type OAuthAppOctokitClassType = typeof OAuthAppOctokit;
export type GithubAppUserAuthenticationWithOptionalExpiration = GitHubAppUserAuthentication & Partial<GitHubAppUserAuthenticationWithExpiration>;
export type Scope = string;
export type ClientId = string;
export type ClientSecret = string;
export type Token = string;
export type EventName = "token" | "authorization";
export type ActionName = "created" | "reset" | "deleted" | "refreshed" | "scoped";
export type EventAndActionName = "token" | "token.created" | "token.reset" | "token.refreshed" | "token.scoped" | "token.deleted" | "authorization" | "authorization.deleted";
type CommonOptions<TOctokit extends OAuthAppOctokitClassType> = {
clientId?: ClientId;
clientSecret?: ClientSecret;
allowSignup?: boolean;
baseUrl?: string;
redirectUrl?: string;
log?: typeof console;
Octokit?: TOctokit;
};
export type Options<TClientType extends ClientType, TOctokit extends OAuthAppOctokitClassType = OAuthAppOctokitClassType> = TClientType extends "oauth-app" ? CommonOptions<TOctokit> & {
clientType?: TClientType;
defaultScopes?: Scope[];
} : CommonOptions<TOctokit> & {
clientType?: TClientType;
};
export type ConstructorOptions<TOptions extends Options<ClientType>> = TOptions & {
clientId: ClientId;
clientSecret: ClientSecret;
};
export type OctokitTypeFromOptions<TOptions extends Options<ClientType>> = TOptions["Octokit"] extends typeof Octokit ? InstanceType<TOptions["Octokit"]> : Octokit;
export type OctokitClassTypeFromOptions<TOptions extends Options<ClientType>> = TOptions["Octokit"] extends typeof Octokit ? TOptions["Octokit"] : typeof Octokit;
export type ClientTypeFromOptions<TOptions extends Options<ClientType>> = TOptions["clientType"] extends "github-app" ? "github-app" : "oauth-app";
export type OctokitInstance = InstanceType<OAuthAppOctokitClassType>;
export type State = {
clientType: ClientType;
clientId: ClientId;
clientSecret: ClientSecret;
defaultScopes: Scope[];
allowSignup?: boolean | undefined;
baseUrl?: string | undefined;
redirectUrl?: string | undefined;
log?: typeof console | undefined;
Octokit: OAuthAppOctokitClassType;
octokit: OctokitInstance;
eventHandlers: {
[key: string]: EventHandler<Options<ClientType>>[];
};
};
export type EventHandlerContext<TOptions extends Options<ClientType>> = ClientTypeFromOptions<TOptions> extends "oauth-app" ? {
name: EventName;
action: ActionName;
token: Token;
scopes?: Scope[];
octokit: OctokitTypeFromOptions<TOptions>;
authentication?: OAuthAppUserAuthentication | GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration;
} : {
name: EventName;
action: ActionName;
token: Token;
octokit: OctokitTypeFromOptions<TOptions>;
authentication?: GithubAppUserAuthenticationWithOptionalExpiration;
};
export type EventHandler<TOptions extends Options<ClientType>> = (context: EventHandlerContext<TOptions>) => void;
export type AddEventHandler<TOptions extends Options<ClientType>> = (eventName: EventAndActionName | EventAndActionName[], eventHandler: EventHandler<TOptions>) => void;
export {};

View File

@@ -0,0 +1 @@
export declare const VERSION = "8.0.3";

59
node_modules/@octokit/oauth-app/package.json generated vendored Normal file
View File

@@ -0,0 +1,59 @@
{
"name": "@octokit/oauth-app",
"version": "8.0.3",
"description": "GitHub OAuth toolset for Node.js",
"type": "module",
"repository": "github:octokit/oauth-app.js",
"keywords": [
"github",
"api",
"sdk",
"toolkit"
],
"author": "Gregor Martynus (https://twitter.com/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/auth-oauth-app": "^9.0.2",
"@octokit/auth-oauth-user": "^6.0.1",
"@octokit/auth-unauthenticated": "^7.0.2",
"@octokit/core": "^7.0.5",
"@octokit/oauth-authorization-url": "^8.0.0",
"@octokit/oauth-methods": "^6.0.1",
"@types/aws-lambda": "^8.10.83",
"universal-user-agent": "^7.0.0"
},
"devDependencies": {
"@octokit/tsconfig": "^4.0.0",
"@types/node": "^22.10.5",
"@vitest/coverage-v8": "^3.0.0",
"esbuild": "^0.25.0",
"express": "^4.17.1",
"fetch-mock": "^11.0.0",
"nock": "^14.0.0",
"prettier": "3.5.3",
"semantic-release-plugin-update-version-in-files": "^2.0.0",
"tinyglobby": "^0.2.13",
"typescript": "^5.0.0",
"vitest": "^3.0.0"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"engines": {
"node": ">= 20"
},
"files": [
"dist-*/**",
"bin/**"
],
"types": "./dist-types/index.d.ts",
"exports": {
".": {
"types": "./dist-types/index.d.ts",
"import": "./dist-node/index.js",
"default": "./dist-node/index.js"
}
},
"sideEffects": false
}