Skip to content

Commit 38b45ab

Browse files
authored
fix: add keep-alive to connections (#16)
* fix: add keep-alive tp connections * chore: update yarn.lock * chore: fix tests * chore: tests on more node version
1 parent 62d7caa commit 38b45ab

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

.github/workflows/publish-npm.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Publish NPM package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish-npm:
9+
uses: snapshot-labs/actions/.github/workflows/publish-npm.yml@main
10+
secrets: inherit

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ on: [push]
44

55
jobs:
66
test:
7+
strategy:
8+
matrix:
9+
target: ['16', '18', '20']
10+
711
uses: snapshot-labs/actions/.github/workflows/test.yml@main
812
secrets: inherit
13+
with:
14+
target: ${{ matrix.target }}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/pineapple",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
1818
},
1919
"prettier": "@snapshot-labs/prettier-config",
2020
"dependencies": {
21-
"cross-fetch": "^3.1.5"
21+
"node-fetch": "^2.7.0"
2222
},
2323
"devDependencies": {
2424
"@snapshot-labs/eslint-config": "^0.1.0-beta.9",

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import fetch from 'cross-fetch';
1+
import fetch from 'node-fetch';
2+
import http from 'node:http';
3+
import https from 'node:https';
24

35
const PINEAPPLE_URL = 'https://pineapple.fyi';
6+
const agentOptions = { keepAlive: true };
47

58
export async function pin(json: any, url: string = PINEAPPLE_URL) {
69
const init = {
@@ -14,7 +17,11 @@ export async function pin(json: any, url: string = PINEAPPLE_URL) {
1417
method: 'pin',
1518
params: json,
1619
id: null
17-
})
20+
}),
21+
agent:
22+
new URL(url).protocol === 'http:'
23+
? new http.Agent(agentOptions)
24+
: new https.Agent(agentOptions)
1825
};
1926
const res = await fetch(url, init);
2027
const content = await res.json();

test/upload.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('upload()', () => {
1010
formData.append('file', createReadStream(path.join(__dirname, './fixtures/valid.png')));
1111
const receipt = await upload(formData);
1212
expect(receipt.provider).toBe('4everland');
13-
expect(receipt.cid).toBe('bafkreibenzwnm4pckgeqdyzlwnxemfavkofaynnpxj6o23oojcfe77hvte');
13+
expect(receipt.cid).toBe('bafkreidxvfyqu6l3tb3y5gi2nq5zqyincpev2rangnv7nmaocrk7q3o2fi');
1414
}, 30e3);
1515
});
1616

yarn.lock

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,13 +1240,6 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
12401240
dependencies:
12411241
safe-buffer "~5.1.1"
12421242

1243-
cross-fetch@^3.1.5:
1244-
version "3.1.5"
1245-
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
1246-
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
1247-
dependencies:
1248-
node-fetch "2.6.7"
1249-
12501243
cross-spawn@^7.0.2, cross-spawn@^7.0.3:
12511244
version "7.0.3"
12521245
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@@ -2732,10 +2725,10 @@ natural-compare@^1.4.0:
27322725
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
27332726
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==
27342727

2735-
node-fetch@2.6.7:
2736-
version "2.6.7"
2737-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
2738-
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
2728+
node-fetch@^2.7.0:
2729+
version "2.7.0"
2730+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
2731+
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
27392732
dependencies:
27402733
whatwg-url "^5.0.0"
27412734

@@ -3327,7 +3320,7 @@ tr46@^2.1.0:
33273320
tr46@~0.0.3:
33283321
version "0.0.3"
33293322
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
3330-
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
3323+
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
33313324

33323325
ts-jest@^27.1.4:
33333326
version "27.1.5"
@@ -3459,7 +3452,7 @@ walker@^1.0.7:
34593452
webidl-conversions@^3.0.0:
34603453
version "3.0.1"
34613454
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
3462-
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
3455+
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
34633456

34643457
webidl-conversions@^5.0.0:
34653458
version "5.0.0"
@@ -3486,7 +3479,7 @@ whatwg-mimetype@^2.3.0:
34863479
whatwg-url@^5.0.0:
34873480
version "5.0.0"
34883481
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
3489-
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
3482+
integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==
34903483
dependencies:
34913484
tr46 "~0.0.3"
34923485
webidl-conversions "^3.0.0"

0 commit comments

Comments
 (0)