@pinata/sdk 1.2.0 → 1.2.1
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/README.md +21 -5
- package/lib/pinata-sdk.js +305 -155
- package/lib/pinata-sdk.min.js +5 -5
- package/package.json +1 -1
- package/src/commands/data/getFilesByCount/getFilesByCount.js +2 -5
- package/src/commands/data/pinList/pinList.js +4 -11
- package/src/commands/data/testAuthentication.js +4 -11
- package/src/commands/data/userPinnedDataTotal.js +4 -11
- package/src/commands/pinning/hashMetadata.js +4 -11
- package/src/commands/pinning/hashPinPolicy.js +4 -10
- package/src/commands/pinning/pinByHash.js +4 -11
- package/src/commands/pinning/pinFileToIPFS.js +5 -16
- package/src/commands/pinning/pinFromFS.js +6 -23
- package/src/commands/pinning/pinJSONToIPFS.js +4 -10
- package/src/commands/pinning/pinJobs/pinJobs.js +4 -10
- package/src/commands/pinning/unpin.js +4 -11
- package/src/commands/pinning/userPinPolicy.js +4 -10
- package/src/constants.js +3 -0
- package/src/index.js +60 -15
- package/src/util/validators.js +88 -12
- package/test/commands/data/getFilesByCount/getFilesByCount.test.js +17 -21
- package/test/commands/data/pinList/pinList.test.js +20 -15
- package/test/commands/data/testAuthentication.test.js +17 -13
- package/test/commands/data/userPinnedDataTotal.test.js +3 -3
- package/test/commands/pinning/hashMetadata.test.js +7 -7
- package/test/commands/pinning/hashPinPolicy.test.js +6 -6
- package/test/commands/pinning/pinByHash.test.js +4 -4
- package/test/commands/pinning/pinFileToIPFS.test.js +5 -5
- package/test/commands/pinning/pinFromFS.js +3 -3
- package/test/commands/pinning/pinJSONToIPFS.test.js +4 -4
- package/test/commands/pinning/pinJobs/pinJobs.test.js +3 -3
- package/test/commands/pinning/unpin.test.js +5 -5
- package/test/commands/pinning/userPinPolicy.test.js +51 -22
- package/test/util/validators.test.js +114 -72
- package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +1 -1
- package/types/commands/data/pinList/pinList.d.ts +1 -1
- package/types/commands/data/testAuthentication.d.ts +1 -1
- package/types/commands/data/userPinnedDataTotal.d.ts +1 -1
- package/types/commands/pinning/hashMetadata.d.ts +1 -1
- package/types/commands/pinning/hashPinPolicy.d.ts +1 -1
- package/types/commands/pinning/pinByHash.d.ts +1 -1
- package/types/commands/pinning/pinFileToIPFS.d.ts +1 -1
- package/types/commands/pinning/pinFromFS.d.ts +1 -1
- package/types/commands/pinning/pinJSONToIPFS.d.ts +1 -1
- package/types/commands/pinning/pinJobs/pinJobs.d.ts +1 -1
- package/types/commands/pinning/unpin.d.ts +1 -1
- package/types/commands/pinning/userPinPolicy.d.ts +1 -1
- package/types/constants.d.ts +1 -0
- package/types/index.d.ts +9 -174
- package/types/util/validators.d.ts +34 -0
package/src/util/validators.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import isIPFS from 'is-ipfs';
|
|
2
|
-
|
|
2
|
+
import { ERROR_NO_CREDENTIALS_PROVIDED} from '../constants';
|
|
3
3
|
/**
|
|
4
4
|
* Validate API Keys
|
|
5
5
|
* @param {string} pinataApiKey
|
|
@@ -7,11 +7,53 @@ import isIPFS from 'is-ipfs';
|
|
|
7
7
|
*/
|
|
8
8
|
export function validateApiKeys(pinataApiKey, pinataSecretApiKey) {
|
|
9
9
|
if (!pinataApiKey || pinataApiKey === '') {
|
|
10
|
-
throw new Error(
|
|
10
|
+
throw new Error(
|
|
11
|
+
'No pinataApiKey provided! Please provide your pinata api key as an argument when you start this script'
|
|
12
|
+
);
|
|
11
13
|
}
|
|
12
14
|
if (!pinataSecretApiKey || pinataSecretApiKey === '') {
|
|
13
|
-
throw new Error(
|
|
15
|
+
throw new Error(
|
|
16
|
+
'No pinataSecretApiKey provided! Please provide your pinata secret api key as an argument when you start this script'
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createConfigForAxiosHeaders(config) {
|
|
22
|
+
if (
|
|
23
|
+
config.pinataApiKey && config.pinataApiKey.length > 0 &&
|
|
24
|
+
config.pinataSecretApiKey && config.pinataSecretApiKey.length > 0
|
|
25
|
+
) {
|
|
26
|
+
return {
|
|
27
|
+
withCredentials: true,
|
|
28
|
+
headers: {
|
|
29
|
+
pinata_api_key: config.pinataApiKey,
|
|
30
|
+
pinata_secret_api_key: config.pinataSecretApiKey
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (config.pinataJWTKey && config.pinataJWTKey.length > 0) {
|
|
36
|
+
return {
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: `Bearer ${config.pinataJWTKey}`
|
|
39
|
+
}
|
|
40
|
+
};
|
|
14
41
|
}
|
|
42
|
+
|
|
43
|
+
throw new Error(ERROR_NO_CREDENTIALS_PROVIDED);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createConfigForAxiosHeadersWithFormData(config, boundaryValue) {
|
|
47
|
+
const requestOptions = {
|
|
48
|
+
...createConfigForAxiosHeaders(config),
|
|
49
|
+
maxContentLength: Infinity, //this is needed to prevent axios from erroring out with large files
|
|
50
|
+
maxBodyLength: Infinity
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
requestOptions.headers[
|
|
54
|
+
'Content-type'
|
|
55
|
+
] = `multipart/form-data; boundary= ${boundaryValue}`;
|
|
56
|
+
return requestOptions;
|
|
15
57
|
}
|
|
16
58
|
|
|
17
59
|
/**
|
|
@@ -24,7 +66,9 @@ export function validateHostNodes(hostNodes) {
|
|
|
24
66
|
}
|
|
25
67
|
hostNodes.forEach((node) => {
|
|
26
68
|
if (!isIPFS.peerMultiaddr(node)) {
|
|
27
|
-
throw new Error(
|
|
69
|
+
throw new Error(
|
|
70
|
+
`host_node array entry: ${node} is not a valid peer multiaddr`
|
|
71
|
+
);
|
|
28
72
|
}
|
|
29
73
|
});
|
|
30
74
|
}
|
|
@@ -35,7 +79,12 @@ export function validateHostNodes(hostNodes) {
|
|
|
35
79
|
*/
|
|
36
80
|
export function validateMetadata(metadata) {
|
|
37
81
|
if (metadata.name) {
|
|
38
|
-
if (
|
|
82
|
+
if (
|
|
83
|
+
!(
|
|
84
|
+
typeof metadata.name === 'string' ||
|
|
85
|
+
metadata.name instanceof String
|
|
86
|
+
)
|
|
87
|
+
) {
|
|
39
88
|
throw new Error('metadata name must be of type string');
|
|
40
89
|
}
|
|
41
90
|
}
|
|
@@ -49,11 +98,21 @@ export function validateMetadata(metadata) {
|
|
|
49
98
|
|
|
50
99
|
Object.entries(metadata.keyvalues).forEach(function (keyValue) {
|
|
51
100
|
if (i > 9) {
|
|
52
|
-
throw new Error(
|
|
101
|
+
throw new Error(
|
|
102
|
+
'No more than 10 keyvalues can be provided for metadata entries'
|
|
103
|
+
);
|
|
53
104
|
}
|
|
54
105
|
// we want to make sure that the input is a string, a boolean, or a number, so we don't get an object passed in by accident
|
|
55
|
-
if (
|
|
56
|
-
|
|
106
|
+
if (
|
|
107
|
+
!(
|
|
108
|
+
typeof keyValue[1] === 'string' ||
|
|
109
|
+
typeof keyValue[1] === 'boolean' ||
|
|
110
|
+
!isNaN(keyValue[1])
|
|
111
|
+
)
|
|
112
|
+
) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
'Metadata keyvalue values must be strings, booleans, or numbers'
|
|
115
|
+
);
|
|
57
116
|
}
|
|
58
117
|
i++;
|
|
59
118
|
});
|
|
@@ -75,11 +134,23 @@ export function validatePinPolicyStructure(pinPolicy) {
|
|
|
75
134
|
}
|
|
76
135
|
if (pinPolicy.regions.length) {
|
|
77
136
|
pinPolicy.regions.forEach((region) => {
|
|
78
|
-
if (
|
|
137
|
+
if (
|
|
138
|
+
!region.id ||
|
|
139
|
+
!(
|
|
140
|
+
Object.prototype.toString.call(region.id) ===
|
|
141
|
+
'[object String]'
|
|
142
|
+
)
|
|
143
|
+
) {
|
|
79
144
|
throw new Error('region id must be a string');
|
|
80
145
|
}
|
|
81
146
|
|
|
82
|
-
if (
|
|
147
|
+
if (
|
|
148
|
+
!(
|
|
149
|
+
region.desiredReplicationCount ||
|
|
150
|
+
region.desiredReplicationCount === 0
|
|
151
|
+
) ||
|
|
152
|
+
!Number.isInteger(region.desiredReplicationCount)
|
|
153
|
+
) {
|
|
83
154
|
throw new Error('desiredReplicationCount must be an integer');
|
|
84
155
|
}
|
|
85
156
|
});
|
|
@@ -103,8 +174,13 @@ export function validatePinataOptions(options) {
|
|
|
103
174
|
}
|
|
104
175
|
if (options.wrapWithDirectory) {
|
|
105
176
|
// eslint-disable-next-line eqeqeq
|
|
106
|
-
if (
|
|
107
|
-
|
|
177
|
+
if (
|
|
178
|
+
options.wrapWithDirectory !== true &&
|
|
179
|
+
options.wrapWithDirectory !== false
|
|
180
|
+
) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
'wrapWithDirectory must be a boolean value of true or false'
|
|
183
|
+
);
|
|
108
184
|
}
|
|
109
185
|
}
|
|
110
186
|
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import getFilesByCount from "../../../../src/commands/data/getFilesByCount/getFilesByCount";
|
|
2
2
|
import axios from "axios";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
APIData,
|
|
5
|
+
pinListAxiosMockPages,
|
|
6
|
+
fakeHeaders,
|
|
7
|
+
} from "../pinlist-sample-api";
|
|
4
8
|
|
|
5
9
|
jest.mock("axios");
|
|
6
10
|
|
|
7
11
|
const metadataName = (item) => {
|
|
8
12
|
return item.metadata.name;
|
|
9
13
|
};
|
|
10
|
-
const callIterableObject = async (
|
|
11
|
-
pinataKey,
|
|
12
|
-
pinataSecret,
|
|
13
|
-
filterToApply,
|
|
14
|
-
pinsCount
|
|
15
|
-
) => {
|
|
14
|
+
const callIterableObject = async (config, filterToApply, pinsCount) => {
|
|
16
15
|
const pins = [];
|
|
17
16
|
for await (const item of getFilesByCount(
|
|
18
|
-
|
|
19
|
-
pinataSecret,
|
|
17
|
+
config,
|
|
20
18
|
filterToApply,
|
|
21
19
|
pinsCount
|
|
22
20
|
)) {
|
|
@@ -27,6 +25,10 @@ const callIterableObject = async (
|
|
|
27
25
|
};
|
|
28
26
|
|
|
29
27
|
describe("Get Files By Count", () => {
|
|
28
|
+
const pinataConfig = {
|
|
29
|
+
pinataApiKey: fakeHeaders.headers.pinata_api_key,
|
|
30
|
+
pinataSecretApiKey: fakeHeaders.headers.pinata_secret_api_key,
|
|
31
|
+
};
|
|
30
32
|
const filterToApply = {
|
|
31
33
|
status: "pinned",
|
|
32
34
|
};
|
|
@@ -43,8 +45,7 @@ describe("Get Files By Count", () => {
|
|
|
43
45
|
.mockResolvedValueOnce(pinListAxiosMockPages.secondPage.response);
|
|
44
46
|
|
|
45
47
|
const pins = await callIterableObject(
|
|
46
|
-
|
|
47
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
48
|
+
pinataConfig,
|
|
48
49
|
filterToApply,
|
|
49
50
|
pinsToRequest
|
|
50
51
|
);
|
|
@@ -74,8 +75,7 @@ describe("Get Files By Count", () => {
|
|
|
74
75
|
pinListAxiosMockPages.firstPage.response
|
|
75
76
|
);
|
|
76
77
|
const pins = await callIterableObject(
|
|
77
|
-
|
|
78
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
78
|
+
pinataConfig,
|
|
79
79
|
filterToApply,
|
|
80
80
|
pinsToRequest
|
|
81
81
|
);
|
|
@@ -102,8 +102,7 @@ describe("Get Files By Count", () => {
|
|
|
102
102
|
pinListAxiosMockPages.thirdPageEmpty.response
|
|
103
103
|
);
|
|
104
104
|
const pins = await callIterableObject(
|
|
105
|
-
|
|
106
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
105
|
+
pinataConfig,
|
|
107
106
|
filterToApply,
|
|
108
107
|
pinsToRequest
|
|
109
108
|
);
|
|
@@ -139,8 +138,7 @@ describe("Get Files By Count", () => {
|
|
|
139
138
|
pinListAxiosMockPages.firstPageEmpty.response
|
|
140
139
|
);
|
|
141
140
|
const pins = await callIterableObject(
|
|
142
|
-
|
|
143
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
141
|
+
pinataConfig,
|
|
144
142
|
filterToApply,
|
|
145
143
|
pinsToRequest
|
|
146
144
|
);
|
|
@@ -165,8 +163,7 @@ describe("Get Files By Count", () => {
|
|
|
165
163
|
pinListAxiosMockPages.thirdPageEmpty.response
|
|
166
164
|
);
|
|
167
165
|
const pins = await callIterableObject(
|
|
168
|
-
|
|
169
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
166
|
+
pinataConfig,
|
|
170
167
|
filterToApply
|
|
171
168
|
);
|
|
172
169
|
expect(pins).toEqual(APIData.rows.map(metadataName));
|
|
@@ -196,8 +193,7 @@ describe("Get Files By Count", () => {
|
|
|
196
193
|
pinListAxiosMockPages.firstPageEmpty.response
|
|
197
194
|
);
|
|
198
195
|
const pins = await callIterableObject(
|
|
199
|
-
|
|
200
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
196
|
+
pinataConfig,
|
|
201
197
|
filterToApply
|
|
202
198
|
);
|
|
203
199
|
|
|
@@ -19,13 +19,17 @@ describe("Get Files By Count", () => {
|
|
|
19
19
|
.mockResolvedValueOnce(pinListAxiosMockPages.secondPage.response);
|
|
20
20
|
|
|
21
21
|
const resp = await pinList(
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
{
|
|
23
|
+
pinataApiKey: fakeHeaders.headers.pinata_api_key,
|
|
24
|
+
pinataSecretApiKey: fakeHeaders.headers.pinata_secret_api_key,
|
|
25
|
+
},
|
|
24
26
|
{ pageLimit: 10, pageOffset: 0 }
|
|
25
27
|
);
|
|
26
28
|
const resp2 = await pinList(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
{
|
|
30
|
+
pinataApiKey: fakeHeaders.headers.pinata_api_key,
|
|
31
|
+
pinataSecretApiKey: fakeHeaders.headers.pinata_secret_api_key,
|
|
32
|
+
},
|
|
29
33
|
{ pageLimit: 10, pageOffset: 10 }
|
|
30
34
|
);
|
|
31
35
|
expect(resp).toEqual(pinListAxiosMockPages.firstPage.response.data);
|
|
@@ -46,25 +50,26 @@ describe("Get Files By Count", () => {
|
|
|
46
50
|
});
|
|
47
51
|
|
|
48
52
|
test("Call empty page", async () => {
|
|
49
|
-
axios.get
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
axios.get.mockResolvedValueOnce(
|
|
54
|
+
pinListAxiosMockPages.firstPageEmpty.response
|
|
55
|
+
);
|
|
52
56
|
|
|
53
57
|
const resp = await pinList(
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
{
|
|
59
|
+
pinataApiKey: fakeHeaders.headers.pinata_api_key,
|
|
60
|
+
pinataSecretApiKey: fakeHeaders.headers.pinata_secret_api_key,
|
|
61
|
+
},
|
|
56
62
|
{ pageLimit: 10, pageOffset: 0 }
|
|
57
63
|
);
|
|
58
|
-
|
|
59
|
-
expect(resp).toEqual({rows: []});
|
|
60
64
|
|
|
65
|
+
expect(resp).toEqual({ rows: [] });
|
|
61
66
|
|
|
62
67
|
expect(axios.get).toHaveBeenNthCalledWith(
|
|
63
68
|
1,
|
|
64
69
|
pinListAxiosMockPages.firstPageEmpty.url,
|
|
65
70
|
pinListAxiosMockPages.firstPageEmpty.headers
|
|
66
71
|
);
|
|
67
|
-
|
|
72
|
+
|
|
68
73
|
expect(axios.get).toHaveBeenCalledTimes(1);
|
|
69
74
|
});
|
|
70
75
|
test("Result other than 200 status is returned", () => {
|
|
@@ -73,7 +78,7 @@ describe("Get Files By Count", () => {
|
|
|
73
78
|
};
|
|
74
79
|
axios.get.mockResolvedValue(badStatus);
|
|
75
80
|
expect.assertions(1);
|
|
76
|
-
expect(pinList(
|
|
81
|
+
expect(pinList({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual(
|
|
77
82
|
Error(
|
|
78
83
|
`unknown server response while attempting to retrieve user pin list: ${badStatus}`
|
|
79
84
|
)
|
|
@@ -87,12 +92,12 @@ describe("Get Files By Count", () => {
|
|
|
87
92
|
};
|
|
88
93
|
axios.get.mockResolvedValue(goodStatus);
|
|
89
94
|
expect.assertions(1);
|
|
90
|
-
expect(pinList(
|
|
95
|
+
expect(pinList({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).resolves.toEqual(goodStatus.data);
|
|
91
96
|
});
|
|
92
97
|
|
|
93
98
|
test("Rejection handled", () => {
|
|
94
99
|
axios.get.mockRejectedValue("test error");
|
|
95
100
|
expect.assertions(1);
|
|
96
|
-
expect(pinList(
|
|
101
|
+
expect(pinList({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual("test error");
|
|
97
102
|
});
|
|
98
103
|
});
|
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import testAuthentication from
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import testAuthentication from "../../../src/commands/data/testAuthentication";
|
|
3
3
|
|
|
4
|
-
jest.mock(
|
|
4
|
+
jest.mock("axios");
|
|
5
5
|
|
|
6
|
-
test(
|
|
6
|
+
test("Result other than 200 status is returned", () => {
|
|
7
7
|
const badStatus = {
|
|
8
|
-
status: 700
|
|
8
|
+
status: 700,
|
|
9
9
|
};
|
|
10
10
|
axios.get.mockResolvedValue(badStatus);
|
|
11
11
|
expect.assertions(1);
|
|
12
|
-
return expect(testAuthentication('test', 'test')).rejects.toEqual(
|
|
12
|
+
return expect(testAuthentication({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual(
|
|
13
|
+
Error(`unknown server response while authenticating: ${badStatus}`)
|
|
14
|
+
);
|
|
13
15
|
});
|
|
14
16
|
|
|
15
|
-
test(
|
|
17
|
+
test("200 status is returned", () => {
|
|
16
18
|
const goodStatus = {
|
|
17
|
-
status: 200
|
|
19
|
+
status: 200,
|
|
18
20
|
};
|
|
19
21
|
axios.get.mockResolvedValue(goodStatus);
|
|
20
22
|
expect.assertions(1);
|
|
21
|
-
return expect(testAuthentication('test', 'test')).resolves.toEqual({
|
|
22
|
-
authenticated: true
|
|
23
|
+
return expect(testAuthentication({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).resolves.toEqual({
|
|
24
|
+
authenticated: true,
|
|
23
25
|
});
|
|
24
26
|
});
|
|
25
27
|
|
|
26
|
-
test(
|
|
27
|
-
axios.get.mockRejectedValue(
|
|
28
|
+
test("Rejection handled", () => {
|
|
29
|
+
axios.get.mockRejectedValue("test error");
|
|
28
30
|
expect.assertions(1);
|
|
29
|
-
return expect(testAuthentication('test', 'test')).rejects.toEqual(
|
|
31
|
+
return expect(testAuthentication({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual(
|
|
32
|
+
"test error"
|
|
33
|
+
);
|
|
30
34
|
});
|
|
@@ -9,7 +9,7 @@ test('Result other than 200 status is returned', () => {
|
|
|
9
9
|
};
|
|
10
10
|
axios.get.mockResolvedValue(badStatus);
|
|
11
11
|
expect.assertions(1);
|
|
12
|
-
expect(userPinnedDataTotal('test', 'test')).rejects.toEqual(Error(`unknown server response while attempting to retrieve pinned data total: ${badStatus}`));
|
|
12
|
+
expect(userPinnedDataTotal({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual(Error(`unknown server response while attempting to retrieve pinned data total: ${badStatus}`));
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
test('200 status is returned', () => {
|
|
@@ -19,11 +19,11 @@ test('200 status is returned', () => {
|
|
|
19
19
|
};
|
|
20
20
|
axios.get.mockResolvedValue(goodStatus);
|
|
21
21
|
expect.assertions(1);
|
|
22
|
-
expect(userPinnedDataTotal('test', 'test')).resolves.toEqual(goodStatus.data);
|
|
22
|
+
expect(userPinnedDataTotal({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).resolves.toEqual(goodStatus.data);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('Rejection handled', () => {
|
|
26
26
|
axios.get.mockRejectedValue('test error');
|
|
27
27
|
expect.assertions(1);
|
|
28
|
-
expect(userPinnedDataTotal('test', 'test')).rejects.toEqual('test error');
|
|
28
|
+
expect(userPinnedDataTotal({ pinataApiKey: 'test', pinataSecretApiKey: 'test' })).rejects.toEqual('test error');
|
|
29
29
|
});
|
|
@@ -23,19 +23,19 @@ const metadataTwo = {
|
|
|
23
23
|
|
|
24
24
|
test('No ipfsPinHash value provided should error', () => {
|
|
25
25
|
expect(() => {
|
|
26
|
-
hashMetadata('test', 'test', null, metadata);
|
|
26
|
+
hashMetadata({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, null, metadata);
|
|
27
27
|
}).toThrow();
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('Invalid ipfsPinHash value is provided', () => {
|
|
31
31
|
expect(() => {
|
|
32
|
-
hashMetadata('test', 'test', badHash, metadata);
|
|
32
|
+
hashMetadata({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badHash, metadata);
|
|
33
33
|
}).toThrow();
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('No metadata object provided should error', () => {
|
|
37
37
|
expect(() => {
|
|
38
|
-
hashMetadata('test', 'test', goodHash);
|
|
38
|
+
hashMetadata({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash);
|
|
39
39
|
}).toThrow();
|
|
40
40
|
});
|
|
41
41
|
|
|
@@ -46,7 +46,7 @@ test('One keyvalue pair is added', () => {
|
|
|
46
46
|
};
|
|
47
47
|
axios.put.mockResolvedValue(goodStatus);
|
|
48
48
|
expect.assertions(1);
|
|
49
|
-
expect(hashMetadata('test', 'test', goodHash, metadata)).resolves.toEqual(goodStatus.data);
|
|
49
|
+
expect(hashMetadata({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, metadata)).resolves.toEqual(goodStatus.data);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
test('Two keyvalue pairs is added', () => {
|
|
@@ -56,7 +56,7 @@ test('Two keyvalue pairs is added', () => {
|
|
|
56
56
|
};
|
|
57
57
|
axios.put.mockResolvedValue(goodStatus);
|
|
58
58
|
expect.assertions(1);
|
|
59
|
-
expect(hashMetadata('test', 'test', goodHash, metadataTwo)).resolves.toEqual(goodStatus.data);
|
|
59
|
+
expect(hashMetadata({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, metadataTwo)).resolves.toEqual(goodStatus.data);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
test('Result other than 200 status is returned', () => {
|
|
@@ -65,13 +65,13 @@ test('Result other than 200 status is returned', () => {
|
|
|
65
65
|
};
|
|
66
66
|
axios.put.mockResolvedValue(badStatus);
|
|
67
67
|
expect.assertions(1);
|
|
68
|
-
expect(hashMetadata('test', 'test', goodHash, metadata)).rejects.toEqual(Error(`unknown server response while changing pin policy for hash: ${badStatus}`));
|
|
68
|
+
expect(hashMetadata({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, metadata)).rejects.toEqual(Error(`unknown server response while changing pin policy for hash: ${badStatus}`));
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
test('Rejection handled', () => {
|
|
72
72
|
axios.put.mockRejectedValue('test error');
|
|
73
73
|
expect.assertions(1);
|
|
74
|
-
expect(hashMetadata('test', 'test', goodHash, metadata)).rejects.toEqual('test error');
|
|
74
|
+
expect(hashMetadata({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, metadata)).rejects.toEqual('test error');
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
|
|
@@ -21,19 +21,19 @@ const newPinPolicy = {
|
|
|
21
21
|
|
|
22
22
|
test('No ipfsPinHash value provided should error', () => {
|
|
23
23
|
expect(() => {
|
|
24
|
-
hashPinPolicy('test', 'test', null, newPinPolicy);
|
|
24
|
+
hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, null, newPinPolicy);
|
|
25
25
|
}).toThrow();
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('Invalid ipfsPinHash value is provided', () => {
|
|
29
29
|
expect(() => {
|
|
30
|
-
hashPinPolicy('test', 'test', badHash, newPinPolicy);
|
|
30
|
+
hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badHash, newPinPolicy);
|
|
31
31
|
}).toThrow();
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test('No newPinPolicy value provided should error', () => {
|
|
35
35
|
expect(() => {
|
|
36
|
-
hashPinPolicy('test', 'test', goodHash);
|
|
36
|
+
hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash);
|
|
37
37
|
}).toThrow();
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ test('200 status is returned', () => {
|
|
|
44
44
|
};
|
|
45
45
|
axios.put.mockResolvedValue(goodStatus);
|
|
46
46
|
expect.assertions(1);
|
|
47
|
-
expect(hashPinPolicy('test', 'test', goodHash, newPinPolicy)).resolves.toEqual(goodStatus.data);
|
|
47
|
+
expect(hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, newPinPolicy)).resolves.toEqual(goodStatus.data);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
test('Result other than 200 status is returned', () => {
|
|
@@ -53,13 +53,13 @@ test('Result other than 200 status is returned', () => {
|
|
|
53
53
|
};
|
|
54
54
|
axios.put.mockResolvedValue(badStatus);
|
|
55
55
|
expect.assertions(1);
|
|
56
|
-
expect(hashPinPolicy('test', 'test', goodHash, newPinPolicy)).rejects.toEqual(Error(`unknown server response while changing pin policy for hash: ${badStatus}`));
|
|
56
|
+
expect(hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, newPinPolicy)).rejects.toEqual(Error(`unknown server response while changing pin policy for hash: ${badStatus}`));
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
test('Rejection handled', () => {
|
|
60
60
|
axios.put.mockRejectedValue('test error');
|
|
61
61
|
expect.assertions(1);
|
|
62
|
-
expect(hashPinPolicy('test', 'test', goodHash, newPinPolicy)).rejects.toEqual('test error');
|
|
62
|
+
expect(hashPinPolicy({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHash, newPinPolicy)).rejects.toEqual('test error');
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
|
|
@@ -15,7 +15,7 @@ test('No hashToPin value is provided should error', () => {
|
|
|
15
15
|
|
|
16
16
|
test('Invalid HashToPin value is provided', () => {
|
|
17
17
|
expect(() => {
|
|
18
|
-
pinByHash('test', 'test', badHashToPin);
|
|
18
|
+
pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badHashToPin);
|
|
19
19
|
}).toThrow();
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -26,7 +26,7 @@ test('200 status is returned', () => {
|
|
|
26
26
|
};
|
|
27
27
|
axios.post.mockResolvedValue(goodStatus);
|
|
28
28
|
expect.assertions(1);
|
|
29
|
-
expect(pinByHash('test', 'test', goodHashToPin)).resolves.toEqual(goodStatus.data);
|
|
29
|
+
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).resolves.toEqual(goodStatus.data);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
test('Result other than 200 status is returned', () => {
|
|
@@ -35,13 +35,13 @@ test('Result other than 200 status is returned', () => {
|
|
|
35
35
|
};
|
|
36
36
|
axios.post.mockResolvedValue(badStatus);
|
|
37
37
|
expect.assertions(1);
|
|
38
|
-
expect(pinByHash('test', 'test', goodHashToPin)).rejects.toEqual(Error(`unknown server response while adding to pin queue: ${badStatus}`));
|
|
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
42
|
axios.post.mockRejectedValue('test error');
|
|
43
43
|
expect.assertions(1);
|
|
44
|
-
expect(pinByHash('test', 'test', goodHashToPin)).rejects.toEqual('test error');
|
|
44
|
+
expect(pinByHash({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodHashToPin)).rejects.toEqual('test error');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
|
|
@@ -12,7 +12,7 @@ validFormData.append('file', validStream, {filepath: 'test/filepath'});
|
|
|
12
12
|
|
|
13
13
|
|
|
14
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'));
|
|
15
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, nonStream)).rejects.toEqual(Error('readStream is not a readable stream or form data'));
|
|
16
16
|
|
|
17
17
|
return undefined;
|
|
18
18
|
});
|
|
@@ -24,7 +24,7 @@ test('200 status is returned with valid stream', () => {
|
|
|
24
24
|
};
|
|
25
25
|
axios.post.mockResolvedValue(goodStatus);
|
|
26
26
|
expect.assertions(1);
|
|
27
|
-
expect(pinFileToIPFS('test', 'test', validStream)).resolves.toEqual(goodStatus.data);
|
|
27
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream)).resolves.toEqual(goodStatus.data);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('200 status is returned with valid form data', () => {
|
|
@@ -34,7 +34,7 @@ test('200 status is returned with valid form data', () => {
|
|
|
34
34
|
};
|
|
35
35
|
axios.post.mockResolvedValue(goodStatus);
|
|
36
36
|
expect.assertions(1);
|
|
37
|
-
expect(pinFileToIPFS('test', 'test', validFormData)).resolves.toEqual(goodStatus.data);
|
|
37
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validFormData)).resolves.toEqual(goodStatus.data);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
test('Result other than 200 status is returned', () => {
|
|
@@ -43,13 +43,13 @@ test('Result other than 200 status is returned', () => {
|
|
|
43
43
|
};
|
|
44
44
|
axios.post.mockResolvedValue(badStatus);
|
|
45
45
|
expect.assertions(1);
|
|
46
|
-
expect(pinFileToIPFS('test', 'test', validStream)).rejects.toEqual(Error(`unknown server response while pinning File to IPFS: ${badStatus}`));
|
|
46
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream)).rejects.toEqual(Error(`unknown server response while pinning File to IPFS: ${badStatus}`));
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('Rejection handled', () => {
|
|
50
50
|
axios.post.mockRejectedValue('test error');
|
|
51
51
|
expect.assertions(1);
|
|
52
|
-
expect(pinFileToIPFS('test', 'test', validStream)).rejects.toEqual('test error');
|
|
52
|
+
expect(pinFileToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, validStream)).rejects.toEqual('test error');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
|
|
@@ -12,7 +12,7 @@ test('200 status is returned', () => {
|
|
|
12
12
|
};
|
|
13
13
|
axios.post.mockResolvedValue(goodStatus);
|
|
14
14
|
expect.assertions(1);
|
|
15
|
-
expect(pinFromFS('test', 'test', testSource)).resolves.toEqual(goodStatus.data);
|
|
15
|
+
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).resolves.toEqual(goodStatus.data);
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
test('Result other than 200 status is returned', () => {
|
|
@@ -21,13 +21,13 @@ test('Result other than 200 status is returned', () => {
|
|
|
21
21
|
};
|
|
22
22
|
axios.post.mockResolvedValue(badStatus);
|
|
23
23
|
expect.assertions(1);
|
|
24
|
-
expect(pinFromFS('test', 'test', testSource)).rejects.toEqual(Error(`unknown server response while pinning to IPFS: ${badStatus}`));
|
|
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
28
|
axios.post.mockRejectedValue('test error');
|
|
29
29
|
expect.assertions(1);
|
|
30
|
-
expect(pinFromFS('test', 'test', testSource)).rejects.toEqual('test error');
|
|
30
|
+
expect(pinFromFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, testSource)).rejects.toEqual('test error');
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
|
|
@@ -11,7 +11,7 @@ const goodJSON = {
|
|
|
11
11
|
|
|
12
12
|
test('non-object is passed in', () => {
|
|
13
13
|
expect(() => {
|
|
14
|
-
pinJSONToIPFS('test', 'test', badJSON);
|
|
14
|
+
pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, badJSON);
|
|
15
15
|
}).toThrow('body must be a valid JSON object');
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ test('200 status is returned', () => {
|
|
|
22
22
|
};
|
|
23
23
|
axios.post.mockResolvedValue(goodStatus);
|
|
24
24
|
expect.assertions(1);
|
|
25
|
-
expect(pinJSONToIPFS('test', 'test', goodJSON)).resolves.toEqual(goodStatus.data);
|
|
25
|
+
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).resolves.toEqual(goodStatus.data);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('Result other than 200 status is returned', () => {
|
|
@@ -31,13 +31,13 @@ test('Result other than 200 status is returned', () => {
|
|
|
31
31
|
};
|
|
32
32
|
axios.post.mockResolvedValue(badStatus);
|
|
33
33
|
expect.assertions(1);
|
|
34
|
-
expect(pinJSONToIPFS('test', 'test', goodJSON)).rejects.toEqual(Error(`unknown server response while pinning JSON to IPFS: ${badStatus}`));
|
|
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
38
|
axios.post.mockRejectedValue('test error');
|
|
39
39
|
expect.assertions(1);
|
|
40
|
-
expect(pinJSONToIPFS('test', 'test', goodJSON)).rejects.toEqual('test error');
|
|
40
|
+
expect(pinJSONToIPFS({ pinataApiKey: 'test', pinataSecretApiKey: 'test' }, goodJSON)).rejects.toEqual('test error');
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
|