forked from eshaham/israeli-bank-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.ts
158 lines (134 loc) · 4.49 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { type Browser, type Page } from 'puppeteer';
import { type CompanyTypes, type ScraperProgressTypes } from '../definitions';
import { type TransactionsAccount } from '../transactions';
import { type ErrorResult, type ScraperErrorTypes } from './errors';
// TODO: Remove this type when the scraper 'factory' will return concrete scraper types
// Instead of a generic interface (which in turn uses this type)
export type ScraperCredentials =
{ userCode: string, password: string } |
{ username: string, password: string } |
{ id: string, password: string } |
{ id: string, password: string, num: string } |
{ id: string, password: string, card6Digits: string } |
{ username: string, nationalID: string, password: string } |
({ email: string, password: string } & ({
otpCodeRetriever: () => Promise<string>;
phoneNumber: string;
} | {
otpLongTermToken: string;
}));
export interface FutureDebit {
amount: number;
amountCurrency: string;
chargeDate?: string;
bankAccountNumber?: string;
}
export interface ScraperOptions {
/**
* The company you want to scrape
*/
companyId: CompanyTypes;
/**
* include more debug info about in the output
*/
verbose?: boolean;
/**
* the date to fetch transactions from (can't be before the minimum allowed time difference for the scraper)
*/
startDate: Date;
/**
* shows the browser while scraping, good for debugging (default false)
*/
showBrowser?: boolean;
/**
* scrape transactions to be processed X months in the future
*/
futureMonthsToScrape?: number;
/**
* option from init puppeteer browser instance outside the libary scope. you can get
* browser diretly from puppeteer via `puppeteer.launch()`
*/
browser?: any;
/**
* provide a patch to local chromium to be used by puppeteer. Relevant when using
* `israeli-bank-scrapers-core` library
*/
executablePath?: string;
/**
* if set to true, all installment transactions will be combine into the first one
*/
combineInstallments?: boolean;
/**
* additional arguments to pass to the browser instance. The list of flags can be found in
*
* https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options
* https://peter.sh/experiments/chromium-command-line-switches/
*/
args?: string[];
/**
* Maximum navigation time in milliseconds, pass 0 to disable timeout.
* @default 30000
*/
timeout?: number | undefined;
/**
* adjust the browser instance before it is being used
*
* @param browser
*/
prepareBrowser?: (browser: Browser) => Promise<void>;
/**
* adjust the page instance before it is being used.
*
* @param page
*/
preparePage?: (page: Page) => Promise<void>;
/**
* if set, store a screenshot if failed to scrape. Used for debug purposes
*/
storeFailureScreenShotPath?: string;
/**
* if set, will set the timeout in milliseconds of puppeteer's `page.setDefaultTimeout`.
*/
defaultTimeout?: number;
/**
* Options for manipulation of output data
*/
outputData?: OutputDataOptions;
/**
* Perform additional operation for each transaction to get more information (Like category) about it.
* Please note: It will take more time to finish the process.
*/
additionalTransactionInformation?: boolean;
}
export interface OutputDataOptions {
/**
* if true, the result wouldn't be filtered out by date, and you will return unfiltered scrapped data.
*/
enableTransactionsFilterByDate?: boolean;
}
export interface ScraperScrapingResult {
success: boolean;
accounts?: TransactionsAccount[];
futureDebits?: FutureDebit[];
errorType?: ScraperErrorTypes;
errorMessage?: string; // only on success=false
}
export interface Scraper<TCredentials extends ScraperCredentials> {
scrape(credentials: TCredentials): Promise<ScraperScrapingResult>;
onProgress(func: (companyId: CompanyTypes, payload: { type: ScraperProgressTypes }) => void): void;
triggerTwoFactorAuth(phoneNumber: string): Promise<ScraperTwoFactorAuthTriggerResult>;
getLongTermTwoFactorToken(otpCode: string): Promise<ScraperGetLongTermTwoFactorTokenResult>;
}
export type ScraperTwoFactorAuthTriggerResult = ErrorResult | {
success: true;
};
export type ScraperGetLongTermTwoFactorTokenResult = ErrorResult | {
success: true;
longTermTwoFactorAuthToken: string;
};
export interface ScraperLoginResult {
success: boolean;
errorType?: ScraperErrorTypes;
errorMessage?: string; // only on success=false
persistentOtpToken?: string;
}