@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,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @param {string} pinataSecretApiKey
|
|
5
|
-
* @param {*} body
|
|
6
|
-
* @param {*} options
|
|
7
|
-
* @returns {Promise<unknown>}
|
|
8
|
-
*/
|
|
9
|
-
export default function pinJSONToIPFS(pinataApiKey: string, pinataSecretApiKey: string, body: any, options: any): Promise<unknown>;
|
|
1
|
+
import { PinataConfig } from '../..';
|
|
2
|
+
import { PinataPinOptions, PinataPinResponse } from './pinFileToIPFS';
|
|
3
|
+
export default function pinJSONToIPFS(config: PinataConfig, body: any, options?: PinataPinOptions): Promise<PinataPinResponse>;
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { PinataConfig } from '../../..';
|
|
2
|
+
export interface PinataPinJobsResponseRow {
|
|
3
|
+
id: number | string;
|
|
4
|
+
ipfs_pin_hash: string;
|
|
5
|
+
date_queued: string;
|
|
6
|
+
name: string | undefined | null;
|
|
7
|
+
status: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PinataPinJobsResponse {
|
|
10
|
+
count: number;
|
|
11
|
+
rows: PinataPinJobsResponseRow[];
|
|
12
|
+
}
|
|
13
|
+
export interface PinataPinJobsFilterOptions {
|
|
14
|
+
sort: 'ASC' | 'DESC';
|
|
15
|
+
status?: string | undefined;
|
|
16
|
+
ipfs_pin_hash?: string | undefined;
|
|
17
|
+
limit?: number | undefined;
|
|
18
|
+
offset?: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
export default function pinJobs(config: PinataConfig, filters?: PinataPinJobsFilterOptions): Promise<PinataPinJobsResponse>;
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @param {string} pinataApiKey
|
|
4
|
-
* @param {string} pinataSecretApiKey
|
|
5
|
-
* @param {string} hashToUnpin
|
|
6
|
-
* @returns {Promise<unknown>}
|
|
7
|
-
*/
|
|
8
|
-
export default function unpin(pinataApiKey: string, pinataSecretApiKey: string, hashToUnpin: string): Promise<unknown>;
|
|
1
|
+
import { PinataConfig } from '../..';
|
|
2
|
+
export default function unpin(config: PinataConfig, hashToUnpin: string): Promise<unknown>;
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* @param {*} newPinPolicy
|
|
6
6
|
* @returns {Promise<unknown>}
|
|
7
7
|
*/
|
|
8
|
-
export default function userPinPolicy(
|
|
8
|
+
export default function userPinPolicy(config: any, newPinPolicy: any): Promise<unknown>;
|
package/types/constants.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export const baseUrl
|
|
1
|
+
export declare const baseUrl = "https://api.pinata.cloud";
|
|
2
|
+
export declare const ERROR_NO_CREDENTIALS_PROVIDED = "No credentials provided! Please provide your pinata api key and pinata secret api key or your pinata JWT key as an argument when you start this script";
|
package/types/index.d.ts
CHANGED
|
@@ -1,331 +1,38 @@
|
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
* @property {number} [offset]
|
|
40
|
-
*/
|
|
41
|
-
/**
|
|
42
|
-
* @typedef PinataPinListFilterOptions
|
|
43
|
-
* @property {string} [hashContains]
|
|
44
|
-
* @property {string} [pinStart]
|
|
45
|
-
* @property {string} [pinEnd]
|
|
46
|
-
* @property {string} [unpinStart]
|
|
47
|
-
* @property {string} [unpinEnd]
|
|
48
|
-
* @property {number} [pinSizeMin]
|
|
49
|
-
* @property {number} [pinSizeMax]
|
|
50
|
-
* @property {string} [status]
|
|
51
|
-
* @property {number} [pageLimit]
|
|
52
|
-
* @property {number} [pageOffset]
|
|
53
|
-
* @property {PinataMetadataFilter} [metadata]
|
|
54
|
-
*/
|
|
55
|
-
/**
|
|
56
|
-
* @typedef PinataPinByHashResponse
|
|
57
|
-
* @property {number | string} id
|
|
58
|
-
* @property {string} ipfsHash
|
|
59
|
-
* @property {string} status
|
|
60
|
-
* @property {string} name
|
|
61
|
-
*/
|
|
62
|
-
/**
|
|
63
|
-
* @typedef PinataPinResponse
|
|
64
|
-
* @property {string} IpfsHash
|
|
65
|
-
* @property {number} PinSize
|
|
66
|
-
* @property {string} Timestamp
|
|
67
|
-
*/
|
|
68
|
-
/**
|
|
69
|
-
* @typedef PinataPinJobsResponseRow
|
|
70
|
-
* @property {number | string} id
|
|
71
|
-
* @property {string} ipfs_pin_hash
|
|
72
|
-
* @property {string} date_queued
|
|
73
|
-
* @property {string | undefined | null} name
|
|
74
|
-
* @property {string} status
|
|
75
|
-
*/
|
|
76
|
-
/**
|
|
77
|
-
* @typedef PinataPinJobsResponse
|
|
78
|
-
* @property {number} count
|
|
79
|
-
* @property {PinataPinJobsResponseRow[]} rows
|
|
80
|
-
*/
|
|
81
|
-
/**
|
|
82
|
-
* @typedef PinataPinListResponseRow
|
|
83
|
-
* @property {number | string} id
|
|
84
|
-
* @property {string} ipfs_pin_hash
|
|
85
|
-
* @property {number} size
|
|
86
|
-
* @property {string | number} user_id
|
|
87
|
-
* @property {string} date_pinned
|
|
88
|
-
* @property {string} date_unpinned
|
|
89
|
-
* @property {PinataMetadata} metadata
|
|
90
|
-
*/
|
|
91
|
-
/**
|
|
92
|
-
* @typedef PinataPinListResponse
|
|
93
|
-
* @property {number} count
|
|
94
|
-
* @property {PinataPinListResponseRow[]} rows
|
|
95
|
-
*/
|
|
96
|
-
/**
|
|
97
|
-
* Hash meta data
|
|
98
|
-
* @callback hashMetadata
|
|
99
|
-
* @param {string} ipfsPinHash
|
|
100
|
-
* @param {PinataMetadata} metadata
|
|
101
|
-
* @returns {Promise<any>}
|
|
102
|
-
*/
|
|
103
|
-
/**
|
|
104
|
-
* Pin by hash
|
|
105
|
-
* @callback pinByHash
|
|
106
|
-
* @param {string} hashToPin
|
|
107
|
-
* @param {PinataPinByHashPinOptions} [options]
|
|
108
|
-
* @returns {Promise<PinataPinByHashResponse>}
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* Pin file to IPFS
|
|
112
|
-
* @callback pinFileToIPFS
|
|
113
|
-
* @param {ReadStream} readableStream
|
|
114
|
-
* @param {PinataPinOptions} [options]
|
|
115
|
-
* @returns {Promise<PinataPinResponse>}
|
|
116
|
-
*/
|
|
117
|
-
/**
|
|
118
|
-
* Pin from FS
|
|
119
|
-
* @callback pinFromFS
|
|
120
|
-
* @param {string} sourcePath
|
|
121
|
-
* @param {PinataPinOptions} [options]
|
|
122
|
-
* @returns {Promise<PinataPinResponse>}
|
|
123
|
-
*/
|
|
124
|
-
/**
|
|
125
|
-
* Pin Jobs
|
|
126
|
-
* @callback pinJobs
|
|
127
|
-
* @param {PinataPinJobsFilterOptions} [filters]
|
|
128
|
-
* @returns {Promise<PinataPinJobsResponse>}
|
|
129
|
-
*/
|
|
130
|
-
/**
|
|
131
|
-
* Pin JSON to IPFS
|
|
132
|
-
* @callback pinJSONToIPFS
|
|
133
|
-
* @param {Object} body
|
|
134
|
-
* @param {PinataPinOptions} [options]
|
|
135
|
-
* @returns {Promise<PinataPinResponse>}
|
|
136
|
-
*/
|
|
137
|
-
/**
|
|
138
|
-
* Unpin
|
|
139
|
-
* @callback unpin
|
|
140
|
-
* @param {string} hashToUnpin
|
|
141
|
-
* @returns {Promise<any>}
|
|
142
|
-
*/
|
|
143
|
-
/**
|
|
144
|
-
* Test Authentication
|
|
145
|
-
* @callback testAuthentication
|
|
146
|
-
* @returns {Promise<{authenticated: boolean}>}
|
|
147
|
-
*/
|
|
148
|
-
/**
|
|
149
|
-
* Pin List
|
|
150
|
-
* @callback pinList
|
|
151
|
-
* @param {PinataPinListFilterOptions} [filters]
|
|
152
|
-
* @returns {Promise<PinataPinListResponse>}
|
|
153
|
-
*/
|
|
154
|
-
/**
|
|
155
|
-
* User Pinned Data Total
|
|
156
|
-
* @callback userPinnedDataTotal
|
|
157
|
-
* @returns {Promise<number>}
|
|
158
|
-
*/
|
|
159
|
-
/**
|
|
160
|
-
* @typedef PinataClient
|
|
161
|
-
* @property {pinByHash} pinByHash
|
|
162
|
-
* @property {hashMetadata} hashMetadata
|
|
163
|
-
* @property {pinFileToIPFS} pinFileToIPFS
|
|
164
|
-
* @property {pinFromFS} pinFromFS
|
|
165
|
-
* @property {pinJSONToIPFS} pinJSONToIPFS
|
|
166
|
-
* @property {pinJobs} pinJobs
|
|
167
|
-
* @property {unpin} unpin
|
|
168
|
-
* @property {testAuthentication} testAuthentication
|
|
169
|
-
* @property {pinList} pinList
|
|
170
|
-
* @property {userPinnedDataTotal} userPinnedDataTotal
|
|
171
|
-
*/
|
|
172
|
-
/**
|
|
173
|
-
* Pinata Client
|
|
174
|
-
*
|
|
175
|
-
* @param {string} pinataApiKey
|
|
176
|
-
* @param {string} pinataSecretApiKey
|
|
177
|
-
* @returns {PinataClient}
|
|
178
|
-
*/
|
|
179
|
-
export default function pinataClient(pinataApiKey: string, pinataSecretApiKey: string): PinataClient;
|
|
180
|
-
export type PinataMetadata = Record<string, string | number | null>;
|
|
181
|
-
export type PinataMetadataFilter = {
|
|
182
|
-
name?: string | undefined;
|
|
183
|
-
keyvalues: Record<string, {
|
|
184
|
-
value: string;
|
|
185
|
-
op: string;
|
|
186
|
-
}>;
|
|
187
|
-
};
|
|
188
|
-
export type PinataPinPolicyItem = {
|
|
189
|
-
id: string;
|
|
190
|
-
desiredReplicationCount: number;
|
|
191
|
-
};
|
|
192
|
-
export type PinataPinByHashOptions = {
|
|
193
|
-
hostNodes?: string[] | undefined;
|
|
194
|
-
customPinPolicy?: {
|
|
195
|
-
regions: PinataPinPolicyItem[];
|
|
196
|
-
} | undefined;
|
|
197
|
-
};
|
|
198
|
-
export type PinataPinByHashPinOptions = {
|
|
199
|
-
pinataMetadata?: Record<string, string | number | null> | undefined;
|
|
200
|
-
pinataOptions?: PinataPinByHashOptions | undefined;
|
|
201
|
-
};
|
|
202
|
-
export type PinataOptions = {
|
|
203
|
-
cidVersion?: 0 | 1 | undefined;
|
|
204
|
-
wrapWithDirectory?: boolean | undefined;
|
|
205
|
-
customPinPolicy?: {
|
|
206
|
-
regions: PinataPinPolicyItem[];
|
|
207
|
-
} | undefined;
|
|
208
|
-
};
|
|
209
|
-
export type PinataPinOptions = {
|
|
210
|
-
pinataMetadata?: Record<string, string | number | null> | undefined;
|
|
211
|
-
pinataOptions?: PinataOptions | undefined;
|
|
212
|
-
};
|
|
213
|
-
export type PinataPinJobsFilterOptions = {
|
|
214
|
-
sort: 'ASC' | 'DESC';
|
|
215
|
-
status?: string | undefined;
|
|
216
|
-
ipfs_pin_hash?: string | undefined;
|
|
217
|
-
limit?: number | undefined;
|
|
218
|
-
offset?: number | undefined;
|
|
219
|
-
};
|
|
220
|
-
export type PinataPinListFilterOptions = {
|
|
221
|
-
hashContains?: string | undefined;
|
|
222
|
-
pinStart?: string | undefined;
|
|
223
|
-
pinEnd?: string | undefined;
|
|
224
|
-
unpinStart?: string | undefined;
|
|
225
|
-
unpinEnd?: string | undefined;
|
|
226
|
-
pinSizeMin?: number | undefined;
|
|
227
|
-
pinSizeMax?: number | undefined;
|
|
228
|
-
status?: string | undefined;
|
|
229
|
-
pageLimit?: number | undefined;
|
|
230
|
-
pageOffset?: number | undefined;
|
|
231
|
-
metadata?: PinataMetadataFilter | undefined;
|
|
232
|
-
};
|
|
233
|
-
export type PinataPinByHashResponse = {
|
|
234
|
-
id: number | string;
|
|
235
|
-
ipfsHash: string;
|
|
236
|
-
status: string;
|
|
237
|
-
name: string;
|
|
238
|
-
};
|
|
239
|
-
export type PinataPinResponse = {
|
|
240
|
-
IpfsHash: string;
|
|
241
|
-
PinSize: number;
|
|
242
|
-
Timestamp: string;
|
|
243
|
-
};
|
|
244
|
-
export type PinataPinJobsResponseRow = {
|
|
245
|
-
id: number | string;
|
|
246
|
-
ipfs_pin_hash: string;
|
|
247
|
-
date_queued: string;
|
|
248
|
-
name: string | undefined | null;
|
|
249
|
-
status: string;
|
|
250
|
-
};
|
|
251
|
-
export type PinataPinJobsResponse = {
|
|
252
|
-
count: number;
|
|
253
|
-
rows: PinataPinJobsResponseRow[];
|
|
254
|
-
};
|
|
255
|
-
export type PinataPinListResponseRow = {
|
|
256
|
-
id: number | string;
|
|
257
|
-
ipfs_pin_hash: string;
|
|
258
|
-
size: number;
|
|
259
|
-
user_id: string | number;
|
|
260
|
-
date_pinned: string;
|
|
261
|
-
date_unpinned: string;
|
|
262
|
-
metadata: PinataMetadata;
|
|
263
|
-
};
|
|
264
|
-
export type PinataPinListResponse = {
|
|
265
|
-
count: number;
|
|
266
|
-
rows: PinataPinListResponseRow[];
|
|
267
|
-
};
|
|
268
|
-
/**
|
|
269
|
-
* Hash meta data
|
|
270
|
-
*/
|
|
271
|
-
export type hashMetadata = (ipfsPinHash: string, metadata: PinataMetadata) => Promise<any>;
|
|
272
|
-
/**
|
|
273
|
-
* Pin by hash
|
|
274
|
-
*/
|
|
275
|
-
export type pinByHash = (hashToPin: string, options?: PinataPinByHashPinOptions | undefined) => Promise<PinataPinByHashResponse>;
|
|
276
|
-
/**
|
|
277
|
-
* Pin file to IPFS
|
|
278
|
-
*/
|
|
279
|
-
export type pinFileToIPFS = (readableStream: any, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
|
|
280
|
-
/**
|
|
281
|
-
* Pin from FS
|
|
282
|
-
*/
|
|
283
|
-
export type pinFromFS = (sourcePath: string, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
|
|
284
|
-
/**
|
|
285
|
-
* Pin Jobs
|
|
286
|
-
*/
|
|
287
|
-
export type pinJobs = (filters?: PinataPinJobsFilterOptions | undefined) => Promise<PinataPinJobsResponse>;
|
|
288
|
-
/**
|
|
289
|
-
* Pin JSON to IPFS
|
|
290
|
-
*/
|
|
291
|
-
export type pinJSONToIPFS = (body: Object, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
|
|
292
|
-
/**
|
|
293
|
-
* Unpin
|
|
294
|
-
*/
|
|
295
|
-
export type unpin = (hashToUnpin: string) => Promise<any>;
|
|
296
|
-
/**
|
|
297
|
-
* Test Authentication
|
|
298
|
-
*/
|
|
299
|
-
export type testAuthentication = () => Promise<{
|
|
300
|
-
authenticated: boolean;
|
|
301
|
-
}>;
|
|
302
|
-
/**
|
|
303
|
-
* Pin List
|
|
304
|
-
*/
|
|
305
|
-
export type pinList = (filters?: PinataPinListFilterOptions | undefined) => Promise<PinataPinListResponse>;
|
|
306
|
-
/**
|
|
307
|
-
* User Pinned Data Total
|
|
308
|
-
*/
|
|
309
|
-
export type userPinnedDataTotal = () => Promise<number>;
|
|
310
|
-
export type PinataClient = {
|
|
311
|
-
pinByHash: pinByHash;
|
|
312
|
-
hashMetadata: hashMetadata;
|
|
313
|
-
pinFileToIPFS: pinFileToIPFS;
|
|
314
|
-
pinFromFS: pinFromFS;
|
|
315
|
-
pinJSONToIPFS: pinJSONToIPFS;
|
|
316
|
-
pinJobs: pinJobs;
|
|
317
|
-
unpin: unpin;
|
|
318
|
-
testAuthentication: testAuthentication;
|
|
319
|
-
pinList: pinList;
|
|
320
|
-
userPinnedDataTotal: userPinnedDataTotal;
|
|
321
|
-
};
|
|
322
|
-
import pinByHash from "./commands/pinning/pinByHash";
|
|
323
|
-
import hashMetadata from "./commands/pinning/hashMetadata";
|
|
324
|
-
import pinFileToIPFS from "./commands/pinning/pinFileToIPFS";
|
|
325
|
-
import pinFromFS from "./commands/pinning/pinFromFS";
|
|
326
|
-
import pinJSONToIPFS from "./commands/pinning/pinJSONToIPFS";
|
|
327
|
-
import pinJobs from "./commands/pinning/pinJobs/pinJobs";
|
|
328
|
-
import unpin from "./commands/pinning/unpin";
|
|
329
|
-
import testAuthentication from "./commands/data/testAuthentication";
|
|
330
|
-
import pinList from "./commands/data/pinList/pinList";
|
|
331
|
-
import userPinnedDataTotal from "./commands/data/userPinnedDataTotal";
|
|
1
|
+
import { PinataPinByHashPinOptions } from './commands/pinning/pinByHash';
|
|
2
|
+
import { PinataPinOptions } from './commands/pinning/pinFileToIPFS';
|
|
3
|
+
import { PinataPinJobsFilterOptions } from './commands/pinning/pinJobs/pinJobs';
|
|
4
|
+
import { PinataMetadata, PinataPinListFilterOptions } from './commands/data/pinList/pinList';
|
|
5
|
+
export interface PinataConfig {
|
|
6
|
+
pinataApiKey?: string;
|
|
7
|
+
pinataSecretApiKey?: string;
|
|
8
|
+
pinataJWTKey?: string;
|
|
9
|
+
}
|
|
10
|
+
declare class PinataClient {
|
|
11
|
+
config: PinataConfig;
|
|
12
|
+
constructor(pinataApiKey?: string | PinataConfig, pinataSecretApiKey?: string);
|
|
13
|
+
pinByHash(hashToPin: string, options?: PinataPinByHashPinOptions): Promise<any>;
|
|
14
|
+
hashMetadata(ipfsPinHash: string, metadata: PinataMetadata): Promise<any>;
|
|
15
|
+
pinFileToIPFS(readableStream: any, options?: PinataPinOptions): Promise<import("./commands/pinning").PinataPinResponse>;
|
|
16
|
+
pinFromFS(sourcePath: string, options?: PinataPinOptions): Promise<import("./commands/pinning").PinataPinResponse>;
|
|
17
|
+
pinJSONToIPFS(body: any, options?: PinataPinOptions): Promise<import("./commands/pinning").PinataPinResponse>;
|
|
18
|
+
pinJobs(filters?: PinataPinJobsFilterOptions): Promise<import("./commands/pinning").PinataPinJobsResponse>;
|
|
19
|
+
unpin(hashToUnpin: string): Promise<unknown>;
|
|
20
|
+
pinList(filters: PinataPinListFilterOptions): Promise<import("./commands/data").PinataPinListResponse>;
|
|
21
|
+
getFilesByCount(filters: PinataPinListFilterOptions, maxCount?: number): {
|
|
22
|
+
[Symbol.asyncIterator]: () => {
|
|
23
|
+
next(): Promise<{
|
|
24
|
+
value: import("./commands/data").PinataPin;
|
|
25
|
+
done: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
return(): Promise<{
|
|
28
|
+
value: number;
|
|
29
|
+
done: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
testAuthentication(): Promise<import("./commands/data").PinataTestAuthenticationResponse>;
|
|
34
|
+
userPinnedDataTotal(): Promise<number>;
|
|
35
|
+
}
|
|
36
|
+
export * from './commands/data';
|
|
37
|
+
export * from './commands/pinning';
|
|
38
|
+
export default PinataClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const handleError: (error: any) => any;
|
|
@@ -1,26 +1,43 @@
|
|
|
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
|
-
|
|
1
|
+
import { PinataConfig } from '..';
|
|
2
|
+
export declare function validateApiKeys(pinataApiKey?: string, pinataSecretApiKey?: string): void;
|
|
3
|
+
export declare function createConfigForAxiosHeaders(config: PinataConfig): {
|
|
4
|
+
withCredentials: boolean;
|
|
5
|
+
headers: {
|
|
6
|
+
pinata_api_key: string;
|
|
7
|
+
pinata_secret_api_key: string;
|
|
8
|
+
Authorization?: undefined;
|
|
9
|
+
};
|
|
10
|
+
} | {
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: string;
|
|
13
|
+
pinata_api_key?: undefined;
|
|
14
|
+
pinata_secret_api_key?: undefined;
|
|
15
|
+
};
|
|
16
|
+
withCredentials?: undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare function createConfigForAxiosHeadersWithFormData(config: PinataConfig, boundaryValue: string): {
|
|
19
|
+
maxContentLength: number;
|
|
20
|
+
maxBodyLength: number;
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-type': string;
|
|
23
|
+
};
|
|
24
|
+
withCredentials: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
maxContentLength: number;
|
|
27
|
+
maxBodyLength: number;
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-type': string;
|
|
30
|
+
};
|
|
31
|
+
withCredentials?: undefined;
|
|
32
|
+
};
|
|
33
|
+
export declare function validateHostNodes(hostNodes: any): void;
|
|
34
|
+
export declare function validateMetadata(metadata: any): void;
|
|
35
|
+
export declare function validatePinPolicyStructure(pinPolicy: {
|
|
36
|
+
regions: any[];
|
|
37
|
+
}): void;
|
|
38
|
+
export declare function validatePinataOptions(options: {
|
|
39
|
+
cidVersion?: number;
|
|
40
|
+
wrapWithDirectory?: boolean;
|
|
41
|
+
hostNodes?: any;
|
|
42
|
+
customPinPolicy?: any;
|
|
43
|
+
}): void;
|
package/webpack.config.js
CHANGED
|
@@ -1,61 +1,58 @@
|
|
|
1
|
-
/* global __dirname, require, module*/
|
|
2
|
-
|
|
3
1
|
const webpack = require('webpack');
|
|
4
2
|
const path = require('path');
|
|
5
|
-
const env = require('yargs').argv.env; // use --env with webpack 2
|
|
6
|
-
const pkg = require('./package.json');
|
|
7
3
|
|
|
8
|
-
|
|
4
|
+
const libraryName = 'pinata-sdk';
|
|
9
5
|
|
|
10
|
-
|
|
6
|
+
module.exports = (env) => {
|
|
7
|
+
let outputFile, mode;
|
|
11
8
|
|
|
12
|
-
if (env === 'build') {
|
|
13
|
-
|
|
14
|
-
outputFile = libraryName + '.min.js';
|
|
15
|
-
} else {
|
|
16
|
-
mode = 'development';
|
|
17
|
-
outputFile = libraryName + '.js';
|
|
18
|
-
}
|
|
9
|
+
if (env === 'build') {
|
|
10
|
+
mode = 'production';
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
output: {
|
|
25
|
-
path: __dirname + '/lib',
|
|
26
|
-
filename: outputFile,
|
|
27
|
-
library: libraryName,
|
|
28
|
-
libraryTarget: 'umd',
|
|
29
|
-
umdNamedDefine: true,
|
|
30
|
-
globalObject: 'typeof self !== \'undefined\' ? self : this'
|
|
31
|
-
},
|
|
32
|
-
module: {
|
|
33
|
-
rules: [
|
|
34
|
-
{
|
|
35
|
-
test: /(\.jsx|\.js)$/,
|
|
36
|
-
loader: 'babel-loader',
|
|
37
|
-
exclude: /(node_modules|bower_components)/
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
test: /(\.jsx|\.js)$/,
|
|
41
|
-
loader: 'eslint-loader',
|
|
42
|
-
exclude: /node_modules/
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
},
|
|
46
|
-
target: 'node',
|
|
47
|
-
node: {
|
|
48
|
-
process: false
|
|
49
|
-
},
|
|
50
|
-
plugins: [
|
|
51
|
-
new webpack.DefinePlugin({
|
|
52
|
-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
|
53
|
-
})
|
|
54
|
-
],
|
|
55
|
-
resolve: {
|
|
56
|
-
modules: [path.resolve('./node_modules'), path.resolve('./src')],
|
|
57
|
-
extensions: ['.json', '.js']
|
|
12
|
+
outputFile = libraryName + '.min.js';
|
|
13
|
+
} else {
|
|
14
|
+
mode = 'development';
|
|
15
|
+
outputFile = libraryName + '.js';
|
|
58
16
|
}
|
|
17
|
+
return {
|
|
18
|
+
mode: mode,
|
|
19
|
+
entry: ['babel-polyfill', __dirname + '/src/index.ts'],
|
|
20
|
+
devtool: 'inline-source-map',
|
|
21
|
+
output: {
|
|
22
|
+
path: __dirname + '/lib',
|
|
23
|
+
filename: outputFile,
|
|
24
|
+
library: libraryName,
|
|
25
|
+
libraryTarget: 'umd',
|
|
26
|
+
umdNamedDefine: true,
|
|
27
|
+
globalObject: "typeof self !== 'undefined' ? self : this"
|
|
28
|
+
},
|
|
29
|
+
module: {
|
|
30
|
+
rules: [
|
|
31
|
+
{
|
|
32
|
+
test: /\.ts?$/,
|
|
33
|
+
loader: 'babel-loader',
|
|
34
|
+
exclude: /(node_modules|bower_components)/
|
|
35
|
+
},
|
|
36
|
+
// {
|
|
37
|
+
// test: /\.ts?$/,
|
|
38
|
+
// loader: 'eslint-loader',
|
|
39
|
+
// exclude: /node_modules/,
|
|
40
|
+
|
|
41
|
+
// }
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
target: 'node',
|
|
45
|
+
node: {
|
|
46
|
+
process: false
|
|
47
|
+
},
|
|
48
|
+
plugins: [
|
|
49
|
+
new webpack.DefinePlugin({
|
|
50
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
|
51
|
+
})
|
|
52
|
+
],
|
|
53
|
+
resolve: {
|
|
54
|
+
modules: [path.resolve('./node_modules'), path.resolve('./src')],
|
|
55
|
+
extensions: ['.json', '.js', '.ts']
|
|
56
|
+
}
|
|
57
|
+
};
|
|
59
58
|
};
|
|
60
|
-
|
|
61
|
-
module.exports = config;
|
|
@@ -1,41 +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
|
-
import queryBuilder from './queryBuilder';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Pin List
|
|
9
|
-
* @param {string} pinataApiKey
|
|
10
|
-
* @param {string} pinataSecretApiKey
|
|
11
|
-
* @param {any} filters
|
|
12
|
-
* @returns {Promise<unknown>}
|
|
13
|
-
*/
|
|
14
|
-
export default function pinList(pinataApiKey, pinataSecretApiKey, filters = {}) {
|
|
15
|
-
validateApiKeys(pinataApiKey, pinataSecretApiKey);
|
|
16
|
-
|
|
17
|
-
filters = {...filters, ...{includeCount: 'false' }};
|
|
18
|
-
|
|
19
|
-
const baseEndpoint = `${baseUrl}/data/pinList`;
|
|
20
|
-
const endpoint = queryBuilder(baseEndpoint, filters);
|
|
21
|
-
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
axios.get(
|
|
24
|
-
endpoint,
|
|
25
|
-
{
|
|
26
|
-
withCredentials: true,
|
|
27
|
-
headers: {
|
|
28
|
-
'pinata_api_key': pinataApiKey,
|
|
29
|
-
'pinata_secret_api_key': pinataSecretApiKey
|
|
30
|
-
}
|
|
31
|
-
}).then(function (result) {
|
|
32
|
-
if (result.status !== 200) {
|
|
33
|
-
reject(new Error(`unknown server response while attempting to retrieve user pin list: ${result}`));
|
|
34
|
-
}
|
|
35
|
-
resolve(result.data);
|
|
36
|
-
}).catch(function (error) {
|
|
37
|
-
const formattedError = handleError(error);
|
|
38
|
-
reject(formattedError);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|