@pinata/sdk 1.1.26 → 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.
Files changed (54) hide show
  1. package/.babelrc +4 -3
  2. package/.nvmrc +1 -1
  3. package/README.md +103 -19
  4. package/lib/pinata-sdk.js +615 -157
  5. package/lib/pinata-sdk.min.js +5 -5
  6. package/package.json +3 -2
  7. package/src/commands/data/getFilesByCount/getFilesByCount.js +67 -0
  8. package/src/commands/data/pinList/pinList.js +6 -11
  9. package/src/commands/data/pinList/queryBuilder.js +4 -0
  10. package/src/commands/data/testAuthentication.js +4 -11
  11. package/src/commands/data/userPinnedDataTotal.js +4 -11
  12. package/src/commands/pinning/hashMetadata.js +4 -11
  13. package/src/commands/pinning/hashPinPolicy.js +4 -10
  14. package/src/commands/pinning/pinByHash.js +4 -11
  15. package/src/commands/pinning/pinFileToIPFS.js +5 -16
  16. package/src/commands/pinning/pinFromFS.js +6 -23
  17. package/src/commands/pinning/pinJSONToIPFS.js +4 -10
  18. package/src/commands/pinning/pinJobs/pinJobs.js +4 -10
  19. package/src/commands/pinning/unpin.js +4 -11
  20. package/src/commands/pinning/userPinPolicy.js +4 -10
  21. package/src/constants.js +3 -0
  22. package/src/index.js +63 -13
  23. package/src/util/validators.js +88 -12
  24. package/test/commands/data/getFilesByCount/getFilesByCount.test.js +211 -0
  25. package/test/commands/data/pinList/pinList.test.js +100 -26
  26. package/test/commands/data/pinlist-sample-api.js +540 -0
  27. package/test/commands/data/testAuthentication.test.js +17 -13
  28. package/test/commands/data/userPinnedDataTotal.test.js +3 -3
  29. package/test/commands/pinning/hashMetadata.test.js +7 -7
  30. package/test/commands/pinning/hashPinPolicy.test.js +6 -6
  31. package/test/commands/pinning/pinByHash.test.js +4 -4
  32. package/test/commands/pinning/pinFileToIPFS.test.js +5 -5
  33. package/test/commands/pinning/pinFromFS.js +3 -3
  34. package/test/commands/pinning/pinJSONToIPFS.test.js +4 -4
  35. package/test/commands/pinning/pinJobs/pinJobs.test.js +3 -3
  36. package/test/commands/pinning/unpin.test.js +5 -5
  37. package/test/commands/pinning/userPinPolicy.test.js +51 -22
  38. package/test/util/validators.test.js +114 -72
  39. package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +12 -0
  40. package/types/commands/data/pinList/pinList.d.ts +2 -2
  41. package/types/commands/data/testAuthentication.d.ts +1 -1
  42. package/types/commands/data/userPinnedDataTotal.d.ts +1 -1
  43. package/types/commands/pinning/hashMetadata.d.ts +1 -1
  44. package/types/commands/pinning/hashPinPolicy.d.ts +1 -1
  45. package/types/commands/pinning/pinByHash.d.ts +1 -1
  46. package/types/commands/pinning/pinFileToIPFS.d.ts +1 -1
  47. package/types/commands/pinning/pinFromFS.d.ts +1 -1
  48. package/types/commands/pinning/pinJSONToIPFS.d.ts +1 -1
  49. package/types/commands/pinning/pinJobs/pinJobs.d.ts +1 -1
  50. package/types/commands/pinning/unpin.d.ts +1 -1
  51. package/types/commands/pinning/userPinPolicy.d.ts +1 -1
  52. package/types/constants.d.ts +1 -0
  53. package/types/index.d.ts +9 -174
  54. package/types/util/validators.d.ts +34 -0
package/.babelrc CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
- "presets": [["@babel/env", { "modules": "commonjs" }]],
3
- "plugins": ["add-module-exports"]
4
- }
2
+ "presets": [["@babel/env", { "modules": "commonjs" , "useBuiltIns": "usage"}] ],
3
+ "plugins": ["add-module-exports", "@babel/plugin-transform-runtime"]
4
+ }
5
+
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- v6.10
1
+ v10.24
package/README.md CHANGED
@@ -14,12 +14,28 @@ npm install --save @pinata/sdk
14
14
  ```
15
15
 
16
16
  ## Setup
17
- To start, simply require the Pinata SDK and set up an instance with your Pinata API Keys. Don't know what your keys are? Check out your [Account Page](https://pinata.cloud/account).
17
+ To start, simply require the Pinata SDK and set up an instance with your Pinata API Keys or your JWT key. Don't know what your keys are? Check out your [Account Page](https://pinata.cloud/account).
18
+ In the example below we provided with 3 ways to call the pinata SDK.
19
+
18
20
  ```javascript
