(token_path: string = ACCESS_TOKEN_PATH)
| 55 | } |
| 56 | |
| 57 | export async function checkToken(token_path: string = ACCESS_TOKEN_PATH): Promise<string> { |
| 58 | const reqInput = () => input({message: 'Token cannot be found, Enter token', required: true}); |
| 59 | |
| 60 | const envToken = process.env.SUBQL_ACCESS_TOKEN; |
| 61 | if (envToken) return envToken; |
| 62 | if (existsSync(token_path)) { |
| 63 | try { |
| 64 | const authToken = readFileSync(token_path, 'utf8'); |
| 65 | if (!authToken) { |
| 66 | return await reqInput(); |
| 67 | } |
| 68 | return authToken.trim(); |
| 69 | } catch (e) { |
| 70 | return reqInput(); |
| 71 | } |
| 72 | } else { |
| 73 | return reqInput(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | export function getOptionalToken(token_path: string = ACCESS_TOKEN_PATH): string | undefined { |
| 78 | const envToken = process.env.SUBQL_ACCESS_TOKEN; |
no test coverage detected