@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
package/package.json
CHANGED
|
@@ -1,74 +1,86 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/PinataCloud/Pinata-SDK/issues"
|
|
34
|
-
},
|
|
35
|
-
"homepage": "https://github.com/PinataCloud/Pinata-SDK",
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@babel/cli": "^7.8.4",
|
|
38
|
-
"@babel/core": "^7.8.4",
|
|
39
|
-
"@babel/plugin-transform-runtime": "^7.19.1",
|
|
40
|
-
"@babel/preset-env": "^7.19.4",
|
|
41
|
-
"@babel/register": "^7.8.3",
|
|
42
|
-
"@types/node": "^15.6.1",
|
|
43
|
-
"acorn": "^7.1.0",
|
|
44
|
-
"babel-eslint": "^10.0.3",
|
|
45
|
-
"babel-loader": "^8.0.6",
|
|
46
|
-
"babel-plugin-add-module-exports": "^1.0.2",
|
|
47
|
-
"babel-polyfill": "^6.26.0",
|
|
48
|
-
"eslint": "^6.8.0",
|
|
49
|
-
"eslint-loader": "^3.0.3",
|
|
50
|
-
"jest": "^25.1.0",
|
|
51
|
-
"typescript": "^4.2.3",
|
|
52
|
-
"uglifyjs-webpack-plugin": "^2.2.0",
|
|
53
|
-
"webpack": "^4.41.6",
|
|
54
|
-
"webpack-cli": "^3.3.11",
|
|
55
|
-
"yargs": "^10.0.3"
|
|
56
|
-
},
|
|
57
|
-
"dependencies": {
|
|
58
|
-
"axios": "^0.21.1",
|
|
59
|
-
"base-path-converter": "^1.0.2",
|
|
60
|
-
"form-data": "^2.3.3",
|
|
61
|
-
"is-ipfs": "^0.6.0",
|
|
62
|
-
"recursive-fs": "^1.1.2"
|
|
63
|
-
},
|
|
64
|
-
"jest": {
|
|
65
|
-
"collectCoverage": true,
|
|
66
|
-
"coverageReporters": [
|
|
67
|
-
"text",
|
|
68
|
-
"html"
|
|
2
|
+
"name": "@pinata/sdk",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"description": "Official SDK for the Pinata IPFS platform",
|
|
5
|
+
"main": "lib/pinata-sdk.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prepare": "husky install",
|
|
9
|
+
"build": "npm run build-dev && npm run build-prod && npm run test && tsc",
|
|
10
|
+
"build-dev": "webpack --env dev",
|
|
11
|
+
"build-prod": "webpack --env build",
|
|
12
|
+
"coverage": "jest --coverage",
|
|
13
|
+
"dev": "webpack --progress --colors --watch --env dev",
|
|
14
|
+
"html": "open coverage/index.html",
|
|
15
|
+
"lint": "eslint src --quiet ",
|
|
16
|
+
"lint:fix": "eslint src test --fix",
|
|
17
|
+
"test": "./node_modules/.bin/jest --env=node",
|
|
18
|
+
"repl": "node -i -e \"$(< ./lib/pinata-sdk.js)\""
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/PinataCloud/Pinata-SDK.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"webpack",
|
|
26
|
+
"es6",
|
|
27
|
+
"starter",
|
|
28
|
+
"library",
|
|
29
|
+
"universal",
|
|
30
|
+
"umd",
|
|
31
|
+
"commonjs"
|
|
69
32
|
],
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
33
|
+
"author": "Matt Ober",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/PinataCloud/Pinata-SDK/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/PinataCloud/Pinata-SDK",
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@babel/cli": "^7.8.4",
|
|
41
|
+
"@babel/core": "^7.8.4",
|
|
42
|
+
"@babel/plugin-transform-runtime": "^7.19.1",
|
|
43
|
+
"@babel/preset-env": "^7.19.4",
|
|
44
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
45
|
+
"@babel/register": "^7.8.3",
|
|
46
|
+
"@types/jest": "^29.2.0",
|
|
47
|
+
"@types/node": "^15.6.1",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
49
|
+
"@typescript-eslint/parser": "^5.41.0",
|
|
50
|
+
"acorn": "^7.1.0",
|
|
51
|
+
"babel-eslint": "^10.0.3",
|
|
52
|
+
"babel-loader": "^8.0.6",
|
|
53
|
+
"babel-plugin-add-module-exports": "^1.0.2",
|
|
54
|
+
"babel-polyfill": "^6.26.0",
|
|
55
|
+
"eslint": "^8.26.0",
|
|
56
|
+
"eslint-loader": "^3.0.3",
|
|
57
|
+
"husky": "^8.0.0",
|
|
58
|
+
"jest": "^25.1.0",
|
|
59
|
+
"source-map-loader": "^4.0.1",
|
|
60
|
+
"typescript": "^4.8.4",
|
|
61
|
+
"uglifyjs-webpack-plugin": "^2.2.0",
|
|
62
|
+
"webpack": "^4.41.6",
|
|
63
|
+
"webpack-cli": "^3.3.11"
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"axios": "^0.21.1",
|
|
67
|
+
"base-path-converter": "^1.0.2",
|
|
68
|
+
"form-data": "^2.3.3",
|
|
69
|
+
"is-ipfs": "^0.6.0",
|
|
70
|
+
"recursive-fs": "^1.1.2"
|
|
71
|
+
},
|
|
72
|
+
"jest": {
|
|
73
|
+
"collectCoverage": true,
|
|
74
|
+
"coverageReporters": [
|
|
75
|
+
"text",
|
|
76
|
+
"html"
|
|
77
|
+
],
|
|
78
|
+
"moduleFileExtensions": [
|
|
79
|
+
"ts",
|
|
80
|
+
"tsx",
|
|
81
|
+
"js",
|
|
82
|
+
"jsx",
|
|
83
|
+
"json"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
74
86
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import pinList from '../pinList/pinList';
|
|
1
|
+
import { PinataConfig } from '../../..';
|
|
2
|
+
import pinList, { PinataPin, PinataPinListFilterOptions } from '../pinList/pinList';
|
|
3
3
|
|
|
4
4
|
export default function getFilesByCount(
|
|
5
|
-
|
|
6
|
-
pinataSecretApiKey,
|
|
5
|
+
config: PinataConfig,
|
|
7
6
|
|
|
8
|
-
filters = {},
|
|
7
|
+
filters: PinataPinListFilterOptions = {},
|
|
9
8
|
maxCount = -1
|
|
10
9
|
) {
|
|
11
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
12
10
|
if (maxCount === 0) {
|
|
13
11
|
throw Error("Max count can't be 0");
|
|
14
12
|
}
|
|
@@ -18,7 +16,7 @@ export default function getFilesByCount(
|
|
|
18
16
|
let i = 0;
|
|
19
17
|
const pageLimit = 10;
|
|
20
18
|
let pageOffset = 0;
|
|
21
|
-
let cache = [];
|
|
19
|
+
let cache: PinataPin[] = [];
|
|
22
20
|
let keepLooping = false;
|
|
23
21
|
|
|
24
22
|
return {
|
|
@@ -26,8 +24,8 @@ export default function getFilesByCount(
|
|
|
26
24
|
return new Promise((resolve, reject) => {
|
|
27
25
|
if (i === 0 || (i % pageLimit === 0 && keepLooping)) {
|
|
28
26
|
resolve(
|
|
29
|
-
pinList(
|
|
30
|
-
filters,
|
|
27
|
+
pinList(config, {
|
|
28
|
+
...filters,
|
|
31
29
|
...{ pageOffset, pageLimit }
|
|
32
30
|
}).then((resp) => {
|
|
33
31
|
cache = resp.rows;
|
|
@@ -36,13 +34,11 @@ export default function getFilesByCount(
|
|
|
36
34
|
// If the user requested all pins we have to keep looping if the limit page was not fulfill
|
|
37
35
|
keepLooping =
|
|
38
36
|
cache.length !== 0 &&
|
|
39
|
-
(maxCount === -1 ?
|
|
40
|
-
cache.length === pageLimit :
|
|
41
|
-
i < maxCount);
|
|
37
|
+
(maxCount === -1 ? cache.length === pageLimit : i < maxCount);
|
|
42
38
|
})
|
|
43
39
|
);
|
|
44
40
|
}
|
|
45
|
-
resolve();
|
|
41
|
+
resolve(0);
|
|
46
42
|
}).then(() => {
|
|
47
43
|
const valueToReturn = cache[i % pageLimit];
|
|
48
44
|
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { baseUrl } from '../../../constants';
|
|
3
|
+
import { createConfigForAxiosHeaders } from '../../../util/validators';
|
|
4
|
+
import { handleError } from '../../../util/errorResponse';
|
|
5
|
+
import queryBuilder from './queryBuilder';
|
|
6
|
+
import { PinataConfig } from '../../..';
|
|
7
|
+
export interface PinataPinRegion {
|
|
8
|
+
regionId: string;
|
|
9
|
+
currentReplicationCount: number;
|
|
10
|
+
desiredReplicationCount: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PinataMetadata { [key: string]: string | number | null }
|
|
14
|
+
export interface PinataMetadataFilter {
|
|
15
|
+
name?: string | undefined;
|
|
16
|
+
keyvalues: { [key: string]: {
|
|
17
|
+
value: string;
|
|
18
|
+
op: string;
|
|
19
|
+
} }
|
|
20
|
+
}
|
|
21
|
+
export interface PinataPin {
|
|
22
|
+
id: string | number;
|
|
23
|
+
ipfs_pin_hash: string;
|
|
24
|
+
size: number;
|
|
25
|
+
user_id: string | number;
|
|
26
|
+
date_pinned: string;
|
|
27
|
+
date_unpinned: string | null;
|
|
28
|
+
metadata: PinataMetadata,
|
|
29
|
+
regions: PinataPinRegion[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type PinataPinListFilterOptions = {
|
|
33
|
+
hashContains?: string | undefined;
|
|
34
|
+
pinStart?: string | undefined;
|
|
35
|
+
pinEnd?: string | undefined;
|
|
36
|
+
unpinStart?: string | undefined;
|
|
37
|
+
unpinEnd?: string | undefined;
|
|
38
|
+
pinSizeMin?: number | undefined;
|
|
39
|
+
pinSizeMax?: number | undefined;
|
|
40
|
+
status?: string | undefined;
|
|
41
|
+
pageLimit?: number | undefined;
|
|
42
|
+
pageOffset?: number | undefined;
|
|
43
|
+
metadata?: PinataMetadataFilter | undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export interface PinataPinListResponse {
|
|
47
|
+
rows: PinataPin[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default function pinList(
|
|
51
|
+
config: PinataConfig,
|
|
52
|
+
filters:PinataPinListFilterOptions = {}
|
|
53
|
+
): Promise<PinataPinListResponse> {
|
|
54
|
+
filters = { ...filters, ...{ includeCount: 'false' } };
|
|
55
|
+
|
|
56
|
+
const baseEndpoint = `${baseUrl}/data/pinList`;
|
|
57
|
+
const endpoint = queryBuilder(baseEndpoint, filters);
|
|
58
|
+
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
axios
|
|
61
|
+
.get(endpoint, { ...createConfigForAxiosHeaders(config) })
|
|
62
|
+
.then(function (result) {
|
|
63
|
+
if (result.status !== 200) {
|
|
64
|
+
reject(
|
|
65
|
+
new Error(
|
|
66
|
+
`unknown server response while attempting to retrieve user pin list: ${result}`
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
resolve(result.data);
|
|
71
|
+
})
|
|
72
|
+
.catch(function (error) {
|
|
73
|
+
const formattedError = handleError(error);
|
|
74
|
+
reject(formattedError);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @returns {*}
|
|
5
|
-
*/
|
|
6
|
-
function validateAndReturnDate(dateToValidate) {
|
|
7
|
-
let dateParsed = new Date(Date.parse(dateToValidate));
|
|
1
|
+
|
|
2
|
+
function validateAndReturnDate(dateToValidate: any): any {
|
|
3
|
+
const dateParsed = new Date(Date.parse(dateToValidate));
|
|
8
4
|
|
|
9
5
|
try {
|
|
10
6
|
if (dateParsed.toISOString() === dateToValidate) {
|
|
@@ -17,13 +13,7 @@ function validateAndReturnDate(dateToValidate) {
|
|
|
17
13
|
}
|
|
18
14
|
}
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
* Query Builder
|
|
22
|
-
* @param {string} baseUrl
|
|
23
|
-
* @param {*} filters
|
|
24
|
-
* @returns {string}
|
|
25
|
-
*/
|
|
26
|
-
export default function queryBuilder(baseUrl, filters) {
|
|
16
|
+
export default function queryBuilder(baseUrl: string, filters?: any): string {
|
|
27
17
|
if (!baseUrl) {
|
|
28
18
|
throw new Error('no baseUrl provided');
|
|
29
19
|
}
|
|
@@ -106,11 +96,11 @@ export default function queryBuilder(baseUrl, filters) {
|
|
|
106
96
|
throw new Error('metadata keyvalues must be an object');
|
|
107
97
|
}
|
|
108
98
|
|
|
109
|
-
const prunedKeyValues = {}; // we want to make sure we're only grabbing the values we want for the query, and nothing extra
|
|
99
|
+
const prunedKeyValues: any = {}; // we want to make sure we're only grabbing the values we want for the query, and nothing extra
|
|
110
100
|
|
|
111
101
|
Object.entries(filters.metadata.keyvalues).forEach((keyValue) => {
|
|
112
102
|
const key = keyValue[0];
|
|
113
|
-
const value = keyValue[1];
|
|
103
|
+
const value: any = keyValue[1];
|
|
114
104
|
|
|
115
105
|
if (typeof value !== 'object') {
|
|
116
106
|
throw new Error(`keyValue: ${key} is not an object`);
|
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '
|
|
3
|
-
import {
|
|
2
|
+
import { baseUrl } from '../../constants';
|
|
3
|
+
import {createConfigForAxiosHeaders} from '../../util/validators';
|
|
4
4
|
import { handleError } from '../../util/errorResponse';
|
|
5
|
+
import { PinataConfig } from '../..';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @param {string} pinataSecretApiKey
|
|
10
|
-
* @returns {Promise<unknown>}
|
|
11
|
-
*/
|
|
12
|
-
export default function testAuthentication(pinataApiKey, pinataSecretApiKey) {
|
|
13
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
7
|
+
export interface PinataTestAuthenticationResponse {
|
|
8
|
+
authenticated: boolean;
|
|
9
|
+
}
|
|
14
10
|
|
|
11
|
+
export default function testAuthentication(config: PinataConfig): Promise<PinataTestAuthenticationResponse> {
|
|
15
12
|
// test authentication to make sure that the user's provided keys are legit
|
|
16
13
|
const endpoint = `${baseUrl}/data/testAuthentication`;
|
|
17
14
|
|
|
18
15
|
return new Promise((resolve, reject) => {
|
|
19
16
|
axios.get(
|
|
20
17
|
endpoint,
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
headers: {
|
|
24
|
-
'pinata_api_key': pinataApiKey,
|
|
25
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
26
|
-
}
|
|
27
|
-
}).then(function (result) {
|
|
18
|
+
{...createConfigForAxiosHeaders(config)})
|
|
19
|
+
.then(function (result) {
|
|
28
20
|
if (result.status !== 200) {
|
|
29
21
|
reject(new Error(`unknown server response while authenticating: ${result}`));
|
|
30
22
|
}
|
|
@@ -36,4 +28,4 @@ export default function testAuthentication(pinataApiKey, pinataSecretApiKey) {
|
|
|
36
28
|
reject(formattedError);
|
|
37
29
|
});
|
|
38
30
|
});
|
|
39
|
-
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { baseUrl } from '../../constants';
|
|
3
|
+
import { createConfigForAxiosHeaders } from '../../util/validators';
|
|
4
|
+
import { handleError } from '../../util/errorResponse';
|
|
5
|
+
import { PinataConfig } from '../..';
|
|
6
|
+
|
|
7
|
+
export default function userPinnedDataTotal(config: PinataConfig): Promise<number> {
|
|
8
|
+
const endpoint = `${baseUrl}/data/userPinnedDataTotal`;
|
|
9
|
+
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
axios.get(
|
|
12
|
+
endpoint,
|
|
13
|
+
{...createConfigForAxiosHeaders(config)})
|
|
14
|
+
.then(function (result) {
|
|
15
|
+
if (result.status !== 200) {
|
|
16
|
+
reject(new Error(`unknown server response while attempting to retrieve pinned data total: ${result}`));
|
|
17
|
+
}
|
|
18
|
+
resolve(result.data);
|
|
19
|
+
}).catch(function (error) {
|
|
20
|
+
const formattedError = handleError(error);
|
|
21
|
+
reject(formattedError);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '
|
|
3
|
-
import {
|
|
2
|
+
import { baseUrl } from '../../constants';
|
|
3
|
+
import { createConfigForAxiosHeaders, validateMetadata } from '../../util/validators';
|
|
4
4
|
import isIPFS from 'is-ipfs';
|
|
5
5
|
import { handleError } from '../../util/errorResponse';
|
|
6
|
+
import { PinataConfig } from '../..';
|
|
7
|
+
import { PinataMetadata } from '../data/pinList/pinList';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
* Hash Meta Data
|
|
9
|
-
* @param {string} pinataApiKey
|
|
10
|
-
* @param {string} pinataSecretApiKey
|
|
11
|
-
* @param {*} ipfsPinHash
|
|
12
|
-
* @param {*} metadata
|
|
13
|
-
* @returns {Promise<unknown>}
|
|
14
|
-
*/
|
|
15
|
-
export default function hashMetadata(pinataApiKey, pinataSecretApiKey, ipfsPinHash, metadata) {
|
|
16
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
17
|
-
|
|
9
|
+
export default function hashMetadata(config: PinataConfig, ipfsPinHash: string, metadata:PinataMetadata): Promise<any> {
|
|
18
10
|
if (!ipfsPinHash) {
|
|
19
11
|
throw new Error('ipfsPinHash value is required for changing the pin policy of a pin');
|
|
20
12
|
}
|
|
@@ -30,7 +22,11 @@ export default function hashMetadata(pinataApiKey, pinataSecretApiKey, ipfsPinHa
|
|
|
30
22
|
validateMetadata(metadata);
|
|
31
23
|
|
|
32
24
|
const endpoint = `${baseUrl}/pinning/hashMetadata`;
|
|
33
|
-
const body
|
|
25
|
+
const body: {
|
|
26
|
+
ipfsPinHash: string,
|
|
27
|
+
name?: any,
|
|
28
|
+
keyvalues?: any
|
|
29
|
+
} = {
|
|
34
30
|
ipfsPinHash: ipfsPinHash
|
|
35
31
|
};
|
|
36
32
|
|
|
@@ -46,13 +42,8 @@ export default function hashMetadata(pinataApiKey, pinataSecretApiKey, ipfsPinHa
|
|
|
46
42
|
axios.put(
|
|
47
43
|
endpoint,
|
|
48
44
|
body,
|
|
49
|
-
{
|
|
50
|
-
|
|
51
|
-
headers: {
|
|
52
|
-
'pinata_api_key': pinataApiKey,
|
|
53
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
54
|
-
}
|
|
55
|
-
}).then(function (result) {
|
|
45
|
+
{...createConfigForAxiosHeaders(config)})
|
|
46
|
+
.then(function (result) {
|
|
56
47
|
if (result.status !== 200) {
|
|
57
48
|
reject(new Error(`unknown server response while changing metadata for hash: ${result}`));
|
|
58
49
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './pinJobs/pinJobs';
|
|
2
|
+
export * from './pinJobs/queryBuilder';
|
|
3
|
+
export * from './hashMetadata';
|
|
4
|
+
export * from './pinByHash';
|
|
5
|
+
export * from './pinFileToIPFS';
|
|
6
|
+
export * from './pinFromFS';
|
|
7
|
+
export * from './pinJSONToIPFS';
|
|
8
|
+
export * from './unpin';
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '
|
|
3
|
-
import {
|
|
2
|
+
import { baseUrl } from '../../constants';
|
|
3
|
+
import { createConfigForAxiosHeaders, validateMetadata } from '../../util/validators';
|
|
4
4
|
import isIPFS from 'is-ipfs';
|
|
5
5
|
import { handleError } from '../../util/errorResponse';
|
|
6
|
+
import { PinataConfig } from '../..';
|
|
7
|
+
import { PinataOptions } from './pinFileToIPFS';
|
|
8
|
+
import { PinataMetadata } from '../data/pinList/pinList';
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
export interface PinataPinByHashPinOptions {
|
|
11
|
+
pinataMetadata?: PinataMetadata;
|
|
12
|
+
pinataOptions?: PinataOptions ;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface PinataPinByHashResponse {
|
|
16
|
+
id: number | string;
|
|
17
|
+
ipfsHash: string;
|
|
18
|
+
status: string;
|
|
19
|
+
name: string;
|
|
20
|
+
}
|
|
17
21
|
|
|
22
|
+
export default function pinByHash(config: PinataConfig, hashToPin: string, options: any): Promise<any> {
|
|
18
23
|
if (!hashToPin) {
|
|
19
24
|
throw new Error('hashToPin value is required for pinning by hash');
|
|
20
25
|
}
|
|
@@ -23,7 +28,11 @@ export default function pinByHash(pinataApiKey, pinataSecretApiKey, hashToPin, o
|
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
const endpoint = `${baseUrl}/pinning/pinByHash`;
|
|
26
|
-
const body
|
|
31
|
+
const body : {
|
|
32
|
+
hashToPin: any,
|
|
33
|
+
pinataOptions: any,
|
|
34
|
+
pinataMetadata?: any,
|
|
35
|
+
} = {
|
|
27
36
|
hashToPin: hashToPin,
|
|
28
37
|
pinataOptions: {}
|
|
29
38
|
};
|
|
@@ -42,13 +51,8 @@ export default function pinByHash(pinataApiKey, pinataSecretApiKey, hashToPin, o
|
|
|
42
51
|
axios.post(
|
|
43
52
|
endpoint,
|
|
44
53
|
body,
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
headers: {
|
|
48
|
-
'pinata_api_key': pinataApiKey,
|
|
49
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
50
|
-
}
|
|
51
|
-
}).then(function (result) {
|
|
54
|
+
{...createConfigForAxiosHeaders(config)})
|
|
55
|
+
.then(function (result) {
|
|
52
56
|
if (result.status !== 200) {
|
|
53
57
|
reject(new Error(`unknown server response while adding to pin queue: ${result}`));
|
|
54
58
|
}
|
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '
|
|
2
|
+
import { baseUrl } from '../../constants';
|
|
3
3
|
import NodeFormData from 'form-data';
|
|
4
4
|
import stream from 'stream';
|
|
5
|
-
import {
|
|
5
|
+
import {createConfigForAxiosHeadersWithFormData, validateMetadata, validatePinataOptions} from '../../util/validators';
|
|
6
6
|
import { handleError } from '../../util/errorResponse';
|
|
7
|
+
import { PinataConfig } from '../..';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
export interface PinataPinPolicyItem {
|
|
10
|
+
id: string;
|
|
11
|
+
desiredReplicationCount: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PinataOptions {
|
|
14
|
+
hostNodes?: string[] | undefined;
|
|
15
|
+
cidVersion?: 0 | 1 ;
|
|
16
|
+
wrapWithDirectory?: boolean;
|
|
17
|
+
customPinPolicy?: {
|
|
18
|
+
regions: PinataPinPolicyItem[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PinataPinResponse {
|
|
23
|
+
IpfsHash: string;
|
|
24
|
+
PinSize: number;
|
|
25
|
+
Timestamp: string;
|
|
26
|
+
}
|
|
27
|
+
export interface PinataPinOptions {
|
|
28
|
+
pinataMetadata?: { [key: string]: string | number | null },
|
|
29
|
+
pinataOptions?: PinataOptions | undefined;
|
|
30
|
+
}
|
|
18
31
|
|
|
32
|
+
export default function pinFileToIPFS(config: PinataConfig, readStream: any, options?: PinataPinOptions):Promise<PinataPinResponse> {
|
|
19
33
|
return new Promise((resolve, reject) => {
|
|
20
34
|
|
|
21
35
|
const data = new NodeFormData();
|
|
@@ -38,20 +52,11 @@ export default function pinFileToIPFS(pinataApiKey, pinataSecretApiKey, readStre
|
|
|
38
52
|
data.append('pinataOptions', JSON.stringify(options.pinataOptions));
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
|
-
|
|
42
|
-
axios.post(
|
|
55
|
+
axios.post(
|
|
43
56
|
endpoint,
|
|
44
57
|
readStream instanceof NodeFormData ? readStream : data,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
maxContentLength: 'Infinity', //this is needed to prevent axios from erroring out with large files
|
|
48
|
-
maxBodyLength: 'Infinity',
|
|
49
|
-
headers: {
|
|
50
|
-
'Content-type': `multipart/form-data; boundary= ${data._boundary}`,
|
|
51
|
-
'pinata_api_key': pinataApiKey,
|
|
52
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
53
|
-
}
|
|
54
|
-
}).then(function (result) {
|
|
58
|
+
createConfigForAxiosHeadersWithFormData(config, data.getBoundary())
|
|
59
|
+
).then(function (result) {
|
|
55
60
|
if (result.status !== 200) {
|
|
56
61
|
reject(new Error(`unknown server response while pinning File to IPFS: ${result}`));
|
|
57
62
|
}
|