@pinata/sdk 1.2.1 → 2.0.0-beta.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.
Files changed (74) hide show
  1. package/.babelrc +1 -1
  2. package/.eslintrc +7 -7
  3. package/.husky/pre-commit +6 -0
  4. package/.nvmrc +1 -1
  5. package/README.md +3 -3
  6. package/lib/pinata-sdk.js +494 -468
  7. package/lib/pinata-sdk.min.js +5 -5
  8. package/package.json +83 -71
  9. package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +8 -9
  10. package/src/commands/data/index.ts +4 -0
  11. package/src/commands/data/pinList/pinList.ts +77 -0
  12. package/src/commands/data/pinList/{queryBuilder.js → queryBuilder.ts} +6 -16
  13. package/src/commands/data/{testAuthentication.js → testAuthentication.ts} +8 -9
  14. package/src/commands/data/{userPinnedDataTotal.js → userPinnedDataTotal.ts} +4 -9
  15. package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +9 -11
  16. package/src/commands/pinning/index.ts +8 -0
  17. package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +22 -11
  18. package/src/commands/pinning/{pinFileToIPFS.js → pinFileToIPFS.ts} +27 -11
  19. package/src/commands/pinning/{pinFromFS.js → pinFromFS.ts} +14 -19
  20. package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +5 -11
  21. package/src/commands/pinning/pinJobs/{pinJobs.js → pinJobs.ts} +23 -9
  22. package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
  23. package/src/commands/pinning/{unpin.js → unpin.ts} +3 -9
  24. package/src/{constants.js → constants.ts} +0 -0
  25. package/src/index.ts +120 -0
  26. package/src/third-party/base-path-converter.d.ts +3 -0
  27. package/src/third-party/is-ipfs.d.ts +5 -0
  28. package/src/third-party/recursive-fs.d.ts +5 -0
  29. package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
  30. package/src/util/{validators.js → validators.ts} +14 -33
  31. package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +23 -22
  32. package/test/commands/data/pinList/{pinList.test.js → pinList.test.ts} +25 -26
  33. package/test/commands/data/pinList/{queryBuilder.test.js → queryBuilder.test.ts} +9 -10
  34. package/test/commands/data/pinlist-sample-api.ts +540 -0
  35. package/test/commands/data/{testAuthentication.test.js → testAuthentication.test.ts} +13 -13
  36. package/test/commands/data/{userPinnedDataTotal.test.js → userPinnedDataTotal.test.ts} +4 -4
  37. package/test/commands/pinning/{hashMetadata.test.js → hashMetadata.test.ts} +7 -8
  38. package/test/commands/pinning/{pinByHash.test.js → pinByHash.test.ts} +4 -5
  39. package/test/commands/pinning/{pinFileToIPFS.test.js → pinFileToIPFS.test.ts} +5 -7
  40. package/test/commands/pinning/{pinFromFS.js → pinFromFS.ts} +5 -6
  41. package/test/commands/pinning/{pinJSONToIPFS.test.js → pinJSONToIPFS.test.ts} +4 -5
  42. package/test/commands/pinning/pinJobs/{pinJobs.test.js → pinJobs.test.ts} +4 -4
  43. package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
  44. package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +4 -5
  45. package/test/util/validators.test.ts +234 -0
  46. package/tsconfig.json +2 -2
  47. package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +4 -2
  48. package/types/commands/data/index.d.ts +4 -0
  49. package/types/commands/data/pinList/pinList.d.ts +45 -8
  50. package/types/commands/data/pinList/queryBuilder.d.ts +1 -7
  51. package/types/commands/data/testAuthentication.d.ts +5 -7
  52. package/types/commands/data/userPinnedDataTotal.d.ts +2 -7
  53. package/types/commands/pinning/hashMetadata.d.ts +3 -9
  54. package/types/commands/pinning/index.d.ts +8 -0
  55. package/types/commands/pinning/pinByHash.d.ts +14 -9
  56. package/types/commands/pinning/pinFileToIPFS.d.ts +25 -1
  57. package/types/commands/pinning/pinFromFS.d.ts +3 -9
  58. package/types/commands/pinning/pinJSONToIPFS.d.ts +3 -9
  59. package/types/commands/pinning/pinJobs/pinJobs.d.ts +20 -8
  60. package/types/commands/pinning/pinJobs/queryBuilder.d.ts +1 -7
  61. package/types/commands/pinning/unpin.d.ts +2 -8
  62. package/types/constants.d.ts +2 -2
  63. package/types/index.d.ts +37 -165
  64. package/types/util/errorResponse.d.ts +1 -1
  65. package/types/util/validators.d.ts +20 -37
  66. package/webpack.config.js +50 -53
  67. package/src/commands/data/pinList/pinList.js +0 -34
  68. package/src/commands/pinning/hashPinPolicy.js +0 -51
  69. package/src/commands/pinning/userPinPolicy.js +0 -40
  70. package/src/index.js +0 -307
  71. package/test/commands/data/pinlist-sample-api.js +0 -540
  72. package/test/commands/pinning/hashPinPolicy.test.js +0 -65
  73. package/test/commands/pinning/userPinPolicy.test.js +0 -80
  74. package/test/util/validators.test.js +0 -234
