Files
airllm-fork-nodejs/node_modules/@octokit/auth-app/dist-src/index.js
2026-02-05 15:27:49 +08:00

59 lines
1.8 KiB
JavaScript

import { getUserAgent } from "universal-user-agent";
import { request as defaultRequest } from "@octokit/request";
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
import { auth } from "./auth.js";
import { hook } from "./hook.js";
import { getCache } from "./cache.js";
import { VERSION } from "./version.js";
import { createOAuthUserAuth } from "@octokit/auth-oauth-user";
function createAppAuth(options) {
if (!options.appId) {
throw new Error("[@octokit/auth-app] appId option is required");
}
if (!options.privateKey && !options.createJwt) {
throw new Error("[@octokit/auth-app] privateKey option is required");
} else if (options.privateKey && options.createJwt) {
throw new Error(
"[@octokit/auth-app] privateKey and createJwt options are mutually exclusive"
);
}
if ("installationId" in options && !options.installationId) {
throw new Error(
"[@octokit/auth-app] installationId is set to a falsy value"
);
}
const log = options.log || {};
if (typeof log.warn !== "function") {
log.warn = console.warn.bind(console);
}
const request = options.request || defaultRequest.defaults({
headers: {
"user-agent": `octokit-auth-app.js/${VERSION} ${getUserAgent()}`
}
});
const state = Object.assign(
{
request,
cache: getCache()
},
options,
options.installationId ? { installationId: Number(options.installationId) } : {},
{
log,
oauthApp: createOAuthAppAuth({
clientType: "github-app",
clientId: options.clientId || "",
clientSecret: options.clientSecret || "",
request
})
}
);
return Object.assign(auth.bind(null, state), {
hook: hook.bind(null, state)
});
}
export {
createAppAuth,
createOAuthUserAuth
};