@pinata/sdk 1.1.23 → 1.1.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinata/sdk",
3
- "version": "1.1.23",
3
+ "version": "1.1.26",
4
4
  "description": "Official SDK for the Pinata IPFS platform",
5
5
  "main": "lib/pinata-sdk.js",
6
6
  "types": "types/index.d.ts",
@@ -24,8 +24,8 @@ export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStre
24
24
 
25
25
  const endpoint = `${baseUrl}/pinning/pinFileToIPFS`;
26
26
 
27
- if (!(readStream instanceof stream.Readable)) {
28
- reject(new Error('readStream is not a readable stream'));
27
+ if (!(readStream instanceof stream.Readable || readStream instanceof NodeFormData)) {
28
+ reject(new Error('readStream is not a readable stream or form data'));
29
29
  }
30
30
 
31
31
  if (options) {
@@ -41,7 +41,7 @@ export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStre
41
41
 
42
42
  axios.post(
43
43
  endpoint,
44
- data,
44
+ readStream instanceof NodeFormData ? readStream : data,
45
45
  {
46
46
  withCredentials: true,
47
47
  maxContentLength: 'Infinity', //this is needed to prevent axios from erroring out with large files
package/src/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  import pinByHash from './commands/pinning/pinByHash';
2
2
  import hashMetadata from './commands/pinning/hashMetadata';
3
- import hashPinPolicy from './commands/pinning/hashPinPolicy';
4
3
  import pinFileToIPFS from './commands/pinning/pinFileToIPFS';
5
4
  import pinFromFS from './commands/pinning/pinFromFS';
6
5
  import pinJSONToIPFS from './commands/pinning/pinJSONToIPFS';
7
6
  import pinJobs from './commands/pinning/pinJobs/pinJobs';
8
7
  import unpin from './commands/pinning/unpin';
9
- import userPinPolicy from './commands/pinning/userPinPolicy';
10
8
  import testAuthentication from './commands/data/testAuthentication';
11
9
  import pinList from './commands/data/pinList/pinList';
12
10
  import userPinnedDataTotal from './commands/data/userPinnedDataTotal';
@@ -135,14 +133,6 @@ import userPinnedDataTotal from './commands/data/userPinnedDataTotal';
135
133
  * @returns {Promise<any>}
136
134
  */
137
135
 
138
- /**
139
- * Hash pin policy
140
- * @callback hashPinPolicy
141
- * @param {string} ipfsPinHash
142
- * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
143
- * @returns {Promise<any>}
144
- */
145
-
146
136
  /**
147
137
  * Pin by hash
148
138
  * @callback pinByHash
@@ -189,13 +179,6 @@ import userPinnedDataTotal from './commands/data/userPinnedDataTotal';
189
179
  * @returns {Promise<any>}
190
180
  */
191
181
 
192
- /**
193
- * User Pin Policy
194
- * @callback userPinPolicy
195
- * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
196
- * @returns {Promise<any>}
197
- */
198
-
199
182
  /**
200
183
  * Test Authentication
201
184
  * @callback testAuthentication
@@ -219,13 +202,11 @@ import userPinnedDataTotal from './commands/data/userPinnedDataTotal';
219
202
  * @typedef PinataClient
220
203
  * @property {pinByHash} pinByHash
221
204
  * @property {hashMetadata} hashMetadata
222
- * @property {hashPinPolicy} hashPinPolicy
223
205
  * @property {pinFileToIPFS} pinFileToIPFS
224
206
  * @property {pinFromFS} pinFromFS
225
207
  * @property {pinJSONToIPFS} pinJSONToIPFS
226
208
  * @property {pinJobs} pinJobs
227
209
  * @property {unpin} unpin
228
- * @property {userPinPolicy} userPinPolicy
229
210
  * @property {testAuthentication} testAuthentication
230
211
  * @property {pinList} pinList
231
212
  * @property {userPinnedDataTotal} userPinnedDataTotal
@@ -248,9 +229,6 @@ export default function pinataClient(pinataApiKey, pinataSecretApiKey) {
248
229
  client.hashMetadata = function (ipfsPinHash, metadata) {
249
230
  return hashMetadata(pinataApiKey, pinataSecretApiKey, ipfsPinHash, metadata);
250
231
  };
251
- client.hashPinPolicy = function (ipfsPinHash, newPinPolicy) {
252
- return hashPinPolicy(pinataApiKey, pinataSecretApiKey, ipfsPinHash, newPinPolicy);
253
- };
254
232
  client.pinFileToIPFS = function (readableStream, options) {
255
233
  return pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readableStream, options);
256
234
  };
@@ -266,9 +244,6 @@ export default function pinataClient(pinataApiKey, pinataSecretApiKey) {
266
244
  client.unpin = function (hashToUnpin) {
267
245
  return unpin(pinataApiKey, pinataSecretApiKey, hashToUnpin);
268
246
  };
269
- client.userPinPolicy = function (newPinPolicy) {
270
- return userPinPolicy(pinataApiKey, pinataSecretApiKey, newPinPolicy);
271
- };
272
247
  client.testAuthentication = function () {
273
248
  return testAuthentication(pinataApiKey, pinataSecretApiKey);
274
249
  };
@@ -1,20 +1,23 @@
1
1
  import axios from 'axios';
2
2
  import pinFileToIPFS from'../../../src/commands/pinning/pinFileToIPFS';
3
3
  import fs from 'fs';
4
+ import NodeFormData from 'form-data';
4
5
  jest.mock('axios');
5
6
 
6
7
  //common values
7
8
  const nonStream = 'test';
8
9
  const validStream = fs.createReadStream('./pinata.png');
10
+ const validFormData = new NodeFormData();
11
+ validFormData.append('file', validStream, {filepath: 'test/filepath'});
9
12
 
10
13
 
11
- test('non-readableStream is passed in', () => {
12
- expect(pinFileToIPFS('test', 'test', nonStream)).rejects.toEqual(Error('readStream is not a readable stream'));
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'));
13
16
 
14
17
  return undefined;
15
18
  });
16
19
 
17
- test('200 status is returned', () => {
20
+ test('200 status is returned with valid stream', () => {
18
21
  const goodStatus = {
19
22
  status: 200,
20
23
  data: 'testData'
@@ -24,6 +27,16 @@ test('200 status is returned', () => {
24
27
  expect(pinFileToIPFS('test', 'test', validStream)).resolves.toEqual(goodStatus.data);
25
28
  });
26
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
+
27
40
  test('Result other than 200 status is returned', () => {
28
41
  const badStatus = {
29
42
  status: 700
package/types/index.d.ts CHANGED
@@ -100,13 +100,6 @@
100
100
  * @param {PinataMetadata} metadata
101
101
  * @returns {Promise<any>}
102
102
  */
103
- /**
104
- * Hash pin policy
105
- * @callback hashPinPolicy
106
- * @param {string} ipfsPinHash
107
- * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
108
- * @returns {Promise<any>}
109
- */
110
103
  /**
111
104
  * Pin by hash
112
105
  * @callback pinByHash
@@ -147,12 +140,6 @@
147
140
  * @param {string} hashToUnpin
148
141
  * @returns {Promise<any>}
149
142
  */
150
- /**
151
- * User Pin Policy
152
- * @callback userPinPolicy
153
- * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
154
- * @returns {Promise<any>}
155
- */
156
143
  /**
157
144
  * Test Authentication
158
145
  * @callback testAuthentication
@@ -173,13 +160,11 @@
173
160
  * @typedef PinataClient
174
161
  * @property {pinByHash} pinByHash
175
162
  * @property {hashMetadata} hashMetadata
176
- * @property {hashPinPolicy} hashPinPolicy
177
163
  * @property {pinFileToIPFS} pinFileToIPFS
178
164
  * @property {pinFromFS} pinFromFS
179
165
  * @property {pinJSONToIPFS} pinJSONToIPFS
180
166
  * @property {pinJobs} pinJobs
181
167
  * @property {unpin} unpin
182
- * @property {userPinPolicy} userPinPolicy
183
168
  * @property {testAuthentication} testAuthentication
184
169
  * @property {pinList} pinList
185
170
  * @property {userPinnedDataTotal} userPinnedDataTotal
@@ -284,12 +269,6 @@ export type PinataPinListResponse = {
284
269
  * Hash meta data
285
270
  */
286
271
  export type hashMetadata = (ipfsPinHash: string, metadata: PinataMetadata) => Promise<any>;
287
- /**
288
- * Hash pin policy
289
- */
290
- export type hashPinPolicy = (ipfsPinHash: string, newPinPolicy: {
291
- regions: PinataPinPolicyItem[];
292
- }) => Promise<any>;
293
272
  /**
294
273
  * Pin by hash
295
274
  */
@@ -314,12 +293,6 @@ export type pinJSONToIPFS = (body: Object, options?: PinataPinOptions | undefine
314
293
  * Unpin
315
294
  */
316
295
  export type unpin = (hashToUnpin: string) => Promise<any>;
317
- /**
318
- * User Pin Policy
319
- */
320
- export type userPinPolicy = (newPinPolicy: {
321
- regions: PinataPinPolicyItem[];
322
- }) => Promise<any>;
323
296
  /**
324
297
  * Test Authentication
325
298
  */
@@ -337,26 +310,22 @@ export type userPinnedDataTotal = () => Promise<number>;
337
310
  export type PinataClient = {
338
311
  pinByHash: pinByHash;
339
312
  hashMetadata: hashMetadata;
340
- hashPinPolicy: hashPinPolicy;
341
313
  pinFileToIPFS: pinFileToIPFS;
342
314
  pinFromFS: pinFromFS;
343
315
  pinJSONToIPFS: pinJSONToIPFS;
344
316
  pinJobs: pinJobs;
345
317
  unpin: unpin;
346
- userPinPolicy: userPinPolicy;
347
318
  testAuthentication: testAuthentication;
348
319
  pinList: pinList;
349
320
  userPinnedDataTotal: userPinnedDataTotal;
350
321
  };
351
322
  import pinByHash from "./commands/pinning/pinByHash";
352
323
  import hashMetadata from "./commands/pinning/hashMetadata";
353
- import hashPinPolicy from "./commands/pinning/hashPinPolicy";
354
324
  import pinFileToIPFS from "./commands/pinning/pinFileToIPFS";
355
325
  import pinFromFS from "./commands/pinning/pinFromFS";
356
326
  import pinJSONToIPFS from "./commands/pinning/pinJSONToIPFS";
357
327
  import pinJobs from "./commands/pinning/pinJobs/pinJobs";
358
328
  import unpin from "./commands/pinning/unpin";
359
- import userPinPolicy from "./commands/pinning/userPinPolicy";
360
329
  import testAuthentication from "./commands/data/testAuthentication";
361
330
  import pinList from "./commands/data/pinList/pinList";
362
331
  import userPinnedDataTotal from "./commands/data/userPinnedDataTotal";