@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
@@ -0,0 +1,46 @@
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
+
@@ -0,0 +1,53 @@
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)).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)).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)).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)).rejects.toEqual('test error');
52
+ });
53
+
@@ -0,0 +1,32 @@
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
+
@@ -0,0 +1,42 @@
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
+
@@ -0,0 +1,29 @@
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,4 +1,4 @@
1
- import queryBuilder from './../../../../src/commands/pinning/pinJobs/queryBuilder';
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
- queryBuilder();
11
- }).toThrow('no baseUrl provided');
9
+ // expect(() => {
10
+ // queryBuilder();
11
+ // }).toThrow('no baseUrl provided');
12
12
  });
13
- test('if no filters are provided, return base url', () => {
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
 
@@ -9,13 +9,13 @@ const goodHashToUnpin = 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp';
9
9
 
10
10
  test('No hashToUnpin value is provided should error', () => {
11
11
  expect(() => {
12
- unpin('test', 'test');
12
+ unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' });
13
13
  }).toThrow('hashToUnpin value is required for removing a pin from Pinata');
14
14
  });
15
15
 
16
16
  test('Invalid hashToUnpin value is provided', () => {
17
17
  expect(() => {
18
- unpin('test', 'test', badHashToUnpin);
18
+ unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badHashToUnpin);
19
19
  }).toThrow(`${badHashToUnpin} is an invalid IPFS CID`);
20
20
  });
21
21
 
@@ -24,24 +24,23 @@ 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
- expect(unpin('test', 'test', goodHashToUnpin)).resolves.toEqual(goodStatus.data);
29
+ expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).resolves.toEqual(goodStatus.data);
30
30
  });
31
31
 
32
32
  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
- expect(unpin('test', 'test', goodHashToUnpin)).rejects.toEqual(Error(`unknown server response while removing pin from IPFS: ${badStatus}`));
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
- expect(unpin('test', 'test', goodHashToUnpin)).rejects.toEqual('test error');
44
+ expect(unpin({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToUnpin)).rejects.toEqual('test error');
45
45
  });
46
46
 
47
-
@@ -1,16 +1,54 @@
1
- import { validateApiKeys, validateHostNodes, validateMetadata, validatePinPolicyStructure, validatePinataOptions } from "../../src/util/validators";
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';
2
10
 
3
11
  describe('validateApiKeys function testing', () => {
4
12
  test('check to throw if either pinataApiKey or pinataSecretApiKey are not provided', () => {
5
13
  expect(() => {
6
14
  validateApiKeys('', 'test');
7
- }).toThrow('No pinataApiKey provided! Please provide your pinata api key as an argument when you start this script');
15
+ }).toThrow(
16
+ 'No pinataApiKey provided! Please provide your pinata api key as an argument when you start this script'
17
+ );
8
18
  expect(() => {
9
19
  validateApiKeys('test', '');
10
- }).toThrow('No pinataSecretApiKey provided! Please provide your pinata secret api key as an argument when you start this script');
20
+ }).toThrow(
21
+ 'No pinataSecretApiKey provided! Please provide your pinata secret api key as an argument when you start this script'
22
+ );
11
23
  });
12
24
  });
