@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
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@pinata/sdk",
3
- "version": "1.1.20",
3
+ "version": "1.1.24",
4
4
  "description": "Official SDK for the Pinata IPFS platform",
5
5
  "main": "lib/pinata-sdk.js",
6
+ "types": "types/index.d.ts",
6
7
  "scripts": {
7
- "build": "webpack --env dev && webpack --env build && npm run test",
8
+ "build": "webpack --env dev && webpack --env build && npm run test && tsc",
8
9
  "coverage": "jest --coverage",
9
10
  "dev": "webpack --progress --colors --watch --env dev",
10
11
  "html": "open coverage/index.html",
@@ -37,6 +38,7 @@
37
38
  "@babel/core": "^7.8.4",
38
39
  "@babel/preset-env": "^7.9.0",
39
40
  "@babel/register": "^7.8.3",
41
+ "@types/node": "^15.6.1",
40
42
  "acorn": "^7.1.0",
41
43
  "babel-eslint": "^10.0.3",
42
44
  "babel-loader": "^8.0.6",
@@ -45,6 +47,7 @@
45
47
  "eslint": "^6.8.0",
46
48
  "eslint-loader": "^3.0.3",
47
49
  "jest": "^25.1.0",
50
+ "typescript": "^4.2.3",
48
51
  "uglifyjs-webpack-plugin": "^2.2.0",
49
52
  "webpack": "^4.41.6",
50
53
  "webpack-cli": "^3.3.11",
@@ -4,6 +4,13 @@ import { validateApiKeys } from '../../../util/validators';
4
4
  import { handleError } from '../../../util/errorResponse';
5
5
  import queryBuilder from './queryBuilder';
6
6
 
7
+ /**
8
+ * Pin List
9
+ * @param {string} pinataApiKey
10
+ * @param {string} pinataSecretApiKey
11
+ * @param {string} filters
12
+ * @returns {Promise<unknown>}
13
+ */
7
14
  export default function pinList(pinataApiKey, pinataSecretApiKey, filters) {
8
15
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
9
16
 
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Validate and return data
3
+ * @param {*} dateToValidate
4
+ * @returns {*}
5
+ */
1
6
  function validateAndReturnDate(dateToValidate) {
2
7
  let dateParsed = new Date(Date.parse(dateToValidate));
3
8
 
@@ -12,6 +17,12 @@ function validateAndReturnDate(dateToValidate) {
12
17
  }
13
18
  }
14
19
 
20
+ /**
21
+ * Query Builder
22
+ * @param {string} baseUrl
23
+ * @param {*} filters
24
+ * @returns {string}
25
+ */
15
26
  export default function queryBuilder(baseUrl, filters) {
16
27
  if (!baseUrl) {
17
28
  throw new Error('no baseUrl provided');
@@ -3,6 +3,12 @@ import { baseUrl } from './../../constants';
3
3
  import {validateApiKeys} from '../../util/validators';
4
4
  import { handleError } from '../../util/errorResponse';
5
5
 
6
+ /**
7
+ * Test Authentication
8
+ * @param {string} pinataApiKey
9
+ * @param {string} pinataSecretApiKey
10
+ * @returns {Promise<unknown>}
11
+ */
6
12
  export default function testAuthentication(pinataApiKey, pinataSecretApiKey) {
7
13
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
8
14
 
@@ -3,6 +3,12 @@ import { baseUrl } from './../../constants';
3
3
  import { validateApiKeys } from '../../util/validators';
4
4
  import { handleError } from '../../util/errorResponse';
5
5
 
6
+ /**
7
+ * User Pinned Data Total
8
+ * @param {string} pinataApiKey
9
+ * @param {string} pinataSecretApiKey
10
+ * @returns {Promise<unknown>}
11
+ */
6
12
  export default function userPinnedDataTotal(pinataApiKey, pinataSecretApiKey) {
7
13
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
8
14
 
@@ -4,6 +4,14 @@ import { validateApiKeys, validateMetadata } from '../../util/validators';
4
4
  import isIPFS from 'is-ipfs';
5
5
  import { handleError } from '../../util/errorResponse';
6
6
 
7
+ /**
8
+ * Hash Meta Data
9
+ * @param {string} pinataApiKey
10
+ * @param {string} pinataSecretApiKey
11
+ * @param {*} ipfsPinHash
12
+ * @param {*} metadata
13
+ * @returns {Promise<unknown>}
14
+ */
7
15
  export default function hashMetadata(pinataApiKey, pinataSecretApiKey, ipfsPinHash, metadata) {
8
16
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
9
17
 
@@ -4,6 +4,14 @@ import { validateApiKeys, validatePinPolicyStructure } from '../../util/validato
4
4
  import isIPFS from 'is-ipfs';
5
5
  import { handleError } from '../../util/errorResponse';
6
6
 
7
+ /**
8
+ * Hash Pin Policy
9
+ * @param {string} pinataApiKey
10
+ * @param {string} pinataSecretApiKey
11
+ * @param {*} ipfsPinHash
12
+ * @param {*} newPinPolicy
13
+ * @returns {Promise<unknown>}
14
+ */
7
15
  export default function hashPinPolicy(pinataApiKey, pinataSecretApiKey, ipfsPinHash, newPinPolicy) {
8
16
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
9
17
  validatePinPolicyStructure(newPinPolicy);
@@ -4,6 +4,14 @@ import { validateApiKeys, validateMetadata } from '../../util/validators';
4
4
  import isIPFS from 'is-ipfs';
5
5
  import { handleError } from '../../util/errorResponse';
6
6
 
7
+ /**
8
+ * Pin By Hash
9
+ * @param {string} pinataApiKey
10
+ * @param {string} pinataSecretApiKey
11
+ * @param {*} hashToPin
12
+ * @param {*} options
13
+ * @returns {Promise<unknown>}
14
+ */
7
15
  export default function pinByHash(pinataApiKey, pinataSecretApiKey, hashToPin, options) {
8
16
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
9
17
 
@@ -5,6 +5,14 @@ import stream from 'stream';
5
5
  import {validateApiKeys, validateMetadata, validatePinataOptions} from '../../util/validators';
6
6
  import { handleError } from '../../util/errorResponse';
7
7
 
8
+ /**
9
+ * Pin File to IPFS
10
+ * @param {string} pinataApiKey
11
+ * @param {string} pinataSecretApiKey
12
+ * @param {*} readStream
13
+ * @param {*} options
14
+ * @returns {Promise<unknown>}
15
+ */
8
16
  export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStream, options) {
9
17
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
10
18
 
@@ -16,8 +24,8 @@ export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStre
16
24
 
17
25
  const endpoint = `${baseUrl}/pinning/pinFileToIPFS`;
18
26
 
19
- if (!(readStream instanceof stream.Readable)) {
20
- reject(new Error('readStream is not a readable stream'));
27
+ if (!(readStream instanceof stream.Readable || readStream instanceof NodeFormData)) {
28
+ reject(new Error('readStream is not a readable stream or form data'));
21
29
  }
22
30
 
23
31
  if (options) {
@@ -33,7 +41,7 @@ export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStre
33
41
 
34
42
  axios.post(
35
43
  endpoint,
36
- data,
44
+ readStream instanceof NodeFormData ? readStream : data,
37
45
  {
38
46
  withCredentials: true,
39
47
  maxContentLength: 'Infinity', //this is needed to prevent axios from erroring out with large files
@@ -7,6 +7,14 @@ import { handleError } from '../../util/errorResponse';
7
7
  const fs = require('fs');
8
8
  const recursive = require('recursive-fs');
9
9
 
10
+ /**
11
+ * PinFromFS
12
+ * @param {string} pinataApiKey
13
+ * @param {string} pinataSecretApiKey
14
+ * @param {string} sourcePath
15
+ * @param {*} options
16
+ * @returns {Promise<unknown>}
17
+ */
10
18
  export default function pinFromFS(pinataApiKey, pinataSecretApiKey, sourcePath, options) {
11
19
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
12
20
 
@@ -3,6 +3,14 @@ import { baseUrl } from './../../constants';
3
3
  import { validateApiKeys, validateMetadata, validatePinataOptions } from '../../util/validators';
4
4
  import { handleError } from '../../util/errorResponse';
5
5
 
6
+ /**
7
+ * Pin JSON to IPFS
8
+ * @param {string} pinataApiKey
9
+ * @param {string} pinataSecretApiKey
10
+ * @param {*} body
11
+ * @param {*} options
12
+ * @returns {Promise<unknown>}
13
+ */
6
14
  export default function pinJSONToIPFS(pinataApiKey, pinataSecretApiKey, body, options) {
7
15
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
8
16
 
@@ -4,6 +4,13 @@ import { validateApiKeys } from '../../../util/validators';
4
4
  import queryBuilder from './queryBuilder';
5
5
  import { handleError } from '../../../util/errorResponse';
6
6
 
7
+ /**
8
+ * Pin Jobs
9
+ * @param {string} pinataApiKey
10
+ * @param {string} pinataSecretApiKey
11
+ * @param {*} filters
12
+ * @returns {Promise<unknown>}
13
+ */
7
14
  export default function pinJobs(pinataApiKey, pinataSecretApiKey, filters) {
8
15
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
9
16
 
@@ -1,5 +1,11 @@
1
1
  import isIPFS from 'is-ipfs';
2
2
 
3
+ /**
4
+ * Query Buidler
5
+ * @param {string} baseUrl
6
+ * @param {*} filters
7
+ * @returns {*}
8
+ */
3
9
  export default function queryBuilder(baseUrl, filters) {
4
10
  if (!baseUrl) {
5
11
  throw new Error('no baseUrl provided');
@@ -4,6 +4,13 @@ import { validateApiKeys } from '../../util/validators';
4
4
  import isIPFS from 'is-ipfs';
5
5
  import { handleError } from '../../util/errorResponse';
6
6
 
7
+ /**
8
+ * Unpin
9
+ * @param {string} pinataApiKey
10
+ * @param {string} pinataSecretApiKey
11
+ * @param {string} hashToUnpin
12
+ * @returns {Promise<unknown>}
13
+ */
7
14
  export default function unpin(pinataApiKey, pinataSecretApiKey, hashToUnpin) {
8
15
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
9
16
 
@@ -3,6 +3,13 @@ import { baseUrl } from './../../constants';
3
3
  import { validateApiKeys, validatePinPolicyStructure } from '../../util/validators';
4
4
  import { handleError } from '../../util/errorResponse';
5
5
 
6
+ /**
7
+ * User Pin Policy
8
+ * @param {string} pinataApiKey
9
+ * @param {string} pinataSecretApiKey
10
+ * @param {*} newPinPolicy
11
+ * @returns {Promise<unknown>}
12
+ */
6
13
  export default function userPinPolicy(pinataApiKey, pinataSecretApiKey, newPinPolicy) {
7
14
  validateApiKeys(pinataApiKey, pinataSecretApiKey);
8
15
  validatePinPolicyStructure(newPinPolicy);
package/src/index.js CHANGED
@@ -11,6 +11,233 @@ import testAuthentication from './commands/data/testAuthentication';
11
11
  import pinList from './commands/data/pinList/pinList';
12
12
  import userPinnedDataTotal from './commands/data/userPinnedDataTotal';
13
13
 
14
+ // OPTIONS
15
+
16
+ /**
17
+ * @typedef {Record<string, string | number | null>} PinataMetadata
18
+ */
19
+
20
+ /**
21
+ * @typedef PinataMetadataFilter
22
+ * @property {string} [name]
23
+ * @property {Record<string, {value: string, op: string}>} keyvalues
24
+ */
25
+
26
+ /**
27
+ * @typedef {{id: string, desiredReplicationCount: number}} PinataPinPolicyItem
28
+ */
29
+
30
+ /**
31
+ * @typedef PinataPinByHashOptions
32
+ * @property {string[]} [hostNodes]
33
+ * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
34
+ */
35
+
36
+ /**
37
+ * @typedef PinataPinByHashPinOptions
38
+ * @property {PinataMetadata} [pinataMetadata]
39
+ * @property {PinataPinByHashOptions} [pinataOptions]
40
+ */
41
+
42
+ /**
43
+ * @typedef PinataOptions
44
+ * @property {0 | 1} [cidVersion]
45
+ * @property {boolean} [wrapWithDirectory]
46
+ * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
47
+ */
48
+
49
+ /**
50
+ * @typedef PinataPinOptions
51
+ * @property {PinataMetadata} [pinataMetadata]
52
+ * @property {PinataOptions} [pinataOptions]
53
+ */
54
+
55
+ /**
56
+ * @typedef PinataPinJobsFilterOptions
57
+ * @property {'ASC' | 'DESC'} sort
58
+ * @property {string} [status]
59
+ * @property {string} [ipfs_pin_hash]
60
+ * @property {number} [limit]
61
+ * @property {number} [offset]
62
+ */
63
+
64
+ /**
65
+ * @typedef PinataPinListFilterOptions
66
+ * @property {string} [hashContains]
67
+ * @property {string} [pinStart]
68
+ * @property {string} [pinEnd]
69
+ * @property {string} [unpinStart]
70
+ * @property {string} [unpinEnd]
71
+ * @property {number} [pinSizeMin]
72
+ * @property {number} [pinSizeMax]
73
+ * @property {string} [status]
74
+ * @property {number} [pageLimit]
75
+ * @property {number} [pageOffset]
76
+ * @property {PinataMetadataFilter} [metadata]
77
+ */
78
+
79
+ // RESPONSES
80
+
81
+ /**
82
+ * @typedef PinataPinByHashResponse
83
+ * @property {number | string} id
84
+ * @property {string} ipfsHash
85
+ * @property {string} status
86
+ * @property {string} name
87
+ */
88
+
89
+ /**
90
+ * @typedef PinataPinResponse
91
+ * @property {string} IpfsHash
92
+ * @property {number} PinSize
93
+ * @property {string} Timestamp
94
+ */
95
+
96
+ /**
97
+ * @typedef PinataPinJobsResponseRow
98
+ * @property {number | string} id
99
+ * @property {string} ipfs_pin_hash
100
+ * @property {string} date_queued
101
+ * @property {string | undefined | null} name
102
+ * @property {string} status
103
+ */
104
+
105
+ /**
106
+ * @typedef PinataPinJobsResponse
107
+ * @property {number} count
108
+ * @property {PinataPinJobsResponseRow[]} rows
109
+ */
110
+
111
+ /**
112
+ * @typedef PinataPinListResponseRow
113
+ * @property {number | string} id
114
+ * @property {string} ipfs_pin_hash
115
+ * @property {number} size
116
+ * @property {string | number} user_id
117
+ * @property {string} date_pinned
118
+ * @property {string} date_unpinned
119
+ * @property {PinataMetadata} metadata
120
+ */
121
+
122
+ /**
123
+ * @typedef PinataPinListResponse
124
+ * @property {number} count
125
+ * @property {PinataPinListResponseRow[]} rows
126
+ */
127
+
128
+ // METHODS
129
+
130
+ /**
131
+ * Hash meta data
132
+ * @callback hashMetadata
133
+ * @param {string} ipfsPinHash
134
+ * @param {PinataMetadata} metadata
135
+ * @returns {Promise<any>}
136
+ */
137
+
138
+ /**
139
+ * Hash pin policy
140
+ * @callback hashPinPolicy
141
+ * @param {string} ipfsPinHash
142
+ * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
143
+ * @returns {Promise<any>}
144
+ */
145
+
146
+ /**
147
+ * Pin by hash
148
+ * @callback pinByHash
149
+ * @param {string} hashToPin
150
+ * @param {PinataPinByHashPinOptions} [options]
151
+ * @returns {Promise<PinataPinByHashResponse>}
152
+ */
153
+
154
+ /**
155
+ * Pin file to IPFS
156
+ * @callback pinFileToIPFS
157
+ * @param {ReadStream} readableStream
158
+ * @param {PinataPinOptions} [options]
159
+ * @returns {Promise<PinataPinResponse>}
160
+ */
161
+
162
+ /**
163
+ * Pin from FS
164
+ * @callback pinFromFS
165
+ * @param {string} sourcePath
166
+ * @param {PinataPinOptions} [options]
167
+ * @returns {Promise<PinataPinResponse>}
168
+ */
169
+
170
+ /**
171
+ * Pin Jobs
172
+ * @callback pinJobs
173
+ * @param {PinataPinJobsFilterOptions} [filters]
174
+ * @returns {Promise<PinataPinJobsResponse>}
175
+ */
176
+
177
+ /**
178
+ * Pin JSON to IPFS
179
+ * @callback pinJSONToIPFS
180
+ * @param {Object} body
181
+ * @param {PinataPinOptions} [options]
182
+ * @returns {Promise<PinataPinResponse>}
183
+ */
184
+
185
+ /**
186
+ * Unpin
187
+ * @callback unpin
188
+ * @param {string} hashToUnpin
189
+ * @returns {Promise<any>}
190
+ */
191
+
192
+ /**
193
+ * User Pin Policy
194
+ * @callback userPinPolicy
195
+ * @param {{regions: PinataPinPolicyItem[]}} newPinPolicy
196
+ * @returns {Promise<any>}
197
+ */
198
+
199
+ /**
200
+ * Test Authentication
201
+ * @callback testAuthentication
202
+ * @returns {Promise<{authenticated: boolean}>}
203
+ */
204
+
205
+ /**
206
+ * Pin List
207
+ * @callback pinList
208
+ * @param {PinataPinListFilterOptions} [filters]
209
+ * @returns {Promise<PinataPinListResponse>}
210
+ */
211
+
212
+ /**
213
+ * User Pinned Data Total
214
+ * @callback userPinnedDataTotal
215
+ * @returns {Promise<number>}
216
+ */
217
+
218
+ /**
219
+ * @typedef PinataClient
220
+ * @property {pinByHash} pinByHash
221
+ * @property {hashMetadata} hashMetadata
222
+ * @property {hashPinPolicy} hashPinPolicy
223
+ * @property {pinFileToIPFS} pinFileToIPFS
224
+ * @property {pinFromFS} pinFromFS
225
+ * @property {pinJSONToIPFS} pinJSONToIPFS
226
+ * @property {pinJobs} pinJobs
227
+ * @property {unpin} unpin
228
+ * @property {userPinPolicy} userPinPolicy
229
+ * @property {testAuthentication} testAuthentication
230
+ * @property {pinList} pinList
231
+ * @property {userPinnedDataTotal} userPinnedDataTotal
232
+ */
233
+
234
+ /**
235
+ * Pinata Client
236
+ *
237
+ * @param {string} pinataApiKey
238
+ * @param {string} pinataSecretApiKey
239
+ * @returns {PinataClient}
240
+ */
14
241
  export default function pinataClient(pinataApiKey, pinataSecretApiKey) {
15
242
  let client = {};
16
243
 
@@ -1,5 +1,10 @@
1
1
  import isIPFS from 'is-ipfs';
2
2
 
3
+ /**
4
+ * Validate API Keys
5
+ * @param {string} pinataApiKey
6
+ * @param {string} pinataSecretApiKey
7
+ */
3
8
  export function validateApiKeys(pinataApiKey, pinataSecretApiKey) {
4
9
  if (!pinataApiKey || pinataApiKey === '') {
5
10
  throw new Error('No pinataApiKey provided! Please provide your pinata api key as an argument when you start this script');
@@ -9,6 +14,10 @@ export function validateApiKeys(pinataApiKey, pinataSecretApiKey) {
9
14
  }
10
15
  }
11
16
 
17
+ /**
18
+ * Validate host Nodes
19
+ * @param {*} hostNodes
20
+ */
12
21
  export function validateHostNodes(hostNodes) {
13
22
  if (!Array.isArray(hostNodes)) {
14
23
  throw new Error('host_nodes value must be an array');
@@ -20,6 +29,10 @@ export function validateHostNodes(hostNodes) {
20
29
  });
21
30
  }
22
31
 
32
+ /**
33
+ * Validate MetaData
34
+ * @param {*} metadata
35
+ */
23
36
  export function validateMetadata(metadata) {
24
37
  if (metadata.name) {
25
38
  if (!(typeof metadata.name === 'string' || metadata.name instanceof String)) {
@@ -47,6 +60,10 @@ export function validateMetadata(metadata) {
47
60
  }
48
61
  }
49
62
 
63
+ /**
64
+ * Validate Pin Policy Structure
65
+ * @param {*} pinPolicy
66
+ */
50
67
  export function validatePinPolicyStructure(pinPolicy) {
51
68
  //this function takes in a pin policy and checks the JSON structure to make sure it's valid
52
69
  if (!pinPolicy) {
@@ -69,6 +86,10 @@ export function validatePinPolicyStructure(pinPolicy) {
69
86
  }
70
87
  }
71
88
 
89
+ /**
90
+ * Validate Pinata Options
91
+ * @param {*} options
92
+ */
72
93
  export function validatePinataOptions(options) {
73
94
  if (typeof options !== 'object') {
74
95
  throw new Error('options must be an object');
@@ -1,20 +1,23 @@
1
1
  import axios from 'axios';
2
2
  import pinFileToIPFS from'../../../src/commands/pinning/pinFileToIPFS';
3
3
  import fs from 'fs';
4
+ import NodeFormData from 'form-data';
4
5
  jest.mock('axios');
5
6
 
6
7
  //common values
7
8
  const nonStream = 'test';
8
9
  const validStream = fs.createReadStream('./pinata.png');
10
+ const validFormData = new NodeFormData();
11
+ validFormData.append('file', validStream, {filepath: 'test/filepath'});
9
12
 
10
13
 
11
- test('non-readableStream is passed in', () => {
12
- expect(pinFileToIPFS('test', 'test', nonStream)).rejects.toEqual(Error('readStream is not a readable stream'));
14
+ test('non-readableStream and non-formData is passed in', () => {
15
+ expect(pinFileToIPFS('test', 'test', nonStream)).rejects.toEqual(Error('readStream is not a readable stream or form data'));
13
16
 
14
17
  return undefined;
15
18
  });
16
19
 
17
- test('200 status is returned', () => {
20
+ test('200 status is returned with valid stream', () => {
18
21
  const goodStatus = {
19
22
  status: 200,
20
23
  data: 'testData'
@@ -24,6 +27,16 @@ test('200 status is returned', () => {
24
27
  expect(pinFileToIPFS('test', 'test', validStream)).resolves.toEqual(goodStatus.data);
25
28
  });
26
29
 
30
+ test('200 status is returned with valid form data', () => {
31
+ const goodStatus = {
32
+ status: 200,
33
+ data: 'testData'
34
+ };
35
+ axios.post.mockResolvedValue(goodStatus);
36
+ expect.assertions(1);
37
+ expect(pinFileToIPFS('test', 'test', validFormData)).resolves.toEqual(goodStatus.data);
38
+ });
39
+
27
40
  test('Result other than 200 status is returned', () => {
28
41
  const badStatus = {
29
42
  status: 700
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "include": [
3
+ "src/**/*.js"
4
+ ],
5
+ "compilerOptions": {
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true,
8
+ "allowJs": true,
9
+ "outDir": "types",
10
+ "target": "es5",
11
+ "module": "commonjs",
12
+ "lib": ["es2017", "es7", "es6", "dom"],
13
+ "strict": true,
14
+ "esModuleInterop": true,
15
+ "resolveJsonModule": true
16
+ },
17
+ "exclude": [
18
+ "node_modules",
19
+ "lib",
20
+ "test",
21
+ "coverage"
22
+ ]
23
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Pin List
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {string} filters
6
+ * @returns {Promise<unknown>}
7
+ */
8
+ export default function pinList(pinataApiKey: string, pinataSecretApiKey: string, filters: string): Promise<unknown>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Query Builder
3
+ * @param {string} baseUrl
4
+ * @param {*} filters
5
+ * @returns {string}
6
+ */
7
+ export default function queryBuilder(baseUrl: string, filters: any): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Test Authentication
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @returns {Promise<unknown>}
6
+ */
7
+ export default function testAuthentication(pinataApiKey: string, pinataSecretApiKey: string): Promise<unknown>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * User Pinned Data Total
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @returns {Promise<unknown>}
6
+ */
7
+ export default function userPinnedDataTotal(pinataApiKey: string, pinataSecretApiKey: string): Promise<unknown>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hash Meta Data
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {*} ipfsPinHash
6
+ * @param {*} metadata
7
+ * @returns {Promise<unknown>}
8
+ */
9
+ export default function hashMetadata(pinataApiKey: string, pinataSecretApiKey: string, ipfsPinHash: any, metadata: any): Promise<unknown>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hash Pin Policy
3
+ * @param {string} pinataApiKey
4
+ * @param {string} pinataSecretApiKey
5
+ * @param {*} ipfsPinHash
6
+ * @param {*} newPinPolicy
7
+ * @returns {Promise<unknown>}
8
+ */
9
+ export default function hashPinPolicy(pinataApiKey: string, pinataSecretApiKey: string, ipfsPinHash: any, newPinPolicy: any): Promise<unknown>;