@pinata/sdk 2.0.0 → 3.0.0
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/LICENSE +1 -2
- package/README.md +58 -695
- package/index.d.ts +9 -0
- package/index.js +6 -0
- package/index.mjs +4 -0
- package/legacy.js +15 -0
- package/package.json +58 -84
- package/react/index.d.ts +1 -0
- package/react/index.js +3 -0
- package/react/index.mjs +1 -0
- package/.babelrc +0 -5
- package/.editorconfig +0 -12
- package/.eslintrc +0 -173
- package/.husky/pre-commit +0 -6
- package/.nvmrc +0 -1
- package/.travis.yml +0 -5
- package/lib/pinata-sdk.js +0 -24514
- package/lib/pinata-sdk.min.js +0 -22
- package/pinata.png +0 -0
- package/src/commands/data/getFilesByCount/getFilesByCount.ts +0 -66
- package/src/commands/data/index.ts +0 -4
- package/src/commands/data/pinList/pinList.ts +0 -77
- package/src/commands/data/pinList/queryBuilder.ts +0 -239
- package/src/commands/data/testAuthentication.ts +0 -31
- package/src/commands/data/userPinnedDataTotal.ts +0 -24
- package/src/commands/pinning/hashMetadata.ts +0 -56
- package/src/commands/pinning/index.ts +0 -8
- package/src/commands/pinning/pinByHash.ts +0 -65
- package/src/commands/pinning/pinFileToIPFS.ts +0 -118
- package/src/commands/pinning/pinFromFS.ts +0 -50
- package/src/commands/pinning/pinJSONToIPFS.ts +0 -47
- package/src/commands/pinning/pinJobs/pinJobs.ts +0 -50
- package/src/commands/pinning/pinJobs/queryBuilder.ts +0 -75
- package/src/commands/pinning/unpin.ts +0 -32
- package/src/constants.ts +0 -4
- package/src/index.ts +0 -123
- package/src/third-party/base-path-converter.d.ts +0 -3
- package/src/third-party/is-ipfs.d.ts +0 -5
- package/src/util/errorResponse.ts +0 -10
- package/src/util/validators.ts +0 -182
- package/test/commands/data/getFilesByCount/getFilesByCount.test.ts +0 -212
- package/test/commands/data/pinList/pinList.test.ts +0 -102
- package/test/commands/data/pinList/queryBuilder.test.ts +0 -439
- package/test/commands/data/pinlist-sample-api.ts +0 -540
- package/test/commands/data/testAuthentication.test.ts +0 -34
- package/test/commands/data/userPinnedDataTotal.test.ts +0 -29
- package/test/commands/pinning/hashMetadata.test.ts +0 -76
- package/test/commands/pinning/pinByHash.test.ts +0 -46
- package/test/commands/pinning/pinFileToIPFS.test.ts +0 -53
- package/test/commands/pinning/pinFromFS.ts +0 -32
- package/test/commands/pinning/pinJSONToIPFS.test.ts +0 -42
- package/test/commands/pinning/pinJobs/pinJobs.test.ts +0 -29
- package/test/commands/pinning/pinJobs/queryBuilder.test.ts +0 -120
- package/test/commands/pinning/unpin.test.ts +0 -46
- package/test/util/validators.test.ts +0 -234
- package/tsconfig.json +0 -23
- package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +0 -14
- package/types/commands/data/index.d.ts +0 -4
- package/types/commands/data/pinList/pinList.d.ts +0 -45
- package/types/commands/data/pinList/queryBuilder.d.ts +0 -1
- package/types/commands/data/testAuthentication.d.ts +0 -5
- package/types/commands/data/userPinnedDataTotal.d.ts +0 -2
- package/types/commands/pinning/hashMetadata.d.ts +0 -3
- package/types/commands/pinning/hashPinPolicy.d.ts +0 -9
- package/types/commands/pinning/index.d.ts +0 -8
- package/types/commands/pinning/pinByHash.d.ts +0 -14
- package/types/commands/pinning/pinFileToIPFS.d.ts +0 -25
- package/types/commands/pinning/pinFromFS.d.ts +0 -3
- package/types/commands/pinning/pinJSONToIPFS.d.ts +0 -3
- package/types/commands/pinning/pinJobs/pinJobs.d.ts +0 -20
- package/types/commands/pinning/pinJobs/queryBuilder.d.ts +0 -1
- package/types/commands/pinning/unpin.d.ts +0 -2
- package/types/commands/pinning/userPinPolicy.d.ts +0 -8
- package/types/constants.d.ts +0 -2
- package/types/index.d.ts +0 -38
- package/types/util/errorResponse.d.ts +0 -1
- package/types/util/validators.d.ts +0 -37
- package/webpack.config.js +0 -58
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import pinByHash from '../../../src/commands/pinning/pinByHash';
|
|
3
|
-
|
|
4
|
-
jest.mock('axios');
|
|
5
|
-
|
|
6
|
-
//common values
|
|
7
|
-
const badHashToPin = 'test';
|
|
8
|
-
const goodHashToPin = 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp';
|
|
9
|
-
|
|
10
|
-
test('No hashToPin value is provided should error', () => {
|
|
11
|
-
expect(() => {
|
|
12
|
-
pinByHash('test', 'test');
|
|
13
|
-
}).toThrow();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Invalid HashToPin value is provided', () => {
|
|
17
|
-
expect(() => {
|
|
18
|
-
pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badHashToPin);
|
|
19
|
-
}).toThrow();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('200 status is returned', () => {
|
|
23
|
-
const goodStatus = {
|
|
24
|
-
status: 200,
|
|
25
|
-
data: 'testData'
|
|
26
|
-
};
|
|
27
|
-
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
28
|
-
expect.assertions(1);
|
|
29
|
-
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).resolves.toEqual(goodStatus.data);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('Result other than 200 status is returned', () => {
|
|
33
|
-
const badStatus = {
|
|
34
|
-
status: 700
|
|
35
|
-
};
|
|
36
|
-
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
37
|
-
expect.assertions(1);
|
|
38
|
-
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).rejects.toEqual(Error(`unknown server response while adding to pin queue: ${badStatus}`));
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('Rejection handled', () => {
|
|
42
|
-
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
43
|
-
expect.assertions(1);
|
|
44
|
-
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).rejects.toEqual('test error');
|
|
45
|
-
});
|
|
46
|
-
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import pinFileToIPFS from '../../../src/commands/pinning/pinFileToIPFS';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import NodeFormData from 'form-data';
|
|
5
|
-
jest.mock('axios');
|
|
6
|
-
|
|
7
|
-
//common values
|
|
8
|
-
const nonStream = 'test';
|
|
9
|
-
const validStream = fs.createReadStream('./pinata.png');
|
|
10
|
-
const validFormData = new NodeFormData();
|
|
11
|
-
validFormData.append('file', validStream, {filepath: 'test/filepath'});
|
|
12
|
-
|
|
13
|
-
test('non-readableStream and non-formData is passed in', () => {
|
|
14
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, nonStream)).rejects.toEqual(Error('readStream is not a readable stream or form data'));
|
|
15
|
-
|
|
16
|
-
return undefined;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('200 status is returned with valid stream', () => {
|
|
20
|
-
const goodStatus = {
|
|
21
|
-
status: 200,
|
|
22
|
-
data: 'testData'
|
|
23
|
-
};
|
|
24
|
-
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
25
|
-
expect.assertions(1);
|
|
26
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream, {pinataMetadata: { name: 'text.txt'}})).resolves.toEqual(goodStatus.data);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('200 status is returned with valid form data', () => {
|
|
30
|
-
const goodStatus = {
|
|
31
|
-
status: 200,
|
|
32
|
-
data: 'testData'
|
|
33
|
-
};
|
|
34
|
-
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
35
|
-
expect.assertions(1);
|
|
36
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validFormData, {pinataMetadata: { name: 'text.txt'}})).resolves.toEqual(goodStatus.data);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('Result other than 200 status is returned', () => {
|
|
40
|
-
const badStatus = {
|
|
41
|
-
status: 700
|
|
42
|
-
};
|
|
43
|
-
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
44
|
-
expect.assertions(1);
|
|
45
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream, {pinataMetadata: { name: 'text.txt'}})).rejects.toEqual(Error(`unknown server response while pinning File to IPFS: ${badStatus}`));
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('Rejection handled', () => {
|
|
49
|
-
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
50
|
-
expect.assertions(1);
|
|
51
|
-
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream, {pinataMetadata: { name: 'text.txt'}})).rejects.toEqual('test error');
|
|
52
|
-
});
|
|
53
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import pinFromFS from '../../../src/commands/pinning/pinFromFS';
|
|
3
|
-
jest.mock('axios');
|
|
4
|
-
|
|
5
|
-
//common values
|
|
6
|
-
const testSource = './testing/testing';
|
|
7
|
-
|
|
8
|
-
test('200 status is returned', () => {
|
|
9
|
-
const goodStatus = {
|
|
10
|
-
status: 200,
|
|
11
|
-
data: 'testData'
|
|
12
|
-
};
|
|
13
|
-
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
14
|
-
expect.assertions(1);
|
|
15
|
-
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).resolves.toEqual(goodStatus.data);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('Result other than 200 status is returned', () => {
|
|
19
|
-
const badStatus = {
|
|
20
|
-
status: 700
|
|
21
|
-
};
|
|
22
|
-
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
23
|
-
expect.assertions(1);
|
|
24
|
-
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).rejects.toEqual(Error(`unknown server response while pinning to IPFS: ${badStatus}`));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('Rejection handled', () => {
|
|
28
|
-
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
29
|
-
expect.assertions(1);
|
|
30
|
-
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).rejects.toEqual('test error');
|
|
31
|
-
});
|
|
32
|
-
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import pinJSONToIPFS from '../../../src/commands/pinning/pinJSONToIPFS';
|
|
3
|
-
|
|
4
|
-
jest.mock('axios');
|
|
5
|
-
|
|
6
|
-
//common values
|
|
7
|
-
const badJSON = 'test';
|
|
8
|
-
const goodJSON = {
|
|
9
|
-
test: 'test'
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
test('non-object is passed in', () => {
|
|
13
|
-
expect(() => {
|
|
14
|
-
pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badJSON);
|
|
15
|
-
}).toThrow('body must be a valid JSON object');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('200 status is returned', () => {
|
|
19
|
-
const goodStatus = {
|
|
20
|
-
status: 200,
|
|
21
|
-
data: 'testData'
|
|
22
|
-
};
|
|
23
|
-
(axios.post as jest.Mock).mockResolvedValue(goodStatus);
|
|
24
|
-
expect.assertions(1);
|
|
25
|
-
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).resolves.toEqual(goodStatus.data);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('Result other than 200 status is returned', () => {
|
|
29
|
-
const badStatus = {
|
|
30
|
-
status: 700
|
|
31
|
-
};
|
|
32
|
-
(axios.post as jest.Mock).mockResolvedValue(badStatus);
|
|
33
|
-
expect.assertions(1);
|
|
34
|
-
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).rejects.toEqual(Error(`unknown server response while pinning JSON to IPFS: ${badStatus}`));
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('Rejection handled', () => {
|
|
38
|
-
(axios.post as jest.Mock).mockRejectedValue('test error');
|
|
39
|
-
expect.assertions(1);
|
|
40
|
-
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).rejects.toEqual('test error');
|
|
41
|
-
});
|
|
42
|
-
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import pinJobs from '../../../../src/commands/pinning/pinJobs/pinJobs';
|
|
3
|
-
|
|
4
|
-
jest.mock('axios');
|
|
5
|
-
|
|
6
|
-
test('Result other than 200 status is returned', () => {
|
|
7
|
-
const badStatus = {
|
|
8
|
-
status: 700
|
|
9
|
-
};
|
|
10
|
-
(axios.get as jest.Mock).mockResolvedValue(badStatus);
|
|
11
|
-
expect.assertions(1);
|
|
12
|
-
expect(pinJobs({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual(Error(`unknown server response while attempting to retrieve pin jobs: ${badStatus}`));
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('200 status is returned', () => {
|
|
16
|
-
const goodStatus = {
|
|
17
|
-
status: 200,
|
|
18
|
-
data: 'testData'
|
|
19
|
-
};
|
|
20
|
-
(axios.get as jest.Mock).mockResolvedValue(goodStatus);
|
|
21
|
-
expect.assertions(1);
|
|
22
|
-
expect(pinJobs({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).resolves.toEqual(goodStatus.data);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('Rejection handled', () => {
|
|
26
|
-
(axios.get as jest.Mock).mockRejectedValue('test error');
|
|
27
|
-
expect.assertions(1);
|
|
28
|
-
expect(pinJobs({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual('test error');
|
|
29
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import queryBuilder from '../../../../src/commands/pinning/pinJobs/queryBuilder';
|
|
2
|
-
|
|
3
|
-
const baseUrl = 'testing.com/test';
|
|
4
|
-
const badFilterValue = 'badFilterValue';
|
|
5
|
-
const goodHashToPin = 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp';
|
|
6
|
-
|
|
7
|
-
describe('queryBuilder no params provided', () => {
|
|
8
|
-
test('if no baseUrl is provided', () => {
|
|
9
|
-
// expect(() => {
|
|
10
|
-
// queryBuilder();
|
|
11
|
-
// }).toThrow('no baseUrl provided');
|
|
12
|
-
});
|
|
13
|
-
test('if no filters are provided, return a non filtered url', () => {
|
|
14
|
-
expect(queryBuilder(baseUrl)).toEqual(baseUrl);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('queryBuilder multiple filters', () => {
|
|
19
|
-
test('one bad filter and one good are provided', () => {
|
|
20
|
-
const filter = {
|
|
21
|
-
limit: 5,
|
|
22
|
-
offset: badFilterValue
|
|
23
|
-
};
|
|
24
|
-
expect(() => {
|
|
25
|
-
queryBuilder(baseUrl, filter);
|
|
26
|
-
}).toThrow(`Invalid offset: ${badFilterValue}. Please provide a positive integer for the offset`);
|
|
27
|
-
});
|
|
28
|
-
test('two good filters are provided', () => {
|
|
29
|
-
const filter = {
|
|
30
|
-
status: 'searching',
|
|
31
|
-
offset: 5
|
|
32
|
-
};
|
|
33
|
-
expect(queryBuilder(baseUrl, filter)).toEqual(`${baseUrl}?status=searching&offset=5`);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('queryBuilder filter: sort', () => {
|
|
38
|
-
test('unknown sort is provided', () => {
|
|
39
|
-
const filter = {
|
|
40
|
-
sort: badFilterValue
|
|
41
|
-
};
|
|
42
|
-
expect(() => {
|
|
43
|
-
queryBuilder(baseUrl, filter);
|
|
44
|
-
}).toThrow(`Unknown sort value: ${badFilterValue} provided`);
|
|
45
|
-
});
|
|
46
|
-
test('good sort value is provided', () => {
|
|
47
|
-
const filter = {
|
|
48
|
-
sort: 'ASC'
|
|
49
|
-
};
|
|
50
|
-
expect(queryBuilder(baseUrl, filter)).toEqual(`${baseUrl}?sort=ASC`);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('queryBuilder filter: status', () => {
|
|
55
|
-
test('unknown status is provided', () => {
|
|
56
|
-
const filter = {
|
|
57
|
-
status: badFilterValue
|
|
58
|
-
};
|
|
59
|
-
expect(() => {
|
|
60
|
-
queryBuilder(baseUrl, filter);
|
|
61
|
-
}).toThrow(`Unknown status value: ${badFilterValue} provided`);
|
|
62
|
-
});
|
|
63
|
-
test('good status value is provided', () => {
|
|
64
|
-
const filter = {
|
|
65
|
-
status: 'searching'
|
|
66
|
-
};
|
|
67
|
-
expect(queryBuilder(baseUrl, filter)).toEqual(`${baseUrl}?status=searching`);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('queryBuilder filter: ipfs_pin_hash', () => {
|
|
72
|
-
test('bad hash is provided', () => {
|
|
73
|
-
const filter = {
|
|
74
|
-
ipfs_pin_hash: badFilterValue
|
|
75
|
-
};
|
|
76
|
-
expect(() => {
|
|
77
|
-
queryBuilder(baseUrl, filter);
|
|
78
|
-
}).toThrow(`Invalid IPFS hash: ${badFilterValue}`);
|
|
79
|
-
});
|
|
80
|
-
test('good hash is provided', () => {
|
|
81
|
-
const filter = {
|
|
82
|
-
ipfs_pin_hash: goodHashToPin
|
|
83
|
-
};
|
|
84
|
-
expect(queryBuilder(baseUrl, filter)).toEqual(`${baseUrl}?ipfs_pin_hash=${goodHashToPin}`);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('queryBuilder filter: limit', () => {
|
|
89
|
-
test('bad hash is provided', () => {
|
|
90
|
-
const filter = {
|
|
91
|
-
limit: badFilterValue
|
|
92
|
-
};
|
|
93
|
-
expect(() => {
|
|
94
|
-
queryBuilder(baseUrl, filter);
|
|
95
|
-
}).toThrow(`Invalid limit: ${badFilterValue}. Valid limits are 1-100`);
|
|
96
|
-
});
|
|
97
|
-
test('good limit is provided', () => {
|
|
98
|
-
const filter = {
|
|
99
|
-
limit: 5
|
|
100
|
-
};
|
|
101
|
-
expect(queryBuilder(baseUrl, filter)).toEqual(`${baseUrl}?limit=5`);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('queryBuilder filter: offset', () => {
|
|
106
|
-
test('bad hash is provided', () => {
|
|
107
|
-
const filter = {
|
|
108
|
-
offset: badFilterValue
|
|
109
|
-
};
|
|
110
|
-
expect(() => {
|
|
111
|
-
queryBuilder(baseUrl, filter);
|
|
112
|
-
}).toThrow(`Invalid offset: ${badFilterValue}. Please provide a positive integer for the offset`);
|
|
113
|
-
});
|
|
114
|
-
test('good offset is provided', () => {
|
|
115
|
-
const filter = {
|
|
116
|
-
offset: 5
|
|
117
|
-
};
|
|
118
|
-
expect(queryBuilder(baseUrl, filter)).toEqual(`${baseUrl}?offset=5`);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import unpin from '../../../src/commands/pinning/unpin';
|
|
3
|
-
|
|
4
|
-
jest.mock('axios');
|
|
5
|
-
|
|
6
|
-
//common values
|
|
7
|
-
const badHashToUnpin = 'test';
|
|
8
|
-
const goodHashToUnpin = 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp';
|
|
9
|
-
|
|
10
|
-
test('No hashToUnpin value is provided should error', () => {
|
|
11
|
-
expect(() => {
|
|
12
|
-
unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' });
|
|
13
|
-
}).toThrow('hashToUnpin value is required for removing a pin from Pinata');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Invalid hashToUnpin value is provided', () => {
|
|
17
|
-
expect(() => {
|
|
18
|
-
unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badHashToUnpin);
|
|
19
|
-
}).toThrow(`${badHashToUnpin} is an invalid IPFS CID`);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('200 status is returned', () => {
|
|
23
|
-
const goodStatus = {
|
|
24
|
-
status: 200,
|
|
25
|
-
data: 'testData'
|
|
26
|
-
};
|
|
27
|
-
(axios.delete as jest.Mock).mockResolvedValue(goodStatus);
|
|
28
|
-
expect.assertions(1);
|
|
29
|
-
expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).resolves.toEqual(goodStatus.data);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('Result other than 200 status is returned', () => {
|
|
33
|
-
const badStatus = {
|
|
34
|
-
status: 700
|
|
35
|
-
};
|
|
36
|
-
(axios.delete as jest.Mock).mockResolvedValue(badStatus);
|
|
37
|
-
expect.assertions(1);
|
|
38
|
-
expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).rejects.toEqual(Error(`unknown server response while removing pin from IPFS: ${badStatus}`));
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('Rejection handled', () => {
|
|
42
|
-
(axios.delete as jest.Mock).mockRejectedValue('test error');
|
|
43
|
-
expect.assertions(1);
|
|
44
|
-
expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).rejects.toEqual('test error');
|
|
45
|
-
});
|
|
46
|
-
|
|
@@ -1,234 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": [
|
|
3
|
-
"src/**/*.ts", "src/**/*.js"],
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"emitDeclarationOnly": true,
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"allowJs": true,
|
|
9
|
-
"outDir": "types",
|
|
10
|
-
"target": "es5",
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
"lib": ["es2017", "es7", "es6", "dom"],
|
|
13
|
-
"strict": true,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
"resolveJsonModule": true
|
|
16
|
-
},
|
|
17
|
-
"exclude": [
|
|
18
|
-
"node_modules",
|
|
19
|
-
"lib",
|
|
20
|
-
"test",
|
|
21
|
-
"coverage"
|
|
22
|
-
]
|
|
23
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PinataConfig } from '../../..';
|
|
2
|
-
import { PinataPin, PinataPinListFilterOptions } from '../pinList/pinList';
|
|
3
|
-
export default function getFilesByCount(config: PinataConfig, filters?: PinataPinListFilterOptions, maxCount?: number): {
|
|
4
|
-
[Symbol.asyncIterator]: () => {
|
|
5
|
-
next(): Promise<{
|
|
6
|
-
value: PinataPin;
|
|
7
|
-
done: boolean;
|
|
8
|
-
}>;
|
|
9
|
-
return(): Promise<{
|
|
10
|
-
value: number;
|
|
11
|
-
done: boolean;
|
|
12
|
-
}>;
|
|
13
|
-
};
|
|
14
|
-
};
|