@pinata/sdk 1.2.0 → 2.0.0-beta.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.
Files changed (88) hide show
  1. package/.babelrc +1 -1
  2. package/.eslintrc +7 -7
  3. package/.husky/pre-commit +6 -0
  4. package/.nvmrc +1 -1
  5. package/README.md +22 -6
  6. package/lib/pinata-sdk.js +780 -604
  7. package/lib/pinata-sdk.min.js +5 -5
  8. package/package.json +83 -71
  9. package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +9 -13
  10. package/src/commands/data/index.ts +4 -0
  11. package/src/commands/data/pinList/pinList.ts +77 -0
  12. package/src/commands/data/pinList/{queryBuilder.js → queryBuilder.ts} +6 -16
  13. package/src/commands/data/{testAuthentication.js → testAuthentication.ts} +10 -18
  14. package/src/commands/data/userPinnedDataTotal.ts +24 -0
  15. package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +12 -21
  16. package/src/commands/pinning/index.ts +8 -0
  17. package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +24 -20
  18. package/src/commands/pinning/{pinFileToIPFS.js → pinFileToIPFS.ts} +29 -24
  19. package/src/commands/pinning/{pinFromFS.js → pinFromFS.ts} +17 -39
  20. package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +8 -20
  21. package/src/commands/pinning/pinJobs/pinJobs.ts +50 -0
  22. package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
  23. package/src/commands/pinning/{unpin.js → unpin.ts} +6 -19
  24. package/src/constants.ts +4 -0
  25. package/src/index.ts +120 -0
  26. package/src/third-party/base-path-converter.d.ts +3 -0
  27. package/src/third-party/is-ipfs.d.ts +5 -0
  28. package/src/third-party/recursive-fs.d.ts +5 -0
  29. package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
  30. package/src/util/validators.ts +175 -0
  31. package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +36 -39
  32. package/test/commands/data/pinList/pinList.test.ts +102 -0
  33. package/test/commands/data/pinList/{queryBuilder.test.js → queryBuilder.test.ts} +9 -10
  34. package/test/commands/data/pinlist-sample-api.ts +540 -0
  35. package/test/commands/data/testAuthentication.test.ts +34 -0
  36. package/test/commands/data/userPinnedDataTotal.test.ts +29 -0
  37. package/test/commands/pinning/hashMetadata.test.ts +76 -0
  38. package/test/commands/pinning/pinByHash.test.ts +46 -0
  39. package/test/commands/pinning/pinFileToIPFS.test.ts +53 -0
  40. package/test/commands/pinning/pinFromFS.ts +32 -0
  41. package/test/commands/pinning/pinJSONToIPFS.test.ts +42 -0
  42. package/test/commands/pinning/pinJobs/pinJobs.test.ts +29 -0
  43. package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
  44. package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +9 -10
  45. package/test/util/{validators.test.js → validators.test.ts} +60 -18
  46. package/tsconfig.json +2 -2
  47. package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +4 -2
  48. package/types/commands/data/index.d.ts +4 -0
  49. package/types/commands/data/pinList/pinList.d.ts +45 -8
  50. package/types/commands/data/pinList/queryBuilder.d.ts +1 -7
  51. package/types/commands/data/testAuthentication.d.ts +5 -7
  52. package/types/commands/data/userPinnedDataTotal.d.ts +2 -7
  53. package/types/commands/pinning/hashMetadata.d.ts +3 -9
  54. package/types/commands/pinning/hashPinPolicy.d.ts +1 -1
  55. package/types/commands/pinning/index.d.ts +8 -0
  56. package/types/commands/pinning/pinByHash.d.ts +14 -9
  57. package/types/commands/pinning/pinFileToIPFS.d.ts +25 -1
  58. package/types/commands/pinning/pinFromFS.d.ts +3 -9
  59. package/types/commands/pinning/pinJSONToIPFS.d.ts +3 -9
  60. package/types/commands/pinning/pinJobs/pinJobs.d.ts +20 -8
  61. package/types/commands/pinning/pinJobs/queryBuilder.d.ts +1 -7
  62. package/types/commands/pinning/unpin.d.ts +2 -8
  63. package/types/commands/pinning/userPinPolicy.d.ts +1 -1
  64. package/types/constants.d.ts +2 -1
  65. package/types/index.d.ts +38 -331
  66. package/types/util/errorResponse.d.ts +1 -1
  67. package/types/util/validators.d.ts +43 -26
  68. package/webpack.config.js +50 -53
  69. package/src/commands/data/pinList/pinList.js +0 -41
  70. package/src/commands/data/userPinnedDataTotal.js +0 -36
  71. package/src/commands/pinning/hashPinPolicy.js +0 -57
  72. package/src/commands/pinning/pinJobs/pinJobs.js +0 -42
  73. package/src/commands/pinning/userPinPolicy.js +0 -46
  74. package/src/constants.js +0 -1
  75. package/src/index.js +0 -262
  76. package/src/util/validators.js +0 -118
  77. package/test/commands/data/pinList/pinList.test.js +0 -98
  78. package/test/commands/data/pinlist-sample-api.js +0 -540
  79. package/test/commands/data/testAuthentication.test.js +0 -30
  80. package/test/commands/data/userPinnedDataTotal.test.js +0 -29
  81. package/test/commands/pinning/hashMetadata.test.js +0 -77
  82. package/test/commands/pinning/hashPinPolicy.test.js +0 -65
  83. package/test/commands/pinning/pinByHash.test.js +0 -47
  84. package/test/commands/pinning/pinFileToIPFS.test.js +0 -55
  85. package/test/commands/pinning/pinFromFS.js +0 -33
  86. package/test/commands/pinning/pinJSONToIPFS.test.js +0 -43
  87. package/test/commands/pinning/pinJobs/pinJobs.test.js +0 -29
  88. package/test/commands/pinning/userPinPolicy.test.js +0 -51
