@pinata/sdk 1.2.0 → 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.
- package/.babelrc +1 -1
- package/.eslintrc +7 -7
- package/.husky/pre-commit +6 -0
- package/.nvmrc +1 -1
- package/README.md +22 -6
- package/lib/pinata-sdk.js +780 -604
- package/lib/pinata-sdk.min.js +5 -5
- package/package.json +83 -71
- package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +9 -13
- 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} +10 -18
- package/src/commands/data/userPinnedDataTotal.ts +24 -0
- package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +12 -21
- package/src/commands/pinning/index.ts +8 -0
- package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +24 -20
- package/src/commands/pinning/{pinFileToIPFS.js → pinFileToIPFS.ts} +29 -24
- package/src/commands/pinning/{pinFromFS.js → pinFromFS.ts} +17 -39
- package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +8 -20
- package/src/commands/pinning/pinJobs/pinJobs.ts +50 -0
- package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
- package/src/commands/pinning/{unpin.js → unpin.ts} +6 -19
- package/src/constants.ts +4 -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/third-party/recursive-fs.d.ts +5 -0
- package/src/util/{errorResponse.js → errorResponse.ts} +1 -1
- package/src/util/validators.ts +175 -0
- package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +36 -39
- package/test/commands/data/pinList/pinList.test.ts +102 -0
- 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.ts +34 -0
- package/test/commands/data/userPinnedDataTotal.test.ts +29 -0
- package/test/commands/pinning/hashMetadata.test.ts +76 -0
- package/test/commands/pinning/pinByHash.test.ts +46 -0
- package/test/commands/pinning/pinFileToIPFS.test.ts +53 -0
- package/test/commands/pinning/pinFromFS.ts +32 -0
- package/test/commands/pinning/pinJSONToIPFS.test.ts +42 -0
- package/test/commands/pinning/pinJobs/pinJobs.test.ts +29 -0
- package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
- package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +9 -10
- package/test/util/{validators.test.js → validators.test.ts} +60 -18
- 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/hashPinPolicy.d.ts +1 -1
- 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 -1
- 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/commands/pinning/userPinPolicy.d.ts +1 -1
- package/types/constants.d.ts +2 -1
- package/types/index.d.ts +38 -331
- package/types/util/errorResponse.d.ts +1 -1
- package/types/util/validators.d.ts +43 -26
- package/webpack.config.js +50 -53
- package/src/commands/data/pinList/pinList.js +0 -41
- package/src/commands/data/userPinnedDataTotal.js +0 -36
- package/src/commands/pinning/hashPinPolicy.js +0 -57
- package/src/commands/pinning/pinJobs/pinJobs.js +0 -42
- package/src/commands/pinning/userPinPolicy.js +0 -46
- package/src/constants.js +0 -1
- package/src/index.js +0 -262
- package/src/util/validators.js +0 -118
- package/test/commands/data/pinList/pinList.test.js +0 -98
- package/test/commands/data/pinlist-sample-api.js +0 -540
- package/test/commands/data/testAuthentication.test.js +0 -30
- package/test/commands/data/userPinnedDataTotal.test.js +0 -29
- package/test/commands/pinning/hashMetadata.test.js +0 -77
- package/test/commands/pinning/hashPinPolicy.test.js +0 -65
- package/test/commands/pinning/pinByHash.test.js +0 -47
- package/test/commands/pinning/pinFileToIPFS.test.js +0 -55
- package/test/commands/pinning/pinFromFS.js +0 -33
- package/test/commands/pinning/pinJSONToIPFS.test.js +0 -43
- package/test/commands/pinning/pinJobs/pinJobs.test.js +0 -29
- package/test/commands/pinning/userPinPolicy.test.js +0 -51
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from './../../constants';
|
|
3
|
-
import { validateApiKeys } from '../../util/validators';
|
|
4
|
-
import { handleError } from '../../util/errorResponse';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* User Pinned Data Total
|
|
8
|
-
* @param {string} pinataApiKey
|
|
9
|
-
* @param {string} pinataSecretApiKey
|
|
10
|
-
* @returns {Promise<unknown>}
|
|
11
|
-
*/
|
|
12
|
-
export default function userPinnedDataTotal(pinataApiKey, pinataSecretApiKey) {
|
|
13
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
14
|
-
|
|
15
|
-
let endpoint = `${baseUrl}/data/userPinnedDataTotal`;
|
|
16
|
-
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
axios.get(
|
|
19
|
-
endpoint,
|
|
20
|
-
{
|
|
21
|
-
withCredentials: true,
|
|
22
|
-
headers: {
|
|
23
|
-
'pinata_api_key': pinataApiKey,
|
|
24
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
25
|
-
}
|
|
26
|
-
}).then(function (result) {
|
|
27
|
-
if (result.status !== 200) {
|
|
28
|
-
reject(new Error(`unknown server response while attempting to retrieve pinned data total: ${result}`));
|
|
29
|
-
}
|
|
30
|
-
resolve(result.data);
|
|
31
|
-
}).catch(function (error) {
|
|
32
|
-
const formattedError = handleError(error);
|
|
33
|
-
reject(formattedError);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from './../../constants';
|
|
3
|
-
import { validateApiKeys, validatePinPolicyStructure } from '../../util/validators';
|
|
4
|
-
import isIPFS from 'is-ipfs';
|
|
5
|
-
import { handleError } from '../../util/errorResponse';
|
|
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
|
-
*/
|
|
15
|
-
export default function hashPinPolicy(pinataApiKey, pinataSecretApiKey, ipfsPinHash, newPinPolicy) {
|
|
16
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
17
|
-
validatePinPolicyStructure(newPinPolicy);
|
|
18
|
-
|
|
19
|
-
if (!ipfsPinHash) {
|
|
20
|
-
throw new Error('ipfsPinHash value is required for changing the pin policy of a pin');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!isIPFS.cid(ipfsPinHash)) {
|
|
24
|
-
throw new Error('ipfsPinHash value is an invalid IPFS CID');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!newPinPolicy) {
|
|
28
|
-
throw new Error('newPinPolicy is required for changing the pin policy of a pin');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const endpoint = `${baseUrl}/pinning/hashPinPolicy`;
|
|
32
|
-
const body = {
|
|
33
|
-
ipfsPinHash: ipfsPinHash,
|
|
34
|
-
newPinPolicy: newPinPolicy
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
axios.put(
|
|
39
|
-
endpoint,
|
|
40
|
-
body,
|
|
41
|
-
{
|
|
42
|
-
withCredentials: true,
|
|
43
|
-
headers: {
|
|
44
|
-
'pinata_api_key': pinataApiKey,
|
|
45
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
46
|
-
}
|
|
47
|
-
}).then(function (result) {
|
|
48
|
-
if (result.status !== 200) {
|
|
49
|
-
reject(new Error(`unknown server response while changing pin policy for hash: ${result}`));
|
|
50
|
-
}
|
|
51
|
-
resolve(result.data);
|
|
52
|
-
}).catch(function (error) {
|
|
53
|
-
const formattedError = handleError(error);
|
|
54
|
-
reject(formattedError);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from './../../../constants';
|
|
3
|
-
import { validateApiKeys } from '../../../util/validators';
|
|
4
|
-
import queryBuilder from './queryBuilder';
|
|
5
|
-
import { handleError } from '../../../util/errorResponse';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Pin Jobs
|
|
9
|
-
* @param {string} pinataApiKey
|
|
10
|
-
* @param {string} pinataSecretApiKey
|
|
11
|
-
* @param {*} filters
|
|
12
|
-
* @returns {Promise<unknown>}
|
|
13
|
-
*/
|
|
14
|
-
export default function pinJobs(pinataApiKey, pinataSecretApiKey, filters) {
|
|
15
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
16
|
-
|
|
17
|
-
let endpoint = `${baseUrl}/pinning/pinJobs`;
|
|
18
|
-
|
|
19
|
-
if (filters) {
|
|
20
|
-
endpoint = queryBuilder(endpoint, filters);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
axios.get(
|
|
25
|
-
endpoint,
|
|
26
|
-
{
|
|
27
|
-
withCredentials: true,
|
|
28
|
-
headers: {
|
|
29
|
-
'pinata_api_key': pinataApiKey,
|
|
30
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
31
|
-
}
|
|
32
|
-
}).then(function (result) {
|
|
33
|
-
if (result.status !== 200) {
|
|
34
|
-
reject(new Error(`unknown server response while attempting to retrieve pin jobs: ${result}`));
|
|
35
|
-
}
|
|
36
|
-
resolve(result.data);
|
|
37
|
-
}).catch(function (error) {
|
|
38
|
-
const formattedError = handleError(error);
|
|
39
|
-
reject(formattedError);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from './../../constants';
|
|
3
|
-
import { validateApiKeys, 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(pinataApiKey, pinataSecretApiKey, newPinPolicy) {
|
|
14
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
15
|
-
validatePinPolicyStructure(newPinPolicy);
|
|
16
|
-
|
|
17
|
-
if (!newPinPolicy) {
|
|
18
|
-
throw new Error('newPinPolicy is required for changing the pin policy of a pin');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const endpoint = `${baseUrl}/pinning/userPinPolicy`;
|
|
22
|
-
const body = {
|
|
23
|
-
newPinPolicy: newPinPolicy
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
axios.put(
|
|
28
|
-
endpoint,
|
|
29
|
-
body,
|
|
30
|
-
{
|
|
31
|
-
withCredentials: true,
|
|
32
|
-
headers: {
|
|
33
|
-
'pinata_api_key': pinataApiKey,
|
|
34
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
35
|
-
}
|
|
36
|
-
}).then(function (result) {
|
|
37
|
-
if (result.status !== 200) {
|
|
38
|
-
reject(new Error(`unknown server response while changing pin policy for user: ${result}`));
|
|
39
|
-
}
|
|
40
|
-
resolve(result.data);
|
|
41
|
-
}).catch(function (error) {
|
|
42
|
-
const formattedError = handleError(error);
|
|
43
|
-
reject(formattedError);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
package/src/constants.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const baseUrl = 'https://api.pinata.cloud';
|
package/src/index.js
DELETED
|
@@ -1,262 +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 PinataClient
|
|
204
|
-
* @property {pinByHash} pinByHash
|
|
205
|
-
* @property {hashMetadata} hashMetadata
|
|
206
|
-
* @property {pinFileToIPFS} pinFileToIPFS
|
|
207
|
-
* @property {pinFromFS} pinFromFS
|
|
208
|
-
* @property {pinJSONToIPFS} pinJSONToIPFS
|
|
209
|
-
* @property {pinJobs} pinJobs
|
|
210
|
-
* @property {unpin} unpin
|
|
211
|
-
* @property {testAuthentication} testAuthentication
|
|
212
|
-
* @property {pinList} pinList
|
|
213
|
-
* @property {userPinnedDataTotal} userPinnedDataTotal
|
|
214
|
-
*/
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Pinata Client
|
|
218
|
-
*
|
|
219
|
-
* @param {string} pinataApiKey
|
|
220
|
-
* @param {string} pinataSecretApiKey
|
|
221
|
-
* @returns {PinataClient}
|
|
222
|
-
*/
|
|
223
|
-
export default function pinataClient(pinataApiKey, pinataSecretApiKey) {
|
|
224
|
-
let client = {};
|
|
225
|
-
|
|
226
|
-
// setting up the actual calls you can make using this package
|
|
227
|
-
client.pinByHash = function (hashToPin, options) {
|
|
228
|
-
return pinByHash(pinataApiKey, pinataSecretApiKey, hashToPin, options);
|
|
229
|
-
};
|
|
230
|
-
client.hashMetadata = function (ipfsPinHash, metadata) {
|
|
231
|
-
return hashMetadata(pinataApiKey, pinataSecretApiKey, ipfsPinHash, metadata);
|
|
232
|
-
};
|
|
233
|
-
client.pinFileToIPFS = function (readableStream, options) {
|
|
234
|
-
return pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readableStream, options);
|
|
235
|
-
};
|
|
236
|
-
client.pinFromFS = function (sourcePath, options) {
|
|
237
|
-
return pinFromFS(pinataApiKey, pinataSecretApiKey, sourcePath, options);
|
|
238
|
-
};
|
|
239
|
-
client.pinJSONToIPFS = function (body, options) {
|
|
240
|
-
return pinJSONToIPFS(pinataApiKey, pinataSecretApiKey, body, options);
|
|
241
|
-
};
|
|
242
|
-
client.pinJobs = function (filters) {
|
|
243
|
-
return pinJobs(pinataApiKey, pinataSecretApiKey, filters);
|
|
244
|
-
};
|
|
245
|
-
client.unpin = function (hashToUnpin) {
|
|
246
|
-
return unpin(pinataApiKey, pinataSecretApiKey, hashToUnpin);
|
|
247
|
-
};
|
|
248
|
-
client.testAuthentication = function () {
|
|
249
|
-
return testAuthentication(pinataApiKey, pinataSecretApiKey);
|
|
250
|
-
};
|
|
251
|
-
client.pinList = function (filters) {
|
|
252
|
-
return pinList(pinataApiKey, pinataSecretApiKey, filters);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
client.getFilesByCount = function (filters, maxCount,) {
|
|
256
|
-
return getFilesByCount(pinataApiKey, pinataSecretApiKey, filters, maxCount);
|
|
257
|
-
};
|
|
258
|
-
client.userPinnedDataTotal = function () {
|
|
259
|
-
return userPinnedDataTotal(pinataApiKey, pinataSecretApiKey);
|
|
260
|
-
};
|
|
261
|
-
return client;
|
|
262
|
-
}
|
package/src/util/validators.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import isIPFS from 'is-ipfs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Validate API Keys
|
|
5
|
-
* @param {string} pinataApiKey
|
|
6
|
-
* @param {string} pinataSecretApiKey
|
|
7
|
-
*/
|
|
8
|
-
export function validateApiKeys(pinataApiKey, pinataSecretApiKey) {
|
|
9
|
-
if (!pinataApiKey || pinataApiKey === '') {
|
|
10
|
-
throw new Error('No pinataApiKey provided! Please provide your pinata api key as an argument when you start this script');
|
|
11
|
-
}
|
|
12
|
-
if (!pinataSecretApiKey || pinataSecretApiKey === '') {
|
|
13
|
-
throw new Error('No pinataSecretApiKey provided! Please provide your pinata secret api key as an argument when you start this script');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Validate host Nodes
|
|
19
|
-
* @param {*} hostNodes
|
|
20
|
-
*/
|
|
21
|
-
export function validateHostNodes(hostNodes) {
|
|
22
|
-
if (!Array.isArray(hostNodes)) {
|
|
23
|
-
throw new Error('host_nodes value must be an array');
|
|
24
|
-
}
|
|
25
|
-
hostNodes.forEach((node) => {
|
|
26
|
-
if (!isIPFS.peerMultiaddr(node)) {
|
|
27
|
-
throw new Error(`host_node array entry: ${node} is not a valid peer multiaddr`);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Validate MetaData
|
|
34
|
-
* @param {*} metadata
|
|
35
|
-
*/
|
|
36
|
-
export function validateMetadata(metadata) {
|
|
37
|
-
if (metadata.name) {
|
|
38
|
-
if (!(typeof metadata.name === 'string' || metadata.name instanceof String)) {
|
|
39
|
-
throw new Error('metadata name must be of type string');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (metadata.keyvalues) {
|
|
44
|
-
if (!(typeof metadata.keyvalues === 'object')) {
|
|
45
|
-
throw new Error('metatadata keyvalues must be an object');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let i = 0;
|
|
49
|
-
|
|
50
|
-
Object.entries(metadata.keyvalues).forEach(function (keyValue) {
|
|
51
|
-
if (i > 9) {
|
|
52
|
-
throw new Error('No more than 10 keyvalues can be provided for metadata entries');
|
|
53
|
-
}
|
|
54
|
-
// we want to make sure that the input is a string, a boolean, or a number, so we don't get an object passed in by accident
|
|
55
|
-
if (!(typeof keyValue[1] === 'string' || typeof keyValue[1] === 'boolean' || !isNaN(keyValue[1]))) {
|
|
56
|
-
throw new Error('Metadata keyvalue values must be strings, booleans, or numbers');
|
|
57
|
-
}
|
|
58
|
-
i++;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Validate Pin Policy Structure
|
|
65
|
-
* @param {*} pinPolicy
|
|
66
|
-
*/
|
|
67
|
-
export function validatePinPolicyStructure(pinPolicy) {
|
|
68
|
-
//this function takes in a pin policy and checks the JSON structure to make sure it's valid
|
|
69
|
-
if (!pinPolicy) {
|
|
70
|
-
throw new Error('No pin policy provided');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!pinPolicy.regions) {
|
|
74
|
-
throw new Error('No regions provided in pin policy');
|
|
75
|
-
}
|
|
76
|
-
if (pinPolicy.regions.length) {
|
|
77
|
-
pinPolicy.regions.forEach((region) => {
|
|
78
|
-
if (!region.id || !(Object.prototype.toString.call(region.id) === '[object String]')) {
|
|
79
|
-
throw new Error('region id must be a string');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!(region.desiredReplicationCount || region.desiredReplicationCount === 0) || !Number.isInteger(region.desiredReplicationCount)) {
|
|
83
|
-
throw new Error('desiredReplicationCount must be an integer');
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Validate Pinata Options
|
|
91
|
-
* @param {*} options
|
|
92
|
-
*/
|
|
93
|
-
export function validatePinataOptions(options) {
|
|
94
|
-
if (typeof options !== 'object') {
|
|
95
|
-
throw new Error('options must be an object');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (options.cidVersion) {
|
|
99
|
-
// eslint-disable-next-line eqeqeq
|
|
100
|
-
if (options.cidVersion != 0 && options.cidVersion != 1) {
|
|
101
|
-
throw new Error('unsupported or invalid cidVersion');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (options.wrapWithDirectory) {
|
|
105
|
-
// eslint-disable-next-line eqeqeq
|
|
106
|
-
if (options.wrapWithDirectory !== true && options.wrapWithDirectory !== false) {
|
|
107
|
-
throw new Error('wrapWithDirectory must be a boolean value of true or false');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (options.hostNodes) {
|
|
112
|
-
validateHostNodes(options.hostNodes);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (options.customPinPolicy) {
|
|
116
|
-
validatePinPolicyStructure(options.customPinPolicy);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import pinList from "./../../../../src/commands/data/pinList/pinList";
|
|
3
|
-
import {
|
|
4
|
-
APIData,
|
|
5
|
-
pinListAxiosMockPages,
|
|
6
|
-
fakeHeaders,
|
|
7
|
-
} from "../pinlist-sample-api";
|
|
8
|
-
|
|
9
|
-
jest.mock("axios");
|
|
10
|
-
|
|
11
|
-
describe("Get Files By Count", () => {
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
jest.resetAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("Call two pages in a row", async () => {
|
|
17
|
-
axios.get
|
|
18
|
-
.mockResolvedValueOnce(pinListAxiosMockPages.firstPage.response)
|
|
19
|
-
.mockResolvedValueOnce(pinListAxiosMockPages.secondPage.response);
|
|
20
|
-
|
|
21
|
-
const resp = await pinList(
|
|
22
|
-
fakeHeaders.headers.pinata_api_key,
|
|
23
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
24
|
-
{ pageLimit: 10, pageOffset: 0 }
|
|
25
|
-
);
|
|
26
|
-
const resp2 = await pinList(
|
|
27
|
-
fakeHeaders.headers.pinata_api_key,
|
|
28
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
29
|
-
{ pageLimit: 10, pageOffset: 10 }
|
|
30
|
-
);
|
|
31
|
-
expect(resp).toEqual(pinListAxiosMockPages.firstPage.response.data);
|
|
32
|
-
expect(resp2).toEqual(pinListAxiosMockPages.secondPage.response.data);
|
|
33
|
-
|
|
34
|
-
expect(axios.get).toHaveBeenNthCalledWith(
|
|
35
|
-
1,
|
|
36
|
-
pinListAxiosMockPages.firstPage.url,
|
|
37
|
-
pinListAxiosMockPages.firstPage.headers
|
|
38
|
-
);
|
|
39
|
-
expect(axios.get).toHaveBeenNthCalledWith(
|
|
40
|
-
2,
|
|
41
|
-
pinListAxiosMockPages.secondPage.url,
|
|
42
|
-
pinListAxiosMockPages.secondPage.headers
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
expect(axios.get).toHaveBeenCalledTimes(2);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("Call empty page", async () => {
|
|
49
|
-
axios.get
|
|
50
|
-
.mockResolvedValueOnce(pinListAxiosMockPages.firstPageEmpty.response)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const resp = await pinList(
|
|
54
|
-
fakeHeaders.headers.pinata_api_key,
|
|
55
|
-
fakeHeaders.headers.pinata_secret_api_key,
|
|
56
|
-
{ pageLimit: 10, pageOffset: 0 }
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
expect(resp).toEqual({rows: []});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
expect(axios.get).toHaveBeenNthCalledWith(
|
|
63
|
-
1,
|
|
64
|
-
pinListAxiosMockPages.firstPageEmpty.url,
|
|
65
|
-
pinListAxiosMockPages.firstPageEmpty.headers
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(axios.get).toHaveBeenCalledTimes(1);
|
|
69
|
-
});
|
|
70
|
-
test("Result other than 200 status is returned", () => {
|
|
71
|
-
const badStatus = {
|
|
72
|
-
status: 700,
|
|
73
|
-
};
|
|
74
|
-
axios.get.mockResolvedValue(badStatus);
|
|
75
|
-
expect.assertions(1);
|
|
76
|
-
expect(pinList("test", "test")).rejects.toEqual(
|
|
77
|
-
Error(
|
|
78
|
-
`unknown server response while attempting to retrieve user pin list: ${badStatus}`
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("200 status is returned", () => {
|
|
84
|
-
const goodStatus = {
|
|
85
|
-
status: 200,
|
|
86
|
-
data: "testData",
|
|
87
|
-
};
|
|
88
|
-
axios.get.mockResolvedValue(goodStatus);
|
|
89
|
-
expect.assertions(1);
|
|
90
|
-
expect(pinList("test", "test")).resolves.toEqual(goodStatus.data);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("Rejection handled", () => {
|
|
94
|
-
axios.get.mockRejectedValue("test error");
|
|
95
|
-
expect.assertions(1);
|
|
96
|
-
expect(pinList("test", "test")).rejects.toEqual("test error");
|
|
97
|
-
});
|
|
98
|
-
});
|