-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Introducing 2FA scrapers infrastructure + OneZero experimental scraper #760
Conversation
@orzarchi thank you for this contribution 💯 . I'll free sometime soon to review and play with the PR. @eshaham @baruchiro @brafdlog as this is a major change in the design / capabilities of the scrapers, you might want to review it as well? |
I need to understand the interface changes more. Meanwhile, I think you can continue with this change, it will not break our app because we will have to enable the new bank manually after getting your version. CC: @brafdlog |
Any news? |
Hi @orzarchi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work :)
Please see my comments
src/helpers/fetch.ts
Outdated
return result.data as Promise<TResult>; | ||
} | ||
|
||
export async function fetchGetWithinPage<TResult>(page: Page, url: string): Promise<TResult | null> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No await -> no need for this to be marked async
ScraperGetLongTermTwoFactorTokenResult, ScraperCredentials, | ||
} from './interface'; | ||
|
||
export type ScraperLoginResult = ErrorResult | { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move to interface
?
|
||
|
||
export class BaseTwoFactorAuthScraper<TTwoFactorCredentials> implements TwoFactorAuthScraper { | ||
constructor(protected options: ScraperOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
} | ||
|
||
private async fetchPortfolioMovements(portfolio: Portfolio, startDate: Date): Promise<TransactionsAccount> { | ||
const account = portfolio.accounts[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please open a task for future multi account support
const movements = []; | ||
|
||
|
||
while (!movements.length || new Date(movements[0].movementTimestamp) >= startDate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use moment
and not Date
to avoid timezone issues
} | ||
} | ||
|
||
movements.sort((x, y) => new Date(x.movementTimestamp).valueOf() - new Date(y.movementTimestamp).valueOf()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
|
||
movements.sort((x, y) => new Date(x.movementTimestamp).valueOf() - new Date(y.movementTimestamp).valueOf()); | ||
|
||
const matchingMovements = movements.filter((movement) => new Date(movement.movementTimestamp) >= startDate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
@orzarchi @erikash Hi, TL;DRLong time ago I suggested a modular architecture that would let us compose flows with atomic operations. But it was archived and we should assume for now that we will keep current architecture of the library. We should favor features over infrastructure consistency as this library is in low maintenance but I believe we can easily modify the PR to use the existing scrapers while supporting OTP with the great work of @orzarchi. I verified it with Max account. You should verify the One zero as well. Please checkout changes here #765. There are still the other code review comments but they are pretty much minor. Feel free to pull branch Adjustments done in the PR
Motivation behind my suggestionThe new scraper
|
Great insights @esakal I've make a small comment here: @esakal : can you rephrase your second comment, I didn't understand it... |
@erikash thanks :)
Today we have two base scrapers:
In the original pull request, @orzarchi introduced a new scraper that wasn't inherited from either of the existing ones. Since this scraper doesn't require puppeteer support, it doesn't use puppeteer. My comment was that if we keep all three base scrapers, we may need to provide a fourth base scraper in the future for scrapers that require both OTP and puppeteer. However, in the suggested modification, this issue is no longer a concern. I hope this clarifies things. |
hi @esakal - no problems, I'll fix @erikash's comments on top of your new PR with your changes.
|
@orzarchi, I agree with you on both topics. Ideally, we should switch to a new composition-based architecture, but this will require active development work from developers to refactor all the scrapers. Unfortunately, this library is not currently being actively evolved by a group of developers; we are mostly focused on ongoing maintenance and limited by depending on developers that has actual access to each institute. This makes it challenging to change the architecture of the project. However, if you do have a suggestion for a new architecture, testing it out on new scrapers could be a good way to gradually transition to it. For instance, One Zero might be a good candidate for this. Regarding the credentials, you can certainly implement them. Just keep in mind that they will only work for those who initiate the scraper explicitly. Those who use the createScraper with Typescript might encounter runtime errors because the common credentials declaration is export declare type ScraperCredentials = Record<string, string>; |
Hey @erikash and @esakal, I've incorporated all of your suggestions and code. |
fa2fdee
to
db4c832
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orzarchi this is awesome! I want to merge it this weekend. There are few minor comments. Please review and decide if to fix them or not. I'm ok with having it like that. Please check my comment about the ...extraHeaders
.
Once you'll reply or commit fixes I'll merge it.
Sure, go ahead and merge it 🤩 |
🎉 This PR is included in version 3.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Hi there!
Hopefully this is the first PR in the era of 2FA scrapers.
I've loosely followed the guidelines set up here.
BaseTwoFactorAuthScraper
.base-scraper
file was getting a bit long, I've cleaned up a bit and moved error related types toerrors.ts
, and public facing interfaces (e.g.ScraperOptions
,ScraperScrapingResult
) tointerface.ts
README
to learn more about it.Some limitations about OneZero:
closes #765