@pinata/sdk 2.0.0 → 3.0.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/LICENSE +1 -2
- package/README.md +58 -695
- package/index.d.ts +9 -0
- package/index.js +6 -0
- package/index.mjs +4 -0
- package/legacy.js +15 -0
- package/package.json +58 -84
- package/react/index.d.ts +1 -0
- package/react/index.js +3 -0
- package/react/index.mjs +1 -0
- package/.babelrc +0 -5
- package/.editorconfig +0 -12
- package/.eslintrc +0 -173
- package/.husky/pre-commit +0 -6
- package/.nvmrc +0 -1
- package/.travis.yml +0 -5
- package/lib/pinata-sdk.js +0 -24514
- package/lib/pinata-sdk.min.js +0 -22
- package/pinata.png +0 -0
- package/src/commands/data/getFilesByCount/getFilesByCount.ts +0 -66
- package/src/commands/data/index.ts +0 -4
- package/src/commands/data/pinList/pinList.ts +0 -77
- package/src/commands/data/pinList/queryBuilder.ts +0 -239
- package/src/commands/data/testAuthentication.ts +0 -31
- package/src/commands/data/userPinnedDataTotal.ts +0 -24
- package/src/commands/pinning/hashMetadata.ts +0 -56
- package/src/commands/pinning/index.ts +0 -8
- package/src/commands/pinning/pinByHash.ts +0 -65
- package/src/commands/pinning/pinFileToIPFS.ts +0 -118
- package/src/commands/pinning/pinFromFS.ts +0 -50
- package/src/commands/pinning/pinJSONToIPFS.ts +0 -47
- package/src/commands/pinning/pinJobs/pinJobs.ts +0 -50
- package/src/commands/pinning/pinJobs/queryBuilder.ts +0 -75
- package/src/commands/pinning/unpin.ts +0 -32
- package/src/constants.ts +0 -4
- package/src/index.ts +0 -123
- package/src/third-party/base-path-converter.d.ts +0 -3
- package/src/third-party/is-ipfs.d.ts +0 -5
- package/src/util/errorResponse.ts +0 -10
- package/src/util/validators.ts +0 -182
- package/test/commands/data/getFilesByCount/getFilesByCount.test.ts +0 -212
- package/test/commands/data/pinList/pinList.test.ts +0 -102
- package/test/commands/data/pinList/queryBuilder.test.ts +0 -439
- package/test/commands/data/pinlist-sample-api.ts +0 -540
- package/test/commands/data/testAuthentication.test.ts +0 -34
- package/test/commands/data/userPinnedDataTotal.test.ts +0 -29
- package/test/commands/pinning/hashMetadata.test.ts +0 -76
- package/test/commands/pinning/pinByHash.test.ts +0 -46
- package/test/commands/pinning/pinFileToIPFS.test.ts +0 -53
- package/test/commands/pinning/pinFromFS.ts +0 -32
- package/test/commands/pinning/pinJSONToIPFS.test.ts +0 -42
- package/test/commands/pinning/pinJobs/pinJobs.test.ts +0 -29
- package/test/commands/pinning/pinJobs/queryBuilder.test.ts +0 -120
- package/test/commands/pinning/unpin.test.ts +0 -46
- package/test/util/validators.test.ts +0 -234
- package/tsconfig.json +0 -23
- package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +0 -14
- package/types/commands/data/index.d.ts +0 -4
- package/types/commands/data/pinList/pinList.d.ts +0 -45
- package/types/commands/data/pinList/queryBuilder.d.ts +0 -1
- package/types/commands/data/testAuthentication.d.ts +0 -5
- package/types/commands/data/userPinnedDataTotal.d.ts +0 -2
- package/types/commands/pinning/hashMetadata.d.ts +0 -3
- package/types/commands/pinning/hashPinPolicy.d.ts +0 -9
- package/types/commands/pinning/index.d.ts +0 -8
- package/types/commands/pinning/pinByHash.d.ts +0 -14
- package/types/commands/pinning/pinFileToIPFS.d.ts +0 -25
- package/types/commands/pinning/pinFromFS.d.ts +0 -3
- package/types/commands/pinning/pinJSONToIPFS.d.ts +0 -3
- package/types/commands/pinning/pinJobs/pinJobs.d.ts +0 -20
- package/types/commands/pinning/pinJobs/queryBuilder.d.ts +0 -1
- package/types/commands/pinning/unpin.d.ts +0 -2
- package/types/commands/pinning/userPinPolicy.d.ts +0 -8
- package/types/constants.d.ts +0 -2
- package/types/index.d.ts +0 -38
- package/types/util/errorResponse.d.ts +0 -1
- package/types/util/validators.d.ts +0 -37
- package/webpack.config.js +0 -58
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '../../constants';
|
|
3
|
-
import NodeFormData from 'form-data';
|
|
4
|
-
import stream from 'stream';
|
|
5
|
-
import {
|
|
6
|
-
createConfigForAxiosHeadersWithFormData,
|
|
7
|
-
validateMetadata,
|
|
8
|
-
validatePinataOptions
|
|
9
|
-
} from '../../util/validators';
|
|
10
|
-
import { handleError } from '../../util/errorResponse';
|
|
11
|
-
import { PinataConfig, PinataMetadata } from '../..';
|
|
12
|
-
|
|
13
|
-
export interface PinataPinPolicyItem {
|
|
14
|
-
id: string;
|
|
15
|
-
desiredReplicationCount: number;
|
|
16
|
-
}
|
|
17
|
-
export interface PinataOptions {
|
|
18
|
-
hostNodes?: string[] | undefined;
|
|
19
|
-
cidVersion?: 0 | 1;
|
|
20
|
-
wrapWithDirectory?: boolean;
|
|
21
|
-
customPinPolicy?: {
|
|
22
|
-
regions: PinataPinPolicyItem[];
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface PinataPinResponse {
|
|
27
|
-
IpfsHash: string;
|
|
28
|
-
PinSize: number;
|
|
29
|
-
Timestamp: string;
|
|
30
|
-
}
|
|
31
|
-
export interface PinataPinOptions {
|
|
32
|
-
pinataMetadata?: PinataMetadata;
|
|
33
|
-
pinataOptions?: PinataOptions | undefined;
|
|
34
|
-
}
|
|
35
|
-
const endpoint = `${baseUrl}/pinning/pinFileToIPFS`;
|
|
36
|
-
|
|
37
|
-
export function uploadToIPFS(
|
|
38
|
-
config: PinataConfig,
|
|
39
|
-
data: NodeFormData,
|
|
40
|
-
options?: PinataPinOptions
|
|
41
|
-
): Promise<PinataPinResponse> {
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
if (options && options.pinataMetadata) {
|
|
44
|
-
validateMetadata(options.pinataMetadata);
|
|
45
|
-
data.append(
|
|
46
|
-
'pinataMetadata',
|
|
47
|
-
JSON.stringify(options.pinataMetadata)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
if (options && options.pinataOptions) {
|
|
51
|
-
validatePinataOptions(options.pinataOptions);
|
|
52
|
-
data.append('pinataOptions', JSON.stringify(options.pinataOptions));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
axios
|
|
56
|
-
.post(
|
|
57
|
-
endpoint,
|
|
58
|
-
data,
|
|
59
|
-
createConfigForAxiosHeadersWithFormData(
|
|
60
|
-
config,
|
|
61
|
-
data.getBoundary()
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
.then(function (result) {
|
|
65
|
-
if (result.status !== 200) {
|
|
66
|
-
reject(
|
|
67
|
-
new Error(
|
|
68
|
-
`unknown server response while pinning File to IPFS: ${result}`
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
resolve(result.data);
|
|
73
|
-
})
|
|
74
|
-
.catch(function (error) {
|
|
75
|
-
const formattedError = handleError(error);
|
|
76
|
-
reject(formattedError);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export default function pinFileToIPFS(
|
|
82
|
-
config: PinataConfig,
|
|
83
|
-
readStream: any,
|
|
84
|
-
options?: PinataPinOptions
|
|
85
|
-
): Promise<PinataPinResponse> {
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
const data = new NodeFormData();
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
!(
|
|
91
|
-
options?.pinataMetadata?.name &&
|
|
92
|
-
typeof options.pinataMetadata.name === 'string' &&
|
|
93
|
-
options.pinataMetadata.name.length > 0
|
|
94
|
-
)
|
|
95
|
-
) {
|
|
96
|
-
throw Error(
|
|
97
|
-
'filename was not provide, make sure to provide options.pinataMetadata.name'
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
data.append('file', readStream, {
|
|
102
|
-
filename: options.pinataMetadata.name
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
!(
|
|
107
|
-
readStream instanceof stream.Readable ||
|
|
108
|
-
readStream instanceof NodeFormData
|
|
109
|
-
)
|
|
110
|
-
) {
|
|
111
|
-
reject(
|
|
112
|
-
new Error('readStream is not a readable stream or form data')
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
resolve(uploadToIPFS(config, data, options));
|
|
117
|
-
});
|
|
118
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import NodeFormData from 'form-data';
|
|
3
|
-
|
|
4
|
-
import basePathConverter from 'base-path-converter';
|
|
5
|
-
import { PinataConfig } from '../..';
|
|
6
|
-
import {
|
|
7
|
-
PinataPinOptions,
|
|
8
|
-
PinataPinResponse,
|
|
9
|
-
uploadToIPFS
|
|
10
|
-
} from './pinFileToIPFS';
|
|
11
|
-
import fs from 'fs';
|
|
12
|
-
|
|
13
|
-
import path from 'path';
|
|
14
|
-
|
|
15
|
-
export default async function pinFromFS(
|
|
16
|
-
config: PinataConfig,
|
|
17
|
-
sourcePath: string,
|
|
18
|
-
options?: PinataPinOptions
|
|
19
|
-
): Promise<PinataPinResponse> {
|
|
20
|
-
try {
|
|
21
|
-
const stats = await fs.promises.stat(sourcePath);
|
|
22
|
-
if (stats.isFile()) {
|
|
23
|
-
|
|
24
|
-
const stream = fs.createReadStream(sourcePath);
|
|
25
|
-
const data = new NodeFormData();
|
|
26
|
-
|
|
27
|
-
data.append('file', stream, {
|
|
28
|
-
filename: path.basename(sourcePath)
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return uploadToIPFS(config, data, options);
|
|
32
|
-
}
|
|
33
|
-
const files = await fs.promises.readdir(sourcePath);
|
|
34
|
-
const data = new NodeFormData();
|
|
35
|
-
|
|
36
|
-
files.forEach((file: string) => {
|
|
37
|
-
//for each file stream, we need to include the correct relative file path
|
|
38
|
-
data.append('file', fs.createReadStream(file), {
|
|
39
|
-
filepath: basePathConverter(sourcePath, file)
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return uploadToIPFS(config, data, options);
|
|
44
|
-
|
|
45
|
-
} catch (err) {
|
|
46
|
-
console.log(err);
|
|
47
|
-
throw err;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '../../constants';
|
|
3
|
-
import { createConfigForAxiosHeaders, validateMetadata, validatePinataOptions } from '../../util/validators';
|
|
4
|
-
import { handleError } from '../../util/errorResponse';
|
|
5
|
-
import { PinataConfig } from '../..';
|
|
6
|
-
import { PinataPinOptions, PinataPinResponse } from './pinFileToIPFS';
|
|
7
|
-
|
|
8
|
-
export default function pinJSONToIPFS(config: PinataConfig, body: any, options? : PinataPinOptions):Promise<PinataPinResponse> {
|
|
9
|
-
|
|
10
|
-
let requestBody: any = body;
|
|
11
|
-
|
|
12
|
-
if (typeof body !== 'object') {
|
|
13
|
-
throw new Error('body must be a valid JSON object');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (options) {
|
|
17
|
-
requestBody = {
|
|
18
|
-
pinataContent: body
|
|
19
|
-
};
|
|
20
|
-
if (options.pinataMetadata) {
|
|
21
|
-
validateMetadata(options.pinataMetadata);
|
|
22
|
-
requestBody.pinataMetadata = options.pinataMetadata;
|
|
23
|
-
}
|
|
24
|
-
if (options.pinataOptions) {
|
|
25
|
-
validatePinataOptions(options.pinataOptions);
|
|
26
|
-
requestBody.pinataOptions = options.pinataOptions;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const endpoint = `${baseUrl}/pinning/pinJSONToIPFS`;
|
|
31
|
-
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
axios.post(
|
|
34
|
-
endpoint,
|
|
35
|
-
requestBody,
|
|
36
|
-
{...createConfigForAxiosHeaders(config)})
|
|
37
|
-
.then(function (result) {
|
|
38
|
-
if (result.status !== 200) {
|
|
39
|
-
reject(new Error(`unknown server response while pinning JSON to IPFS: ${result}`));
|
|
40
|
-
}
|
|
41
|
-
resolve(result.data);
|
|
42
|
-
}).catch(function (error) {
|
|
43
|
-
const formattedError = handleError(error);
|
|
44
|
-
reject(formattedError);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '../../../constants';
|
|
3
|
-
import { createConfigForAxiosHeaders } from '../../../util/validators';
|
|
4
|
-
import queryBuilder from './queryBuilder';
|
|
5
|
-
import { handleError } from '../../../util/errorResponse';
|
|
6
|
-
import { PinataConfig } from '../../..';
|
|
7
|
-
|
|
8
|
-
export interface PinataPinJobsResponseRow {
|
|
9
|
-
id: number | string;
|
|
10
|
-
ipfs_pin_hash: string;
|
|
11
|
-
date_queued: string;
|
|
12
|
-
name: string | undefined | null;
|
|
13
|
-
status: string;
|
|
14
|
-
}
|
|
15
|
-
export interface PinataPinJobsResponse {
|
|
16
|
-
count: number;
|
|
17
|
-
rows: PinataPinJobsResponseRow[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface PinataPinJobsFilterOptions {
|
|
21
|
-
sort: 'ASC' | 'DESC';
|
|
22
|
-
status?: string | undefined;
|
|
23
|
-
ipfs_pin_hash?: string | undefined;
|
|
24
|
-
limit?: number | undefined;
|
|
25
|
-
offset?: number | undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default function pinJobs(config: PinataConfig, filters? : PinataPinJobsFilterOptions): Promise<PinataPinJobsResponse> {
|
|
29
|
-
|
|
30
|
-
let endpoint = `${baseUrl}/pinning/pinJobs`;
|
|
31
|
-
|
|
32
|
-
if (filters) {
|
|
33
|
-
endpoint = queryBuilder(endpoint, filters);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
axios.get(
|
|
38
|
-
endpoint,
|
|
39
|
-
{...createConfigForAxiosHeaders(config)})
|
|
40
|
-
.then(function (result) {
|
|
41
|
-
if (result.status !== 200) {
|
|
42
|
-
reject(new Error(`unknown server response while attempting to retrieve pin jobs: ${result}`));
|
|
43
|
-
}
|
|
44
|
-
resolve(result.data);
|
|
45
|
-
}).catch(function (error) {
|
|
46
|
-
const formattedError = handleError(error);
|
|
47
|
-
reject(formattedError);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import isIPFS from 'is-ipfs';
|
|
2
|
-
|
|
3
|
-
export default function queryBuilder(baseUrl: string, filters?: any): string {
|
|
4
|
-
if (!baseUrl) {
|
|
5
|
-
throw new Error('no baseUrl provided');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (!filters) {
|
|
9
|
-
return baseUrl;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
let newUrl = baseUrl;
|
|
13
|
-
|
|
14
|
-
let firstFilterApplied = false; // we want to make sure that the "?" character is only applied once
|
|
15
|
-
|
|
16
|
-
function addFilter(newFilter: string) {
|
|
17
|
-
if (firstFilterApplied) {
|
|
18
|
-
newUrl = `${newUrl}&${newFilter}`;
|
|
19
|
-
} else {
|
|
20
|
-
firstFilterApplied = true;
|
|
21
|
-
newUrl = `${newUrl}?${newFilter}`;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (filters) {
|
|
26
|
-
// now we need to construct the actual URL based on the given filters provided
|
|
27
|
-
if (filters.sort) {
|
|
28
|
-
if (filters.sort === 'ASC' ||
|
|
29
|
-
filters.sort === 'DESC') {
|
|
30
|
-
addFilter(`sort=${filters.sort}`);
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error(`Unknown sort value: ${filters.sort} provided`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (filters.status) {
|
|
37
|
-
if (filters.status === 'searching' ||
|
|
38
|
-
filters.status === 'expired' ||
|
|
39
|
-
filters.status === 'over_free_limit' ||
|
|
40
|
-
filters.status === 'over_max_size' ||
|
|
41
|
-
filters.status === 'invalid_object' ||
|
|
42
|
-
filters.status === 'bad_host_node'
|
|
43
|
-
) {
|
|
44
|
-
addFilter(`status=${filters.status}`);
|
|
45
|
-
} else {
|
|
46
|
-
throw new Error(`Unknown status value: ${filters.status} provided`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (filters.ipfs_pin_hash) {
|
|
51
|
-
if (isIPFS.cid(filters.ipfs_pin_hash)) {
|
|
52
|
-
addFilter(`ipfs_pin_hash=${filters.ipfs_pin_hash}`);
|
|
53
|
-
} else {
|
|
54
|
-
throw new Error(`Invalid IPFS hash: ${filters.ipfs_pin_hash}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (filters.limit) {
|
|
59
|
-
if (Number.isInteger(filters.limit) && (filters.limit > 0) && (filters.limit < 100)) {
|
|
60
|
-
addFilter(`limit=${filters.limit}`);
|
|
61
|
-
} else {
|
|
62
|
-
throw new Error(`Invalid limit: ${filters.limit}. Valid limits are 1-100`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (filters.offset) {
|
|
67
|
-
if (Number.isInteger(filters.offset) && (filters.offset > 0)) {
|
|
68
|
-
addFilter(`offset=${filters.offset}`);
|
|
69
|
-
} else {
|
|
70
|
-
throw new Error(`Invalid offset: ${filters.offset}. Please provide a positive integer for the offset`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return newUrl;
|
|
75
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '../../constants';
|
|
3
|
-
import { createConfigForAxiosHeaders } from '../../util/validators';
|
|
4
|
-
import isIPFS from 'is-ipfs';
|
|
5
|
-
import { handleError } from '../../util/errorResponse';
|
|
6
|
-
import { PinataConfig } from '../..';
|
|
7
|
-
|
|
8
|
-
export default function unpin(config: PinataConfig, hashToUnpin: string) {
|
|
9
|
-
if (!hashToUnpin) {
|
|
10
|
-
throw new Error('hashToUnpin value is required for removing a pin from Pinata');
|
|
11
|
-
}
|
|
12
|
-
if (!isIPFS.cid(hashToUnpin)) {
|
|
13
|
-
throw new Error(`${hashToUnpin} is an invalid IPFS CID`);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const endpoint = `${baseUrl}/pinning/unpin/${hashToUnpin}`;
|
|
17
|
-
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
axios.delete(
|
|
20
|
-
endpoint,
|
|
21
|
-
{...createConfigForAxiosHeaders(config)})
|
|
22
|
-
.then(function (result) {
|
|
23
|
-
if (result.status !== 200) {
|
|
24
|
-
reject(new Error(`unknown server response while removing pin from IPFS: ${result}`));
|
|
25
|
-
}
|
|
26
|
-
resolve(result.data);
|
|
27
|
-
}).catch(function (error) {
|
|
28
|
-
const formattedError = handleError(error);
|
|
29
|
-
reject(formattedError);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
package/src/constants.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import pinByHash, {
|
|
2
|
-
PinataPinByHashPinOptions
|
|
3
|
-
} from './commands/pinning/pinByHash';
|
|
4
|
-
import hashMetadata from './commands/pinning/hashMetadata';
|
|
5
|
-
import pinFileToIPFS, {
|
|
6
|
-
PinataPinOptions
|
|
7
|
-
} from './commands/pinning/pinFileToIPFS';
|
|
8
|
-
import pinFromFS from './commands/pinning/pinFromFS';
|
|
9
|
-
import pinJSONToIPFS from './commands/pinning/pinJSONToIPFS';
|
|
10
|
-
import pinJobs, {
|
|
11
|
-
PinataPinJobsFilterOptions
|
|
12
|
-
} from './commands/pinning/pinJobs/pinJobs';
|
|
13
|
-
import unpin from './commands/pinning/unpin';
|
|
14
|
-
import testAuthentication from './commands/data/testAuthentication';
|
|
15
|
-
import pinList, {
|
|
16
|
-
PinataMetadata,
|
|
17
|
-
PinataPinListFilterOptions
|
|
18
|
-
} from './commands/data/pinList/pinList';
|
|
19
|
-
import getFilesByCount from './commands/data/getFilesByCount/getFilesByCount';
|
|
20
|
-
import userPinnedDataTotal from './commands/data/userPinnedDataTotal';
|
|
21
|
-
|
|
22
|
-
export interface PinataConfig {
|
|
23
|
-
pinataApiKey?: string;
|
|
24
|
-
pinataSecretApiKey?: string;
|
|
25
|
-
pinataJWTKey?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function refactorConfig(pinataConfigParam: PinataConfig): PinataConfig {
|
|
29
|
-
const config: PinataConfig = {};
|
|
30
|
-
if (pinataConfigParam.pinataApiKey) {
|
|
31
|
-
config.pinataApiKey = pinataConfigParam.pinataApiKey;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (pinataConfigParam.pinataSecretApiKey) {
|
|
35
|
-
config.pinataSecretApiKey = pinataConfigParam.pinataSecretApiKey;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (pinataConfigParam.pinataJWTKey) {
|
|
39
|
-
config.pinataJWTKey = pinataConfigParam.pinataJWTKey;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return config;
|
|
43
|
-
}
|
|
44
|
-
function sanitizeConfig(
|
|
45
|
-
pinataApiKey?: string | PinataConfig,
|
|
46
|
-
pinataSecretApiKey?: string
|
|
47
|
-
): PinataConfig {
|
|
48
|
-
let config: PinataConfig = {};
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
typeof pinataApiKey === 'string' &&
|
|
52
|
-
typeof pinataSecretApiKey === 'string'
|
|
53
|
-
) {
|
|
54
|
-
config.pinataApiKey = pinataApiKey;
|
|
55
|
-
config.pinataSecretApiKey = pinataSecretApiKey;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const isPinataConfigParam = typeof pinataApiKey === 'object';
|
|
59
|
-
if (isPinataConfigParam) {
|
|
60
|
-
config = refactorConfig(pinataApiKey);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return config;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
class PinataClient {
|
|
67
|
-
config: PinataConfig;
|
|
68
|
-
|
|
69
|
-
constructor(
|
|
70
|
-
pinataApiKey?: string | PinataConfig,
|
|
71
|
-
pinataSecretApiKey?: string
|
|
72
|
-
) {
|
|
73
|
-
this.config = sanitizeConfig(pinataApiKey, pinataSecretApiKey);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
pinByHash(hashToPin: string, options?: PinataPinByHashPinOptions) {
|
|
77
|
-
return pinByHash(this.config, hashToPin, options);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
hashMetadata(ipfsPinHash: string, metadata: PinataMetadata) {
|
|
81
|
-
return hashMetadata(this.config, ipfsPinHash, metadata);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
pinFileToIPFS(readableStream: any, options?: PinataPinOptions) {
|
|
85
|
-
return pinFileToIPFS(this.config, readableStream, options);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
pinFromFS(sourcePath: string, options?: PinataPinOptions) {
|
|
89
|
-
return pinFromFS(this.config, sourcePath, options);
|
|
90
|
-
}
|
|
91
|
-
pinJSONToIPFS(body: any, options?: PinataPinOptions) {
|
|
92
|
-
return pinJSONToIPFS(this.config, body, options);
|
|
93
|
-
}
|
|
94
|
-
pinJobs(filters?: PinataPinJobsFilterOptions) {
|
|
95
|
-
return pinJobs(this.config, filters);
|
|
96
|
-
}
|
|
97
|
-
unpin(hashToUnpin: string) {
|
|
98
|
-
return unpin(this.config, hashToUnpin);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
pinList(filters: PinataPinListFilterOptions) {
|
|
102
|
-
return pinList(this.config, filters);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
getFilesByCount(filters: PinataPinListFilterOptions, maxCount?: number) {
|
|
106
|
-
return getFilesByCount(this.config, filters, maxCount);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
testAuthentication() {
|
|
110
|
-
return testAuthentication(this.config);
|
|
111
|
-
}
|
|
112
|
-
userPinnedDataTotal() {
|
|
113
|
-
return userPinnedDataTotal(this.config);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
module.exports = PinataClient;
|
|
118
|
-
|
|
119
|
-
export * from './commands/data';
|
|
120
|
-
export * from './commands/pinning';
|
|
121
|
-
|
|
122
|
-
export default PinataClient;
|
|
123
|
-
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const handleError = (error : any) => {
|
|
2
|
-
if (error && error.response && error.response && error.response.data && error.response.data.error) {
|
|
3
|
-
return error.response.data.error;
|
|
4
|
-
} else if (error.data && error.data.error) {
|
|
5
|
-
return error.data.error;
|
|
6
|
-
} else if (error.response && error.response.error) {
|
|
7
|
-
return error.response.error;
|
|
8
|
-
}
|
|
9
|
-
return error;
|
|
10
|
-
};
|