@pinata/sdk 1.1.20 → 1.1.24

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 (40) hide show
  1. package/README.md +3 -3
  2. package/lib/pinata-sdk.js +358 -1
  3. package/lib/pinata-sdk.min.js +1 -1
  4. package/package.json +5 -2
  5. package/src/commands/data/pinList/pinList.js +7 -0
  6. package/src/commands/data/pinList/queryBuilder.js +11 -0
  7. package/src/commands/data/testAuthentication.js +6 -0
  8. package/src/commands/data/userPinnedDataTotal.js +6 -0
  9. package/src/commands/pinning/hashMetadata.js +8 -0
  10. package/src/commands/pinning/hashPinPolicy.js +8 -0
  11. package/src/commands/pinning/pinByHash.js +8 -0
  12. package/src/commands/pinning/pinFileToIPFS.js +11 -3
  13. package/src/commands/pinning/pinFromFS.js +8 -0
  14. package/src/commands/pinning/pinJSONToIPFS.js +8 -0
  15. package/src/commands/pinning/pinJobs/pinJobs.js +7 -0
  16. package/src/commands/pinning/pinJobs/queryBuilder.js +6 -0
  17. package/src/commands/pinning/unpin.js +7 -0
  18. package/src/commands/pinning/userPinPolicy.js +7 -0
  19. package/src/index.js +227 -0
  20. package/src/util/validators.js +21 -0
  21. package/test/commands/pinning/pinFileToIPFS.test.js +16 -3
  22. package/tsconfig.json +23 -0
  23. package/types/commands/data/pinList/pinList.d.ts +8 -0
  24. package/types/commands/data/pinList/queryBuilder.d.ts +7 -0
  25. package/types/commands/data/testAuthentication.d.ts +7 -0
  26. package/types/commands/data/userPinnedDataTotal.d.ts +7 -0
  27. package/types/commands/pinning/hashMetadata.d.ts +9 -0
  28. package/types/commands/pinning/hashPinPolicy.d.ts +9 -0
  29. package/types/commands/pinning/pinByHash.d.ts +9 -0
  30. package/types/commands/pinning/pinFileToIPFS.d.ts +9 -0
  31. package/types/commands/pinning/pinFromFS.d.ts +9 -0
  32. package/types/commands/pinning/pinJSONToIPFS.d.ts +9 -0
  33. package/types/commands/pinning/pinJobs/pinJobs.d.ts +8 -0
  34. package/types/commands/pinning/pinJobs/queryBuilder.d.ts +7 -0
  35. package/types/commands/pinning/unpin.d.ts +8 -0
  36. package/types/commands/pinning/userPinPolicy.d.ts +8 -0
  37. package/types/constants.d.ts +1 -0
  38. package/types/index.d.ts +362 -0
  39. package/types/util/errorResponse.d.ts +1 -0
  40. package/types/util/validators.d.ts +26 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Pin By Hash
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {*} hashToPin
6
+ * @param {*} options
7
+ * @returns {Promise<unknown>}
8
+ */
9
+ export default function pinByHash(pinataApiKey: string, pinataSecretApiKey: string, hashToPin: any, options: any): Promise<unknown>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Pin File to IPFS
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {*} readStream
6
+ * @param {*} options
7
+ * @returns {Promise<unknown>}
8
+ */
9
+ export default function pinFileToIPFS(pinataApiKey: string, pinataSecretApiKey: string, readStream: any, options: any): Promise<unknown>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * PinFromFS
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {string} sourcePath
6
+ * @param {*} options
7
+ * @returns {Promise<unknown>}
8
+ */
9
+ export default function pinFromFS(pinataApiKey: string, pinataSecretApiKey: string, sourcePath: string, options: any): Promise<unknown>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Pin JSON to IPFS
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {*} body
6
+ * @param {*} options
7
+ * @returns {Promise<unknown>}
8
+ */
9
+ export default function pinJSONToIPFS(pinataApiKey: string, pinataSecretApiKey: string, body: any, options: any): Promise<unknown>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Pin Jobs
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {*} filters
6
+ * @returns {Promise<unknown>}
7
+ */
8
+ export default function pinJobs(pinataApiKey: string, pinataSecretApiKey: string, filters: any): Promise<unknown>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Query Buidler
3
+ * @param {string} baseUrl
4
+ * @param {*} filters
5
+ * @returns {*}
6
+ */
7
+ export default function queryBuilder(baseUrl: string, filters: any): any;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Unpin
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {string} hashToUnpin
6
+ * @returns {Promise<unknown>}
7
+ */
8
+ export default function unpin(pinataApiKey: string, pinataSecretApiKey: string, hashToUnpin: string): Promise<unknown>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * User Pin Policy
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {*} newPinPolicy
6
+ * @returns {Promise<unknown>}
7
+ */
8
+ export default function userPinPolicy(pinataApiKey: string, pinataSecretApiKey: string, newPinPolicy: any): Promise<unknown>;
@@ -0,0 +1 @@
1
+ export const baseUrl: "https://api.pinata.cloud";
@@ -0,0 +1,362 @@
1
+ /**
2
+ * @typedef {Record<string, string | number | null>} PinataMetadata
3
+ */
4
+ /**
5
+ * @typedef PinataMetadataFilter
6
+ * @property {string} [name]
7
+ * @property {Record<string, {value: string, op: string}>} keyvalues
8
+ */
9
+ /**
10
+ * @typedef {{id: string, desiredReplicationCount: number}} PinataPinPolicyItem
11
+ */
12
+ /**
13
+ * @typedef PinataPinByHashOptions
14
+ * @property {string[]} [hostNodes]
15
+ * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
16
+ */
17
+ /**
18
+ * @typedef PinataPinByHashPinOptions
19
+ * @property {PinataMetadata} [pinataMetadata]
20
+ * @property {PinataPinByHashOptions} [pinataOptions]
21
+ */
22
+ /**
23
+ * @typedef PinataOptions
24
+ * @property {0 | 1} [cidVersion]
25
+ * @property {boolean} [wrapWithDirectory]
26
+ * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
27
+ */
28
+ /**
29
+ * @typedef PinataPinOptions
30
+ * @property {PinataMetadata} [pinataMetadata]
31
+ * @property {PinataOptions} [pinataOptions]
32
+ */
33
+ /**
34
+ * @typedef PinataPinJobsFilterOptions
35
+ * @property {'ASC' | 'DESC'} sort
36
+ * @property {string} [status]
37
+ * @property {string} [ipfs_pin_hash]
38
+ * @property {number} [limit]
39
+ * @property {number} [offset]
40
+ */
41
+ /**
42
+ * @typedef PinataPinListFilterOptions
43
+ * @property {string} [hashContains]
44
+ * @property {string} [pinStart]
45
+ * @property {string} [pinEnd]
46
+ * @property {string} [unpinStart]
47
+ * @property {string} [unpinEnd]
48
+ * @property {number} [pinSizeMin]
49
+ * @property {number} [pinSizeMax]
50
+ * @property {string} [status]
51
+ * @property {number} [pageLimit]
52
+ * @property {number} [pageOffset]
53
+ * @property {PinataMetadataFilter} [metadata]
54
+ */
55
+ /**
56
+ * @typedef PinataPinByHashResponse
57
+ * @property {number | string} id
58
+ * @property {string} ipfsHash
59
+ * @property {string} status
60
+ * @property {string} name
61
+ */
62
+ /**
63
+ * @typedef PinataPinResponse
64
+ * @property {string} IpfsHash
65
+ * @property {number} PinSize
66
+ * @property {string} Timestamp
67
+ */
68
+ /**
69
+ * @typedef PinataPinJobsResponseRow
70
+ * @property {number | string} id
71
+ * @property {string} ipfs_pin_hash
72
+ * @property {string} date_queued
73
+ * @property {string | undefined | null} name
74
+ * @property {string} status
75
+ */
76
+ /**
77
+ * @typedef PinataPinJobsResponse
78
+ * @property {number} count
79
+ * @property {PinataPinJobsResponseRow[]} rows
80
+ */
81
+ /**
82
+ * @typedef PinataPinListResponseRow
83
+ * @property {number | string} id
84
+ * @property {string} ipfs_pin_hash
85
+ * @property {number} size
86
+ * @property {string | number} user_id
87
+ * @property {string} date_pinned
88
+ * @property {string} date_unpinned
89
+ * @property {PinataMetadata} metadata
90
+ */
91
+ /**
92
+ * @typedef PinataPinListResponse
93
+ * @property {number} count
94
+ * @property {PinataPinListResponseRow[]} rows
95
+ */
96
+ /**
97
+ * Hash meta data
98
+ * @callback hashMetadata
99
+ * @param {string} ipfsPinHash
100
+ * @param {PinataMetadata} metadata
101
+ * @returns {Promise<any>}
102
+ */
103
+ /**
104
+ * Hash pin policy
105
+ * @callback hashPinPolicy
106
+ * @param {string} ipfsPinHash
107
+ * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
108
+ * @returns {Promise<any>}
109
+ */
110
+ /**
111
+ * Pin by hash
112
+ * @callback pinByHash
113
+ * @param {string} hashToPin
114
+ * @param {PinataPinByHashPinOptions} [options]
115
+ * @returns {Promise<PinataPinByHashResponse>}
116
+ */
117
+ /**
118
+ * Pin file to IPFS
119
+ * @callback pinFileToIPFS
120
+ * @param {ReadStream} readableStream
121
+ * @param {PinataPinOptions} [options]
122
+ * @returns {Promise<PinataPinResponse>}
123
+ */
124
+ /**
125
+ * Pin from FS
126
+ * @callback pinFromFS
127
+ * @param {string} sourcePath
128
+ * @param {PinataPinOptions} [options]
129
+ * @returns {Promise<PinataPinResponse>}
130
+ */
131
+ /**
132
+ * Pin Jobs
133
+ * @callback pinJobs
134
+ * @param {PinataPinJobsFilterOptions} [filters]
135
+ * @returns {Promise<PinataPinJobsResponse>}
136
+ */
137
+ /**
138
+ * Pin JSON to IPFS
139
+ * @callback pinJSONToIPFS
140
+ * @param {Object} body
141
+ * @param {PinataPinOptions} [options]
142
+ * @returns {Promise<PinataPinResponse>}
143
+ */
144
+ /**
145
+ * Unpin
146
+ * @callback unpin
147
+ * @param {string} hashToUnpin
148
+ * @returns {Promise<any>}
149
+ */
150
+ /**
151
+ * User Pin Policy
152
+ * @callback userPinPolicy
153
+ * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
154
+ * @returns {Promise<any>}
155
+ */
156
+ /**
157
+ * Test Authentication
158
+ * @callback testAuthentication
159
+ * @returns {Promise<{authenticated: boolean}>}
160
+ */
161
+ /**
162
+ * Pin List
163
+ * @callback pinList
164
+ * @param {PinataPinListFilterOptions} [filters]
165
+ * @returns {Promise<PinataPinListResponse>}
166
+ */
167
+ /**
168
+ * User Pinned Data Total
169
+ * @callback userPinnedDataTotal
170
+ * @returns {Promise<number>}
171
+ */
172
+ /**
173
+ * @typedef PinataClient
174
+ * @property {pinByHash} pinByHash
175
+ * @property {hashMetadata} hashMetadata
176
+ * @property {hashPinPolicy} hashPinPolicy
177
+ * @property {pinFileToIPFS} pinFileToIPFS
178
+ * @property {pinFromFS} pinFromFS
179
+ * @property {pinJSONToIPFS} pinJSONToIPFS
180
+ * @property {pinJobs} pinJobs
181
+ * @property {unpin} unpin
182
+ * @property {userPinPolicy} userPinPolicy
183
+ * @property {testAuthentication} testAuthentication
184
+ * @property {pinList} pinList
185
+ * @property {userPinnedDataTotal} userPinnedDataTotal
186
+ */
187
+ /**
188
+ * Pinata Client
189
+ *
190
+ * @param {string} pinataApiKey
191
+ * @param {string} pinataSecretApiKey
192
+ * @returns {PinataClient}
193
+ */
194
+ export default function pinataClient(pinataApiKey: string, pinataSecretApiKey: string): PinataClient;
195
+ export type PinataMetadata = Record<string, string | number | null>;
196
+ export type PinataMetadataFilter = {
197
+ name?: string | undefined;
198
+ keyvalues: Record<string, {
199
+ value: string;
200
+ op: string;
201
+ }>;
202
+ };
203
+ export type PinataPinPolicyItem = {
204
+ id: string;
205
+ desiredReplicationCount: number;
206
+ };
207
+ export type PinataPinByHashOptions = {
208
+ hostNodes?: string[] | undefined;
209
+ customPinPolicy?: {
210
+ regions: PinataPinPolicyItem[];
211
+ } | undefined;
212
+ };
213
+ export type PinataPinByHashPinOptions = {
214
+ pinataMetadata?: Record<string, string | number | null> | undefined;
215
+ pinataOptions?: PinataPinByHashOptions | undefined;
216
+ };
217
+ export type PinataOptions = {
218
+ cidVersion?: 0 | 1 | undefined;
219
+ wrapWithDirectory?: boolean | undefined;
220
+ customPinPolicy?: {
221
+ regions: PinataPinPolicyItem[];
222
+ } | undefined;
223
+ };
224
+ export type PinataPinOptions = {
225
+ pinataMetadata?: Record<string, string | number | null> | undefined;
226
+ pinataOptions?: PinataOptions | undefined;
227
+ };
228
+ export type PinataPinJobsFilterOptions = {
229
+ sort: 'ASC' | 'DESC';
230
+ status?: string | undefined;
231
+ ipfs_pin_hash?: string | undefined;
232
+ limit?: number | undefined;
233
+ offset?: number | undefined;
234
+ };
235
+ export type PinataPinListFilterOptions = {
236
+ hashContains?: string | undefined;
237
+ pinStart?: string | undefined;
238
+ pinEnd?: string | undefined;
239
+ unpinStart?: string | undefined;
240
+ unpinEnd?: string | undefined;
241
+ pinSizeMin?: number | undefined;
242
+ pinSizeMax?: number | undefined;
243
+ status?: string | undefined;
244
+ pageLimit?: number | undefined;
245
+ pageOffset?: number | undefined;
246
+ metadata?: PinataMetadataFilter | undefined;
247
+ };
248
+ export type PinataPinByHashResponse = {
249
+ id: number | string;
250
+ ipfsHash: string;
251
+ status: string;
252
+ name: string;
253
+ };
254
+ export type PinataPinResponse = {
255
+ IpfsHash: string;
256
+ PinSize: number;
257
+ Timestamp: string;
258
+ };
259
+ export type PinataPinJobsResponseRow = {
260
+ id: number | string;
261
+ ipfs_pin_hash: string;
262
+ date_queued: string;
263
+ name: string | undefined | null;
264
+ status: string;
265
+ };
266
+ export type PinataPinJobsResponse = {
267
+ count: number;
268
+ rows: PinataPinJobsResponseRow[];
269
+ };
270
+ export type PinataPinListResponseRow = {
271
+ id: number | string;
272
+ ipfs_pin_hash: string;
273
+ size: number;
274
+ user_id: string | number;
275
+ date_pinned: string;
276
+ date_unpinned: string;
277
+ metadata: PinataMetadata;
278
+ };
279
+ export type PinataPinListResponse = {
280
+ count: number;
281
+ rows: PinataPinListResponseRow[];
282
+ };
283
+ /**
284
+ * Hash meta data
285
+ */
286
+ 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
+ /**
294
+ * Pin by hash
295
+ */
296
+ export type pinByHash = (hashToPin: string, options?: PinataPinByHashPinOptions | undefined) => Promise<PinataPinByHashResponse>;
297
+ /**
298
+ * Pin file to IPFS
299
+ */
300
+ export type pinFileToIPFS = (readableStream: any, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
301
+ /**
302
+ * Pin from FS
303
+ */
304
+ export type pinFromFS = (sourcePath: string, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
305
+ /**
306
+ * Pin Jobs
307
+ */
308
+ export type pinJobs = (filters?: PinataPinJobsFilterOptions | undefined) => Promise<PinataPinJobsResponse>;
309
+ /**
310
+ * Pin JSON to IPFS
311
+ */
312
+ export type pinJSONToIPFS = (body: Object, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
313
+ /**
314
+ * Unpin
315
+ */
316
+ 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
+ /**
324
+ * Test Authentication
325
+ */
326
+ export type testAuthentication = () => Promise<{
327
+ authenticated: boolean;
328
+ }>;
329
+ /**
330
+ * Pin List
331
+ */
332
+ export type pinList = (filters?: PinataPinListFilterOptions | undefined) => Promise<PinataPinListResponse>;
333
+ /**
334
+ * User Pinned Data Total
335
+ */
336
+ export type userPinnedDataTotal = () => Promise<number>;
337
+ export type PinataClient = {
338
+ pinByHash: pinByHash;
339
+ hashMetadata: hashMetadata;
340
+ hashPinPolicy: hashPinPolicy;
341
+ pinFileToIPFS: pinFileToIPFS;
342
+ pinFromFS: pinFromFS;
343
+ pinJSONToIPFS: pinJSONToIPFS;
344
+ pinJobs: pinJobs;
345
+ unpin: unpin;
346
+ userPinPolicy: userPinPolicy;
347
+ testAuthentication: testAuthentication;
348
+ pinList: pinList;
349
+ userPinnedDataTotal: userPinnedDataTotal;
350
+ };
351
+ import pinByHash from "./commands/pinning/pinByHash";
352
+ import hashMetadata from "./commands/pinning/hashMetadata";
353
+ import hashPinPolicy from "./commands/pinning/hashPinPolicy";
354
+ import pinFileToIPFS from "./commands/pinning/pinFileToIPFS";
355
+ import pinFromFS from "./commands/pinning/pinFromFS";
356
+ import pinJSONToIPFS from "./commands/pinning/pinJSONToIPFS";
357
+ import pinJobs from "./commands/pinning/pinJobs/pinJobs";
358
+ import unpin from "./commands/pinning/unpin";
359
+ import userPinPolicy from "./commands/pinning/userPinPolicy";
360
+ import testAuthentication from "./commands/data/testAuthentication";
361
+ import pinList from "./commands/data/pinList/pinList";
362
+ import userPinnedDataTotal from "./commands/data/userPinnedDataTotal";
@@ -0,0 +1 @@
1
+ export function handleError(error: any): any;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Validate API Keys
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ */
6
+ export function validateApiKeys(pinataApiKey: string, pinataSecretApiKey: string): void;
7
+ /**
8
+ * Validate host Nodes
9
+ * @param {*} hostNodes
10
+ */
11
+ export function validateHostNodes(hostNodes: any): void;
12
+ /**
13
+ * Validate MetaData
14
+ * @param {*} metadata
15
+ */
16
+ export function validateMetadata(metadata: any): void;
17
+ /**
18
+ * Validate Pin Policy Structure
19
+ * @param {*} pinPolicy
20
+ */
21
+ export function validatePinPolicyStructure(pinPolicy: any): void;
22
+ /**
23
+ * Validate Pinata Options
24
+ * @param {*} options
25
+ */
26
+ export function validatePinataOptions(options: any): void;