@pinata/sdk 1.2.1 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +1 -1
- package/.eslintrc +7 -7
- package/.husky/pre-commit +6 -0
- package/.nvmrc +1 -1
- package/README.md +3 -3
- package/lib/pinata-sdk.js +906 -839
- package/lib/pinata-sdk.min.js +5 -5
- package/package.json +83 -71
- package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +8 -9
- package/src/commands/data/index.ts +4 -0
- package/src/commands/data/pinList/pinList.ts +77 -0
- package/src/commands/data/pinList/{queryBuilder.js → queryBuilder.ts} +6 -16
- package/src/commands/data/{testAuthentication.js → testAuthentication.ts} +8 -9
- package/src/commands/data/{userPinnedDataTotal.js → userPinnedDataTotal.ts} +4 -9
- package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +9 -11
- package/src/commands/pinning/index.ts +8 -0
- package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +22 -11
- package/src/commands/pinning/pinFileToIPFS.ts +118 -0
- package/src/commands/pinning/pinFromFS.ts +50 -0
- package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +5 -11
- package/src/commands/pinning/pinJobs/{pinJobs.js → pinJobs.ts} +23 -9
- package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
- package/src/commands/pinning/{unpin.js → unpin.ts} +3 -9
- package/src/{constants.js → constants.ts} +0 -0
- package/src/index.ts +120 -0
- package/src/third-party/base-path-converter.d.ts +3 -0
- package/src/third-party/is-ipfs.d.ts +5 -0
- package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
- package/src/util/{validators.js → validators.ts} +21 -33
- package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +23 -22
- package/test/commands/data/pinList/{pinList.test.js → pinList.test.ts} +25 -26
- package/test/commands/data/pinList/{queryBuilder.test.js → queryBuilder.test.ts} +9 -10
- package/test/commands/data/pinlist-sample-api.ts +540 -0
- package/test/commands/data/{testAuthentication.test.js → testAuthentication.test.ts} +13 -13
- package/test/commands/data/{userPinnedDataTotal.test.js → userPinnedDataTotal.test.ts} +4 -4
- package/test/commands/pinning/{hashMetadata.test.js → hashMetadata.test.ts} +7 -8
- package/test/commands/pinning/{pinByHash.test.js → pinByHash.test.ts} +4 -5
- package/test/commands/pinning/{pinFileToIPFS.test.js → pinFileToIPFS.test.ts} +9 -11
- package/test/commands/pinning/{pinFromFS.js → pinFromFS.ts} +5 -6
- package/test/commands/pinning/{pinJSONToIPFS.test.js → pinJSONToIPFS.test.ts} +4 -5
- package/test/commands/pinning/pinJobs/{pinJobs.test.js → pinJobs.test.ts} +4 -4
- package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
- package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +4 -5
- package/test/util/validators.test.ts +234 -0
- package/tsconfig.json +2 -2
- package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +4 -2
- package/types/commands/data/index.d.ts +4 -0
- package/types/commands/data/pinList/pinList.d.ts +45 -8
- package/types/commands/data/pinList/queryBuilder.d.ts +1 -7
- package/types/commands/data/testAuthentication.d.ts +5 -7
- package/types/commands/data/userPinnedDataTotal.d.ts +2 -7
- package/types/commands/pinning/hashMetadata.d.ts +3 -9
- package/types/commands/pinning/index.d.ts +8 -0
- package/types/commands/pinning/pinByHash.d.ts +14 -9
- package/types/commands/pinning/pinFileToIPFS.d.ts +25 -9
- package/types/commands/pinning/pinFromFS.d.ts +3 -9
- package/types/commands/pinning/pinJSONToIPFS.d.ts +3 -9
- package/types/commands/pinning/pinJobs/pinJobs.d.ts +20 -8
- package/types/commands/pinning/pinJobs/queryBuilder.d.ts +1 -7
- package/types/commands/pinning/unpin.d.ts +2 -8
- package/types/constants.d.ts +2 -2
- package/types/index.d.ts +37 -165
- package/types/util/errorResponse.d.ts +1 -1
- package/types/util/validators.d.ts +23 -46
- package/webpack.config.js +50 -53
- package/src/commands/data/pinList/pinList.js +0 -34
- package/src/commands/pinning/hashPinPolicy.js +0 -51
- package/src/commands/pinning/pinFileToIPFS.js +0 -53
- package/src/commands/pinning/pinFromFS.js +0 -100
- package/src/commands/pinning/userPinPolicy.js +0 -40
- package/src/index.js +0 -307
- package/test/commands/data/pinlist-sample-api.js +0 -540
- package/test/commands/pinning/hashPinPolicy.test.js +0 -65
- package/test/commands/pinning/userPinPolicy.test.js +0 -80
- package/test/util/validators.test.js +0 -234
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import pinByHash from'../../../src/commands/pinning/pinByHash';
|
|
2
|
+
import pinByHash from '../../../src/commands/pinning/pinByHash';
|
|
3
3
|
|
|
4
4
|
jest.mock('axios');
|
|
5
5
|
|
|
@@ -24,7 +24,7 @@ test('200 status is returned', () => {
|
|
|
24
24
|
status: 200,
|
|
25
25
|
data: 'testData'
|
|
26
26
|
};
|
|
27
|
-
axios.post.mockResolvedValue(goodStatus);
|
|
27
|
+
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
28
28
|
expect.assertions(1);
|
|
29
29
|
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).resolves.toEqual(goodStatus.data);
|
|
30
30
|
});
|
|
@@ -33,15 +33,14 @@ test('Result other than 200 status is returned', () => {
|
|
|
33
33
|
const badStatus = {
|
|
34
34
|
status: 700
|
|
35
35
|
};
|
|
36
|
-
axios.post.mockResolvedValue(badStatus);
|
|
36
|
+
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
37
37
|
expect.assertions(1);
|
|
38
38
|
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).rejects.toEqual(Error(`unknown server response while adding to pin queue: ${badStatus}`));
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
test('Rejection handled', () => {
|
|
42
|
-
axios.post.mockRejectedValue('test error');
|
|
42
|
+
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
43
43
|
expect.assertions(1);
|
|
44
44
|
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).rejects.toEqual('test error');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import pinFileToIPFS from'../../../src/commands/pinning/pinFileToIPFS';
|
|
2
|
+
import pinFileToIPFS from '../../../src/commands/pinning/pinFileToIPFS';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import NodeFormData from 'form-data';
|
|
5
5
|
jest.mock('axios');
|
|
@@ -10,7 +10,6 @@ const validStream = fs.createReadStream('./pinata.png');
|
|
|
10
10
|
const validFormData = new NodeFormData();
|
|
11
11
|
validFormData.append('file', validStream, {filepath: 'test/filepath'});
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
test('non-readableStream and non-formData is passed in', () => {
|
|
15
14
|
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, nonStream)).rejects.toEqual(Error('readStream is not a readable stream or form data'));
|
|
16
15
|
|
|
@@ -22,9 +21,9 @@ test('200 status is returned with valid stream', () => {
|
|
|
22
21
|
status: 200,
|
|
23
22
|
data: 'testData'
|
|
24
23
|
};
|
|
25
|
-
axios.post.mockResolvedValue(goodStatus);
|
|
24
|
+
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
26
25
|
expect.assertions(1);
|
|
27
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream)).resolves.toEqual(goodStatus.data);
|
|
26
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream, {pinataMetadata: { name: 'text.txt'}})).resolves.toEqual(goodStatus.data);
|
|
28
27
|
});
|
|
29
28
|
|
|
30
29
|
test('200 status is returned with valid form data', () => {
|
|
@@ -32,24 +31,23 @@ test('200 status is returned with valid form data', () => {
|
|
|
32
31
|
status: 200,
|
|
33
32
|
data: 'testData'
|
|
34
33
|
};
|
|
35
|
-
axios.post.mockResolvedValue(goodStatus);
|
|
34
|
+
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
36
35
|
expect.assertions(1);
|
|
37
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validFormData)).resolves.toEqual(goodStatus.data);
|
|
36
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validFormData, {pinataMetadata: { name: 'text.txt'}})).resolves.toEqual(goodStatus.data);
|
|
38
37
|
});
|
|
39
38
|
|
|
40
39
|
test('Result other than 200 status is returned', () => {
|
|
41
40
|
const badStatus = {
|
|
42
41
|
status: 700
|
|
43
42
|
};
|
|
44
|
-
axios.post.mockResolvedValue(badStatus);
|
|
43
|
+
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
45
44
|
expect.assertions(1);
|
|
46
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream)).rejects.toEqual(Error(`unknown server response while pinning File to IPFS: ${badStatus}`));
|
|
45
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream, {pinataMetadata: { name: 'text.txt'}})).rejects.toEqual(Error(`unknown server response while pinning File to IPFS: ${badStatus}`));
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
test('Rejection handled', () => {
|
|
50
|
-
axios.post.mockRejectedValue('test error');
|
|
49
|
+
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
51
50
|
expect.assertions(1);
|
|
52
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream)).rejects.toEqual('test error');
|
|
51
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream, {pinataMetadata: { name: 'text.txt'}})).rejects.toEqual('test error');
|
|
53
52
|
});
|
|
54
53
|
|
|
55
|
-
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import pinFromFS from'../../../src/commands/pinning/pinFromFS';
|
|
2
|
+
import pinFromFS from '../../../src/commands/pinning/pinFromFS';
|
|
3
3
|
jest.mock('axios');
|
|
4
4
|
|
|
5
5
|
//common values
|
|
6
|
-
const testSource = './testing/testing'
|
|
6
|
+
const testSource = './testing/testing';
|
|
7
7
|
|
|
8
8
|
test('200 status is returned', () => {
|
|
9
9
|
const goodStatus = {
|
|
10
10
|
status: 200,
|
|
11
11
|
data: 'testData'
|
|
12
12
|
};
|
|
13
|
-
axios.post.mockResolvedValue(goodStatus);
|
|
13
|
+
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
14
14
|
expect.assertions(1);
|
|
15
15
|
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).resolves.toEqual(goodStatus.data);
|
|
16
16
|
});
|
|
@@ -19,15 +19,14 @@ test('Result other than 200 status is returned', () => {
|
|
|
19
19
|
const badStatus = {
|
|
20
20
|
status: 700
|
|
21
21
|
};
|
|
22
|
-
axios.post.mockResolvedValue(badStatus);
|
|
22
|
+
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
23
23
|
expect.assertions(1);
|
|
24
24
|
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).rejects.toEqual(Error(`unknown server response while pinning to IPFS: ${badStatus}`));
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('Rejection handled', () => {
|
|
28
|
-
axios.post.mockRejectedValue('test error');
|
|
28
|
+
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
29
29
|
expect.assertions(1);
|
|
30
30
|
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).rejects.toEqual('test error');
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import pinJSONToIPFS from'../../../src/commands/pinning/pinJSONToIPFS';
|
|
2
|
+
import pinJSONToIPFS from '../../../src/commands/pinning/pinJSONToIPFS';
|
|
3
3
|
|
|
4
4
|
jest.mock('axios');
|
|
5
5
|
|
|
@@ -20,7 +20,7 @@ test('200 status is returned', () => {
|
|
|
20
20
|
status: 200,
|
|
21
21
|
data: 'testData'
|
|
22
22
|
};
|
|
23
|
-
axios.post.mockResolvedValue(goodStatus);
|
|
23
|
+
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
24
24
|
expect.assertions(1);
|
|
25
25
|
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).resolves.toEqual(goodStatus.data);
|
|
26
26
|
});
|
|
@@ -29,15 +29,14 @@ test('Result other than 200 status is returned', () => {
|
|
|
29
29
|
const badStatus = {
|
|
30
30
|
status: 700
|
|
31
31
|
};
|
|
32
|
-
axios.post.mockResolvedValue(badStatus);
|
|
32
|
+
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
33
33
|
expect.assertions(1);
|
|
34
34
|
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).rejects.toEqual(Error(`unknown server response while pinning JSON to IPFS: ${badStatus}`));
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('Rejection handled', () => {
|
|
38
|
-
axios.post.mockRejectedValue('test error');
|
|
38
|
+
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
39
39
|
expect.assertions(1);
|
|
40
40
|
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).rejects.toEqual('test error');
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import pinJobs from '
|
|
2
|
+
import pinJobs from '../../../../src/commands/pinning/pinJobs/pinJobs';
|
|
3
3
|
|
|
4
4
|
jest.mock('axios');
|
|
5
5
|
|
|
@@ -7,7 +7,7 @@ test('Result other than 200 status is returned', () => {
|
|
|
7
7
|
const badStatus = {
|
|
8
8
|
status: 700
|
|
9
9
|
};
|
|
10
|
-
axios.get.mockResolvedValue(badStatus);
|
|
10
|
+
(axios.get as jest.Mock).mockResolvedValue(badStatus);
|
|
11
11
|
expect.assertions(1);
|
|
12
12
|
expect(pinJobs({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual(Error(`unknown server response while attempting to retrieve pin jobs: ${badStatus}`));
|
|
13
13
|
});
|
|
@@ -17,13 +17,13 @@ test('200 status is returned', () => {
|
|
|
17
17
|
status: 200,
|
|
18
18
|
data: 'testData'
|
|
19
19
|
};
|
|
20
|
-
axios.get.mockResolvedValue(goodStatus);
|
|
20
|
+
(axios.get as jest.Mock).mockResolvedValue(goodStatus);
|
|
21
21
|
expect.assertions(1);
|
|
22
22
|
expect(pinJobs({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).resolves.toEqual(goodStatus.data);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('Rejection handled', () => {
|
|
26
|
-
axios.get.mockRejectedValue('test error');
|
|
26
|
+
(axios.get as jest.Mock).mockRejectedValue('test error');
|
|
27
27
|
expect.assertions(1);
|
|
28
28
|
expect(pinJobs({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual('test error');
|
|
29
29
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import queryBuilder from '
|
|
1
|
+
import queryBuilder from '../../../../src/commands/pinning/pinJobs/queryBuilder';
|
|
2
2
|
|
|
3
3
|
const baseUrl = 'testing.com/test';
|
|
4
4
|
const badFilterValue = 'badFilterValue';
|
|
@@ -6,11 +6,11 @@ const goodHashToPin = 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp';
|
|
|
6
6
|
|
|
7
7
|
describe('queryBuilder no params provided', () => {
|
|
8
8
|
test('if no baseUrl is provided', () => {
|
|
9
|
-
expect(() => {
|
|
10
|
-
|
|
11
|
-
}).toThrow('no baseUrl provided');
|
|
9
|
+
// expect(() => {
|
|
10
|
+
// queryBuilder();
|
|
11
|
+
// }).toThrow('no baseUrl provided');
|
|
12
12
|
});
|
|
13
|
-
test('if no filters are provided, return
|
|
13
|
+
test('if no filters are provided, return a non filtered url', () => {
|
|
14
14
|
expect(queryBuilder(baseUrl)).toEqual(baseUrl);
|
|
15
15
|
});
|
|
16
16
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import unpin from'../../../src/commands/pinning/unpin';
|
|
2
|
+
import unpin from '../../../src/commands/pinning/unpin';
|
|
3
3
|
|
|
4
4
|
jest.mock('axios');
|
|
5
5
|
|
|
@@ -24,7 +24,7 @@ test('200 status is returned', () => {
|
|
|
24
24
|
status: 200,
|
|
25
25
|
data: 'testData'
|
|
26
26
|
};
|
|
27
|
-
axios.delete.mockResolvedValue(goodStatus);
|
|
27
|
+
(axios.delete as jest.Mock).mockResolvedValue(goodStatus);
|
|
28
28
|
expect.assertions(1);
|
|
29
29
|
expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).resolves.toEqual(goodStatus.data);
|
|
30
30
|
});
|
|
@@ -33,15 +33,14 @@ test('Result other than 200 status is returned', () => {
|
|
|
33
33
|
const badStatus = {
|
|
34
34
|
status: 700
|
|
35
35
|
};
|
|
36
|
-
axios.delete.mockResolvedValue(badStatus);
|
|
36
|
+
(axios.delete as jest.Mock).mockResolvedValue(badStatus);
|
|
37
37
|
expect.assertions(1);
|
|
38
38
|
expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).rejects.toEqual(Error(`unknown server response while removing pin from IPFS: ${badStatus}`));
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
test('Rejection handled', () => {
|
|
42
|
-
axios.delete.mockRejectedValue('test error');
|
|
42
|
+
(axios.delete as jest.Mock).mockRejectedValue('test error');
|
|
43
43
|
expect.assertions(1);
|
|
44
44
|
expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).rejects.toEqual('test error');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateApiKeys,
|
|
3
|
+
createConfigForAxiosHeaders,
|
|
4
|
+
validateHostNodes,
|
|
5
|
+
validateMetadata,
|
|
6
|
+
validatePinPolicyStructure,
|
|
7
|
+
validatePinataOptions
|
|
8
|
+
} from '../../src/util/validators';
|
|
9
|
+
import { ERROR_NO_CREDENTIALS_PROVIDED } from '../../src/constants';
|
|
10
|
+
|
|
11
|
+
describe('validateApiKeys function testing', () => {
|
|
12
|
+
test('check to throw if either pinataApiKey or pinataSecretApiKey are not provided', () => {
|
|
13
|
+
expect(() => {
|
|
14
|
+
validateApiKeys('', 'test');
|
|
15
|
+
}).toThrow(
|
|
16
|
+
'No pinataApiKey provided! Please provide your pinata api key as an argument when you start this script'
|
|
17
|
+
);
|
|
18
|
+
expect(() => {
|
|
19
|
+
validateApiKeys('test', '');
|
|
20
|
+
}).toThrow(
|
|
21
|
+
'No pinataSecretApiKey provided! Please provide your pinata secret api key as an argument when you start this script'
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('createConfigForAxiosHeaders function testing', () => {
|
|
27
|
+
expect(() => {
|
|
28
|
+
createConfigForAxiosHeaders({});
|
|
29
|
+
}).toThrow(ERROR_NO_CREDENTIALS_PROVIDED);
|
|
30
|
+
|
|
31
|
+
expect(() => {
|
|
32
|
+
createConfigForAxiosHeaders({ pinataApiKey: 'some api key' });
|
|
33
|
+
}).toThrow(ERROR_NO_CREDENTIALS_PROVIDED);
|
|
34
|
+
|
|
35
|
+
expect(() => {
|
|
36
|
+
createConfigForAxiosHeaders({ pinataSecretApiKey: 'some api secret' });
|
|
37
|
+
}).toThrow(ERROR_NO_CREDENTIALS_PROVIDED);
|
|
38
|
+
|
|
39
|
+
expect(
|
|
40
|
+
createConfigForAxiosHeaders({
|
|
41
|
+
pinataApiKey: 'some api key',
|
|
42
|
+
pinataSecretApiKey: 'some api secret'
|
|
43
|
+
})
|
|
44
|
+
).toEqual({
|
|
45
|
+
withCredentials: true,
|
|
46
|
+
headers: {
|
|
47
|
+
pinata_api_key: 'some api key',
|
|
48
|
+
pinata_secret_api_key: 'some api secret'
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('validateHostNodes function testing', () => {
|
|
53
|
+
test('host_nodes is not an array', () => {
|
|
54
|
+
const hostNodes = {
|
|
55
|
+
test: 'test'
|
|
56
|
+
};
|
|
57
|
+
expect(() => {
|
|
58
|
+
validateHostNodes(hostNodes);
|
|
59
|
+
}).toThrow('host_nodes value must be an array');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('invalid host_node entry', () => {
|
|
63
|
+
const validHost =
|
|
64
|
+
'/ip4/127.0.0.1/tcp/1234/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj';
|
|
65
|
+
const invalidHost = 'invalid host';
|
|
66
|
+
const hostNodes = [validHost, invalidHost];
|
|
67
|
+
expect(() => {
|
|
68
|
+
validateHostNodes(hostNodes);
|
|
69
|
+
}).toThrow(
|
|
70
|
+
`host_node array entry: ${invalidHost} is not a valid peer multiaddr`
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('validateMetadata function testing', () => {
|
|
76
|
+
test('name is not a string', () => {
|
|
77
|
+
const badName = {
|
|
78
|
+
test: 'testing'
|
|
79
|
+
};
|
|
80
|
+
expect(() => {
|
|
81
|
+
validateMetadata({
|
|
82
|
+
name: badName
|
|
83
|
+
});
|
|
84
|
+
}).toThrow('metadata name must be of type string');
|
|
85
|
+
});
|
|
86
|
+
test('keyvalues is not an object', () => {
|
|
87
|
+
const badKeyValues = 'testing';
|
|
88
|
+
expect(() => {
|
|
89
|
+
validateMetadata({
|
|
90
|
+
keyvalues: badKeyValues
|
|
91
|
+
});
|
|
92
|
+
}).toThrow('metatadata keyvalues must be an object');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('more than 10 keyvalues was provided', () => {
|
|
96
|
+
const tooManyKeyValues = {
|
|
97
|
+
one: 1,
|
|
98
|
+
two: 2,
|
|
99
|
+
three: 3,
|
|
100
|
+
four: 4,
|
|
101
|
+
five: 5,
|
|
102
|
+
six: 6,
|
|
103
|
+
seven: 7,
|
|
104
|
+
eight: 8,
|
|
105
|
+
nine: 9,
|
|
106
|
+
ten: 10,
|
|
107
|
+
eleven: 11
|
|
108
|
+
};
|
|
109
|
+
expect(() => {
|
|
110
|
+
validateMetadata({
|
|
111
|
+
keyvalues: tooManyKeyValues
|
|
112
|
+
});
|
|
113
|
+
}).toThrow(
|
|
114
|
+
'No more than 10 keyvalues can be provided for metadata entries'
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
test('Throws error on an object being passed in as a value for a keyvalue', () => {
|
|
118
|
+
const invalidValue = {
|
|
119
|
+
one: 1,
|
|
120
|
+
two: {
|
|
121
|
+
test: 'test'
|
|
122
|
+
},
|
|
123
|
+
three: 3,
|
|
124
|
+
four: 4,
|
|
125
|
+
five: 5,
|
|
126
|
+
six: 6,
|
|
127
|
+
seven: 7,
|
|
128
|
+
eight: 8,
|
|
129
|
+
nine: 9,
|
|
130
|
+
ten: 10,
|
|
131
|
+
eleven: 11
|
|
132
|
+
};
|
|
133
|
+
expect(() => {
|
|
134
|
+
validateMetadata({
|
|
135
|
+
keyvalues: invalidValue
|
|
136
|
+
});
|
|
137
|
+
}).toThrow(
|
|
138
|
+
'Metadata keyvalue values must be strings, booleans, or numbers'
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
test('Does not throw an error if metadata is valid', () => {
|
|
142
|
+
const invalidValue = {
|
|
143
|
+
one: 1,
|
|
144
|
+
two: 2,
|
|
145
|
+
three: 3,
|
|
146
|
+
four: 4,
|
|
147
|
+
five: 5,
|
|
148
|
+
six: 6,
|
|
149
|
+
seven: 7,
|
|
150
|
+
eight: 8,
|
|
151
|
+
nine: 9,
|
|
152
|
+
ten: 10
|
|
153
|
+
};
|
|
154
|
+
expect(() => {
|
|
155
|
+
validateMetadata({
|
|
156
|
+
keyvalues: invalidValue
|
|
157
|
+
});
|
|
158
|
+
}).not.toThrow();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('validatePinPolicyStructure function testing', () => {
|
|
163
|
+
test('No Policy Provided', () => {
|
|
164
|
+
expect(() => {
|
|
165
|
+
validatePinPolicyStructure();
|
|
166
|
+
}).toThrow('No pin policy provided');
|
|
167
|
+
});
|
|
168
|
+
test('No Regions Provided', () => {
|
|
169
|
+
expect(() => {
|
|
170
|
+
validatePinPolicyStructure({
|
|
171
|
+
test: 'test'
|
|
172
|
+
});
|
|
173
|
+
}).toThrow('No regions provided in pin policy');
|
|
174
|
+
});
|
|
175
|
+
test('region id is not a string', () => {
|
|
176
|
+
expect(() => {
|
|
177
|
+
validatePinPolicyStructure({
|
|
178
|
+
regions: [
|
|
179
|
+
{
|
|
180
|
+
id: 'goodRegionId',
|
|
181
|
+
desiredReplicationCount: 1
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
id: 0,
|
|
185
|
+
desiredReplicationCount: 1
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
}).toThrow('region id must be a string');
|
|
190
|
+
});
|
|
191
|
+
test('desiredReplicationCount is not an integer', () => {
|
|
192
|
+
expect(() => {
|
|
193
|
+
validatePinPolicyStructure({
|
|
194
|
+
regions: [
|
|
195
|
+
{
|
|
196
|
+
id: 'goodRegionId',
|
|
197
|
+
desiredReplicationCount: 1
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: 'goodRegionId2',
|
|
201
|
+
desiredReplicationCount: 'string that should fail'
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
});
|
|
205
|
+
}).toThrow('desiredReplicationCount must be an integer');
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('validatePinataOptions function testing', () => {
|
|
210
|
+
test('options is not an object', () => {
|
|
211
|
+
expect(() => {
|
|
212
|
+
validatePinataOptions('test');
|
|
213
|
+
}).toThrow('options must be an object');
|
|
214
|
+
});
|
|
215
|
+
test('cidVersion is not a 0 or 1', () => {
|
|
216
|
+
const badVersion = {
|
|
217
|
+
test: 'testing'
|
|
218
|
+
};
|
|
219
|
+
expect(() => {
|
|
220
|
+
validatePinataOptions({
|
|
221
|
+
cidVersion: badVersion
|
|
222
|
+
});
|
|
223
|
+
}).toThrow('unsupported or invalid cidVersion');
|
|
224
|
+
});
|
|
225
|
+
test('wrapWithDirectory is not true or false', () => {
|
|
226
|
+
expect(() => {
|
|
227
|
+
validatePinataOptions({
|
|
228
|
+
wrapWithDirectory: 'test'
|
|
229
|
+
});
|
|
230
|
+
}).toThrow(
|
|
231
|
+
'wrapWithDirectory must be a boolean value of true or false'
|
|
232
|
+
);
|
|
233
|
+
});
|
|
234
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { PinataConfig } from '../../..';
|
|
2
|
+
import { PinataPin, PinataPinListFilterOptions } from '../pinList/pinList';
|
|
3
|
+
export default function getFilesByCount(config: PinataConfig, filters?: PinataPinListFilterOptions, maxCount?: number): {
|
|
2
4
|
[Symbol.asyncIterator]: () => {
|
|
3
5
|
next(): Promise<{
|
|
4
|
-
value:
|
|
6
|
+
value: PinataPin;
|
|
5
7
|
done: boolean;
|
|
6
8
|
}>;
|
|
7
9
|
return(): Promise<{
|
|
@@ -1,8 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { PinataConfig } from '../../..';
|
|
2
|
+
export interface PinataPinRegion {
|
|
3
|
+
regionId: string;
|
|
4
|
+
currentReplicationCount: number;
|
|
5
|
+
desiredReplicationCount: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PinataMetadata {
|
|
8
|
+
[key: string]: string | number | null;
|
|
9
|
+
}
|
|
10
|
+
export interface PinataMetadataFilter {
|
|
11
|
+
name?: string | undefined;
|
|
12
|
+
keyvalues: {
|
|
13
|
+
[key: string]: {
|
|
14
|
+
value: string | number | null;
|
|
15
|
+
op: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface PinataPin {
|
|
20
|
+
id: string | number;
|
|
21
|
+
ipfs_pin_hash: string;
|
|
22
|
+
size: number;
|
|
23
|
+
user_id: string | number;
|
|
24
|
+
date_pinned: string;
|
|
25
|
+
date_unpinned: string | null;
|
|
26
|
+
metadata: PinataMetadata;
|
|
27
|
+
regions: PinataPinRegion[];
|
|
28
|
+
}
|
|
29
|
+
export declare type PinataPinListFilterOptions = {
|
|
30
|
+
hashContains?: string | undefined;
|
|
31
|
+
pinStart?: string | undefined;
|
|
32
|
+
pinEnd?: string | undefined;
|
|
33
|
+
unpinStart?: string | undefined;
|
|
34
|
+
unpinEnd?: string | undefined;
|
|
35
|
+
pinSizeMin?: number | undefined;
|
|
36
|
+
pinSizeMax?: number | undefined;
|
|
37
|
+
status?: string | undefined;
|
|
38
|
+
pageLimit?: number | undefined;
|
|
39
|
+
pageOffset?: number | undefined;
|
|
40
|
+
metadata?: PinataMetadataFilter | undefined;
|
|
41
|
+
};
|
|
42
|
+
export interface PinataPinListResponse {
|
|
43
|
+
rows: PinataPin[];
|
|
44
|
+
}
|
|
45
|
+
export default function pinList(config: PinataConfig, filters?: PinataPinListFilterOptions): Promise<PinataPinListResponse>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export default function testAuthentication(config: any): Promise<unknown>;
|
|
1
|
+
import { PinataConfig } from '../..';
|
|
2
|
+
export interface PinataTestAuthenticationResponse {
|
|
3
|
+
authenticated: boolean;
|
|
4
|
+
}
|
|
5
|
+
export default function testAuthentication(config: PinataConfig): Promise<PinataTestAuthenticationResponse>;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @param {string} pinataApiKey
|
|
4
|
-
* @param {string} pinataSecretApiKey
|
|
5
|
-
* @returns {Promise<unknown>}
|
|
6
|
-
*/
|
|
7
|
-
export default function userPinnedDataTotal(config: any): Promise<unknown>;
|
|
1
|
+
import { PinataConfig } from '../..';
|
|
2
|
+
export default function userPinnedDataTotal(config: PinataConfig): Promise<number>;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @param {string} pinataSecretApiKey
|
|
5
|
-
* @param {*} ipfsPinHash
|
|
6
|
-
* @param {*} metadata
|
|
7
|
-
* @returns {Promise<unknown>}
|
|
8
|
-
*/
|
|
9
|
-
export default function hashMetadata(config: any, ipfsPinHash: any, metadata: any): Promise<unknown>;
|
|
1
|
+
import { PinataConfig } from '../..';
|
|
2
|
+
import { PinataMetadata } from '../data/pinList/pinList';
|
|
3
|
+
export default function hashMetadata(config: PinataConfig, ipfsPinHash: string, metadata: PinataMetadata): Promise<any>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './pinJobs/pinJobs';
|
|
2
|
+
export * from './pinJobs/queryBuilder';
|
|
3
|
+
export * from './hashMetadata';
|
|
4
|
+
export * from './pinByHash';
|
|
5
|
+
export * from './pinFileToIPFS';
|
|
6
|
+
export * from './pinFromFS';
|
|
7
|
+
export * from './pinJSONToIPFS';
|
|
8
|
+
export * from './unpin';
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { PinataConfig } from '../..';
|
|
2
|
+
import { PinataOptions } from './pinFileToIPFS';
|
|
3
|
+
import { PinataMetadata } from '../data/pinList/pinList';
|
|
4
|
+
export interface PinataPinByHashPinOptions {
|
|
5
|
+
pinataMetadata?: PinataMetadata;
|
|
6
|
+
pinataOptions?: PinataOptions;
|
|
7
|
+
}
|
|
8
|
+
export interface PinataPinByHashResponse {
|
|
9
|
+
id: number | string;
|
|
10
|
+
ipfsHash: string;
|
|
11
|
+
status: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
export default function pinByHash(config: PinataConfig, hashToPin: string, options: any): Promise<any>;
|