Skip to content
This repository was archived by the owner on Aug 6, 2021. It is now read-only.

Commit 275aca7

Browse files
committed
Fix axios dependency, improve example logging, test proxy example
1 parent 8c2ecb9 commit 275aca7

11 files changed

+58
-46
lines changed

examples/basic.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ setup()
2626
const activeAccounts = accounts.filter(account => {
2727
// get the account type for this account
2828
const accountType = Object.keys(account)[0];
29-
// get the direct object contents
30-
const accountInfo = account[accountType];
3129

32-
return accountInfo.status === "ACTIVE";
30+
return account[accountType].status === "ACTIVE";
3331
});
3432

3533
if (activeAccounts.length > 0) {
@@ -43,10 +41,9 @@ setup()
4341
}
4442
})
4543
.catch(error => {
44+
console.log(error);
4645
if (error.response) {
4746
console.log(error.response.data);
48-
} else {
49-
console.log(error);
5047
}
5148
})
5249
.finally(() => process.exit());

examples/cards.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ setup()
122122
}
123123
})
124124
.catch(error => {
125+
console.log(error);
125126
if (error.response) {
126127
console.log(error.response.data);
127-
} else {
128-
console.log(error);
129128
}
130129
})
131130
.finally(() => process.exit());

examples/common/setup.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ const setup = async () => {
3535
BunqClient.setKeepAlive(false);
3636

3737
// create/re-use a system installation
38-
await BunqClient.install().catch(defaultErrorLogger);
38+
await BunqClient.install();
3939

4040
// create/re-use a device installation
41-
await BunqClient.registerDevice(process.env.DEVICE_NAME).catch(defaultErrorLogger);
41+
await BunqClient.registerDevice(process.env.DEVICE_NAME);
4242

4343
// create/re-use a bunq session installation
44-
await BunqClient.registerSession().catch(defaultErrorLogger);
44+
await BunqClient.registerSession();
4545

4646
return BunqClient;
4747
};

examples/create_sandbox_apikey.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ setup()
2020
process.exit();
2121
})
2222
.catch(error => {
23-
console.error(error);
24-
process.exit();
25-
});
23+
console.log(error);
24+
if (error.response) {
25+
console.log(error.response.data);
26+
}
27+
})
28+
.finally(() => process.exit());

examples/encrypted_endpoint.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ setup()
3737
console.log(cvcResult);
3838
})
3939
.catch(error => {
40+
console.log(error);
4041
if (error.response) {
4142
console.log(error.response.data);
42-
} else {
43-
console.log(error);
4443
}
4544
})
4645
.finally(() => process.exit());

examples/file_upload.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ setup()
2525
console.log("Public avatar UUID", avatarUuid, "\n");
2626
})
2727
.catch(error => {
28+
console.log(error);
2829
if (error.response) {
2930
console.log(error.response.data);
30-
} else {
31-
console.log(error);
3231
}
3332
})
3433
.finally(() => process.exit());

examples/multiple_instances.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ const example = async () => {
133133
example()
134134
.then(() => {})
135135
.catch(error => {
136+
console.log(error);
136137
if (error.response) {
137138
console.log(error.response.data);
138-
} else {
139-
console.log(error);
140139
}
141140
})
142141
.finally(() => process.exit());

examples/order_cards.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ setup()
5050
console.log(cardOrderResult);
5151
})
5252
.catch(error => {
53+
console.log(error);
5354
if (error.response) {
5455
console.log(error.response.data);
55-
} else {
56-
console.log(error);
5756
}
5857
})
5958
.finally(() => process.exit());

examples/proxy_example.js

+33-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const RequestLimitFactory = require("../dist/RequestLimitFactory").default;
2-
31
require("dotenv").config();
42

53
const setup = require("./common/setup");
@@ -30,24 +28,43 @@ setup()
3028

3129
// filter on the status to get a list of the active accounts
3230
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";
4335
});
4436

4537
if (activeAccounts.length > 0) {
4638
const accountType = Object.keys(activeAccounts[0])[0];
4739
const accountId = activeAccounts[0][accountType].id;
4840

4941
// 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();
5168
await Promise.all([
5269
getPayments(userInfo.id, accountId),
5370
getPayments(userInfo.id, accountId),
@@ -59,14 +76,14 @@ setup()
5976
getPayments(userInfo.id, accountId),
6077
getPayments(userInfo.id, accountId)
6178
]);
62-
console.log(new Date());
79+
const noProxyDuration = new Date().getTime() - noProxyStart.getTime();
80+
console.log(`${noProxyDuration.toLocaleString()}ms duration`);
6381
}
6482
})
6583
.catch(error => {
84+
console.log(error);
6685
if (error.response) {
6786
console.log(error.response.data);
68-
} else {
69-
console.log(error);
7087
}
7188
})
7289
.finally(() => process.exit());

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
],
3333
"dependencies": {
3434
"awaiting": "^3.0.0",
35-
"axios": "^0.19.0",
35+
"axios": "0.18.1",
3636
"loglevel": "^1.4.1",
3737
"node-forge": "^0.7.1",
3838
"socks-proxy-agent": "^4.0.2",

yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,14 @@ aws4@^1.8.0:
13501350
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
13511351
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
13521352

1353+
axios@0.18.1:
1354+
version "0.18.1"
1355+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.1.tgz#ff3f0de2e7b5d180e757ad98000f1081b87bcea3"
1356+
integrity sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==
1357+
dependencies:
1358+
follow-redirects "1.5.10"
1359+
is-buffer "^2.0.2"
1360+
13531361
axios@^0.16.1:
13541362
version "0.16.2"
13551363
resolved "https://registry.yarnpkg.com/axios/-/axios-0.16.2.tgz#ba4f92f17167dfbab40983785454b9ac149c3c6d"
@@ -1358,14 +1366,6 @@ axios@^0.16.1:
13581366
follow-redirects "^1.2.3"
13591367
is-buffer "^1.1.5"
13601368

1361-
axios@^0.19.0:
1362-
version "0.19.0"
1363-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
1364-
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
1365-
dependencies:
1366-
follow-redirects "1.5.10"
1367-
is-buffer "^2.0.2"
1368-
13691369
babel-jest@^24.8.0:
13701370
version "24.8.0"
13711371
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-24.8.0.tgz#5c15ff2b28e20b0f45df43fe6b7f2aae93dba589"

0 commit comments

Comments
 (0)