@@ -1,65 +0,0 @@
1
- import axios from 'axios';
2
- import hashPinPolicy from'../../../src/commands/pinning/hashPinPolicy';
3
-
4
- jest.mock('axios');
5
-
6
- //common values
7
- const badHash = 'test';
8
- const goodHash = 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp';
9
- const newPinPolicy = {
10
- regions: [
11
- {
12
- id: 'FRA1',
13
- desiredReplicationCount: 2
14
- },
15
- {
16
- id: 'NYC1',
17
- desiredReplicationCount: 2
18
- }
19
- ]
20
- };
21
-
22
- test('No ipfsPinHash value provided should error', () => {
23
- expect(() => {
24
- hashPinPolicy('test', 'test', null, newPinPolicy);
25
- }).toThrow();
26
- });
27
-
28
- test('Invalid ipfsPinHash value is provided', () => {
29
- expect(() => {
30
- hashPinPolicy('test', 'test', badHash, newPinPolicy);
31
- }).toThrow();
32
- });
33
-
34
- test('No newPinPolicy value provided should error', () => {
35
- expect(() => {
36
- hashPinPolicy('test', 'test', goodHash);
37
- }).toThrow();
38
- });
39
-
40
- test('200 status is returned', () => {
41
- const goodStatus = {
42
- status: 200,
43
- data: 'testData'
44
- };
45
- axios.put.mockResolvedValue(goodStatus);
46
- expect.assertions(1);
47
- expect(hashPinPolicy('test', 'test', goodHash, newPinPolicy)).resolves.toEqual(goodStatus.data);
48
- });
49
-
50
- test('Result other than 200 status is returned', () => {
51
- const badStatus = {
52
- status: 700
53
- };
54
- axios.put.mockResolvedValue(badStatus);
55
- expect.assertions(1);
56
- expect(hashPinPolicy('test', 'test', goodHash, newPinPolicy)).rejects.toEqual(Error(`unknown server response while changing pin policy for hash: ${badStatus}`));
57
- });
58
-
59
- test('Rejection handled', () => {
60
- axios.put.mockRejectedValue('test error');
61
- expect.assertions(1);
62
- expect(hashPinPolicy('test', 'test', goodHash, newPinPolicy)).rejects.toEqual('test error');
63
- });
64
-
65
-
@@ -1,47 +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('test', '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.mockResolvedValue(goodStatus);
28
- expect.assertions(1);
29
- expect(pinByHash('test', '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.mockResolvedValue(badStatus);
37
- expect.assertions(1);
38
- expect(pinByHash('test', 'test', goodHashToPin)).rejects.toEqual(Error(`unknown server response while adding to pin queue: ${badStatus}`));
39
- });
40
-
41
- test('Rejection handled', () => {
42
- axios.post.mockRejectedValue('test error');
43
- expect.assertions(1);
44
- expect(pinByHash('test', 'test', goodHashToPin)).rejects.toEqual('test error');
45
- });
46
-
47
-
@@ -1,55 +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
-
14
- test('non-readableStream and non-formData is passed in', () => {
15
- expect(pinFileToIPFS('test', 'test', nonStream)).rejects.toEqual(Error('readStream is not a readable stream or form data'));
16
-
17
- return undefined;
18
- });
19
-
20
- test('200 status is returned with valid stream', () => {
21
- const goodStatus = {
22
- status: 200,
23
- data: 'testData'
24
- };
25
- axios.post.mockResolvedValue(goodStatus);
26
- expect.assertions(1);
27
- expect(pinFileToIPFS('test', 'test', validStream)).resolves.toEqual(goodStatus.data);
28
- });
29
-
30
- test('200 status is returned with valid form data', () => {
31
- const goodStatus = {
32
- status: 200,
33
- data: 'testData'
34
- };
35
- axios.post.mockResolvedValue(goodStatus);
36
- expect.assertions(1);
37
- expect(pinFileToIPFS('test', 'test', validFormData)).resolves.toEqual(goodStatus.data);
38
- });
39
-
40
- test('Result other than 200 status is returned', () => {
41
- const badStatus = {
42
- status: 700
43
- };
44
- axios.post.mockResolvedValue(badStatus);
45
- expect.assertions(1);
46
- expect(pinFileToIPFS('test', 'test', validStream)).rejects.toEqual(Error(`unknown server response while pinning File to IPFS: ${badStatus}`));
47
- });
48
-
49
- test('Rejection handled', () => {
50
- axios.post.mockRejectedValue('test error');
51
- expect.assertions(1);
52
- expect(pinFileToIPFS('test', 'test', validStream)).rejects.toEqual('test error');
53
- });
54
-
55
-
@@ -1,33 +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.mockResolvedValue(goodStatus);
14
- expect.assertions(1);
15
- expect(pinFromFS('test', '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.mockResolvedValue(badStatus);
23
- expect.assertions(1);
24
- expect(pinFromFS('test', 'test', testSource)).rejects.toEqual(Error(`unknown server response while pinning to IPFS: ${badStatus}`));
25
- });
26
-
27
- test('Rejection handled', () => {
28
- axios.post.mockRejectedValue('test error');
29
- expect.assertions(1);
30
- expect(pinFromFS('test', 'test', testSource)).rejects.toEqual('test error');
31
- });
32
-
33
-
@@ -1,43 +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('test', '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.mockResolvedValue(goodStatus);
24
- expect.assertions(1);
25
- expect(pinJSONToIPFS('test', '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.mockResolvedValue(badStatus);
33
- expect.assertions(1);
34
- expect(pinJSONToIPFS('test', 'test', goodJSON)).rejects.toEqual(Error(`unknown server response while pinning JSON to IPFS: ${badStatus}`));
35
- });
36
-
37
- test('Rejection handled', () => {
38
- axios.post.mockRejectedValue('test error');
39
- expect.assertions(1);
40
- expect(pinJSONToIPFS('test', 'test', goodJSON)).rejects.toEqual('test error');
41
- });
42
-
43
-
@@ -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.mockResolvedValue(badStatus);
11
- expect.assertions(1);
12
- expect(pinJobs('test', '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.mockResolvedValue(goodStatus);
21
- expect.assertions(1);
22
- expect(pinJobs('test', 'test')).resolves.toEqual(goodStatus.data);
23
- });
24
-
25
- test('Rejection handled', () => {
26
- axios.get.mockRejectedValue('test error');
27
- expect.assertions(1);
28
- expect(pinJobs('test', 'test')).rejects.toEqual('test error');
29
- });
@@ -1,51 +0,0 @@
1
- import axios from 'axios';
2
- import userPinPolicy from'../../../src/commands/pinning/userPinPolicy';
3
-
4
- jest.mock('axios');
5
-
6
- //common values
7
- const newPinPolicy = {
8
- regions: [
9
- {
10
- id: 'FRA1',
11
- desiredReplicationCount: 2
12
- },
13
- {
14
- id: 'NYC1',
15
- desiredReplicationCount: 2
16
- }
17
- ]
18
- };
19
-
20
- test('No newPinPolicy value provided should error', () => {
21
- expect(() => {
22
- userPinPolicy('test', 'test');
23
- }).toThrow();
24
- });
25
-
26
- test('200 status is returned', () => {
27
- const goodStatus = {
28
- status: 200,
29
- data: 'testData'
30
- };
31
- axios.put.mockResolvedValue(goodStatus);
32
- expect.assertions(1);
33
- expect(userPinPolicy('test', 'test', newPinPolicy)).resolves.toEqual(goodStatus.data);
34
- });
35
-
36
- test('Result other than 200 status is returned', () => {
37
- const badStatus = {
38
- status: 700
39
- };
40
- axios.put.mockResolvedValue(badStatus);
41
- expect.assertions(1);
42
- expect(userPinPolicy('test', 'test', newPinPolicy)).rejects.toEqual(Error(`unknown server response while changing pin policy for user: ${badStatus}`));
43
- });
44
-
45
- test('Rejection handled', () => {
46
- axios.put.mockRejectedValue('test error');
47
- expect.assertions(1);
48
- expect(userPinPolicy('test', 'test', newPinPolicy)).rejects.toEqual('test error');
49
- });
50
-
51
-