Notes
Notes - notes.io |
/* istanbul ignore next */
const InsuranceNavigator = require('../insurance.navigator');
const PuppeteerHelper = require('../../lib/helper/puppeteer.helper');
const logger = require('../../lib/common/log').logger;
const MFAHandler = require('../mfa/insr_24xPRACE0bJjv3nwgyNccaNT4OL.mfa.handler');
const ItemIterator = require('../../lib/iterator/item-iterator');
const SUPPORTED_ITEM_TYPE = require('../../lib/common/constants').supportedItemTypes;
const ExtractorClassifier = require('../../lib/extractor/extractor-classifier');
const Controller = require('../../lib/controller');
const BMR = require('../../lib/repository/browser-manager-repository');
const common_navigate_to_item = async (page) => {
logger.debug('Insr_24xPRACE0bJjv3nwgyNccaNT4OL -> common_navigate_to_item - started');
if (await page.url().includes('online2.statefarm.com/apps/pvc/fire/execute.do')) {
return page;
}
this.ph = new PuppeteerHelper(page);
let elements = ['a[id^="active-fire-policy-title"]', 'a[id^="showAllLink"]', 'button#optclosebtn'];
let page_urls = ['https://apps.statefarm.com/my-accounts/'];
//step1 - goto custom url
try {
await this.ph.goto(page_urls[0], page, ['load'], 30000);
} catch (e) {
logger.warn(e);
}
//step2 - wait for custom bottom popup
try {
await this.ph.waitForSelector(elements[2], page, {
visible: false,
timeout: 15000
});
await this.ph.performHiddenClick(elements[2], page);
} catch (e) {
logger.warn(e);
}
//step3 - wait for policy link
await this.ph.waitForSelector(elements[0], page, {
visible: true,
timeout: 20000
});
await this.ph.performClickAndNavigation(elements[0], page);
await this.ph.once(page, 'load'); //Need for sometimes
//step4 - wait for "expand all section link"
try {
await this.ph.waitForSelector(elements[1], page, {
visible: true,
timeout: 20000
});
await this.ph.performClick(elements[1], page);
} catch (e) {
logger.warn(e);
}
return page;
};
/**
* State Farm
* https://proofing.statefarm.com/login-ui/login
*/
class Insr_24xPRACE0bJjv3nwgyNccaNT4OL extends InsuranceNavigator {
constructor(session_id) {
super(session_id);
this.elements = ['input#username', 'input#password'];
this.set_alternative_login(false);
}
async execute_pre_login(page) {
logger.debug('Insr_24xPRACE0bJjv3nwgyNccaNT4OL -> execute_pre_login - started');
await this.ph.waitForSelector(this.elements[1], page, {
visible: true,
timeout: 20000
});
}
async is_login_page(page) {
logger.debug('Insr_24xPRACE0bJjv3nwgyNccaNT4OL -> is_login_page - started');
if (await page.url().includes('authentication-error')) {
logger.warn(await this.ph.getErrorText(page));
return this.session.event_emitter.emit('error', Controller.getError('general', 'badGateway'));
}
let is_username = await this.ph.isElementExist(this.elements[0], page);
let is_password = await this.ph.isElementExist(this.elements[1], page);
const errRegexList = ["This user ID was not found", 'Your account is locked'];
let is_error = await this.ph.searchError(errRegexList, page);
if (is_error) {
logger.warn(await this.ph.getErrorText(page));
}
return (is_username || is_password || is_error);
}
async do_login(page, username, password) {
logger.debug('Insr_24xPRACE0bJjv3nwgyNccaNT4OL -> do_login - started');
await this.ph.waitForSelector(this.elements[0], page, {
visible: true,
timeout: 15000
});
await this.ph.fillElementValue(this.elements[0], username, page);
await this.ph.waitForSelector(this.elements[1], page, {
visible: true,
timeout: 15000
});
await this.ph.fillElementValue(this.elements[1], password, page);
await this.ph.pressEnter(this.elements[1], page);
await Promise.race([this.ph.waitForResponse('login-interceptor/authenticate', page, 'include'), this.ph.waitFor(10000)]);
await this.ph.once(page, 'load');
}
async has_mfa(page) {
const elements = ['//*[text()[contains(.,"having technical issues")]]'];
try {
const eh = await this.ph.getElementHandler(elements[0], page);
if (typeof eh == 'object' && eh.length > 0) {
logger.warn(await this.ph.getErrorText(page));
return await this.navigator_error_handler('error', ['navigation', 'systemUnavailable']);
}
} catch (e) {
logger.warn(e);
}
return await new MFAHandler(this.session_id).has_mfa(page);
}
async navigate_to_insurance_profile(page) {
logger.debug('Insr_24xPRACE0bJjv3nwgyNccaNT4OL -> navigate_to_insurance_profile - started');
page = await common_navigate_to_item(page);
return page;
}
async navigate_to_insurance_policy(page) {
logger.debug('Insr_24xPRACE0bJjv3nwgyNccaNT4OL -> navigate_to_insurance_policy - started');
return page;
}
async get_extractor(page, type) {
if (type == SUPPORTED_ITEM_TYPE.insurance_policy) {
return new ExtractorClassifier(page).get_extractor('pdf', type);
}
return await super.get_extractor(page, type);
}
async get_iterator(page, type) {
if (type == SUPPORTED_ITEM_TYPE.insurance_policy) {
return new Insr_24xPRACE0bJjv3nwgyNccaNT4OL_ItemIterator(page, this.session_id);
}
return await super.get_iterator(page, type);
}
}
class Insr_24xPRACE0bJjv3nwgyNccaNT4OL_ItemIterator extends ItemIterator {
constructor(page, session_id) {
super(page);
this.session_id = session_id;
this.session = global.session_mgr.get_session(session_id);
this.elements = ['a[id="linkViewProofOfInsurance"][title*="Proof"]', 'a[id="linkViewEndorsement"][title="PDF"][target*="HW"]'];
}
async init() {
this.num_of_items = this.elements.length;
logger.info(`Total Policies => ${this.num_of_items}`);
this.ph = new PuppeteerHelper(this.page);
await this.ph.set_pdf_download(this.session, true);
await this.ph.downloadFileInitializer(this.session_id, this.page);
}
async perform_custom_flow(visibility = true) {
try {
if (visibility) {
await this.ph.waitForSelector(this.elements[this.index], this.page, {
visible: true,
timeout: 30000
});
await this.ph.performClick(this.elements[this.index], this.page);
}
if (!visibility) {
await this.ph.waitForSelector(this.elements[this.index], this.page, {
visible: false,
timeout: 10000
});
await this.ph.performHiddenClick(this.elements[this.index], this.page);
}
} catch (e) {
logger.error(e);
if (!visibility) {
throw e;
}
await this.perform_custom_flow(false);
}
}
async next() {
this.page = await common_navigate_to_item(this.page);
await this.perform_custom_flow(true);
try {
let session = global.session_mgr.get_session(this.session_id);
await this.ph.waitForDownload(this.session_id);
session.file_content = await BMR.get_file(this.session_id);
} catch (e) {
logger.warn(e);
if (e.response.status == 404) {
throw new Error('File is not available');
}
}
this.index++;
return this.page;
}
}
module.exports = Insr_24xPRACE0bJjv3nwgyNccaNT4OL;
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team