13
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
+ });
14
52
  describe('validateHostNodes function testing', () => {
15
53
  test('host_nodes is not an array', () => {
16
54
  const hostNodes = {
@@ -22,19 +60,18 @@ describe('validateHostNodes function testing', () => {
22
60
  });
23
61
 
24
62
  test('invalid host_node entry', () => {
25
- const validHost = '/ip4/127.0.0.1/tcp/1234/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj';
63
+ const validHost =
64
+ '/ip4/127.0.0.1/tcp/1234/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj';
26
65
  const invalidHost = 'invalid host';
27
- const hostNodes = [
28
- validHost,
29
- invalidHost
30
- ];
66
+ const hostNodes = [validHost, invalidHost];
31
67
  expect(() => {
32
68
  validateHostNodes(hostNodes);
33
- }).toThrow(`host_node array entry: ${invalidHost} is not a valid peer multiaddr`);
69
+ }).toThrow(
70
+ `host_node array entry: ${invalidHost} is not a valid peer multiaddr`
71
+ );
34
72
  });
35
73
  });
36
74
 
37
-
38
75
  describe('validateMetadata function testing', () => {
39
76
  test('name is not a string', () => {
40
77
  const badName = {
@@ -73,7 +110,9 @@ describe('validateMetadata function testing', () => {
73
110
  validateMetadata({
74
111
  keyvalues: tooManyKeyValues
75
112
  });
76
- }).toThrow('No more than 10 keyvalues can be provided for metadata entries');
113
+ }).toThrow(
114
+ 'No more than 10 keyvalues can be provided for metadata entries'
115
+ );
77
116
  });
78
117
  test('Throws error on an object being passed in as a value for a keyvalue', () => {
79
118
  const invalidValue = {
@@ -95,7 +134,9 @@ describe('validateMetadata function testing', () => {
95
134
  validateMetadata({
96
135
  keyvalues: invalidValue
97
136
  });
98
- }).toThrow('Metadata keyvalue values must be strings, booleans, or numbers');
137
+ }).toThrow(
138
+ 'Metadata keyvalue values must be strings, booleans, or numbers'
139
+ );
99
140
  });
100
141
  test('Does not throw an error if metadata is valid', () => {
101
142
  const invalidValue = {
@@ -122,14 +163,14 @@ describe('validatePinPolicyStructure function testing', () => {
122
163
  test('No Policy Provided', () => {
123
164
  expect(() => {
124
165
  validatePinPolicyStructure();
125
- }).toThrow("No pin policy provided");
166
+ }).toThrow('No pin policy provided');
126
167
  });
127
168
  test('No Regions Provided', () => {
128
169
  expect(() => {
129
170
  validatePinPolicyStructure({
130
171
  test: 'test'
131
172
  });
132
- }).toThrow("No regions provided in pin policy");
173
+ }).toThrow('No regions provided in pin policy');
133
174
  });
134
175
  test('region id is not a string', () => {
135
176
  expect(() => {
@@ -145,7 +186,7 @@ describe('validatePinPolicyStructure function testing', () => {
145
186
  }
146
187
  ]
147
188
  });
148
- }).toThrow("region id must be a string");
189
+ }).toThrow('region id must be a string');
149
190
  });
150
191
  test('desiredReplicationCount is not an integer', () => {
151
192
  expect(() => {
@@ -161,11 +202,10 @@ describe('validatePinPolicyStructure function testing', () => {
161
202
  }
162
203
  ]
163
204
  });
164
- }).toThrow("desiredReplicationCount must be an integer");
205
+ }).toThrow('desiredReplicationCount must be an integer');
165
206
  });
166
207
  });
167
208
 
168
-
169
209
  describe('validatePinataOptions function testing', () => {
170
210
  test('options is not an object', () => {
171
211
  expect(() => {
@@ -187,6 +227,8 @@ describe('validatePinataOptions function testing', () => {
187
227
  validatePinataOptions({
188
228
  wrapWithDirectory: 'test'
189
229
  });
190
- }).toThrow('wrapWithDirectory must be a boolean value of true or false');
230
+ }).toThrow(
231
+ 'wrapWithDirectory must be a boolean value of true or false'
232
+ );
191
233
  });
192
234
  });