21
+ // Use the api keys by providing the strings directly
19
22
  const pinataSDK = require('@pinata/sdk');
20
23
  const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');
21
24
  ```
22
25
 
26
+ ```javascript
27
+ // Use the api keys by specifying your api key and api secret
28
+ const pinataSDK = require('@pinata/sdk');
29
+ const pinata = pinataSDK({ pinataApiKey: 'yourPinataApiKey', pinataSecretApiKey: 'yourPinataSecretApiKey' });
30
+
31
+ ```
32
+
33
+ ```javascript
34
+ // Use the JWT key
35
+ const pinataSDK = require('@pinata/sdk');
36
+ const pinata = pinataSDK({ pinataJWTKey: 'yourPinataJWTKey'});
37
+ ```
38
+
23
39
  Quickly test that you can connect to the API with the following call:
24
40
  ```javascript
25
41
  pinata.testAuthentication().then((result) => {
@@ -47,6 +63,7 @@ Once you've set up your instance, using the Pinata SDK is easy. Simply call your
47
63
  * Data
48
64
  * [testAuthentication](#testAuthentication-anchor)
49
65
  * [pinList](#pinList-anchor)
66
+ * [getFilesByCount](#getFilesByCount-anchor)
50
67
  * [userPinnedDataTotal](#userPinnedDataTotal-anchor)
51
68
  <br />
52
69
 
@@ -190,13 +207,13 @@ pinata.pinFileToIPFS(readableStreamForFile, options).then((result) => {
190
207
  });
191
208
  ```
192
209
 
193
- <a name="pinFromFs-anchor"></a>
210
+ <a name="pinFromFS-anchor"></a>
194
211
  ### `pinFromFS`
195
212
  Read from a location on your local file system and recursively pin the contents to IPFS (node.js only).
196
213
 
197
214
  Both individual files, as well as directories can be read from.
198
215
 
199
- ##### `pinata.pinFromFs(sourcePath, options)`
216
+ ##### `pinata.pinFromFS(sourcePath, options)`
200
217
  ##### Params
201
218
  * `sourcePath` - The location on your local filesystem that should be read from.
202
219
  * `options` (optional): A JSON object that can contain the following keyvalues:
@@ -388,7 +405,7 @@ pinata.testAuthentication().then((result) => {
388
405
 
389
406
  <a name="pinList-anchor"></a>
390
407
  ### `pinList`
391
- Retrieve pin records for your Pinata account
408
+ Retrieve pin records for your Pinata account. In order to get the next page you have to manipulate `pageLimit` and `pageOffset` filter to get the next page. This method no longer return the total count of pins. We highly encourage you to use the auto-pagination method [getFilesByCount](#getFilesByCount-anchor).
392
409
 
393
410
  ##### `pinata.pinList(filters)`
394
411
  ##### Params
@@ -462,14 +479,73 @@ As an example, the following filter would only find records whose name contains
462
479
  }
463
480
  ```
464
481
 
482
+ Our libraries support auto-pagination. This feature easily handles fetching large lists of resources without having to manually paginate results and perform subsequent requests.
465
483
 
466
-
467
- #### Response
484
+ To use the auto-pagination feature in Node 10+, simply iterate over a "list" call with the parameters you need in a for await loop.
485
+
486
+ <a name="getFilesByCount-anchor"></a>
487
+ ### `getFilesByCount`
488
+ This method support auto-pagination. This feature easily handles fetching large lists of pin records for your Pinata account without having to manually paginate results and perform subsequent requests. To use the auto-pagination feature in Node 10+.
489
+
490
+ ##### `pinata.getFilesByCount(filters, count)`
491
+ ##### Params
492
+ * `filters` (optional): An object that can consist of the following optional query parameters:
493
+ * `hashContains` (optional): A string of alphanumeric characters that desires hashes must contain
494
+ * `pinStart` (optional): The earliest date the content is allowed to have been pinned. Must be a valid [ISO_8601](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) date.
495
+ * `pinEnd` (optional): The earliest date the content is allowed to have been pinned. Must be a valid [ISO_8601](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) date.
496
+ * `unpinStart` (optional): The earlist date the content is allowed to have been unpinned. Must be a valid [ISO_8601](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) date.
497
+ * `unpinEnd` (optional): The latest date the content is allowed to have been unpinned. Must be a valid [ISO_8601](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) date.
498
+ * `pinSizeMin` (optional): The minimum byte size that pin record you're looking for can have
499
+ * `pinSizeMax` (optional): The maximum byte size that pin record you're looking for can have
500
+ * `status` (optional): Filter pins using one of the following options
501
+ * `'all'` (Records for both pinned and unpinned content will be returned)
502
+ * `'pinned'` (Only records for pinned content will be returned)
503
+ * `'unpinned'` (Only records for unpinned content will be returned)
504
+ * `metadata` (optional): A JSON object that can be used to find records for content that had optional metadata included when it was added to Pinata. The metadata object is formatted as follows:
505
+ * `count` (optional): A Number that specifies how many pins you want. if no number is provided then it will pull all the pins based on your filter
506
+
507
+ ##### Metadata filter object formatting
468
508
  ```
469
509
  {
470
- count: (this is the total number of pin records that exist for the query filters you passed in),
471
- rows: [
472
- {
510
+ name: 'exampleName',
511
+ keyvalues: {
512
+ testKeyValue: {
513
+ value: 'exampleFilterValue',
514
+ op: 'exampleFilterOperation'
515
+ },
516
+ testKeyValue2: {
517
+ value: 'exampleFilterValue2',
518
+ op: 'exampleFilterOperation2'
519
+ }
520
+ }
521
+ }
522
+ ```
523
+ Filter explanations:
524
+ * `name` (optional): If provided, any records returned must have a name that contains the string provided for the 'name'.
525
+ * `keyvalues` (optional): Each keyvalue provided in this object have both a `value` and `op`
526
+ * `value` (required): This is the value which will be filtered on
527
+ * `op` (required): This is the filter operation that will be applied to the `value` that was provided. Valid op values are:
528
+ * `'gt'` (greater than the value provided)
529
+ * `'gte'` (greater than or equal to the value provided)
530
+ * `'lt'` (less than the value provided)
531
+ * `'lte'` (less than or equal to the value provided)
532
+ * `'ne'` (not equal to the value provided)
533
+ * `'eq'` (equal to the value provided)
534
+ * `'between'` (between the two values provided) - NOTE - This also requires a `secondValue` be provided as seen in the example below
535
+ * `'notBetween'` (not between the two values provided) - NOTE - This also requires a `secondValue` be provided as seen in the example below
536
+ * `'like'` (like the value provided)
537
+ * `'notLike'` (not like the value provided)
538
+ * `'iLike'` (case insensitive version of `like`)
539
+ * `'notILike'` (case insensitive version of `notLike`)
540
+ * `'regexp'` (filter the value provided based on a provided regular expression)
541
+ * `'iRegexp'` (case insensitive version of regexp)
542
+
543
+ ```
544
+
545
+ #### Response
546
+ ```
547
+ [
548
+ {
473
549
  id: (the id of your pin instance record),
474
550
  ipfs_pin_hash: (the IPFS multi-hash for the content you pinned),
475
551
  size: (this is how large (in bytes) the content pinned is),
@@ -477,7 +553,7 @@ As an example, the following filter would only find records whose name contains
477
553
  date_pinned: (This is the timestamp for when this content was pinned - represented in ISO 8601 format),
478
554
  date_unpinned: (This is the timestamp for when this content was unpinned (if null, then you still have the content pinned on Pinata),
479
555
  metadata: {
480
- name: (this will be the name of the file originally upuloaded, or the custom name you set),
556
+ name: (this will be the name of the file originally uploaded, or the custom name you set),
481
557
  keyvalues: {
482
558
  exampleCustomKey: "exampleCustomValue",
483
559
  exampleCustomKey2: "exampleCustomValue2",
@@ -491,11 +567,15 @@ As an example, the following filter would only find records whose name contains
491
567
  .
492
568
  .
493
569
  .
494
- ]
495
- }
570
+ ]
571
+
496
572
  ```
497
573
  ##### Example Code
574
+
498
575
  ```javascript
576
+ const pinataSDK = require('@pinata/sdk');
577
+ const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');
578
+
499
579
  const metadataFilter = {
500
580
  name: 'exampleName',
501
581
  keyvalues: {
@@ -516,13 +596,17 @@ const filters = {
516
596
  pageOffset: 0,
517
597
  metadata: metadataFilter
518
598
  };
519
- pinata.pinList(filters).then((result) => {
520
- //handle results here
521
- console.log(result);
522
- }).catch((err) => {
523
- //handle error here
524
- console.log(err);
525
- });
599
+
600
+ // more reference at [for await ...](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
601
+ for await (const item of pinata.getFilesByCount(filters, 35)) {
602
+ // ...(item) perform any task with the current item in the array of 35
603
+ }
604
+
605
+
606
+ for await (const item of pinata.getFilesByCount(filters)) {
607
+ // ...(item) perform any task with the current item the array is determined by all your pins
608
+ }
609
+
526
610
  ```
527
611
 
528
612
  <a name="userPinnedDataTotal-anchor"></a>