@pinata/sdk 2.1.0 → 3.0.1
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 +59 -694
- package/index.d.ts +9 -0
- package/index.js +6 -0
- package/index.mjs +4 -0
- package/legacy.js +15 -0
- package/package.json +62 -83
- 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 -24526
- 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 -60
- 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 -124
- package/src/require-babel-polyfill.ts +0 -5
- package/src/third-party/base-path-converter.d.ts +0 -3
- package/src/third-party/global.d.ts +0 -9
- 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 -71
- 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 -4
- 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 -39
- package/types/require-babel-polyfill.d.ts +0 -2
- package/types/util/errorResponse.d.ts +0 -1
- package/types/util/validators.d.ts +0 -37
- package/webpack.config.js +0 -58
package/pinata.png
DELETED
|
Binary file
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { PinataConfig } from '../../..';
|
|
2
|
-
import pinList, { PinataPin, PinataPinListFilterOptions } from '../pinList/pinList';
|
|
3
|
-
|
|
4
|
-
export default function getFilesByCount(
|
|
5
|
-
config: PinataConfig,
|
|
6
|
-
|
|
7
|
-
filters: PinataPinListFilterOptions = {},
|
|
8
|
-
maxCount = -1
|
|
9
|
-
) {
|
|
10
|
-
if (maxCount === 0) {
|
|
11
|
-
throw Error("Max count can't be 0");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const asyncIterable = {
|
|
15
|
-
[Symbol.asyncIterator]: () => {
|
|
16
|
-
let i = 0;
|
|
17
|
-
const pageLimit = 10;
|
|
18
|
-
let pageOffset = 0;
|
|
19
|
-
let cache: PinataPin[] = [];
|
|
20
|
-
let keepLooping = false;
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
next() {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
if (i === 0 || (i % pageLimit === 0 && keepLooping)) {
|
|
26
|
-
resolve(
|
|
27
|
-
pinList(config, {
|
|
28
|
-
...filters,
|
|
29
|
-
...{ pageOffset, pageLimit }
|
|
30
|
-
}).then((resp) => {
|
|
31
|
-
cache = resp.rows;
|
|
32
|
-
pageOffset = pageOffset + cache.length;
|
|
33
|
-
|
|
34
|
-
// If the user requested all pins we have to keep looping if the limit page was not fulfill
|
|
35
|
-
keepLooping =
|
|
36
|
-
cache.length !== 0 &&
|
|
37
|
-
(maxCount === -1 ? cache.length === pageLimit : i < maxCount);
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
resolve(0);
|
|
42
|
-
}).then(() => {
|
|
43
|
-
const valueToReturn = cache[i % pageLimit];
|
|
44
|
-
|
|
45
|
-
const done = !(
|
|
46
|
-
(maxCount === -1 ? i < pageOffset : i < maxCount) &&
|
|
47
|
-
keepLooping
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
i++;
|
|
51
|
-
return Promise.resolve({
|
|
52
|
-
value: valueToReturn,
|
|
53
|
-
done
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
return() {
|
|
58
|
-
// This will be reached if the consumer called 'break' or 'return' early in the loop.
|
|
59
|
-
return Promise.resolve({ value: i, done: true });
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return asyncIterable;
|
|
66
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
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 | number | null;
|
|
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,239 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function validateAndReturnDate(dateToValidate: any): any {
|
|
3
|
-
const dateParsed = new Date(Date.parse(dateToValidate));
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
if (dateParsed.toISOString() === dateToValidate) {
|
|
7
|
-
return dateToValidate;
|
|
8
|
-
}
|
|
9
|
-
throw new Error('dates must be in valid ISO_8601 format');
|
|
10
|
-
|
|
11
|
-
} catch (e) {
|
|
12
|
-
throw new Error('dates must be in valid ISO_8601 format');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default function queryBuilder(baseUrl: string, filters?: any): string {
|
|
17
|
-
if (!baseUrl) {
|
|
18
|
-
throw new Error('no baseUrl provided');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// preset filter values
|
|
22
|
-
let filterQuery = '?';
|
|
23
|
-
|
|
24
|
-
let metadataQuery = '';
|
|
25
|
-
|
|
26
|
-
if (filters) {
|
|
27
|
-
// now we need to construct the actual URL based on the given filters provided
|
|
28
|
-
if (filters.includeCount) {
|
|
29
|
-
filterQuery = filterQuery + `includeCount=${filters.includeCount}&`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (filters.hashContains) {
|
|
33
|
-
if (typeof filters.hashContains !== 'string') {
|
|
34
|
-
throw new Error('hashContains value is not a string');
|
|
35
|
-
}
|
|
36
|
-
filterQuery = filterQuery + `hashContains=${filters.hashContains}&`;
|
|
37
|
-
}
|
|
38
|
-
if (filters.pinStart) {
|
|
39
|
-
filterQuery = filterQuery + `pinStart=${validateAndReturnDate(filters.pinStart)}&`;
|
|
40
|
-
}
|
|
41
|
-
if (filters.pinEnd) {
|
|
42
|
-
filterQuery = filterQuery + `pinEnd=${validateAndReturnDate(filters.pinEnd)}&`;
|
|
43
|
-
}
|
|
44
|
-
if (filters.unpinStart) {
|
|
45
|
-
filterQuery = filterQuery + `unpinStart=${validateAndReturnDate(filters.unpinStart)}&`;
|
|
46
|
-
}
|
|
47
|
-
if (filters.unpinEnd) {
|
|
48
|
-
filterQuery = filterQuery + `unpinEnd=${validateAndReturnDate(filters.unpinEnd)}&`;
|
|
49
|
-
}
|
|
50
|
-
if (filters.pinSizeMin) {
|
|
51
|
-
if (isNaN(filters.pinSizeMin) || filters.pinSizeMin < 0) {
|
|
52
|
-
throw new Error('Please make sure the pinSizeMin is a valid positive integer');
|
|
53
|
-
}
|
|
54
|
-
filterQuery = filterQuery + `pinSizeMin=${filters.pinSizeMin}&`;
|
|
55
|
-
}
|
|
56
|
-
if (filters.pinSizeMax) {
|
|
57
|
-
if (isNaN(filters.pinSizeMax) || filters.pinSizeMax < 0) {
|
|
58
|
-
throw new Error('Please make sure the pinSizeMax is a valid positive integer');
|
|
59
|
-
}
|
|
60
|
-
filterQuery = filterQuery + `pinSizeMax=${filters.pinSizeMax}&`;
|
|
61
|
-
}
|
|
62
|
-
if (filters.status) {
|
|
63
|
-
if (filters.status !== 'all' && filters.status !== 'pinned' && filters.status !== 'unpinned') {
|
|
64
|
-
throw new Error('status value must be either: all, pinned, or unpinned');
|
|
65
|
-
}
|
|
66
|
-
filterQuery = filterQuery + `status=${filters.status}&`;
|
|
67
|
-
}
|
|
68
|
-
if (filters.pageLimit) {
|
|
69
|
-
if (isNaN(filters.pageLimit) || filters.pageLimit <= 0 || filters.pageLimit > 1000) {
|
|
70
|
-
throw new Error('Please make sure the pageLimit is a valid integer between 1-1000');
|
|
71
|
-
}
|
|
72
|
-
filterQuery = filterQuery + `pageLimit=${parseInt(filters.pageLimit)}&`; // we want to make sure that decimals get rounded to integers
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (filters.pageOffset) {
|
|
76
|
-
if (isNaN(filters.pageOffset) || filters.pageOffset <= 0) {
|
|
77
|
-
throw new Error('Please make sure the pageOffset is a positive integer');
|
|
78
|
-
}
|
|
79
|
-
filterQuery = filterQuery + `pageOffset=${parseInt(filters.pageOffset)}&`; // we want to make sure that decimals get rounded to integers
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (filters.metadata) {
|
|
83
|
-
|
|
84
|
-
if (typeof filters.metadata !== 'object') {
|
|
85
|
-
throw new Error('metadata value must be an object');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (filters.metadata.name) {
|
|
89
|
-
metadataQuery = `metadata[name]=${filters.metadata.name}&`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (filters.metadata.keyvalues) {
|
|
93
|
-
metadataQuery = metadataQuery + 'metadata[keyvalues]=';
|
|
94
|
-
|
|
95
|
-
if (typeof filters.metadata.keyvalues !== 'object') {
|
|
96
|
-
throw new Error('metadata keyvalues must be an object');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const prunedKeyValues: any = {}; // we want to make sure we're only grabbing the values we want for the query, and nothing extra
|
|
100
|
-
|
|
101
|
-
Object.entries(filters.metadata.keyvalues).forEach((keyValue) => {
|
|
102
|
-
const key = keyValue[0];
|
|
103
|
-
const value: any = keyValue[1];
|
|
104
|
-
|
|
105
|
-
if (typeof value !== 'object') {
|
|
106
|
-
throw new Error(`keyValue: ${key} is not an object`);
|
|
107
|
-
}
|
|
108
|
-
if (!value || !value.value || !value.op) {
|
|
109
|
-
throw new Error(`keyValue: ${key} must have both value and op attributes`);
|
|
110
|
-
}
|
|
111
|
-
if ((typeof value.value !== 'string') && (typeof value.value !== 'boolean') && (typeof value.value !== 'number')) {
|
|
112
|
-
throw new Error('Metadata keyvalue values must be strings, booleans, or numbers');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Run checks to make sure all of the keyvalues are valid
|
|
116
|
-
switch (value.op) {
|
|
117
|
-
case 'gt':
|
|
118
|
-
prunedKeyValues[key] = {
|
|
119
|
-
value: value.value,
|
|
120
|
-
op: value.op
|
|
121
|
-
};
|
|
122
|
-
break;
|
|
123
|
-
//greater than or equal
|
|
124
|
-
case 'gte':
|
|
125
|
-
prunedKeyValues[key] = {
|
|
126
|
-
value: value.value,
|
|
127
|
-
op: value.op
|
|
128
|
-
};
|
|
129
|
-
break;
|
|
130
|
-
// less than
|
|
131
|
-
case 'lt':
|
|
132
|
-
prunedKeyValues[key] = {
|
|
133
|
-
value: value.value,
|
|
134
|
-
op: value.op
|
|
135
|
-
};
|
|
136
|
-
break;
|
|
137
|
-
// less than or equal
|
|
138
|
-
case 'lte':
|
|
139
|
-
prunedKeyValues[key] = {
|
|
140
|
-
value: value.value,
|
|
141
|
-
op: value.op
|
|
142
|
-
};
|
|
143
|
-
break;
|
|
144
|
-
// not equal to
|
|
145
|
-
case 'ne':
|
|
146
|
-
prunedKeyValues[key] = {
|
|
147
|
-
value: value.value,
|
|
148
|
-
op: value.op
|
|
149
|
-
};
|
|
150
|
-
break;
|
|
151
|
-
// equal to
|
|
152
|
-
case 'eq':
|
|
153
|
-
prunedKeyValues[key] = {
|
|
154
|
-
value: value.value,
|
|
155
|
-
op: value.op
|
|
156
|
-
};
|
|
157
|
-
break;
|
|
158
|
-
// between
|
|
159
|
-
case 'between':
|
|
160
|
-
if (!value.secondValue) {
|
|
161
|
-
throw new Error(`Because between op code was passed in, keyValue: ${keyValue[0]} must have both also include a secondValue`);
|
|
162
|
-
}
|
|
163
|
-
if ((typeof value.secondValue !== 'string') && (typeof value.secondValue !== 'boolean') && (typeof value.secondValue !== 'number')) {
|
|
164
|
-
throw new Error('Metadata keyvalue secondValue must be a string, boolean, or number');
|
|
165
|
-
}
|
|
166
|
-
prunedKeyValues[key] = {
|
|
167
|
-
value: value.value,
|
|
168
|
-
op: value.op,
|
|
169
|
-
secondValue: value.secondValue
|
|
170
|
-
};
|
|
171
|
-
break;
|
|
172
|
-
// not between
|
|
173
|
-
case 'notBetween':
|
|
174
|
-
if (!value.secondValue) {
|
|
175
|
-
throw new Error(`Because notBetween op code was passed in, keyValue: ${keyValue[0]} must have both also include a secondValue`);
|
|
176
|
-
}
|
|
177
|
-
if ((typeof value.secondValue !== 'string') && (typeof value.secondValue !== 'boolean') && (typeof value.secondValue !== 'number')) {
|
|
178
|
-
throw new Error('Metadata keyvalue secondValue must be a string, boolean, or number');
|
|
179
|
-
}
|
|
180
|
-
prunedKeyValues[key] = {
|
|
181
|
-
value: value.value,
|
|
182
|
-
op: value.op,
|
|
183
|
-
secondValue: value.secondValue
|
|
184
|
-
};
|
|
185
|
-
break;
|
|
186
|
-
// like
|
|
187
|
-
case 'like':
|
|
188
|
-
prunedKeyValues[key] = {
|
|
189
|
-
value: value.value,
|
|
190
|
-
op: value.op
|
|
191
|
-
};
|
|
192
|
-
break;
|
|
193
|
-
// not like
|
|
194
|
-
case 'notLike':
|
|
195
|
-
prunedKeyValues[key] = {
|
|
196
|
-
value: value.value,
|
|
197
|
-
op: value.op
|
|
198
|
-
};
|
|
199
|
-
break;
|
|
200
|
-
// case insensitive like
|
|
201
|
-
case 'iLike':
|
|
202
|
-
prunedKeyValues[key] = {
|
|
203
|
-
value: value.value,
|
|
204
|
-
op: value.op
|
|
205
|
-
};
|
|
206
|
-
break;
|
|
207
|
-
// case insensitive not like
|
|
208
|
-
case 'notILike':
|
|
209
|
-
prunedKeyValues[key] = {
|
|
210
|
-
value: value.value,
|
|
211
|
-
op: value.op
|
|
212
|
-
};
|
|
213
|
-
break;
|
|
214
|
-
// regex
|
|
215
|
-
case 'regexp':
|
|
216
|
-
prunedKeyValues[key] = {
|
|
217
|
-
value: value.value,
|
|
218
|
-
op: value.op
|
|
219
|
-
};
|
|
220
|
-
break;
|
|
221
|
-
// case insensitive regex
|
|
222
|
-
case 'iRegexp':
|
|
223
|
-
prunedKeyValues[key] = {
|
|
224
|
-
value: value.value,
|
|
225
|
-
op: value.op
|
|
226
|
-
};
|
|
227
|
-
break;
|
|
228
|
-
default:
|
|
229
|
-
throw new Error(`keyValue op: ${value.op} is not a valid op code`);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
metadataQuery = metadataQuery + `${JSON.stringify(prunedKeyValues)}`;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return `${baseUrl}${filterQuery}${metadataQuery}`;
|
|
238
|
-
}
|
|
239
|
-
|
|
@@ -1,31 +0,0 @@
|
|
|
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 interface PinataTestAuthenticationResponse {
|
|
8
|
-
authenticated: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default function testAuthentication(config: PinataConfig): Promise<PinataTestAuthenticationResponse> {
|
|
12
|
-
// test authentication to make sure that the user's provided keys are legit
|
|
13
|
-
const endpoint = `${baseUrl}/data/testAuthentication`;
|
|
14
|
-
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
axios.get(
|
|
17
|
-
endpoint,
|
|
18
|
-
{...createConfigForAxiosHeaders(config)})
|
|
19
|
-
.then(function (result) {
|
|
20
|
-
if (result.status !== 200) {
|
|
21
|
-
reject(new Error(`unknown server response while authenticating: ${result}`));
|
|
22
|
-
}
|
|
23
|
-
resolve({
|
|
24
|
-
authenticated: true
|
|
25
|
-
});
|
|
26
|
-
}).catch(function (error) {
|
|
27
|
-
const formattedError = handleError(error);
|
|
28
|
-
reject(formattedError);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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,56 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '../../constants';
|
|
3
|
-
import { createConfigForAxiosHeaders, validateMetadata } from '../../util/validators';
|
|
4
|
-
import isIPFS from 'is-ipfs';
|
|
5
|
-
import { handleError } from '../../util/errorResponse';
|
|
6
|
-
import { PinataConfig } from '../..';
|
|
7
|
-
import { PinataMetadata } from '../data/pinList/pinList';
|
|
8
|
-
|
|
9
|
-
export default function hashMetadata(config: PinataConfig, ipfsPinHash: string, metadata:PinataMetadata): Promise<any> {
|
|
10
|
-
if (!ipfsPinHash) {
|
|
11
|
-
throw new Error('ipfsPinHash value is required for changing the pin policy of a pin');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!isIPFS.cid(ipfsPinHash)) {
|
|
15
|
-
throw new Error('ipfsPinHash value is an invalid IPFS CID');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!metadata) {
|
|
19
|
-
throw new Error('no metadata object provided');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
validateMetadata(metadata);
|
|
23
|
-
|
|
24
|
-
const endpoint = `${baseUrl}/pinning/hashMetadata`;
|
|
25
|
-
const body: {
|
|
26
|
-
ipfsPinHash: string,
|
|
27
|
-
name?: any,
|
|
28
|
-
keyvalues?: any
|
|
29
|
-
} = {
|
|
30
|
-
ipfsPinHash: ipfsPinHash
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (metadata.name) {
|
|
34
|
-
body.name = metadata.name;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (metadata.keyvalues) {
|
|
38
|
-
body.keyvalues = metadata.keyvalues;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
axios.put(
|
|
43
|
-
endpoint,
|
|
44
|
-
body,
|
|
45
|
-
{...createConfigForAxiosHeaders(config)})
|
|
46
|
-
.then(function (result) {
|
|
47
|
-
if (result.status !== 200) {
|
|
48
|
-
reject(new Error(`unknown server response while changing metadata for hash: ${result}`));
|
|
49
|
-
}
|
|
50
|
-
resolve(result.data);
|
|
51
|
-
}).catch(function (error) {
|
|
52
|
-
const formattedError = handleError(error);
|
|
53
|
-
reject(formattedError);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
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,65 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from '../../constants';
|
|
3
|
-
import { createConfigForAxiosHeaders, validateMetadata } from '../../util/validators';
|
|
4
|
-
import isIPFS from 'is-ipfs';
|
|
5
|
-
import { handleError } from '../../util/errorResponse';
|
|
6
|
-
import { PinataConfig } from '../..';
|
|
7
|
-
import { PinataOptions } from './pinFileToIPFS';
|
|
8
|
-
import { PinataMetadata } from '../data/pinList/pinList';
|
|
9
|
-
|
|
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
|
-
}
|
|
21
|
-
|
|
22
|
-
export default function pinByHash(config: PinataConfig, hashToPin: string, options: any): Promise<any> {
|
|
23
|
-
if (!hashToPin) {
|
|
24
|
-
throw new Error('hashToPin value is required for pinning by hash');
|
|
25
|
-
}
|
|
26
|
-
if (!isIPFS.cid(hashToPin)) {
|
|
27
|
-
throw new Error('hashToPin value is an invalid IPFS CID');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const endpoint = `${baseUrl}/pinning/pinByHash`;
|
|
31
|
-
const body : {
|
|
32
|
-
hashToPin: any,
|
|
33
|
-
pinataOptions: any,
|
|
34
|
-
pinataMetadata?: any,
|
|
35
|
-
} = {
|
|
36
|
-
hashToPin: hashToPin,
|
|
37
|
-
pinataOptions: {}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
if (options) {
|
|
41
|
-
if (options.pinataOptions) {
|
|
42
|
-
body.pinataOptions = options.pinataOptions;
|
|
43
|
-
}
|
|
44
|
-
if (options.pinataMetadata) {
|
|
45
|
-
validateMetadata(options.pinataMetadata);
|
|
46
|
-
body.pinataMetadata = options.pinataMetadata;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
axios.post(
|
|
52
|
-
endpoint,
|
|
53
|
-
body,
|
|
54
|
-
{...createConfigForAxiosHeaders(config)})
|
|
55
|
-
.then(function (result) {
|
|
56
|
-
if (result.status !== 200) {
|
|
57
|
-
reject(new Error(`unknown server response while adding to pin queue: ${result}`));
|
|
58
|
-
}
|
|
59
|
-
resolve(result.data);
|
|
60
|
-
}).catch(function (error) {
|
|
61
|
-
const formattedError = handleError(error);
|
|
62
|
-
reject(formattedError);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|