-
Notifications
You must be signed in to change notification settings - Fork 45
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
New: handle oneZero scrape #628
base: feature/one-zerop-bank
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces enhancements to the configuration management and transaction import processes, with a focus on two-factor authentication handling. A new function Changes
Sequence DiagramsequenceDiagram
participant Scraper
participant EventPublisher
participant IPC
participant ConfigManager
Scraper->>EventPublisher: Trigger Two-Factor Auth
EventPublisher->>IPC: Request OTP
IPC-->>EventPublisher: Receive OTP
Scraper->>Scraper: Get Long-Term Token
Scraper->>ConfigManager: Update OTP Long-Term Token
ConfigManager-->>Scraper: Token Updated
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Pull request has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@coderabbitai review |
✅ Actions performedReview triggered.
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
packages/main/src/backend/import/bankScraper.ts (2)
9-9
: Type safety in.map(...)
Castingkey as CompanyTypes
is reasonable. If the codebase expands or new keys are introduced, consider adding runtime checks to avoid potential type mismatches.
38-38
: Progress event callback
Emitting concise progress messages keeps the UI responsive. Consider logging or storing payload details if deeper analysis is needed later.packages/renderer/src/components/App.tsx (1)
13-13
: RenderGetOtp
Placing<GetOtp />
within the main app ensures the OTP modal is always available. Ensure that the modal’s visibility logic remains controlled via the store to avoid unexpected pop-ups.packages/main/src/backend/configManager/configManager.ts (1)
39-54
: Consider enhancing type safety and validation.While the implementation is generally good, there are a few improvements to consider:
- The type assertion on line 45-47 could be replaced with a more precise type definition
- Consider validating the
otpLongTermToken
format/structure before updatingHere's a suggested improvement:
+interface AccountWithLoginFields { + key: CompanyTypes; + loginFields: { + otpLongTermToken: string; + }; +} export async function updateOtpLongTermToken( key: CompanyTypes, otpLongTermToken: string, configPath: string = configFilePath, ): Promise<void> { const config = await getConfig(configPath); - const account = config.scraping.accountsToScrape.find((acc) => acc.key === key) as { - loginFields: { otpLongTermToken: string }; - }; + const account = config.scraping.accountsToScrape.find((acc): acc is AccountWithLoginFields => + acc.key === key && 'loginFields' in acc && 'otpLongTermToken' in acc.loginFields + ); if (account) { + if (!otpLongTermToken || typeof otpLongTermToken !== 'string') { + throw new Error('Invalid OTP long-term token format'); + } account.loginFields.otpLongTermToken = otpLongTermToken; await updateConfig(configPath, config); } else { throw new Error(`Account with key ${key} not found`); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/main/src/backend/configManager/configManager.ts
(2 hunks)packages/main/src/backend/import/bankScraper.ts
(2 hunks)packages/main/src/backend/import/importTransactions.ts
(3 hunks)packages/main/src/manual/setupHelpers.ts
(0 hunks)packages/renderer/src/components/App.tsx
(2 hunks)packages/renderer/src/components/GetOtp.tsx
(1 hunks)
💤 Files with no reviewable changes (1)
- packages/main/src/manual/setupHelpers.ts
🔇 Additional comments (16)
packages/main/src/backend/import/bankScraper.ts (10)
2-2
: Add clarity on usage ofSCRAPERS
imports
No functional issues identified. If future expansions require customizing scrapers, keep the import path consistent and well-documented.
3-3
: Validate electron IPC usage
ImportingipcMain
is appropriate here, but ensure usage remains restricted to the main process context. Consider future modularization if more IPC functionalities appear.
4-4
: Confirm event-based architecture
IntroducingEventPublisher
fromEventEmitter
is a good approach for decoupling event dispatch logic from the core scraping flow. No immediate issues.
5-5
: Centralize OTP token updates
UsingupdateOtpLongTermToken
from the config manager is clean and maintainable. This ensures OTP management is centralized.
25-25
: NeweventPublisher
parameter
AddingeventPublisher
is a neat way to handle external event emission. Ensure every call site passes a validEventPublisher
instance.
28-32
: Scraperoptions
structure
Good to see the relevant fields (companyId, startDate, etc.) consolidated here. Settingverbose: false
by default may hamper debugging; ensure it meets project requirements.
36-36
: Empty line
No meaningful change.
39-39
: Empty line
No meaningful change.
40-56
: Implement 2FA flow for oneZero
This block introduces a well-structured approach for OTP retrieval and long-term token generation. Pointers:
- Consider encrypting the
otpLongTermToken
if stored on disk.- Handle user inactivity or canceled OTP entry gracefully.
Overall, logic is sound and extends the scraper flow robustly.
58-58
: Return scraper results
Returningawait scraper.scrape(credentials)
is appropriate for an async function. Ensure error handling from the scraper is surfaced for debugging.packages/renderer/src/components/App.tsx (1)
4-4
: ImportGetOtp
Neatly imported from./GetOtp
. This separation of OTP logic into its own component helps keepApp
cleaner.packages/renderer/src/components/GetOtp.tsx (1)
4-4
: Use of relative import
Switching to a relative path foruseConfigStore
confirms the code structure. Verify consistency across the codebase for store imports.packages/main/src/backend/configManager/configManager.ts (1)
7-7
: LGTM!The import of
CompanyTypes
from 'israeli-bank-scrapers-core' is appropriate for type safety.packages/main/src/backend/import/importTransactions.ts (3)
17-17
: LGTM!The addition of
ImporterEvent
to the imports is appropriate for handling OTP-related events.
120-120
: LGTM!Adding the
eventPublisher
parameter tobankScraper.scrape
enables proper event handling for OTP flows.
172-177
: LGTM!The simplified return statement improves code readability without changing functionality.
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.
Didn't finished the review, הילדה שלי התעוררה 🤷♂️
BTW, I don't remember, but are you using the OTP support introduced on israeli-bank-scrapers
here eshaham/israeli-bank-scrapers#760?
export async function updateOtpLongTermToken( | ||
key: CompanyTypes, | ||
otpLongTermToken: string, | ||
configPath: string = configFilePath, | ||
): Promise<void> { |
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.
rename to companyId
export async function updateOtpLongTermToken( | |
key: CompanyTypes, | |
otpLongTermToken: string, | |
configPath: string = configFilePath, | |
): Promise<void> { | |
export async function updateOtpLongTermToken( | |
companyId: CompanyTypes, | |
otpLongTermToken: string, | |
configPath: string = configFilePath, | |
): Promise<void> { |
if (account) { | ||
account.loginFields.otpLongTermToken = otpLongTermToken; | ||
await updateConfig(configPath, config); | ||
} else { | ||
throw new Error(`Account with key ${key} not found`); | ||
} |
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.
return early: if not account
, throw. Otherwise, continue.
if (account) { | |
account.loginFields.otpLongTermToken = otpLongTermToken; | |
await updateConfig(configPath, config); | |
} else { | |
throw new Error(`Account with key ${key} not found`); | |
} | |
if (!account) { | |
throw new Error(`Account with key ${key} not found`); | |
} | |
account.loginFields.otpLongTermToken = otpLongTermToken; | |
await updateConfig(configPath, config); |
export const inputVendors = Object.keys(SCRAPERS) | ||
// Deprecated. see https://github.com/eshaham/israeli-bank-scrapers/blob/07ecd3de0c4aa051f119aa943493f0cda943158c/src/definitions.ts#L26-L29 | ||
.filter((key) => key !== CompanyTypes.hapoalimBeOnline) | ||
.map((key) => ({ | ||
key, | ||
...SCRAPERS[key as CompanyTypes], | ||
})); | ||
.map((key) => ({ key, ...SCRAPERS[key as CompanyTypes] })); | ||
|
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.
don't remove this comment
if (companyId === CompanyTypes.oneZero) { | ||
const creds = credentials as typeof credentials & { otpLongTermToken: string; phoneNumber: string }; | ||
if (!creds.otpLongTermToken) { | ||
await scraper.triggerTwoFactorAuth(creds.phoneNumber); | ||
await eventPublisher.emit(EventNames.GET_OTP); | ||
const otpCode = await new Promise<string>((resolve) => { | ||
ipcMain.once('get-otp-response', (event, input) => resolve(input)); | ||
}); | ||
const result = await scraper.getLongTermTwoFactorToken(otpCode); | ||
if ('longTermTwoFactorAuthToken' in result) { | ||
await updateOtpLongTermToken(companyId, result.longTermTwoFactorAuthToken); | ||
creds.otpLongTermToken = result.longTermTwoFactorAuthToken; | ||
} else { | ||
throw new Error('Failed to get long-term two-factor auth token'); | ||
} | ||
} | ||
} |
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.
This function must be extracted into a function. More than that, think when more banks will require OTP, I expect the "if" to be extracted into a function to.
I hope you understand what I mean. Here should be only handleOtp
function, and inside it there will be if-else/switch-case that will direct into bank-specific function.
await scraper.triggerTwoFactorAuth(creds.phoneNumber); | ||
await eventPublisher.emit(EventNames.GET_OTP); |
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
emitProgressEvent
instead ofeventPublisher.emit
. - Is the
scraper
not emitting events of OTP itself?
const otpCode = await new Promise<string>((resolve) => { | ||
ipcMain.once('get-otp-response', (event, input) => resolve(input)); | ||
}); |
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.
All IPC calls are declared here: packages/main/src/handlers/index.ts
I expect this call to follow that pattern.
if (companyId === CompanyTypes.oneZero) { | ||
const creds = credentials as typeof credentials & { otpLongTermToken: string; phoneNumber: string }; | ||
if (!creds.otpLongTermToken) { | ||
await scraper.triggerTwoFactorAuth(creds.phoneNumber); |
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.
I'm not sure how the process is implemented, but I see the triggerTwoFactorAuth
is called during the scraping on israeli-bank-scrapers
, see triggerTwoFactorAuth, so why running it in our code too?
const result = await scraper.getLongTermTwoFactorToken(otpCode); | ||
if ('longTermTwoFactorAuthToken' in result) { | ||
await updateOtpLongTermToken(companyId, result.longTermTwoFactorAuthToken); | ||
creds.otpLongTermToken = result.longTermTwoFactorAuthToken; | ||
} else { | ||
throw new Error('Failed to get long-term two-factor auth token'); | ||
} |
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 result.success
const result = await scraper.getLongTermTwoFactorToken(otpCode); | |
if ('longTermTwoFactorAuthToken' in result) { | |
await updateOtpLongTermToken(companyId, result.longTermTwoFactorAuthToken); | |
creds.otpLongTermToken = result.longTermTwoFactorAuthToken; | |
} else { | |
throw new Error('Failed to get long-term two-factor auth token'); | |
} | |
const result = await scraper.getLongTermTwoFactorToken(otpCode); | |
if (result.success) { | |
await updateOtpLongTermToken(companyId, result.longTermTwoFactorAuthToken); | |
creds.otpLongTermToken = result.longTermTwoFactorAuthToken; | |
} else { | |
throw new Error('Failed to get long-term two-factor auth token'); | |
} |
} | ||
|
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.
What is it? I see it is unused..?
If it is not related to your work, I prefer you to open a new PR for this, so if there will be a problem with this remove, it will be easy to revert it.
const hash = calculateTransactionHash(transaction, companyId, accountNumber); | ||
// const category = categoryCalculation.getCategoryNameByTransactionDescription(transaction.description); | ||
const enrichedTransaction: EnrichedTransaction = { | ||
return { | ||
...transaction, | ||
accountNumber, | ||
// category, |
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.
Oh I see we don't have a category calculation anymore.
Anyway, please return the comment back.
Yes, I agree that developer should avoid code comments, but this project is in low maintainance and I prefer to keep such comments for the next time I will search something.
Summary by CodeRabbit
Release Notes
New Features
GetOtp
component for handling OTP inputImprovements
Removed
The updates focus on improving authentication and scraping processes for bank transactions.