@pinata/sdk 2.1.0 → 3.0.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 (81) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +59 -694
  3. package/index.d.ts +9 -0
  4. package/index.js +6 -0
  5. package/index.mjs +4 -0
  6. package/legacy.js +15 -0
  7. package/package.json +62 -83
  8. package/react/index.d.ts +1 -0
  9. package/react/index.js +3 -0
  10. package/react/index.mjs +1 -0
  11. package/.babelrc +0 -5
  12. package/.editorconfig +0 -12
  13. package/.eslintrc +0 -173
  14. package/.husky/pre-commit +0 -6
  15. package/.nvmrc +0 -1
  16. package/.travis.yml +0 -5
  17. package/lib/pinata-sdk.js +0 -24526
  18. package/lib/pinata-sdk.min.js +0 -22
  19. package/pinata.png +0 -0
  20. package/src/commands/data/getFilesByCount/getFilesByCount.ts +0 -66
  21. package/src/commands/data/index.ts +0 -4
  22. package/src/commands/data/pinList/pinList.ts +0 -77
  23. package/src/commands/data/pinList/queryBuilder.ts +0 -239
  24. package/src/commands/data/testAuthentication.ts +0 -31
  25. package/src/commands/data/userPinnedDataTotal.ts +0 -24
  26. package/src/commands/pinning/hashMetadata.ts +0 -56
  27. package/src/commands/pinning/index.ts +0 -8
  28. package/src/commands/pinning/pinByHash.ts +0 -65
  29. package/src/commands/pinning/pinFileToIPFS.ts +0 -118
  30. package/src/commands/pinning/pinFromFS.ts +0 -60
  31. package/src/commands/pinning/pinJSONToIPFS.ts +0 -47
  32. package/src/commands/pinning/pinJobs/pinJobs.ts +0 -50
  33. package/src/commands/pinning/pinJobs/queryBuilder.ts +0 -75
  34. package/src/commands/pinning/unpin.ts +0 -32
  35. package/src/constants.ts +0 -4
  36. package/src/index.ts +0 -124
  37. package/src/require-babel-polyfill.ts +0 -5
  38. package/src/third-party/base-path-converter.d.ts +0 -3
  39. package/src/third-party/global.d.ts +0 -9
  40. package/src/third-party/is-ipfs.d.ts +0 -5
  41. package/src/util/errorResponse.ts +0 -10
  42. package/src/util/validators.ts +0 -182
  43. package/test/commands/data/getFilesByCount/getFilesByCount.test.ts +0 -212
  44. package/test/commands/data/pinList/pinList.test.ts +0 -102
  45. package/test/commands/data/pinList/queryBuilder.test.ts +0 -439
  46. package/test/commands/data/pinlist-sample-api.ts +0 -540
  47. package/test/commands/data/testAuthentication.test.ts +0 -34
  48. package/test/commands/data/userPinnedDataTotal.test.ts +0 -29
  49. package/test/commands/pinning/hashMetadata.test.ts +0 -76
  50. package/test/commands/pinning/pinByHash.test.ts +0 -46
  51. package/test/commands/pinning/pinFileToIPFS.test.ts +0 -53
  52. package/test/commands/pinning/pinFromFS.ts +0 -71
  53. package/test/commands/pinning/pinJSONToIPFS.test.ts +0 -42
  54. package/test/commands/pinning/pinJobs/pinJobs.test.ts +0 -29
  55. package/test/commands/pinning/pinJobs/queryBuilder.test.ts +0 -120
  56. package/test/commands/pinning/unpin.test.ts +0 -46
  57. package/test/util/validators.test.ts +0 -234
  58. package/tsconfig.json +0 -23
  59. package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +0 -14
  60. package/types/commands/data/index.d.ts +0 -4
  61. package/types/commands/data/pinList/pinList.d.ts +0 -45
  62. package/types/commands/data/pinList/queryBuilder.d.ts +0 -1
  63. package/types/commands/data/testAuthentication.d.ts +0 -5
  64. package/types/commands/data/userPinnedDataTotal.d.ts +0 -2
  65. package/types/commands/pinning/hashMetadata.d.ts +0 -3
  66. package/types/commands/pinning/hashPinPolicy.d.ts +0 -9
  67. package/types/commands/pinning/index.d.ts +0 -8
  68. package/types/commands/pinning/pinByHash.d.ts +0 -14
  69. package/types/commands/pinning/pinFileToIPFS.d.ts +0 -25
  70. package/types/commands/pinning/pinFromFS.d.ts +0 -4
  71. package/types/commands/pinning/pinJSONToIPFS.d.ts +0 -3
  72. package/types/commands/pinning/pinJobs/pinJobs.d.ts +0 -20
  73. package/types/commands/pinning/pinJobs/queryBuilder.d.ts +0 -1
  74. package/types/commands/pinning/unpin.d.ts +0 -2
  75. package/types/commands/pinning/userPinPolicy.d.ts +0 -8
  76. package/types/constants.d.ts +0 -2
  77. package/types/index.d.ts +0 -39
  78. package/types/require-babel-polyfill.d.ts +0 -2
  79. package/types/util/errorResponse.d.ts +0 -1
  80. package/types/util/validators.d.ts +0 -37
  81. package/webpack.config.js +0 -58
