UNPKG

@bhavinkumarvegad/playwright-email-utils

Version:

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

47 lines (46 loc) 2.12 kB
"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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GmailAuthUtils = void 0; const googleapis_1 = require("googleapis"); const GMAIL_REDIRECT_URI = 'http://localhost'; const GMAIL_SCOPES = [ // 'https://www.googleapis.com/auth/gmail.modify', 'https://www.googleapis.com/auth/gmail.readonly' ]; class GmailAuthUtils { constructor() { } static getAuthUrl(clientId, clientSecret) { return __awaiter(this, void 0, void 0, function* () { const oAuth2Client = new googleapis_1.google.auth.OAuth2(clientId, clientSecret, GMAIL_REDIRECT_URI); return oAuth2Client.generateAuthUrl({ access_type: 'offline', scope: GMAIL_SCOPES, prompt: 'consent', include_granted_scopes: true }); }); } static getRefreshToken(clientId, clientSecret, code) { return __awaiter(this, void 0, void 0, function* () { try { const oAuth2Client = new googleapis_1.google.auth.OAuth2(clientId, clientSecret, GMAIL_REDIRECT_URI); const { tokens } = yield oAuth2Client.getToken(code); return tokens.refresh_token || null; } catch (error) { console.error('Error getting refresh token:', error); return null; } }); } } exports.GmailAuthUtils = GmailAuthUtils;