{
  "version": 3,
  "sources": ["../dist-src/index.js", "../dist-src/get-oauth-access-token.js", "../dist-src/auth.js", "../dist-src/hook.js", "../dist-src/version.js"],
  "sourcesContent": ["import { getUserAgent } from \"universal-user-agent\";\nimport { request as octokitRequest } from \"@octokit/request\";\nimport { auth } from \"./auth\";\nimport { hook } from \"./hook\";\nimport { VERSION } from \"./version\";\nfunction createOAuthDeviceAuth(options) {\n  const requestWithDefaults = options.request || octokitRequest.defaults({\n    headers: {\n      \"user-agent\": `octokit-auth-oauth-device.js/${VERSION} ${getUserAgent()}`\n    }\n  });\n  const { request = requestWithDefaults, ...otherOptions } = options;\n  const state = options.clientType === \"github-app\" ? {\n    ...otherOptions,\n    clientType: \"github-app\",\n    request\n  } : {\n    ...otherOptions,\n    clientType: \"oauth-app\",\n    request,\n    scopes: options.scopes || []\n  };\n  if (!options.clientId) {\n    throw new Error(\n      '[@octokit/auth-oauth-device] \"clientId\" option must be set (https://github.com/octokit/auth-oauth-device.js#usage)'\n    );\n  }\n  if (!options.onVerification) {\n    throw new Error(\n      '[@octokit/auth-oauth-device] \"onVerification\" option must be a function (https://github.com/octokit/auth-oauth-device.js#usage)'\n    );\n  }\n  return Object.assign(auth.bind(null, state), {\n    hook: hook.bind(null, state)\n  });\n}\nexport {\n  createOAuthDeviceAuth\n};\n", "import { createDeviceCode, exchangeDeviceCode } from \"@octokit/oauth-methods\";\nasync function getOAuthAccessToken(state, options) {\n  const cachedAuthentication = getCachedAuthentication(state, options.auth);\n  if (cachedAuthentication)\n    return cachedAuthentication;\n  const { data: verification } = await createDeviceCode({\n    clientType: state.clientType,\n    clientId: state.clientId,\n    request: options.request || state.request,\n    // @ts-expect-error the extra code to make TS happy is not worth it\n    scopes: options.auth.scopes || state.scopes\n  });\n  await state.onVerification(verification);\n  const authentication = await waitForAccessToken(\n    options.request || state.request,\n    state.clientId,\n    state.clientType,\n    verification\n  );\n  state.authentication = authentication;\n  return authentication;\n}\nfunction getCachedAuthentication(state, auth) {\n  if (auth.refresh === true)\n    return false;\n  if (!state.authentication)\n    return false;\n  if (state.clientType === \"github-app\") {\n    return state.authentication;\n  }\n  const authentication = state.authentication;\n  const newScope = (\"scopes\" in auth && auth.scopes || state.scopes).join(\n    \" \"\n  );\n  const currentScope = authentication.scopes.join(\" \");\n  return newScope === currentScope ? authentication : false;\n}\nasync function wait(seconds) {\n  await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));\n}\nasync function waitForAccessToken(request, clientId, clientType, verification) {\n  try {\n    const options = {\n      clientId,\n      request,\n      code: verification.device_code\n    };\n    const { authentication } = clientType === \"oauth-app\" ? await exchangeDeviceCode({\n      ...options,\n      clientType: \"oauth-app\"\n    }) : await exchangeDeviceCode({\n      ...options,\n      clientType: \"github-app\"\n    });\n    return {\n      type: \"token\",\n      tokenType: \"oauth\",\n      ...authentication\n    };\n  } catch (error) {\n    if (!error.response)\n      throw error;\n    const errorType = error.response.data.error;\n    if (errorType === \"authorization_pending\") {\n      await wait(verification.interval);\n      return waitForAccessToken(request, clientId, clientType, verification);\n    }\n    if (errorType === \"slow_down\") {\n      await wait(verification.interval + 5);\n      return waitForAccessToken(request, clientId, clientType, verification);\n    }\n    throw error;\n  }\n}\nexport {\n  getOAuthAccessToken\n};\n", "import { getOAuthAccessToken } from \"./get-oauth-access-token\";\nasync function auth(state, authOptions) {\n  return getOAuthAccessToken(state, {\n    auth: authOptions\n  });\n}\nexport {\n  auth\n};\n", "import { getOAuthAccessToken } from \"./get-oauth-access-token\";\nasync function hook(state, request, route, parameters) {\n  let 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  const { token } = await getOAuthAccessToken(state, {\n    request,\n    auth: { type: \"oauth\" }\n  });\n  endpoint.headers.authorization = `token ${token}`;\n  return request(endpoint);\n}\nexport {\n  hook\n};\n", "const VERSION = \"4.0.5\";\nexport {\n  VERSION\n};\n"],
  "mappings": ";;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