UNPKG

@bhavinkumarvegad/playwright-email-utils

Version:

Reusable utilities for handling emails in Playwright tests from Yopmail, Gmail and other providers.

62 lines (61 loc) 3.28 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const gmailAuthUtils_1 = require("../utils/gmailAuthUtils"); // Or adjust the path/casing as needed to match your project structure. const readline_1 = require("readline"); const dotenv_1 = __importDefault(require("dotenv")); dotenv_1.default.config(); function getTokenFromUser() { return __awaiter(this, void 0, void 0, function* () { const clientId = process.env.GMAIL_CLIENT_ID; const clientSecret = process.env.GMAIL_CLIENT_SECRET; if (!clientId || !clientSecret) { console.error('Please set GMAIL_CLIENT_ID and GMAIL_CLIENT_SECRET in your .env file first.'); process.exit(1); } console.log(clientId, clientSecret); console.log('\nGenerating Gmail Refresh Token...'); const authUrl = yield gmailAuthUtils_1.GmailAuthUtils.getAuthUrl(clientId, clientSecret); console.log('\n1. Visit this URL to authorize the application:'); console.log(authUrl); console.log('\n2. After authorization, you will be redirected to localhost with a code in the URL.'); console.log('3. Copy the code from the URL and paste it below.\n'); const rl = (0, readline_1.createInterface)({ input: process.stdin, output: process.stdout, }); return new Promise((resolve) => { rl.question('Enter the code here: ', (code) => __awaiter(this, void 0, void 0, function* () { const refreshToken = yield gmailAuthUtils_1.GmailAuthUtils.getRefreshToken(clientId, clientSecret, code.trim()); if (refreshToken) { console.log('\n✅ Successfully generated refresh token!\n'); console.log('Add these to your .env file:'); console.log('----------------------------'); console.log(`GMAIL_CLIENT_ID=${clientId}`); console.log(`GMAIL_CLIENT_SECRET=${clientSecret}`); console.log(`GMAIL_REFRESH_TOKEN=${refreshToken}`); console.log('----------------------------\n'); } else { console.error('❌ Failed to retrieve refresh token. Please try again.'); } rl.close(); resolve(); })); }); }); } getTokenFromUser().catch(console.error);