package/src/index.js DELETED
@@ -1,307 +0,0 @@
1
- import pinByHash from './commands/pinning/pinByHash';
2
- import hashMetadata from './commands/pinning/hashMetadata';
3
- import pinFileToIPFS from './commands/pinning/pinFileToIPFS';
4
- import pinFromFS from './commands/pinning/pinFromFS';
5
- import pinJSONToIPFS from './commands/pinning/pinJSONToIPFS';
6
- import pinJobs from './commands/pinning/pinJobs/pinJobs';
7
- import unpin from './commands/pinning/unpin';
8
- import testAuthentication from './commands/data/testAuthentication';
9
- import pinList from './commands/data/pinList/pinList';
10
- import getFilesByCount from './commands/data/getFilesByCount/getFilesByCount';
11
- import userPinnedDataTotal from './commands/data/userPinnedDataTotal';
12
-
13
- // OPTIONS
14
-
15
- /**
16
- * @typedef {Record<string, string | number | null>} PinataMetadata
17
- */
18
-
19
- /**
20
- * @typedef PinataMetadataFilter
21
- * @property {string} [name]
22
- * @property {Record<string, {value: string, op: string}>} keyvalues
23
- */
24
-
25
- /**
26
- * @typedef {{id: string, desiredReplicationCount: number}} PinataPinPolicyItem
27
- */
28
-
29
- /**
30
- * @typedef PinataPinByHashOptions
31
- * @property {string[]} [hostNodes]
32
- * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
33
- */
34
-
35
- /**
36
- * @typedef PinataPinByHashPinOptions
37
- * @property {PinataMetadata} [pinataMetadata]
38
- * @property {PinataPinByHashOptions} [pinataOptions]
39
- */
40
-
41
- /**
42
- * @typedef PinataOptions
43
- * @property {0 | 1} [cidVersion]
44
- * @property {boolean} [wrapWithDirectory]
45
- * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
46
- */
47
-
48
- /**
49
- * @typedef PinataPinOptions
50
- * @property {PinataMetadata} [pinataMetadata]
51
- * @property {PinataOptions} [pinataOptions]
52
- */
53
-
54
- /**
55
- * @typedef PinataPinJobsFilterOptions
56
- * @property {'ASC' | 'DESC'} sort
57
- * @property {string} [status]
58
- * @property {string} [ipfs_pin_hash]
59
- * @property {number} [limit]
60
- * @property {number} [offset]
61
- */
62
-
63
- /**
64
- * @typedef PinataPinListFilterOptions
65
- * @property {string} [hashContains]
66
- * @property {string} [pinStart]
67
- * @property {string} [pinEnd]
68
- * @property {string} [unpinStart]
69
- * @property {string} [unpinEnd]
70
- * @property {number} [pinSizeMin]
71
- * @property {number} [pinSizeMax]
72
- * @property {string} [status]
73
- * @property {number} [pageLimit]
74
- * @property {number} [pageOffset]
75
- * @property {PinataMetadataFilter} [metadata]
76
- */
77
-
78
- // RESPONSES
79
-
80
- /**
81
- * @typedef PinataPinByHashResponse
82
- * @property {number | string} id
83
- * @property {string} ipfsHash
84
- * @property {string} status
85
- * @property {string} name
86
- */
87
-
88
- /**
89
- * @typedef PinataPinResponse
90
- * @property {string} IpfsHash
91
- * @property {number} PinSize
92
- * @property {string} Timestamp
93
- */
94
-
95
- /**
96
- * @typedef PinataPinJobsResponseRow
97
- * @property {number | string} id
98
- * @property {string} ipfs_pin_hash
99
- * @property {string} date_queued
100
- * @property {string | undefined | null} name
101
- * @property {string} status
102
- */
103
-
104
- /**
105
- * @typedef PinataPinJobsResponse
106
- * @property {number} count
107
- * @property {PinataPinJobsResponseRow[]} rows
108
- */
109
-
110
- /**
111
- * @typedef PinataPinListResponseRow
112
- * @property {number | string} id
113
- * @property {string} ipfs_pin_hash
114
- * @property {number} size
115
- * @property {string | number} user_id
116
- * @property {string} date_pinned
117
- * @property {string} date_unpinned
118
- * @property {PinataMetadata} metadata
119
- */
120
-
121
- /**
122
- * @typedef PinataPinListResponse
123
- * @property {number} count
124
- * @property {PinataPinListResponseRow[]} rows
125
- */
126
-
127
- // METHODS
128
-
129
- /**
130
- * Hash meta data
131
- * @callback hashMetadata
132
- * @param {string} ipfsPinHash
133
- * @param {PinataMetadata} metadata
134
- * @returns {Promise<any>}
135
- */
136
-
137
- /**
138
- * Pin by hash
139
- * @callback pinByHash
140
- * @param {string} hashToPin
141
- * @param {PinataPinByHashPinOptions} [options]
142
- * @returns {Promise<PinataPinByHashResponse>}
143
- */
144
-
145
- /**
146
- * Pin file to IPFS
147
- * @callback pinFileToIPFS
148
- * @param {ReadStream} readableStream
149
- * @param {PinataPinOptions} [options]
150
- * @returns {Promise<PinataPinResponse>}
151
- */
152
-
153
- /**
154
- * Pin from FS
155
- * @callback pinFromFS
156
- * @param {string} sourcePath
157
- * @param {PinataPinOptions} [options]
158
- * @returns {Promise<PinataPinResponse>}
159
- */
160
-
161
- /**
162
- * Pin Jobs
163
- * @callback pinJobs
164
- * @param {PinataPinJobsFilterOptions} [filters]
165
- * @returns {Promise<PinataPinJobsResponse>}
166
- */
167
-
168
- /**
169
- * Pin JSON to IPFS
170
- * @callback pinJSONToIPFS
171
- * @param {Object} body
172
- * @param {PinataPinOptions} [options]
173
- * @returns {Promise<PinataPinResponse>}
174
- */
175
-
176
- /**
177
- * Unpin
178
- * @callback unpin
179
- * @param {string} hashToUnpin
180
- * @returns {Promise<any>}
181
- */
182
-
183
- /**
184
- * Test Authentication
185
- * @callback testAuthentication
186
- * @returns {Promise<{authenticated: boolean}>}
187
- */
188
-
189
- /**
190
- * Pin List
191
- * @callback pinList
192
- * @param {PinataPinListFilterOptions} [filters]
193
- * @returns {Promise<PinataPinListResponse>}
194
- */
195
-
196
- /**
197
- * User Pinned Data Total
198
- * @callback userPinnedDataTotal
199
- * @returns {Promise<number>}
200
- */
201
-
202
- /**
203
- * @typedef {Object} PinataConfig
204
- * @property {string} [pinataApiKey]
205
- * @property {string} [pinataSecretApiKey]
206
- * @property {string} [pinataJWTKey]
207
- */
208
-
209
- /**
210
- * @typedef PinataClient
211
- * @property {PinataConfig} config
212
- * @property {pinByHash} pinByHash
213
- * @property {hashMetadata} hashMetadata
214
- * @property {pinFileToIPFS} pinFileToIPFS
215
- * @property {pinFromFS} pinFromFS
216
- * @property {pinJSONToIPFS} pinJSONToIPFS
217
- * @property {pinJobs} pinJobs
218
- * @property {unpin} unpin
219
- * @property {testAuthentication} testAuthentication
220
- * @property {pinList} pinList
221
- * @property {userPinnedDataTotal} userPinnedDataTotal
222
- */
223
-
224
- function refactorConfig(pinataConfigParam) {
225
- const config = {};
226
- if (pinataConfigParam.pinataApiKey) {
227
- config.pinataApiKey = pinataConfigParam.pinataApiKey;
228
- }
229
-
230
- if (pinataConfigParam.pinataSecretApiKey) {
231
- config.pinataSecretApiKey = pinataConfigParam.pinataSecretApiKey;
232
- }
233
-
234
- if (pinataConfigParam.pinataJWTKey) {
235
- config.pinataJWTKey = pinataConfigParam.pinataJWTKey;
236
- }
237
-
238
- return config;
239
- }
240
- function sanitizeConfig(pinataApiKey, pinataSecretApiKey) {
241
- let config = {};
242
-
243
- if (
244
- typeof pinataApiKey === 'string' &&
245
- typeof pinataSecretApiKey === 'string'
246
- ) {
247
- config.pinataApiKey = pinataApiKey;
248
- config.pinataSecretApiKey = pinataSecretApiKey;
249
- }
250
-
251
- const isPinataConfigParam = typeof pinataApiKey === 'object';
252
- if (isPinataConfigParam) {
253
- config = refactorConfig(pinataApiKey);
254
- }
255
-
256
- return config;
257
- }
258
-
259
- /**
260
- * Pinata Client
261
- *
262
- * @param {string | PinataConfig} [pinataApiKey]
263
- * @param {string} [pinataSecretApiKey]
264
- * @returns {PinataClient}
265
- */
266
- export default function pinataClient(pinataApiKey, pinataSecretApiKey) {
267
- const client = {
268
- config: sanitizeConfig(pinataApiKey, pinataSecretApiKey)
269
- };
270
-
271
- // setting up the actual calls you can make using this package
272
- client.pinByHash = function (hashToPin, options) {
273
- return pinByHash(client.config, hashToPin, options);
274
- };
275
- client.hashMetadata = function (ipfsPinHash, metadata) {
276
- return hashMetadata(client.config, ipfsPinHash, metadata);
277
- };
278
- client.pinFileToIPFS = function (readableStream, options) {
279
- return pinFileToIPFS(client.config, readableStream, options);
280
- };
281
- client.pinFromFS = function (sourcePath, options) {
282
- return pinFromFS(client.config, sourcePath, options);
283
- };
284
- client.pinJSONToIPFS = function (body, options) {
285
- return pinJSONToIPFS(client.config, body, options);
286
- };
287
- client.pinJobs = function (filters) {
288
- return pinJobs(client.config, filters);
289
- };
290
- client.unpin = function (hashToUnpin) {
291
- return unpin(client.config, hashToUnpin);
292
- };
293
- client.testAuthentication = function () {
294
- return testAuthentication(client.config);
295
- };
296
- client.pinList = function (filters) {
297
- return pinList(client.config, filters);
298
- };
299
-
300
- client.getFilesByCount = function (filters, maxCount) {
301
- return getFilesByCount(client.config, filters, maxCount);
302
- };
303
- client.userPinnedDataTotal = function () {
304
- return userPinnedDataTotal(client.config);
305
- };
306
- return client;
307
- }