package/tsconfig.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "include": [
3
- "src/**/*.js"
4
- ],
3
+ "src/**/*.ts", "src/**/*.js"],
5
4
  "compilerOptions": {
6
5
  "declaration": true,
7
6
  "emitDeclarationOnly": true,
7
+ "sourceMap": true,
8
8
  "allowJs": true,
9
9
  "outDir": "types",
10
10
  "target": "es5",
@@ -1,7 +1,9 @@
1
- export default function getFilesByCount(pinataApiKey: any, pinataSecretApiKey: any, filters?: {}, maxCount?: number): {
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: any;
6
+ value: PinataPin;
5
7
  done: boolean;
6
8
  }>;
7
9
  return(): Promise<{
@@ -0,0 +1,4 @@
1
+ export * from '../data/pinList/pinList';
2
+ export * from '../data/pinList/queryBuilder';
3
+ export * from './testAuthentication';
4
+ export * from './userPinnedDataTotal';
@@ -1,8 +1,45 @@
1
- /**
2
- * Pin List
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {any} filters
6
- * @returns {Promise<unknown>}
7
- */
8
- export default function pinList(pinataApiKey: string, pinataSecretApiKey: string, filters?: any): Promise<unknown>;
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;
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 @@
1
- /**
2
- * Query Builder
3
- * @param {string} baseUrl
4
- * @param {*} filters
5
- * @returns {string}
6
- */
7
- export default function queryBuilder(baseUrl: string, filters: any): string;
1
+ export default function queryBuilder(baseUrl: string, filters?: any): string;
@@ -1,7 +1,5 @@
1
- /**
2
- * Test Authentication
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @returns {Promise<unknown>}
6
- */
7
- export default function testAuthentication(pinataApiKey: string, pinataSecretApiKey: string): 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
- * User Pinned Data Total
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @returns {Promise<unknown>}
6
- */
7
- export default function userPinnedDataTotal(pinataApiKey: string, pinataSecretApiKey: string): Promise<unknown>;
1
+ import { PinataConfig } from '../..';
2
+ export default function userPinnedDataTotal(config: PinataConfig): Promise<number>;
@@ -1,9 +1,3 @@
1
- /**
2
- * Hash Meta Data
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {*} ipfsPinHash
6
- * @param {*} metadata
7
- * @returns {Promise<unknown>}
8
- */
9
- export default function hashMetadata(pinataApiKey: string, pinataSecretApiKey: string, 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>;
@@ -6,4 +6,4 @@
6
6
  * @param {*} newPinPolicy
7
7
  * @returns {Promise<unknown>}
8
8
  */
9
- export default function hashPinPolicy(pinataApiKey: string, pinataSecretApiKey: string, ipfsPinHash: any, newPinPolicy: any): Promise<unknown>;
9
+ export default function hashPinPolicy(config: any, ipfsPinHash: any, newPinPolicy: any): Promise<unknown>;
@@ -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
- * Pin By Hash
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {*} hashToPin
6
- * @param {*} options
7
- * @returns {Promise<unknown>}
8
- */
9
- export default function pinByHash(pinataApiKey: string, pinataSecretApiKey: string, hashToPin: any, options: any): Promise<unknown>;
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>;
@@ -1,3 +1,27 @@
1
+ import { PinataConfig } from '../..';
2
+ export interface PinataPinPolicyItem {
3
+ id: string;
4
+ desiredReplicationCount: number;
5
+ }
6
+ export interface PinataOptions {
7
+ hostNodes?: string[] | undefined;
8
+ cidVersion?: 0 | 1;
9
+ wrapWithDirectory?: boolean;
10
+ customPinPolicy?: {
11
+ regions: PinataPinPolicyItem[];
12
+ };
13
+ }
14
+ export interface PinataPinResponse {
15
+ IpfsHash: string;
16
+ PinSize: number;
17
+ Timestamp: string;
18
+ }
19
+ export interface PinataPinOptions {
20
+ pinataMetadata?: {
21
+ [key: string]: string | number | null;
22
+ };
23
+ pinataOptions?: PinataOptions | undefined;
24
+ }
1
25
  /**
2
26
  * Pin File to IPFS
3
27
  * @param {string} pinataApiKey
@@ -6,4 +30,4 @@
6
30
  * @param {*} options
7
31
  * @returns {Promise<unknown>}
8
32
  */
9
- export default function pinFileToIPFS(pinataApiKey: string, pinataSecretApiKey: string, readStream: any, options: any): Promise<unknown>;
33
+ export default function pinFileToIPFS(config: PinataConfig, readStream: any, options?: PinataPinOptions): Promise<PinataPinResponse>;
@@ -1,9 +1,3 @@
1
- /**
2
- * PinFromFS
3
- * @param {string} pinataApiKey
4
- * @param {string} pinataSecretApiKey
5
- * @param {string} sourcePath
6
- * @param {*} options
7
- * @returns {Promise<unknown>}
8
- */
9
- export default function pinFromFS(pinataApiKey: string, pinataSecretApiKey: string, sourcePath: string, options: any): Promise<unknown>;
1
+ import { PinataConfig } from '../..';
2
+ import { PinataPinOptions, PinataPinResponse } from './pinFileToIPFS';
3
+ export default function pinFromFS(config: PinataConfig, sourcePath: string, options?: PinataPinOptions): Promise<PinataPinResponse>;