@pinata/sdk 1.2.1 → 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.
- package/.babelrc +1 -1
- package/.eslintrc +7 -7
- package/.husky/pre-commit +6 -0
- package/.nvmrc +1 -1
- package/README.md +3 -3
- package/lib/pinata-sdk.js +494 -468
- package/lib/pinata-sdk.min.js +5 -5
- package/package.json +83 -71
- package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +8 -9
- package/src/commands/data/index.ts +4 -0
- package/src/commands/data/pinList/pinList.ts +77 -0
- package/src/commands/data/pinList/{queryBuilder.js → queryBuilder.ts} +6 -16
- package/src/commands/data/{testAuthentication.js → testAuthentication.ts} +8 -9
- package/src/commands/data/{userPinnedDataTotal.js → userPinnedDataTotal.ts} +4 -9
- package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +9 -11
- package/src/commands/pinning/index.ts +8 -0
- package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +22 -11
- package/src/commands/pinning/{pinFileToIPFS.js → pinFileToIPFS.ts} +27 -11
- package/src/commands/pinning/{pinFromFS.js → pinFromFS.ts} +14 -19
- package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +5 -11
- package/src/commands/pinning/pinJobs/{pinJobs.js → pinJobs.ts} +23 -9
- package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
- package/src/commands/pinning/{unpin.js → unpin.ts} +3 -9
- package/src/{constants.js → constants.ts} +0 -0
- package/src/index.ts +120 -0
- package/src/third-party/base-path-converter.d.ts +3 -0
- package/src/third-party/is-ipfs.d.ts +5 -0
- package/src/third-party/recursive-fs.d.ts +5 -0
- package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
- package/src/util/{validators.js → validators.ts} +14 -33
- package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +23 -22
- package/test/commands/data/pinList/{pinList.test.js → pinList.test.ts} +25 -26
- package/test/commands/data/pinList/{queryBuilder.test.js → queryBuilder.test.ts} +9 -10
- package/test/commands/data/pinlist-sample-api.ts +540 -0
- package/test/commands/data/{testAuthentication.test.js → testAuthentication.test.ts} +13 -13
- package/test/commands/data/{userPinnedDataTotal.test.js → userPinnedDataTotal.test.ts} +4 -4
- package/test/commands/pinning/{hashMetadata.test.js → hashMetadata.test.ts} +7 -8
- package/test/commands/pinning/{pinByHash.test.js → pinByHash.test.ts} +4 -5
- package/test/commands/pinning/{pinFileToIPFS.test.js → pinFileToIPFS.test.ts} +5 -7
- package/test/commands/pinning/{pinFromFS.js → pinFromFS.ts} +5 -6
- package/test/commands/pinning/{pinJSONToIPFS.test.js → pinJSONToIPFS.test.ts} +4 -5
- package/test/commands/pinning/pinJobs/{pinJobs.test.js → pinJobs.test.ts} +4 -4
- package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
- package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +4 -5
- package/test/util/validators.test.ts +234 -0
- package/tsconfig.json +2 -2
- package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +4 -2
- package/types/commands/data/index.d.ts +4 -0
- package/types/commands/data/pinList/pinList.d.ts +45 -8
- package/types/commands/data/pinList/queryBuilder.d.ts +1 -7
- package/types/commands/data/testAuthentication.d.ts +5 -7
- package/types/commands/data/userPinnedDataTotal.d.ts +2 -7
- package/types/commands/pinning/hashMetadata.d.ts +3 -9
- package/types/commands/pinning/index.d.ts +8 -0
- package/types/commands/pinning/pinByHash.d.ts +14 -9
- package/types/commands/pinning/pinFileToIPFS.d.ts +25 -1
- package/types/commands/pinning/pinFromFS.d.ts +3 -9
- package/types/commands/pinning/pinJSONToIPFS.d.ts +3 -9
- package/types/commands/pinning/pinJobs/pinJobs.d.ts +20 -8
- package/types/commands/pinning/pinJobs/queryBuilder.d.ts +1 -7
- package/types/commands/pinning/unpin.d.ts +2 -8
- package/types/constants.d.ts +2 -2
- package/types/index.d.ts +37 -165
- package/types/util/errorResponse.d.ts +1 -1
- package/types/util/validators.d.ts +20 -37
- package/webpack.config.js +50 -53
- package/src/commands/data/pinList/pinList.js +0 -34
- package/src/commands/pinning/hashPinPolicy.js +0 -51
- package/src/commands/pinning/userPinPolicy.js +0 -40
- package/src/index.js +0 -307
- package/test/commands/data/pinlist-sample-api.js +0 -540
- package/test/commands/pinning/hashPinPolicy.test.js +0 -65
- package/test/commands/pinning/userPinPolicy.test.js +0 -80
- package/test/util/validators.test.js +0 -234
|
@@ -1,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
|
-
});
|