blob: 90abf89721f180e6531f72cc0ad091af9a341a7f [file] [log] [blame]
{"version":3,"file":"index.js","sources":["../dist-src/auth.js","../dist-src/with-authorization-prefix.js","../dist-src/hook.js","../dist-src/index.js"],"sourcesContent":["export async function auth(token) {\n const tokenType = token.split(/\\./).length === 3\n ? \"app\"\n : /^v\\d+\\./.test(token)\n ? \"installation\"\n : \"oauth\";\n return {\n type: \"token\",\n token: token,\n tokenType\n };\n}\n","/**\n * Prefix token for usage in the Authorization header\n *\n * @param token OAuth token or JSON Web Token\n */\nexport function withAuthorizationPrefix(token) {\n if (token.split(/\\./).length === 3) {\n return `bearer ${token}`;\n }\n return `token ${token}`;\n}\n","import { withAuthorizationPrefix } from \"./with-authorization-prefix\";\nexport async function hook(token, request, route, parameters) {\n const endpoint = request.endpoint.merge(route, parameters);\n endpoint.headers.authorization = withAuthorizationPrefix(token);\n return request(endpoint);\n}\n","import { auth } from \"./auth\";\nimport { hook } from \"./hook\";\nexport const createTokenAuth = function createTokenAuth(token) {\n if (!token) {\n throw new Error(\"[@octokit/auth-token] No token passed to createTokenAuth\");\n }\n if (typeof token !== \"string\") {\n throw new Error(\"[@octokit/auth-token] Token passed to createTokenAuth is not a string\");\n }\n token = token.replace(/^(token|bearer) +/i, \"\");\n return Object.assign(auth.bind(null, token), {\n hook: hook.bind(null, token)\n });\n};\n"],"names":["auth","token","tokenType","split","length","test","type","withAuthorizationPrefix","hook","request","route","parameters","endpoint","merge","headers","authorization","createTokenAuth","Error","replace","Object","assign","bind"],"mappings":";;;;AAAO,eAAeA,IAAf,CAAoBC,KAApB,EAA2B;QACxBC,SAAS,GAAGD,KAAK,CAACE,KAAN,CAAY,IAAZ,EAAkBC,MAAlB,KAA6B,CAA7B,GACZ,KADY,GAEZ,UAAUC,IAAV,CAAeJ,KAAf,IACI,cADJ,GAEI,OAJV;SAKO;IACHK,IAAI,EAAE,OADH;IAEHL,KAAK,EAAEA,KAFJ;IAGHC;GAHJ;;;ACNJ;;;;;AAKA,AAAO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