1
- const RequestLimitFactory = require ( "../dist/RequestLimitFactory" ) . default ;
2
-
3
1
require ( "dotenv" ) . config ( ) ;
4
2
5
3
const setup = require ( "./common/setup" ) ;
@@ -30,24 +28,43 @@ setup()
30
28
31
29
// filter on the status to get a list of the active accounts
32
30
const activeAccounts = accounts . filter ( account => {
33
- if ( account . MonetaryAccountBank ) {
34
- return account . MonetaryAccountBank . status === "ACTIVE" ;
35
- }
36
- if ( account . MonetaryAccountJoint ) {
37
- return account . MonetaryAccountJoint . status === "ACTIVE" ;
38
- }
39
- if ( account . MonetaryAccountSavings ) {
40
- return account . MonetaryAccountSavings . status === "ACTIVE" ;
41
- }
42
- return false ;
31
+ // get the account type for this account
32
+ const accountType = Object . keys ( account ) [ 0 ] ;
33
+
34
+ return account [ accountType ] . status === "ACTIVE" ;
43
35
} ) ;
44
36
45
37
if ( activeAccounts . length > 0 ) {
46
38
const accountType = Object . keys ( activeAccounts [ 0 ] ) [ 0 ] ;
47
39
const accountId = activeAccounts [ 0 ] [ accountType ] . id ;
48
40
49
41
// get all payments for the first monetary account
50
- console . log ( new Date ( ) ) ;
42
+ console . log ( "\nStart WITH proxy:" ) ;
43
+ const withProxyStart = new Date ( ) ;
44
+ await Promise . all ( [
45
+ getPayments ( userInfo . id , accountId ) ,
46
+ getPayments ( userInfo . id , accountId ) ,
47
+ getPayments ( userInfo . id , accountId ) ,
48
+ getPayments ( userInfo . id , accountId ) ,
49
+ getPayments ( userInfo . id , accountId ) ,
50
+ getPayments ( userInfo . id , accountId ) ,
51
+ getPayments ( userInfo . id , accountId ) ,
52
+ getPayments ( userInfo . id , accountId ) ,
53
+ getPayments ( userInfo . id , accountId )
54
+ ] ) ;
55
+ const withProxyDuration = new Date ( ) . getTime ( ) - withProxyStart . getTime ( ) ;
56
+ console . log ( `${ withProxyDuration . toLocaleString ( ) } ms duration` ) ;
57
+
58
+ console . log ( "\nSetting default connection proxy (none)" ) ;
59
+ // enable proxy support
60
+ BunqClient . setRequestProxies ( [ false ] ) ;
61
+
62
+ console . log ( "Waiting 4s to reset the rate limit to reset" ) ;
63
+ await new Promise ( resolve => setTimeout ( resolve , 4000 ) ) ;
64
+
65
+ // get all payments for the first monetary account
66
+ console . log ( "\nStart regular:" ) ;
67
+ const noProxyStart = new Date ( ) ;
51
68
await Promise . all ( [
52
69
getPayments ( userInfo . id , accountId ) ,
53
70
getPayments ( userInfo . id , accountId ) ,
@@ -59,14 +76,14 @@ setup()
59
76
getPayments ( userInfo . id , accountId ) ,
60
77
getPayments ( userInfo . id , accountId )
61
78
] ) ;
62
- console . log ( new Date ( ) ) ;
79
+ const noProxyDuration = new Date ( ) . getTime ( ) - noProxyStart . getTime ( ) ;
80
+ console . log ( `${ noProxyDuration . toLocaleString ( ) } ms duration` ) ;
63
81
}
64
82
} )
65
83
. catch ( error => {
84
+ console . log ( error ) ;
66
85
if ( error . response ) {
67
86
console . log ( error . response . data ) ;
68
- } else {
69
- console . log ( error ) ;
70
87
}
71
88
} )
72
89
. finally ( ( ) => process . exit ( ) ) ;
0 commit comments