@pinata/sdk 1.1.25 → 1.2.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 +4 -3
- package/.nvmrc +1 -1
- package/README.md +85 -123
- package/lib/pinata-sdk.js +348 -217
- package/lib/pinata-sdk.min.js +5 -5
- package/package.json +3 -2
- package/src/commands/data/getFilesByCount/getFilesByCount.js +70 -0
- package/src/commands/data/pinList/pinList.js +4 -2
- package/src/commands/data/pinList/queryBuilder.js +4 -0
- package/src/index.js +5 -25
- package/test/commands/data/getFilesByCount/getFilesByCount.test.js +215 -0
- package/test/commands/data/pinList/pinList.test.js +95 -26
- package/test/commands/data/pinlist-sample-api.js +540 -0
- package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +12 -0
- package/types/commands/data/pinList/pinList.d.ts +2 -2
- package/types/index.d.ts +0 -31
package/.babelrc
CHANGED
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
v10.24
|
package/README.md
CHANGED
|
@@ -36,7 +36,6 @@ Once you've set up your instance, using the Pinata SDK is easy. Simply call your
|
|
|
36
36
|
|
|
37
37
|
* Pinning
|
|
38
38
|
* [hashMetadata](#hashMetadata-anchor)
|
|
39
|
-
* [hashPinPolicy](#hashPinPolicy-anchor)
|
|
40
39
|
* [pinByHash](#pinByHash-anchor)
|
|
41
40
|
* [pinFileToIPFS](#pinFileToIPFS-anchor)
|
|
42
41
|
* [pinFromFS](#pinFromFS-anchor)
|
|
@@ -48,6 +47,7 @@ Once you've set up your instance, using the Pinata SDK is easy. Simply call your
|
|
|
48
47
|
* Data
|
|
49
48
|
* [testAuthentication](#testAuthentication-anchor)
|
|
50
49
|
* [pinList](#pinList-anchor)
|
|
50
|
+
* [getFilesByCount](#getFilesByCount-anchor)
|
|
51
51
|
* [userPinnedDataTotal](#userPinnedDataTotal-anchor)
|
|
52
52
|
<br />
|
|
53
53
|
|
|
@@ -102,46 +102,6 @@ pinata.hashMetadata('yourHashHere', metadata).then((result) => {
|
|
|
102
102
|
});
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
<a name="hashPinPolicy-anchor"></a>
|
|
107
|
-
### `hashPinPolicy`
|
|
108
|
-
Allows the user to change the pin policy for an individual piece of content.
|
|
109
|
-
Changes made via this endpoint only affect the content for the hash passed in. They do not affect a user's account level pin policy.
|
|
110
|
-
|
|
111
|
-
To read more about pin policies, please check out the [Regions and Replications Documentation](https://pinata.cloud/documentation#RegionsAndReplications).
|
|
112
|
-
|
|
113
|
-
##### `pinata.hashPinPolicy(ipfsPinHash, newPinPolicy)`
|
|
114
|
-
##### Params
|
|
115
|
-
* `ipfsPinHash` - A string for a valid IPFS Hash that you have pinned on Pinata.
|
|
116
|
-
* `newPinPolicy` A JSON object with a new [Pin Policy](#pinPolicies-anchor) for the hash.
|
|
117
|
-
|
|
118
|
-
#### Response
|
|
119
|
-
If the operation is successful, you will receive back an "OK" REST 200 status.
|
|
120
|
-
|
|
121
|
-
##### Example Code
|
|
122
|
-
```javascript
|
|
123
|
-
const newPinPolicy = {
|
|
124
|
-
regions: [
|
|
125
|
-
{
|
|
126
|
-
id: 'FRA1',
|
|
127
|
-
desiredReplicationCount: 2
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
id: 'NYC1',
|
|
131
|
-
desiredReplicationCount: 2
|
|
132
|
-
}
|
|
133
|
-
]
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
pinata.hashPinPolicy('yourHashHere', newPinPolicy).then((result) => {
|
|
137
|
-
//handle results here
|
|
138
|
-
console.log(result);
|
|
139
|
-
}).catch((err) => {
|
|
140
|
-
//handle error here
|
|
141
|
-
console.log(err);
|
|
142
|
-
});
|
|
143
|
-
```
|
|
144
|
-
|
|
145
105
|
<a name="pinByHash-anchor"></a>
|
|
146
106
|
### `pinByHash`
|
|
147
107
|
Adds a hash to Pinata's pin queue to be pinned asynchronously. For the synchronous version of this operation see: [pinHashToIPFS](#pinHashToIPFS-anchor)
|
|
@@ -153,7 +113,6 @@ Adds a hash to Pinata's pin queue to be pinned asynchronously. For the synchrono
|
|
|
153
113
|
* `pinataMetadata` (optional): A JSON object with [optional metadata](#metadata-anchor) for the hash being pinned
|
|
154
114
|
* `pinataOptions`
|
|
155
115
|
* `hostNodes` (optional): An array of [multiaddresses for nodes](#hostNode-anchor) that are currently hosting the content to be pinned
|
|
156
|
-
* `customPinPolicy` A JSON object with a new [Pin Policy](#pinPolicies-anchor) for the hash.
|
|
157
116
|
#### Response
|
|
158
117
|
```
|
|
159
118
|
{
|
|
@@ -177,19 +136,7 @@ const options = {
|
|
|
177
136
|
hostNodes: [
|
|
178
137
|
'/ip4/hostNode1ExternalIP/tcp/4001/ipfs/hostNode1PeerId',
|
|
179
138
|
'/ip4/hostNode2ExternalIP/tcp/4001/ipfs/hostNode2PeerId'
|
|
180
|
-
]
|
|
181
|
-
customPinPolicy: {
|
|
182
|
-
regions: [
|
|
183
|
-
{
|
|
184
|
-
id: 'FRA1',
|
|
185
|
-
desiredReplicationCount: 1
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
id: 'NYC1',
|
|
189
|
-
desiredReplicationCount: 2
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
}
|
|
139
|
+
]
|
|
193
140
|
}
|
|
194
141
|
};
|
|
195
142
|
pinata.pinByHash('yourHashHere', options).then((result) => {
|
|
@@ -414,45 +361,6 @@ pinata.unpin(hashToUnpin).then((result) => {
|
|
|
414
361
|
});
|
|
415
362
|
```
|
|
416
363
|
|
|
417
|
-
<a name="userPinPolicy-anchor"></a>
|
|
418
|
-
### `userPinPolicy`
|
|
419
|
-
This allows the sender to change the pin policy their account.
|
|
420
|
-
|
|
421
|
-
Following a successful call of this endpoint, the new pin policy provided will be utilized for every new piece of content pinned to IPFS via Pinata.
|
|
422
|
-
|
|
423
|
-
To read more about pin policies, please check out the [Regions and Replications Documentation](https://pinata.cloud/documentation#RegionsAndReplications).
|
|
424
|
-
|
|
425
|
-
##### `pinata.userPinPolicy(newPinPolicy)`
|
|
426
|
-
##### Params
|
|
427
|
-
* `newPinPolicy` A JSON object with a new [Pin Policy](#pinPolicies-anchor) for the hash.
|
|
428
|
-
|
|
429
|
-
#### Response
|
|
430
|
-
If the operation is successful, you will receive back an "OK" REST 200 status.
|
|
431
|
-
|
|
432
|
-
##### Example Code
|
|
433
|
-
```javascript
|
|
434
|
-
const newPinPolicy = {
|
|
435
|
-
regions: [
|
|
436
|
-
{
|
|
437
|
-
id: 'FRA1',
|
|
438
|
-
desiredReplicationCount: 2
|
|
439
|
-
},
|
|
440
|
-
{
|
|
441
|
-
id: 'NYC1',
|
|
442
|
-
desiredReplicationCount: 2
|
|
443
|
-
}
|
|
444
|
-
]
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
pinata.userPinPolicy(newPinPolicy).then((result) => {
|
|
448
|
-
//handle results here
|
|
449
|
-
console.log(result);
|
|
450
|
-
}).catch((err) => {
|
|
451
|
-
//handle error here
|
|
452
|
-
console.log(err);
|
|
453
|
-
});
|
|
454
|
-
```
|
|
455
|
-
|
|
456
364
|
<a name="testAuthentication-anchor"></a>
|
|
457
365
|
### `testAuthentication`
|
|
458
366
|
Tests that you can authenticate with Pinata correctly
|
|
@@ -481,7 +389,7 @@ pinata.testAuthentication().then((result) => {
|
|
|
481
389
|
|
|
482
390
|
<a name="pinList-anchor"></a>
|
|
483
391
|
### `pinList`
|
|
484
|
-
Retrieve pin records for your Pinata account
|
|
392
|
+
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).
|
|
485
393
|
|
|
486
394
|
##### `pinata.pinList(filters)`
|
|
487
395
|
##### Params
|
|
@@ -555,14 +463,73 @@ As an example, the following filter would only find records whose name contains
|
|
|
555
463
|
}
|
|
556
464
|
```
|
|
557
465
|
|
|
466
|
+
Our libraries support auto-pagination. This feature easily handles fetching large lists of resources without having to manually paginate results and perform subsequent requests.
|
|
558
467
|
|
|
559
|
-
|
|
560
|
-
|
|
468
|
+
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.
|
|
469
|
+
|
|
470
|
+
<a name="getFilesByCount-anchor"></a>
|
|
471
|
+
### `getFilesByCount-anchor`
|
|
472
|
+
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+.
|
|
473
|
+
|
|
474
|
+
##### `pinata.getFilesByCount(filters, count)`
|
|
475
|
+
##### Params
|
|
476
|
+
* `filters` (optional): An object that can consist of the following optional query parameters:
|
|
477
|
+
* `hashContains` (optional): A string of alphanumeric characters that desires hashes must contain
|
|
478
|
+
* `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.
|
|
479
|
+
* `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.
|
|
480
|
+
* `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.
|
|
481
|
+
* `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.
|
|
482
|
+
* `pinSizeMin` (optional): The minimum byte size that pin record you're looking for can have
|
|
483
|
+
* `pinSizeMax` (optional): The maximum byte size that pin record you're looking for can have
|
|
484
|
+
* `status` (optional): Filter pins using one of the following options
|
|
485
|
+
* `'all'` (Records for both pinned and unpinned content will be returned)
|
|
486
|
+
* `'pinned'` (Only records for pinned content will be returned)
|
|
487
|
+
* `'unpinned'` (Only records for unpinned content will be returned)
|
|
488
|
+
* `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:
|
|
489
|
+
* `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
|
|
490
|
+
|
|
491
|
+
##### Metadata filter object formatting
|
|
561
492
|
```
|
|
562
493
|
{
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
{
|
|
494
|
+
name: 'exampleName',
|
|
495
|
+
keyvalues: {
|
|
496
|
+
testKeyValue: {
|
|
497
|
+
value: 'exampleFilterValue',
|
|
498
|
+
op: 'exampleFilterOperation'
|
|
499
|
+
},
|
|
500
|
+
testKeyValue2: {
|
|
501
|
+
value: 'exampleFilterValue2',
|
|
502
|
+
op: 'exampleFilterOperation2'
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
```
|
|
507
|
+
Filter explanations:
|
|
508
|
+
* `name` (optional): If provided, any records returned must have a name that contains the string provided for the 'name'.
|
|
509
|
+
* `keyvalues` (optional): Each keyvalue provided in this object have both a `value` and `op`
|
|
510
|
+
* `value` (required): This is the value which will be filtered on
|
|
511
|
+
* `op` (required): This is the filter operation that will be applied to the `value` that was provided. Valid op values are:
|
|
512
|
+
* `'gt'` (greater than the value provided)
|
|
513
|
+
* `'gte'` (greater than or equal to the value provided)
|
|
514
|
+
* `'lt'` (less than the value provided)
|
|
515
|
+
* `'lte'` (less than or equal to the value provided)
|
|
516
|
+
* `'ne'` (not equal to the value provided)
|
|
517
|
+
* `'eq'` (equal to the value provided)
|
|
518
|
+
* `'between'` (between the two values provided) - NOTE - This also requires a `secondValue` be provided as seen in the example below
|
|
519
|
+
* `'notBetween'` (not between the two values provided) - NOTE - This also requires a `secondValue` be provided as seen in the example below
|
|
520
|
+
* `'like'` (like the value provided)
|
|
521
|
+
* `'notLike'` (not like the value provided)
|
|
522
|
+
* `'iLike'` (case insensitive version of `like`)
|
|
523
|
+
* `'notILike'` (case insensitive version of `notLike`)
|
|
524
|
+
* `'regexp'` (filter the value provided based on a provided regular expression)
|
|
525
|
+
* `'iRegexp'` (case insensitive version of regexp)
|
|
526
|
+
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
#### Response
|
|
530
|
+
```
|
|
531
|
+
[
|
|
532
|
+
{
|
|
566
533
|
id: (the id of your pin instance record),
|
|
567
534
|
ipfs_pin_hash: (the IPFS multi-hash for the content you pinned),
|
|
568
535
|
size: (this is how large (in bytes) the content pinned is),
|
|
@@ -584,11 +551,15 @@ As an example, the following filter would only find records whose name contains
|
|
|
584
551
|
.
|
|
585
552
|
.
|
|
586
553
|
.
|
|
587
|
-
|
|
588
|
-
|
|
554
|
+
]
|
|
555
|
+
|
|
589
556
|
```
|
|
590
557
|
##### Example Code
|
|
558
|
+
|
|
591
559
|
```javascript
|
|
560
|
+
const pinataSDK = require('@pinata/sdk');
|
|
561
|
+
const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');
|
|
562
|
+
|
|
592
563
|
const metadataFilter = {
|
|
593
564
|
name: 'exampleName',
|
|
594
565
|
keyvalues: {
|
|
@@ -609,13 +580,17 @@ const filters = {
|
|
|
609
580
|
pageOffset: 0,
|
|
610
581
|
metadata: metadataFilter
|
|
611
582
|
};
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
583
|
+
|
|
584
|
+
// more reference at [for await ...](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
|
|
585
|
+
for await (const item of pinata.getFilesByCount(filters, 35)) {
|
|
586
|
+
// ...(item) perform any task with the current item in the array of 35
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
for await (const item of pinata.getFilesByCount(filters)) {
|
|
591
|
+
// ...(item) perform any task with the current item the array is determined by all your pins
|
|
592
|
+
}
|
|
593
|
+
|
|
619
594
|
```
|
|
620
595
|
|
|
621
596
|
<a name="userPinnedDataTotal-anchor"></a>
|
|
@@ -724,26 +699,13 @@ The options object can consist of the following values:
|
|
|
724
699
|
* wrapWithDirectory (optional) - Tells IPFS to wrap your content in a directory to preserve the content's original name. See [this blog post](https://flyingzumwalt.gitbooks.io/decentralized-web-primer/content/files-on-ipfs/lessons/wrap-directories-around-content.html) for more details on what this does. Valid options are:
|
|
725
700
|
* `true`
|
|
726
701
|
* `false`
|
|
727
|
-
* customPinPolicy (optional) - a custom [Pin Policy](#pinPolicies-anchor) for the piece of content being pinned. Providing a custom pin policy as part of a request means that the content being pinned will be replicated differently from the user's default pin policy found under the [Account](https://pinata.cloud/account) page.
|
|
728
702
|
|
|
729
703
|
|
|
730
704
|
##### Example pinataOptions object
|
|
731
705
|
```
|
|
732
706
|
{
|
|
733
707
|
cidVersion: 1,
|
|
734
|
-
wrapWithDirectory: true
|
|
735
|
-
customPinPolicy: {
|
|
736
|
-
regions: [
|
|
737
|
-
{
|
|
738
|
-
id: 'FRA1',
|
|
739
|
-
desiredReplicationCount: 2
|
|
740
|
-
},
|
|
741
|
-
{
|
|
742
|
-
id: 'NYC1',
|
|
743
|
-
desiredReplicationCount: 2
|
|
744
|
-
}
|
|
745
|
-
]
|
|
746
|
-
}
|
|
708
|
+
wrapWithDirectory: true
|
|
747
709
|
}
|
|
748
710
|
```
|
|
749
711
|
|