-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathinterface.ts
181 lines (154 loc) · 5.12 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { type BrowserContext, 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;
}
interface ExternalBrowserOptions {
/**
* An externally created browser instance.
* you can get a browser directly from puppeteer via `puppeteer.launch()`
*
* Note: The browser will be closed by the library after the scraper finishes unless `skipCloseBrowser` is set to true
*/
browser: Browser;
/**
* If true, the browser will not be closed by the library after the scraper finishes
*/
skipCloseBrowser?: boolean;
}
interface ExternalBrowserContextOptions {
/**
* An externally managed browser context. This is useful when you want to manage the browser
*/
browserContext: BrowserContext;
}
interface DefaultBrowserOptions {
/**
* shows the browser while scraping, good for debugging (default false)
*/
showBrowser?: boolean;
/**
* provide a patch to local chromium to be used by puppeteer. Relevant when using
* `israeli-bank-scrapers-core` library
*/
executablePath?: string;
/**
* 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;
/**
* adjust the browser instance before it is being used
*
* @param browser
*/
prepareBrowser?: (browser: Browser) => Promise<void>;
}
type ScraperBrowserOptions =
| ExternalBrowserOptions
| ExternalBrowserContextOptions
| DefaultBrowserOptions;
export type ScraperOptions = ScraperBrowserOptions & {
/**
* 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;
/**
* scrape transactions to be processed X months in the future
*/
futureMonthsToScrape?: number;
/**
* if set to true, all installment transactions will be combine into the first one
*/
combineInstallments?: boolean;
/**
* 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;
}