package/README.md CHANGED
@@ -1,731 +1,96 @@
1
- <img src="https://cdn-images-1.medium.com/max/1200/1*BTGStLRXsQUbkp0t-oxJhQ.png" width="200" />
1
+ # @pinata/sdk
2
2
 
3
- # Pinata SDK
3
+ > **This package is an alias of [`pinata`](https://www.npmjs.com/package/pinata).**
4
+ > For new projects, install `pinata` directly: `npm i pinata`.
4
5
 
5
- Official NodeJS SDK for [Pinata](https://pinata.cloud)
6
+ `@pinata/sdk@3` re-exports the official Pinata SDK, so you get the same API, types and releases as `pinata`. The legacy v2 API (`pinFileToIPFS`, `pinJSONToIPFS`, …) has been removed. If you need it, stay on `@pinata/sdk@2`, but it is deprecated and no longer maintained.
6
7
 
7
- ## Overview
8
+ - Docs: https://docs.pinata.cloud/sdk
9
+ - Source: https://github.com/PinataCloud/pinata
8
10
 
9
- The Pinata NodeJS SDK provides the quickest / easiest path for interacting with the [Pinata API](https://pinata.cloud/documentation#GettingStarted).
11
+ ## Install
10
12
 
11
- ## Installation
12
- ```
13
- npm install --save @pinata/sdk
14
- ```
15
-
16
- ## Setup
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
-
20
- ```javascript
21
- // Use the api keys by providing the strings directly
22
- const pinataSDK = require('@pinata/sdk');
23
- const pinata = new pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');
13
+ ```bash
14
+ npm i @pinata/sdk # or, preferably: npm i pinata
24
15
  ```
25
16
 
26
- ```javascript
27
- // Use the api keys by specifying your api key and api secret
28
- const pinataSDK = require('@pinata/sdk');
29
- const pinata = new pinataSDK({ pinataApiKey: 'yourPinataApiKey', pinataSecretApiKey: 'yourPinataSecretApiKey' });
17
+ While v3 is in preview it's published under the `next` tag, so `npm i @pinata/sdk` still installs the legacy v2. To try v3 now, run `npm i @pinata/sdk@next`.
30
18
 
31
- ```
32
-
33
- ```javascript
34
- // Use the JWT key
35
- const pinataSDK = require('@pinata/sdk');
36
- const pinata = new pinataSDK({ pinataJWTKey: 'yourPinataJWTKey'});
37
- ```
38
-
39
- Quickly test that you can connect to the API with the following call:
40
- ```javascript
41
- pinata.testAuthentication().then((result) => {
42
- //handle successful authentication here
43
- console.log(result);
44
- }).catch((err) => {
45
- //handle error here
46
- console.log(err);
47
- });
48
- ```
19
+ Requires Node.js 20 or newer.
49
20
 
50
21
  ## Usage
51
- Once you've set up your instance, using the Pinata SDK is easy. Simply call your desired function and handle the results of the promise.
52
-
53
- * Pinning
54
- * [hashMetadata](#hashMetadata-anchor)
55
- * [pinByHash](#pinByHash-anchor)
56
- * [pinFileToIPFS](#pinFileToIPFS-anchor)
57
- * [pinFromFS](#pinFromFS-anchor)
58
- * [pinJobs](#pinJobs-anchor)
59
- * [pinJSONToIPFS](#pinJSONToIPFS-anchor)
60
- * [unpin](#unpin-anchor)
61
- * [userPinPolicy](#userPinPolicy-anchor)
62
-
63
- * Data
64
- * [testAuthentication](#testAuthentication-anchor)
65
- * [pinList](#pinList-anchor)
66
- * [getFilesByCount](#getFilesByCount-anchor)
67
- * [userPinnedDataTotal](#userPinnedDataTotal-anchor)
68
- <br />
69
-
70
- <a name="hashMetadata-anchor"></a>
71
- ### `hashMetadata`
72
- Allows the user to change the name and keyvalues associated with content pinned to Pinata.
73
- Changes made via this endpoint only affect the metadata for the hash passed in. [Metadata](#metadata-anchor) is specific to Pinata and does not modify the actual content stored on IPFS in any way. It is simply a convenient way of keeping track of what content you have stored.
74
22
 
75
- ##### `pinata.hashMetadata(ipfsPinHash, metadata)`
76
- ##### Params
77
- * `ipfsPinHash` - A string for a valid IPFS Hash that you have pinned on Pinata.
78
- * `metadata` A JSON object containing the following:
79
- * `name` (optional) - A new name that Pinata will associate with this particular hash.
80
- * `keyvalues` (optional) - A JSON object with the updated keyvalues you want associated with the hash provided (see more below)
81
-
82
- ###### Adding or modifying keyvalues
83
- To add or modify existing keyvalues, simply provide them in the following format for the keyvalues object:
84
- ```
85
- keyvalues: {
86
- newKey: 'newValue', //this adds a keyvalue pair
87
- existingKey: 'newValue' //this modifies the value of an existing key if that key already exists
88
- }
89
- ```
23
+ ```ts
24
+ import { PinataSDK } from "@pinata/sdk";
90
25
 
91
- ###### Removing keyvalues
92
- To remove a keyvalue pair, simply provide null as the value for an existing key like so:
93
- ```
94
- keyvalues: {
95
- existingKeyToRemove: null //this removes a keyvalue pair
96
- }
97
- ```
98
-
99
- #### Response
100
- If the operation is successful, you will receive back an "OK" REST 200 status.
101
-
102
- ##### Example Code
103
- ```javascript
104
- const metadata = {
105
- name: 'new custom name',
106
- keyvalues: {
107
- newKey: 'newValue',
108
- existingKey: 'newValue',
109
- existingKeyToRemove: null
110
- }
111
- };
112
- pinata.hashMetadata('yourHashHere', metadata).then((result) => {
113
- //handle results here
114
- console.log(result);
115
- }).catch((err) => {
116
- //handle error here
117
- console.log(err);
26
+ const pinata = new PinataSDK({
27
+ pinataJwt: process.env.PINATA_JWT,
28
+ pinataGateway: "example-gateway.mypinata.cloud",
118
29
  });
119
- ```
120
30
 
121
- <a name="pinByHash-anchor"></a>
122
- ### `pinByHash`
123
- Adds a hash to Pinata's pin queue to be pinned asynchronously. For the synchronous version of this operation see: [pinHashToIPFS](#pinHashToIPFS-anchor)
124
-
125
- ##### `pinata.pinByHash(hashToPin, options)`
126
- ##### Params
127
- * `hashToPin` - A string for a valid IPFS Hash (Also known as a CID)
128
- * `options` (optional): A JSON object that can contain following keyvalues:
129
- * `pinataMetadata` (optional): A JSON object with [optional metadata](#metadata-anchor) for the hash being pinned
130
- * `pinataOptions`
131
- * `hostNodes` (optional): An array of [multiaddresses for nodes](#hostNode-anchor) that are currently hosting the content to be pinned
132
- #### Response
133
- ```
134
- {
135
- id: This is Pinata's ID for the pin job,
136
- ipfsHash: This is the IPFS multi-hash provided to Pinata to pin,
137
- status: The current status of the pin job. If the request was successful the status should be 'searching'.
138
- name: The name of the pin (if provided initially)
139
- }
140
- ```
141
- ##### Example Code
142
- ```javascript
143
- const options = {
144
- pinataMetadata: {
145
- name: MyCustomName,
146
- keyvalues: {
147
- customKey: 'customValue',
148
- customKey2: 'customValue2'
149
- }
150
- },
151
- pinataOptions: {
152
- hostNodes: [
153
- '/ip4/hostNode1ExternalIP/tcp/4001/ipfs/hostNode1PeerId',
154
- '/ip4/hostNode2ExternalIP/tcp/4001/ipfs/hostNode2PeerId'
155
- ]
156
- }
157
- };
158
- pinata.pinByHash('yourHashHere', options).then((result) => {
159
- //handle results here
160
- console.log(result);
161
- }).catch((err) => {
162
- //handle error here
163
- console.log(err);
164
- });
31
+ const file = new File(["hello world"], "hello.txt", { type: "text/plain" });
32
+ const upload = await pinata.upload.public.file(file);
33
+ console.log(upload.cid);
165
34
  ```
166
35
 
167
- <a name="pinFileToIPFS-anchor"></a>
168
- ### `pinFileToIPFS`
169
- Send a file to Pinata for direct pinning to IPFS.
36
+ React hooks are available from `@pinata/sdk/react`, the same as `pinata/react`.
170
37
 
171
- ##### `pinata.pinFileToIPFS(readableStream, options)`
172
- ##### Params
173
- * `readableStream` - A [readableStream](https://nodejs.org/api/stream.html) of the file to be added
174
- * `options` (optional): A JSON object that can contain the following keyvalues:
175
- * `pinataMetadata` (optional): A JSON object with [optional metadata](#metadata-anchor) for the file being pinned
176
- * `pinataOptions` (optional): A JSON object with additional [options](#metadata-anchor) for the file being pinned
177
- #### Response
178
- ```
179
- {
180
- IpfsHash: This is the IPFS multi-hash provided back for your content,
181
- PinSize: This is how large (in bytes) the content you just pinned is,
182
- Timestamp: This is the timestamp for your content pinning (represented in ISO 8601 format)
183
- }
184
- ```
185
- ##### Example Code
186
- ```javascript
187
- const fs = require('fs');
188
- const readableStreamForFile = fs.createReadStream('./yourfile.png');
189
- const options = {
190
- pinataMetadata: {
191
- name: MyCustomName,
192
- keyvalues: {
193
- customKey: 'customValue',
194
- customKey2: 'customValue2'
195
- }
196
- },
197
- pinataOptions: {
198
- cidVersion: 0
199
- }
200
- };
201
- pinata.pinFileToIPFS(readableStreamForFile, options).then((result) => {
202
- //handle results here
203
- console.log(result);
204
- }).catch((err) => {
205
- //handle error here
206
- console.log(err);
207
- });
208
- ```
38
+ ## Migrating from v2
209
39
 
210
- <a name="pinFromFS-anchor"></a>
211
- ### `pinFromFS`
212
- Read from a location on your local file system and recursively pin the contents to IPFS (node.js only).
40
+ ### Setup
213
41
 
214
- Both individual files, as well as directories can be read from.
215
-
216
- ##### `pinata.pinFromFS(sourcePath, options)`
217
- ##### Params
218
- * `sourcePath` - The location on your local filesystem that should be read from.
219
- * `options` (optional): A JSON object that can contain the following keyvalues:
220
- * `pinataMetadata` (optional): A JSON object with [optional metadata](#metadata-anchor) for the file being pinned
221
- * `pinataOptions` (optional): A JSON object with additional [options](#metadata-anchor) for the file being pinned
222
- #### Response
223
- ```
224
- {
225
- IpfsHash: This is the IPFS multi-hash provided back for your content,
226
- PinSize: This is how large (in bytes) the content you just pinned is,
227
- Timestamp: This is the timestamp for your content pinning (represented in ISO 8601 format)
228
- }
229
- ```
230
- ##### Example Code
231
- ```javascript
232
- const sourcePath = '/Users/me/builds/my-awesome-website/';
233
- const options = {
234
- pinataMetadata: {
235
- name: 'My Awesome Website',
236
- keyvalues: {
237
- customKey: 'customValue',
238
- customKey2: 'customValue2'
239
- }
240
- },
241
- pinataOptions: {
242
- cidVersion: 0
243
- }
244
- };
245
- pinata.pinFromFS(sourcePath, options).then((result) => {
246
- //handle results here
247
- console.log(result);
248
- }).catch((err) => {
249
- //handle error here
250
- console.log(err);
251
- });
252
- ```
42
+ v2 exported a constructor as the default export and accepted API key and secret pairs. v3 uses the named `PinataSDK` export and authenticates with a JWT. Create a JWT in the [Pinata app](https://app.pinata.cloud/developers/api-keys).
253
43
 
254
- <a name="pinJobs-anchor"></a>
255
- ### `pinJobs`
256
- This endpoint allows users to search for the status of all hashes that are currently in Pinata's pin queue. Records in the pin queue arrived there through either the [pinByHash](#addHashToPinQueue-anchor) operation or by failing during a [pinHashToIPFS](#pinHashToIPFS-anchor) operation.
44
+ ```js
45
+ // v2
46
+ const pinataSDK = require("@pinata/sdk");
47
+ const pinata = new pinataSDK("yourApiKey", "yourApiSecret");
257
48
 
258
- ##### `pinata.pinJobs(filters)`
259
- ##### Params
260
- * `filters` (optional): An object that can consist of the following optional query parameters:
261
- * `sort` (optional): How you wish for the records in the response to be sorted. Valid inputs for this are:
262
- * `'ASC'`
263
- * `'DESC'`
264
- * `status` (optional): What the current status of the record is in the pin queue. Valid statuses and their meanings are:
265
- * `prechecking` - Pinata is running preliminary validations on your pin request.
266
- * `searching` - Pinata is actively searching for your content on the IPFS network. This may take some time if your content is isolated.
267
- * `retrieving` - Pinata has located your content and is now in the process of retrieving it.
268
- * `expired` - Pinata wasn't able to find your content after a day of searching the IPFS network. Please make sure your content is hosted on the IPFS network before trying to pin again.
269
- * `over_free_limit` - Pinning this object would put you over the free tier limit. Please add a credit card to continue pinning content.
270
- * `over_max_size` - This object is too large of an item to pin. If you're seeing this, please contact us for a more custom solution.
271
- * `invalid_object` - The object you're attempting to pin isn't readable by IPFS nodes. Please contact us if you receive this, as we'd like to better understand what you're attempting to pin.
272
- * `bad_host_node` - The provided host node(s) were either invalid or unreachable. Please make sure all provided host nodes are online and reachable.
273
-
274
- * `ipfs_pin_hash` (optional): A string for a valid IPFS hash (also known as a CID) to search for
275
- * `limit` (optional): Limit the amount of results returned per page of results (default is 5, and max is also 1000)
276
- * `offset` (optional): Provide the record offset for records being returned. This is how you retrieve records on additional pages (default is 0)
277
- #### Response
278
- ```
279
- {
280
- count: (this is the total number of pin job records that exist for the query filters you passed in),
281
- rows: [
282
- {
283
- id: (the id for the pin job record),
284
- ipfs_pin_hash: (the IPFS multi-hash for the content you pinned),
285
- date_queued: (The date this hash was initially queued to be pinned - represented in ISO 8601 format),
286
- name: (If you passed in a name for your hash, it will be listed here),
287
- status: (The current status for the pin job)
288
- },
289
- {
290
- same record format as above
291
- }
292
- .
293
- .
294
- .
295
- ]
296
- }
297
- ```
298
- ##### Example Code
299
- ```javascript
300
- const filters = {
301
- sort: 'ASC',
302
- status: 'searching',
303
- ipfs_pin_hash: 'Qma6e8dovfLyiG2UUfdkSHNPAySzrWLX9qVXb44v1muqcp',
304
- limit: 10,
305
- offset: 0
306
- };
307
- pinata.pinJobs('yourHashHere', filters).then((result) => {
308
- //handle results here
309
- console.log(result);
310
- }).catch((err) => {
311
- //handle error here
312
- console.log(err);
313
- });
49
+ // v3
50
+ const { PinataSDK } = require("@pinata/sdk");
51
+ const pinata = new PinataSDK({ pinataJwt: process.env.PINATA_JWT });
314
52
  ```
315
53
 
316
- <a name="pinJSONToIPFS-anchor"></a>
317
- ### `pinJSONToIPFS`
318
- Send JSON to Pinata for direct pinning to IPFS.
54
+ Calling the old default export in v3 throws an error that points back to this guide.
319
55
 
320
- ##### `pinata.pinJSONToIPFS(body, options)`
321
- ##### Params
322
- * `body` - Valid JSON you wish to pin to IPFS
323
- * `options` (optional): A JSON object that can contain the following keyvalues:
324
- * `metadata` (optional): A JSON object with [optional metadata](#metadata-anchor) for the hash being pinned
325
- * `pinataOptions` (optional): A JSON object with additional [options](#metadata-anchor) for the JSON being pinned
326
- #### Response
327
- ```
328
- {
329
- IpfsHash: This is the IPFS multi-hash provided back for your content,
330
- PinSize: This is how large (in bytes) the content you just pinned is,
331
- Timestamp: This is the timestamp for your content pinning (represented in ISO 8601 format)
332
- }
333
- ```
334
- ##### Example Code
335
- ```javascript
336
- const body = {
337
- message: 'Pinatas are awesome'
338
- };
339
- const options = {
340
- pinataMetadata: {
341
- name: MyCustomName,
342
- keyvalues: {
343
- customKey: 'customValue',
344
- customKey2: 'customValue2'
345
- }
346
- },
347
- pinataOptions: {
348
- cidVersion: 0
349
- }
350
- };
351
- pinata.pinJSONToIPFS(body, options).then((result) => {
352
- //handle results here
353
- console.log(result);
354
- }).catch((err) => {
355
- //handle error here
356
- console.log(err);
357
- });
358
- ```
359
-
360
- <a name="unpin-anchor"></a>
361
- ### `unpin`
362
- Have Pinata unpin content that you've pinned through the service.
363
-
364
- ##### `pinata.unpin(hashToUnpin)`
365
- ##### Params
366
- * `hashToUnpin` - the hash of the content you wish to unpin from Pinata
367
- #### Response
368
- If the operation is successful, you will simply receive "OK" as your result
369
- ##### Example Code
370
- ```javascript
371
- pinata.unpin(hashToUnpin).then((result) => {
372
- //handle results here
373
- console.log(result);
374
- }).catch((err) => {
375
- //handle error here
376
- console.log(err);
377
- });
378
- ```
56
+ ### Methods
379
57
 
380
- <a name="testAuthentication-anchor"></a>
381
- ### `testAuthentication`
382
- Tests that you can authenticate with Pinata correctly
58
+ | v2 | v3 |
59
+ |---|---|
60
+ | `pinFileToIPFS(stream, { pinataMetadata })` | `upload.public.file(file).name(name).keyvalues(kv)` |
61
+ | `pinFromFS(path)` | `upload.public.fileArray(files)` |
62
+ | `pinJSONToIPFS(obj, { pinataMetadata })` | `upload.public.json(obj).name(name)` |
63
+ | `pinByHash(cid)` | `upload.public.cid(cid)` |
64
+ | `pinList(filters)` | `files.public.list()` with filters such as `.cid()`, `.name()`, `.keyvalues()`, `.limit()` |
65
+ | `hashMetadata(cid, metadata)` | `files.public.update({ id, name, keyvalues })` * |
66
+ | `unpin(cid)` | `files.public.delete([id])` * |
67
+ | `testAuthentication()` | `testAuthentication()` |
383
68
 
384
- ##### `pinata.testAuthentication()`
385
- ##### Params
386
- None
69
+ \* These take a file ID, not a CID. Look the ID up first:
387
70
 
388
- #### Response
389
- ```
390
- {
391
- authenticated: true
392
- }
71
+ ```js
72
+ const { files } = await pinata.files.public.list().cid(cid);
73
+ await pinata.files.public.delete([files[0].id]);
393
74
  ```
394
75
 
395
- ##### Example Code
396
- ```javascript
397
- pinata.testAuthentication().then((result) => {
398
- //handle results here
399
- console.log(result);
400
- }).catch((err) => {
401
- //handle error here
402
- console.log(err);
403
- });
404
- ```
76
+ ### Inputs
405
77
 
406
- <a name="pinList-anchor"></a>
407
- ### `pinList`
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).
78
+ v2 accepted Node.js readable streams (for example `fs.createReadStream`). v3 takes web-standard `File` and `Blob` objects, which are available globally in Node.js 20 and newer:
409
79
 
410
- ##### `pinata.pinList(filters)`
411
- ##### Params
412
- * `filters` (optional): An object that can consist of the following optional query parameters:
413
- * `hashContains` (optional): A string of alphanumeric characters that desires hashes must contain
414
- * `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.
415
- * `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.
416
- * `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.
417
- * `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.
418
- * `pinSizeMin` (optional): The minimum byte size that pin record you're looking for can have
419
- * `pinSizeMax` (optional): The maximum byte size that pin record you're looking for can have
420
- * `status` (optional): Filter pins using one of the following options
421
- * `'all'` (Records for both pinned and unpinned content will be returned)
422
- * `'pinned'` (Only records for pinned content will be returned)
423
- * `'unpinned'` (Only records for unpinned content will be returned)
424
- * `pageLimit` (optional): Limit the amount of results returned per page of results (default is 10, and max is 1000)
425
- * `pageOffset` (optional): Provide the record offset for records being returned. This is how you retrieve records on additional pages (default is 0)
426
- * `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:
427
-
428
- ##### Metadata filter object formatting
429
- ```
430
- {
431
- name: 'exampleName',
432
- keyvalues: {
433
- testKeyValue: {
434
- value: 'exampleFilterValue',
435
- op: 'exampleFilterOperation'
436
- },
437
- testKeyValue2: {
438
- value: 'exampleFilterValue2',
439
- op: 'exampleFilterOperation2'
440
- }
441
- }
442
- }
443
- ```
444
- Filter explanations:
445
- * `name` (optional): If provided, any records returned must have a name that contains the string provided for the 'name'.
446
- * `keyvalues` (optional): Each keyvalue provided in this object have both a `value` and `op`
447
- * `value` (required): This is the value which will be filtered on
448
- * `op` (required): This is the filter operation that will be applied to the `value` that was provided. Valid op values are:
449
- * `'gt'` (greater than the value provided)
450
- * `'gte'` (greater than or equal to the value provided)
451
- * `'lt'` (less than the value provided)
452
- * `'lte'` (less than or equal to the value provided)
453
- * `'ne'` (not equal to the value provided)
454
- * `'eq'` (equal to the value provided)
455
- * `'between'` (between the two values provided) - NOTE - This also requires a `secondValue` be provided as seen in the example below
456
- * `'notBetween'` (not between the two values provided) - NOTE - This also requires a `secondValue` be provided as seen in the example below
457
- * `'like'` (like the value provided)
458
- * `'notLike'` (not like the value provided)
459
- * `'iLike'` (case insensitive version of `like`)
460
- * `'notILike'` (case insensitive version of `notLike`)
461
- * `'regexp'` (filter the value provided based on a provided regular expression)
462
- * `'iRegexp'` (case insensitive version of regexp)
463
-
464
- As an example, the following filter would only find records whose name contains the letters 'invoice', have the metadata key 'company' with a value of 'exampleCompany', and have a metadata key 'total' with values between 500 and 1000:
465
- ```
466
- {
467
- name: 'invoice',
468
- keyvalues: {
469
- company: {
470
- value: 'exampleCompany,
471
- op: 'eq'
472
- },
473
- total: {
474
- value: 500,
475
- secondValue: 1000,
476
- op: 'between'
477
- }
478
- }
479
- }
480
- ```
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.
483
-
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
508
- ```
509
- {
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
- {
549
- id: (the id of your pin instance record),
550
- ipfs_pin_hash: (the IPFS multi-hash for the content you pinned),
551
- size: (this is how large (in bytes) the content pinned is),
552
- user_id: (this is your user id for Pinata),
553
- date_pinned: (This is the timestamp for when this content was pinned - represented in ISO 8601 format),
554
- date_unpinned: (This is the timestamp for when this content was unpinned (if null, then you still have the content pinned on Pinata),
555
- metadata: {
556
- name: (this will be the name of the file originally uploaded, or the custom name you set),
557
- keyvalues: {
558
- exampleCustomKey: "exampleCustomValue",
559
- exampleCustomKey2: "exampleCustomValue2",
560
- ...
561
- }
562
- }
563
- },
564
- {
565
- same record format as above
566
- }
567
- .
568
- .
569
- .
570
- ]
571
-
572
- ```
573
- ##### Example Code
574
-
575
- ```javascript
576
- const pinataSDK = require('@pinata/sdk');
577
- const pinata = pinataSDK('yourPinataApiKey', 'yourPinataSecretApiKey');
578
-
579
- const metadataFilter = {
580
- name: 'exampleName',
581
- keyvalues: {
582
- testKeyValue: {
583
- value: 'exampleFilterValue',
584
- op: 'exampleFilterOperation'
585
- },
586
- testKeyValue2: {
587
- value: 'exampleFilterValue2',
588
- op: 'exampleFilterOperation2'
589
- }
590
- }
591
- };
592
-
593
- const filters = {
594
- status : 'pinned',
595
- pageLimit: 10,
596
- pageOffset: 0,
597
- metadata: metadataFilter
598
- };
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
-
610
- ```
611
-
612
- <a name="userPinnedDataTotal-anchor"></a>
613
- ### `userPinnedDataTotal`
614
- Returns the total combined size (in bytes) of all content you currently have pinned on Pinata.
615
-
616
- ##### `pinata.userPinnedDataTotal()`
617
- ##### Params
618
- None
619
-
620
- #### Response
621
- The response for this call will the total combined size of everything you currently have pinned on pinata.
622
- This value will be expressed in bytes
623
-
624
- ##### Example Code
625
- ```javascript
626
- pinata.userPinnedDataTotal().then((result) => {
627
- //handle results here
628
- console.log(result);
629
- }).catch((err) => {
630
- //handle error here
631
- console.log(err);
632
- });
633
- ```
80
+ ```js
81
+ // v2
82
+ await pinata.pinFileToIPFS(fs.createReadStream("./photo.png"));
634
83
 
635
- <a name="hostNode-anchor"></a>
636
- ## Host Node Multiaddresses
637
- For endpoints that involve Pinata finding and pinning content that already resides on the IPFS network, you can help Pinata find your content faster by optionally providing us with the "multiaddresses" up to five host nodes that your content already resides on.
638
-
639
- To find the multiaddresses of your nodes, simply run the following on your node's command line:
640
- ```
641
- ipfs id
84
+ // v3
85
+ import { openAsBlob } from "node:fs";
86
+ const blob = await openAsBlob("./photo.png");
87
+ await pinata.upload.public.file(new File([blob], "photo.png", { type: "image/png" }));
642
88
  ```
643
- In the response, you'll want to focus on the "Addresses" array that's returned. Here you'll find the multiaddresses of your node. These multiaddresses are what other IPFS nodes use to connect to your node.
644
-
645
- In the "Addresses" array, take note of the multiaddress that contains your external IP address. Not the local ipv4 "127.0.0.1" address or the local ipv6 "::1" address.
646
-
647
- Here's an example of what a full external ipv4 multiaddress would look like (your IP address and node ID will differ):
648
-
649
- `/ip4/123.456.78.90/tcp/4001/ipfs/QmAbCdEfGhIjKlMnOpQrStUvWxYzAbCdEfGhIjKlMnOpQr`
650
89
 
651
- ⚠️ Please make sure every node provided is online. Pinata will attempt to connect to all nodes before pinning the content, and if any these nodes are offline, your request will eventually fail.
90
+ ### What's new in v3
652
91
 
92
+ Groups, private files, signed upload URLs, gateways and access links, resumable uploads for large files, analytics, and more. See the [SDK docs](https://docs.pinata.cloud/sdk).
653
93
 
654
- <a name="pinPolicies-anchor"></a>
655
-
656
- ## Pin Policies
657
- A pin policy tells Pinata how many times content should be replicated, and where that content should be replicated at.
658
-
659
- To read more about pin policies, please check out the [Regions and Replications Documentation](https://pinata.cloud/documentation#RegionsAndReplications).
660
-
661
- Pin policies take the following form:
662
-
663
-
664
- ##### Example pin policy object
665
- ```
666
- {
667
- regions: [
668
- {
669
- id: 'FRA1',
670
- desiredReplicationCount: 1
671
- },
672
- {
673
- id: 'NYC1',
674
- desiredReplicationCount: 2
675
- }
676
- ]
677
- }
678
- ```
679
- The ids of currently available public regions are:
680
-
681
- • FRA1 - Frankfurt, Germany (max 2 replications)
682
-
683
- • NYC1 - New York City, USA (max 2 replications)
684
-
685
- <a name="metadata-anchor"></a>
686
- ## Pinata Metadata
687
- For endpoints that allow you to add content, Pinata lets you add optionally metadata for that content. This metadata can later be used for querying on what you've pinned with our [userPinList](#userPinList-anchor) endpoint. Providing metadata does not alter your content or how it is stored on IPFS in any way.
688
-
689
- The metadata object can consist of the following values:
690
- * name (optional) - A custom string to use as the name for your content
691
- * keyvalues (optional) - An object containing up to 10 custom key / value pairs. The values can be:
692
- * strings
693
- * numbers (integers or decimals)
694
- * dates (provided in ISO_8601 format)
695
-
696
- ##### Example metadata object
697
- ```
698
- {
699
- name: "customName",
700
- keyvalues: {
701
- customKey: "customValue",
702
- customKey2: "customValue2"
703
- }
704
- }
705
- ```
706
- <a name="pinataOptions-anchor"></a>
707
-
708
- ## Pinata Options
709
- Some endpoints allow you to pass additional options for Pinata to take into account when adding content to IPFS.
710
-
711
- The options object can consist of the following values:
712
- * cidVerson (optional) - The [CID version](https://github.com/multiformats/cid#versions) IPFS will use when creating a hash for your content. Valid options are:
713
- * `0` - CIDv0
714
- * `1` - CIDv1
715
- * 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:
716
- * `true`
717
- * `false`
718
-
719
-
720
- ##### Example pinataOptions object
721
- ```
722
- {
723
- cidVersion: 1,
724
- wrapWithDirectory: true
725
- }
726
- ```
727
-
728
- ## Questions? Issues? Suggestions?
729
- Feel free to file a github issue or email us at team@pinata.cloud
94
+ ## License
730
95
 
731
- We'd love to hear from you!
96
+ MIT