{
  "version": 3,
  "sources": ["../dist-src/index.js", "../dist-src/version.js", "../dist-src/get-authentication.js", "../dist-src/auth.js", "../dist-src/hook.js", "../dist-src/requires-basic-auth.js"],
  "sourcesContent": ["import { getUserAgent } from \"universal-user-agent\";\nimport { request as octokitRequest } from \"@octokit/request\";\nimport { VERSION } from \"./version\";\nimport { auth } from \"./auth\";\nimport { hook } from \"./hook\";\nimport { requiresBasicAuth } from \"./requires-basic-auth\";\nfunction createOAuthUserAuth({\n  clientId,\n  clientSecret,\n  clientType = \"oauth-app\",\n  request = octokitRequest.defaults({\n    headers: {\n      \"user-agent\": `octokit-auth-oauth-app.js/${VERSION} ${getUserAgent()}`\n    }\n  }),\n  onTokenCreated,\n  ...strategyOptions\n}) {\n  const state = Object.assign({\n    clientType,\n    clientId,\n    clientSecret,\n    onTokenCreated,\n    strategyOptions,\n    request\n  });\n  return Object.assign(auth.bind(null, state), {\n    // @ts-expect-error not worth the extra code needed to appease TS\n    hook: hook.bind(null, state)\n  });\n}\ncreateOAuthUserAuth.VERSION = VERSION;\nexport {\n  createOAuthUserAuth,\n  requiresBasicAuth\n};\n", "const VERSION = \"2.1.2\";\nexport {\n  VERSION\n};\n", "import { createOAuthDeviceAuth } from \"@octokit/auth-oauth-device\";\nimport { exchangeWebFlowCode } from \"@octokit/oauth-methods\";\nasync function getAuthentication(state) {\n  if (\"code\" in state.strategyOptions) {\n    const { authentication } = await exchangeWebFlowCode({\n      clientId: state.clientId,\n      clientSecret: state.clientSecret,\n      clientType: state.clientType,\n      onTokenCreated: state.onTokenCreated,\n      ...state.strategyOptions,\n      request: state.request\n    });\n    return {\n      type: \"token\",\n      tokenType: \"oauth\",\n      ...authentication\n    };\n  }\n  if (\"onVerification\" in state.strategyOptions) {\n    const deviceAuth = createOAuthDeviceAuth({\n      clientType: state.clientType,\n      clientId: state.clientId,\n      onTokenCreated: state.onTokenCreated,\n      ...state.strategyOptions,\n      request: state.request\n    });\n    const authentication = await deviceAuth({\n      type: \"oauth\"\n    });\n    return {\n      clientSecret: state.clientSecret,\n      ...authentication\n    };\n  }\n  if (\"token\" in state.strategyOptions) {\n    return {\n      type: \"token\",\n      tokenType: \"oauth\",\n      clientId: state.clientId,\n      clientSecret: state.clientSecret,\n      clientType: state.clientType,\n      onTokenCreated: state.onTokenCreated,\n      ...state.strategyOptions\n    };\n  }\n  throw new Error(\"[@octokit/auth-oauth-user] Invalid strategy options\");\n}\nexport {\n  getAuthentication\n};\n", "import { getAuthentication } from \"./get-authentication\";\nimport {\n  checkToken,\n  deleteAuthorization,\n  deleteToken,\n  refreshToken,\n  resetToken\n} from \"@octokit/oauth-methods\";\nasync function auth(state, options = {}) {\n  if (!state.authentication) {\n    state.authentication = state.clientType === \"oauth-app\" ? await getAuthentication(state) : await getAuthentication(state);\n  }\n  if (state.authentication.invalid) {\n    throw new Error(\"[@octokit/auth-oauth-user] Token is invalid\");\n  }\n  const currentAuthentication = state.authentication;\n  if (\"expiresAt\" in currentAuthentication) {\n    if (options.type === \"refresh\" || new Date(currentAuthentication.expiresAt) < /* @__PURE__ */ new Date()) {\n      const { authentication } = await refreshToken({\n        clientType: \"github-app\",\n        clientId: state.clientId,\n        clientSecret: state.clientSecret,\n        refreshToken: currentAuthentication.refreshToken,\n        request: state.request\n      });\n      state.authentication = {\n        tokenType: \"oauth\",\n        type: \"token\",\n        ...authentication\n      };\n    }\n  }\n  if (options.type === \"refresh\") {\n    if (state.clientType === \"oauth-app\") {\n      throw new Error(\n        \"[@octokit/auth-oauth-user] OAuth Apps do not support expiring tokens\"\n      );\n    }\n    if (!currentAuthentication.hasOwnProperty(\"expiresAt\")) {\n      throw new Error(\"[@octokit/auth-oauth-user] Refresh token missing\");\n    }\n    await state.onTokenCreated?.(state.authentication, {\n      type: options.type\n    });\n  }\n  if (options.type === \"check\" || options.type === \"reset\") {\n    const method = options.type === \"check\" ? checkToken : resetToken;\n    try {\n      const { authentication } = await method({\n        // @ts-expect-error making TS happy would require unnecessary code so no\n        clientType: state.clientType,\n        clientId: state.clientId,\n        clientSecret: state.clientSecret,\n        token: state.authentication.token,\n        request: state.request\n      });\n      state.authentication = {\n        tokenType: \"oauth\",\n        type: \"token\",\n        // @ts-expect-error TBD\n        ...authentication\n      };\n      if (options.type === \"reset\") {\n        await state.onTokenCreated?.(state.authentication, {\n          type: options.type\n        });\n      }\n      return state.authentication;\n    } catch (error) {\n      if (error.status === 404) {\n        error.message = \"[@octokit/auth-oauth-user] Token is invalid\";\n        state.authentication.invalid = true;\n      }\n      throw error;\n    }\n  }\n  if (options.type === \"delete\" || options.type === \"deleteAuthorization\") {\n    const method = options.type === \"delete\" ? deleteToken : deleteAuthorization;\n    try {\n      await method({\n        // @ts-expect-error making TS happy would require unnecessary code so no\n        clientType: state.clientType,\n        clientId: state.clientId,\n        clientSecret: state.clientSecret,\n        token: state.authentication.token,\n        request: state.request\n      });\n    } catch (error) {\n      if (error.status !== 404)\n        throw error;\n    }\n    state.authentication.invalid = true;\n    return state.authentication;\n  }\n  return state.authentication;\n}\nexport {\n  auth\n};\n", "import btoa from \"btoa-lite\";\nimport { auth } from \"./auth\";\nimport { requiresBasicAuth } from \"./requires-basic-auth\";\nasync function hook(state, request, route, parameters = {}) {\n  const endpoint = request.endpoint.merge(\n    route,\n    parameters\n  );\n  if (/\\/login\\/(oauth\\/access_token|device\\/code)$/.test(endpoint.url)) {\n    return request(endpoint);\n  }\n  if (requiresBasicAuth(endpoint.url)) {\n    const credentials = btoa(`${state.clientId}:${state.clientSecret}`);\n    endpoint.headers.authorization = `basic ${credentials}`;\n    return request(endpoint);\n  }\n  const { token } = state.clientType === \"oauth-app\" ? await auth({ ...state, request }) : await auth({ ...state, request });\n  endpoint.headers.authorization = \"token \" + token;\n  return request(endpoint);\n}\nexport {\n  hook\n};\n", "const ROUTES_REQUIRING_BASIC_AUTH = /\\/applications\\/[^/]+\\/(token|grant)s?/;\nfunction requiresBasicAuth(url) {\n  return url && ROUTES_REQUIRING_BASIC_AUTH.test(url);\n}\nexport {\n  requ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