@pinata/sdk 1.2.1 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +1 -1
- package/.eslintrc +7 -7
- package/.husky/pre-commit +6 -0
- package/.nvmrc +1 -1
- package/README.md +3 -3
- package/lib/pinata-sdk.js +906 -839
- package/lib/pinata-sdk.min.js +5 -5
- package/package.json +83 -71
- package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +8 -9
- package/src/commands/data/index.ts +4 -0
- package/src/commands/data/pinList/pinList.ts +77 -0
- package/src/commands/data/pinList/{queryBuilder.js → queryBuilder.ts} +6 -16
- package/src/commands/data/{testAuthentication.js → testAuthentication.ts} +8 -9
- package/src/commands/data/{userPinnedDataTotal.js → userPinnedDataTotal.ts} +4 -9
- package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +9 -11
- package/src/commands/pinning/index.ts +8 -0
- package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +22 -11
- package/src/commands/pinning/pinFileToIPFS.ts +118 -0
- package/src/commands/pinning/pinFromFS.ts +50 -0
- package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +5 -11
- package/src/commands/pinning/pinJobs/{pinJobs.js → pinJobs.ts} +23 -9
- package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
- package/src/commands/pinning/{unpin.js → unpin.ts} +3 -9
- package/src/{constants.js → constants.ts} +0 -0
- package/src/index.ts +120 -0
- package/src/third-party/base-path-converter.d.ts +3 -0
- package/src/third-party/is-ipfs.d.ts +5 -0
- package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
- package/src/util/{validators.js → validators.ts} +21 -33
- package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +23 -22
- package/test/commands/data/pinList/{pinList.test.js → pinList.test.ts} +25 -26
- package/test/commands/data/pinList/{queryBuilder.test.js → queryBuilder.test.ts} +9 -10
- package/test/commands/data/pinlist-sample-api.ts +540 -0
- package/test/commands/data/{testAuthentication.test.js → testAuthentication.test.ts} +13 -13
- package/test/commands/data/{userPinnedDataTotal.test.js → userPinnedDataTotal.test.ts} +4 -4
- package/test/commands/pinning/{hashMetadata.test.js → hashMetadata.test.ts} +7 -8
- package/test/commands/pinning/{pinByHash.test.js → pinByHash.test.ts} +4 -5
- package/test/commands/pinning/{pinFileToIPFS.test.js → pinFileToIPFS.test.ts} +9 -11
- package/test/commands/pinning/{pinFromFS.js → pinFromFS.ts} +5 -6
- package/test/commands/pinning/{pinJSONToIPFS.test.js → pinJSONToIPFS.test.ts} +4 -5
- package/test/commands/pinning/pinJobs/{pinJobs.test.js → pinJobs.test.ts} +4 -4
- package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
- package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +4 -5
- package/test/util/validators.test.ts +234 -0
- package/tsconfig.json +2 -2
- package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +4 -2
- package/types/commands/data/index.d.ts +4 -0
- package/types/commands/data/pinList/pinList.d.ts +45 -8
- package/types/commands/data/pinList/queryBuilder.d.ts +1 -7
- package/types/commands/data/testAuthentication.d.ts +5 -7
- package/types/commands/data/userPinnedDataTotal.d.ts +2 -7
- package/types/commands/pinning/hashMetadata.d.ts +3 -9
- package/types/commands/pinning/index.d.ts +8 -0
- package/types/commands/pinning/pinByHash.d.ts +14 -9
- package/types/commands/pinning/pinFileToIPFS.d.ts +25 -9
- package/types/commands/pinning/pinFromFS.d.ts +3 -9
- package/types/commands/pinning/pinJSONToIPFS.d.ts +3 -9
- package/types/commands/pinning/pinJobs/pinJobs.d.ts +20 -8
- package/types/commands/pinning/pinJobs/queryBuilder.d.ts +1 -7
- package/types/commands/pinning/unpin.d.ts +2 -8
- package/types/constants.d.ts +2 -2
- package/types/index.d.ts +37 -165
- package/types/util/errorResponse.d.ts +1 -1
- package/types/util/validators.d.ts +23 -46
- package/webpack.config.js +50 -53
- package/src/commands/data/pinList/pinList.js +0 -34
- package/src/commands/pinning/hashPinPolicy.js +0 -51
- package/src/commands/pinning/pinFileToIPFS.js +0 -53
- package/src/commands/pinning/pinFromFS.js +0 -100
- package/src/commands/pinning/userPinPolicy.js +0 -40
- package/src/index.js +0 -307
- package/test/commands/data/pinlist-sample-api.js +0 -540
- package/test/commands/pinning/hashPinPolicy.test.js +0 -65
- package/test/commands/pinning/userPinPolicy.test.js +0 -80
- package/test/util/validators.test.js +0 -234
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from './../../constants';
|
|
3
|
-
import NodeFormData from 'form-data';
|
|
4
|
-
import {createConfigForAxiosHeadersWithFormData, validateMetadata, validatePinataOptions} from '../../util/validators';
|
|
5
|
-
import basePathConverter from 'base-path-converter';
|
|
6
|
-
import { handleError } from '../../util/errorResponse';
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const recursive = require('recursive-fs');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* PinFromFS
|
|
12
|
-
* @param {string} pinataApiKey
|
|
13
|
-
* @param {string} pinataSecretApiKey
|
|
14
|
-
* @param {string} sourcePath
|
|
15
|
-
* @param {*} options
|
|
16
|
-
* @returns {Promise<unknown>}
|
|
17
|
-
*/
|
|
18
|
-
export default function pinFromFS(config, sourcePath, options) {
|
|
19
|
-
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
const endpoint = `${baseUrl}/pinning/pinFileToIPFS`;
|
|
22
|
-
|
|
23
|
-
fs.stat(sourcePath, (err, stats) => {
|
|
24
|
-
if (err) {
|
|
25
|
-
reject(err);
|
|
26
|
-
}
|
|
27
|
-
if (stats.isFile()) {
|
|
28
|
-
//we need to create a single read stream instead of reading the directory recursively
|
|
29
|
-
const data = new NodeFormData();
|
|
30
|
-
|
|
31
|
-
data.append('file', fs.createReadStream(sourcePath));
|
|
32
|
-
|
|
33
|
-
if (options) {
|
|
34
|
-
if (options.pinataMetadata) {
|
|
35
|
-
validateMetadata(options.pinataMetadata);
|
|
36
|
-
data.append('pinataMetadata', JSON.stringify(options.pinataMetadata));
|
|
37
|
-
}
|
|
38
|
-
if (options.pinataOptions) {
|
|
39
|
-
validatePinataOptions(options.pinataOptions);
|
|
40
|
-
data.append('pinataOptions', JSON.stringify(options.pinataOptions));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
axios.post(
|
|
45
|
-
endpoint,
|
|
46
|
-
data,
|
|
47
|
-
createConfigForAxiosHeadersWithFormData(config, data._boundary))
|
|
48
|
-
.then(function (result) {
|
|
49
|
-
if (result.status !== 200) {
|
|
50
|
-
reject(new Error(`unknown server response while pinning File to IPFS: ${result}`));
|
|
51
|
-
}
|
|
52
|
-
resolve(result.data);
|
|
53
|
-
}).catch(function (error) {
|
|
54
|
-
const formattedError = handleError(error);
|
|
55
|
-
reject(formattedError);
|
|
56
|
-
});
|
|
57
|
-
} else {
|
|
58
|
-
recursive.readdirr(sourcePath, function (err, dirs, files) {
|
|
59
|
-
if (err) {
|
|
60
|
-
reject(new Error(err));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let data = new NodeFormData();
|
|
64
|
-
|
|
65
|
-
files.forEach((file) => {
|
|
66
|
-
//for each file stream, we need to include the correct relative file path
|
|
67
|
-
data.append('file', fs.createReadStream(file), {
|
|
68
|
-
filepath: basePathConverter(sourcePath, file)
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
if (options) {
|
|
73
|
-
if (options.pinataMetadata) {
|
|
74
|
-
validateMetadata(options.pinataMetadata);
|
|
75
|
-
data.append('pinataMetadata', JSON.stringify(options.pinataMetadata));
|
|
76
|
-
}
|
|
77
|
-
if (options.pinataOptions) {
|
|
78
|
-
validatePinataOptions(options.pinataOptions);
|
|
79
|
-
data.append('pinataOptions', JSON.stringify(options.pinataOptions));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
axios.post(
|
|
84
|
-
endpoint,
|
|
85
|
-
data,
|
|
86
|
-
createConfigForAxiosHeadersWithFormData(config, data._boundary))
|
|
87
|
-
.then(function (result) {
|
|
88
|
-
if (result.status !== 200) {
|
|
89
|
-
reject(new Error(`unknown server response while pinning File to IPFS: ${result}`));
|
|
90
|
-
}
|
|
91
|
-
resolve(result.data);
|
|
92
|
-
}).catch(function (error) {
|
|
93
|
-
const formattedError = handleError(error);
|
|
94
|
-
reject(formattedError);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from './../../constants';
|
|
3
|
-
import { createConfigForAxiosHeaders, validatePinPolicyStructure } from '../../util/validators';
|
|
4
|
-
import { handleError } from '../../util/errorResponse';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* User Pin Policy
|
|
8
|
-
* @param {string} pinataApiKey
|
|
9
|
-
* @param {string} pinataSecretApiKey
|
|
10
|
-
* @param {*} newPinPolicy
|
|
11
|
-
* @returns {Promise<unknown>}
|
|
12
|
-
*/
|
|
13
|
-
export default function userPinPolicy(config, newPinPolicy) {
|
|
14
|
-
validatePinPolicyStructure(newPinPolicy);
|
|
15
|
-
|
|
16
|
-
if (!newPinPolicy) {
|
|
17
|
-
throw new Error('newPinPolicy is required for changing the pin policy of a pin');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const endpoint = `${baseUrl}/pinning/userPinPolicy`;
|
|
21
|
-
const body = {
|
|
22
|
-
newPinPolicy: newPinPolicy
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
axios.put(
|
|
27
|
-
endpoint,
|
|
28
|
-
body,
|
|
29
|
-
{...createConfigForAxiosHeaders(config)})
|
|
30
|
-
.then(function (result) {
|
|
31
|
-
if (result.status !== 200) {
|
|
32
|
-
reject(new Error(`unknown server response while changing pin policy for user: ${result}`));
|
|
33
|
-
}
|
|
34
|
-
resolve(result.data);
|
|
35
|
-
}).catch(function (error) {
|
|
36
|
-
const formattedError = handleError(error);
|
|
37
|
-
reject(formattedError);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
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
|
-
}
|