@pinata/sdk 1.2.1 → 2.0.0-beta.2
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 +3 -3
- package/lib/pinata-sdk.js +906 -839
- package/lib/pinata-sdk.min.js +5 -5
- package/package.json +83 -71
- package/src/commands/data/getFilesByCount/{getFilesByCount.js → getFilesByCount.ts} +8 -9
- 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} +8 -9
- package/src/commands/data/{userPinnedDataTotal.js → userPinnedDataTotal.ts} +4 -9
- package/src/commands/pinning/{hashMetadata.js → hashMetadata.ts} +9 -11
- package/src/commands/pinning/index.ts +8 -0
- package/src/commands/pinning/{pinByHash.js → pinByHash.ts} +22 -11
- package/src/commands/pinning/pinFileToIPFS.ts +118 -0
- package/src/commands/pinning/pinFromFS.ts +50 -0
- package/src/commands/pinning/{pinJSONToIPFS.js → pinJSONToIPFS.ts} +5 -11
- package/src/commands/pinning/pinJobs/{pinJobs.js → pinJobs.ts} +23 -9
- package/src/commands/pinning/pinJobs/{queryBuilder.js → queryBuilder.ts} +2 -8
- package/src/commands/pinning/{unpin.js → unpin.ts} +3 -9
- package/src/{constants.js → constants.ts} +0 -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/util/{errorResponse.js → errorResponse.ts} +1 -1
- package/src/util/{validators.js → validators.ts} +21 -33
- package/test/commands/data/getFilesByCount/{getFilesByCount.test.js → getFilesByCount.test.ts} +23 -22
- package/test/commands/data/pinList/{pinList.test.js → pinList.test.ts} +25 -26
- 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.js → testAuthentication.test.ts} +13 -13
- package/test/commands/data/{userPinnedDataTotal.test.js → userPinnedDataTotal.test.ts} +4 -4
- package/test/commands/pinning/{hashMetadata.test.js → hashMetadata.test.ts} +7 -8
- package/test/commands/pinning/{pinByHash.test.js → pinByHash.test.ts} +4 -5
- package/test/commands/pinning/{pinFileToIPFS.test.js → pinFileToIPFS.test.ts} +9 -11
- package/test/commands/pinning/{pinFromFS.js → pinFromFS.ts} +5 -6
- package/test/commands/pinning/{pinJSONToIPFS.test.js → pinJSONToIPFS.test.ts} +4 -5
- package/test/commands/pinning/pinJobs/{pinJobs.test.js → pinJobs.test.ts} +4 -4
- package/test/commands/pinning/pinJobs/{queryBuilder.test.js → queryBuilder.test.ts} +5 -5
- package/test/commands/pinning/{unpin.test.js → unpin.test.ts} +4 -5
- package/test/util/validators.test.ts +234 -0
- 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/index.d.ts +8 -0
- package/types/commands/pinning/pinByHash.d.ts +14 -9
- package/types/commands/pinning/pinFileToIPFS.d.ts +25 -9
- 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/constants.d.ts +2 -2
- package/types/index.d.ts +37 -165
- package/types/util/errorResponse.d.ts +1 -1
- package/types/util/validators.d.ts +23 -46
- package/webpack.config.js +50 -53
- package/src/commands/data/pinList/pinList.js +0 -34
- package/src/commands/pinning/hashPinPolicy.js +0 -51
- package/src/commands/pinning/pinFileToIPFS.js +0 -53
- package/src/commands/pinning/pinFromFS.js +0 -100
- package/src/commands/pinning/userPinPolicy.js +0 -40
- package/src/index.js +0 -307
- package/test/commands/data/pinlist-sample-api.js +0 -540
- package/test/commands/pinning/hashPinPolicy.test.js +0 -65
- package/test/commands/pinning/userPinPolicy.test.js +0 -80
- package/test/util/validators.test.js +0 -234
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import NodeFormData from "form-data";
|
|
2
|
+
import { PinataConfig, PinataMetadata } from "../..";
|
|
3
|
+
export interface PinataPinPolicyItem {
|
|
4
|
+
id: string;
|
|
5
|
+
desiredReplicationCount: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PinataOptions {
|
|
8
|
+
hostNodes?: string[] | undefined;
|
|
9
|
+
cidVersion?: 0 | 1;
|
|
10
|
+
wrapWithDirectory?: boolean;
|
|
11
|
+
customPinPolicy?: {
|
|
12
|
+
regions: PinataPinPolicyItem[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface PinataPinResponse {
|
|
16
|
+
IpfsHash: string;
|
|
17
|
+
PinSize: number;
|
|
18
|
+
Timestamp: string;
|
|
19
|
+
}
|
|
20
|
+
export interface PinataPinOptions {
|
|
21
|
+
pinataMetadata?: PinataMetadata;
|
|
22
|
+
pinataOptions?: PinataOptions | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare function uploadToIPFS(config: PinataConfig, data: NodeFormData, options?: PinataPinOptions): Promise<PinataPinResponse>;
|
|
25
|
+
export default function pinFileToIPFS(config: PinataConfig, readStream: any, options?: PinataPinOptions): Promise<PinataPinResponse>;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @param {string} pinataSecretApiKey
|
|
5
|
-
* @param {string} sourcePath
|
|
6
|
-
* @param {*} options
|
|
7
|
-
* @returns {Promise<unknown>}
|
|
8
|
-
*/
|
|
9
|
-
export default function pinFromFS(config: any, sourcePath: string, options: any): Promise<unknown>;
|
|
1
|
+
import { PinataConfig } from "../..";
|
|
2
|
+
import { PinataPinOptions, PinataPinResponse } from "./pinFileToIPFS";
|
|
3
|
+
export default function pinFromFS(config: PinataConfig, sourcePath: string, options?: PinataPinOptions): Promise<PinataPinResponse>;
|
|
@@ -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(config: any, 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(config: any, hashToUnpin: string): Promise<unknown>;
|
|
1
|
+
import { PinataConfig } from '../..';
|
|
2
|
+
export default function unpin(config: PinataConfig, hashToUnpin: string): Promise<unknown>;
|
package/types/constants.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const baseUrl
|
|
2
|
-
export const ERROR_NO_CREDENTIALS_PROVIDED
|
|
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,166 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
name?: string | undefined;
|
|
12
|
-
keyvalues: Record<string, {
|
|
13
|
-
value: string;
|
|
14
|
-
op: string;
|
|
15
|
-
}>;
|
|
16
|
-
};
|
|
17
|
-
export type PinataPinPolicyItem = {
|
|
18
|
-
id: string;
|
|
19
|
-
desiredReplicationCount: number;
|
|
20
|
-
};
|
|
21
|
-
export type PinataPinByHashOptions = {
|
|
22
|
-
hostNodes?: string[] | undefined;
|
|
23
|
-
customPinPolicy?: {
|
|
24
|
-
regions: PinataPinPolicyItem[];
|
|
25
|
-
} | undefined;
|
|
26
|
-
};
|
|
27
|
-
export type PinataPinByHashPinOptions = {
|
|
28
|
-
pinataMetadata?: Record<string, string | number | null> | undefined;
|
|
29
|
-
pinataOptions?: PinataPinByHashOptions | undefined;
|
|
30
|
-
};
|
|
31
|
-
export type PinataOptions = {
|
|
32
|
-
cidVersion?: 0 | 1 | undefined;
|
|
33
|
-
wrapWithDirectory?: boolean | undefined;
|
|
34
|
-
customPinPolicy?: {
|
|
35
|
-
regions: PinataPinPolicyItem[];
|
|
36
|
-
} | undefined;
|
|
37
|
-
};
|
|
38
|
-
export type PinataPinOptions = {
|
|
39
|
-
pinataMetadata?: Record<string, string | number | null> | undefined;
|
|
40
|
-
pinataOptions?: PinataOptions | undefined;
|
|
41
|
-
};
|
|
42
|
-
export type PinataPinJobsFilterOptions = {
|
|
43
|
-
sort: 'ASC' | 'DESC';
|
|
44
|
-
status?: string | undefined;
|
|
45
|
-
ipfs_pin_hash?: string | undefined;
|
|
46
|
-
limit?: number | undefined;
|
|
47
|
-
offset?: number | undefined;
|
|
48
|
-
};
|
|
49
|
-
export type PinataPinListFilterOptions = {
|
|
50
|
-
hashContains?: string | undefined;
|
|
51
|
-
pinStart?: string | undefined;
|
|
52
|
-
pinEnd?: string | undefined;
|
|
53
|
-
unpinStart?: string | undefined;
|
|
54
|
-
unpinEnd?: string | undefined;
|
|
55
|
-
pinSizeMin?: number | undefined;
|
|
56
|
-
pinSizeMax?: number | undefined;
|
|
57
|
-
status?: string | undefined;
|
|
58
|
-
pageLimit?: number | undefined;
|
|
59
|
-
pageOffset?: number | undefined;
|
|
60
|
-
metadata?: PinataMetadataFilter | undefined;
|
|
61
|
-
};
|
|
62
|
-
export type PinataPinByHashResponse = {
|
|
63
|
-
id: number | string;
|
|
64
|
-
ipfsHash: string;
|
|
65
|
-
status: string;
|
|
66
|
-
name: string;
|
|
67
|
-
};
|
|
68
|
-
export type PinataPinResponse = {
|
|
69
|
-
IpfsHash: string;
|
|
70
|
-
PinSize: number;
|
|
71
|
-
Timestamp: string;
|
|
72
|
-
};
|
|
73
|
-
export type PinataPinJobsResponseRow = {
|
|
74
|
-
id: number | string;
|
|
75
|
-
ipfs_pin_hash: string;
|
|
76
|
-
date_queued: string;
|
|
77
|
-
name: string | undefined | null;
|
|
78
|
-
status: string;
|
|
79
|
-
};
|
|
80
|
-
export type PinataPinJobsResponse = {
|
|
81
|
-
count: number;
|
|
82
|
-
rows: PinataPinJobsResponseRow[];
|
|
83
|
-
};
|
|
84
|
-
export type PinataPinListResponseRow = {
|
|
85
|
-
id: number | string;
|
|
86
|
-
ipfs_pin_hash: string;
|
|
87
|
-
size: number;
|
|
88
|
-
user_id: string | number;
|
|
89
|
-
date_pinned: string;
|
|
90
|
-
date_unpinned: string;
|
|
91
|
-
metadata: PinataMetadata;
|
|
92
|
-
};
|
|
93
|
-
export type PinataPinListResponse = {
|
|
94
|
-
count: number;
|
|
95
|
-
rows: PinataPinListResponseRow[];
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Hash meta data
|
|
99
|
-
*/
|
|
100
|
-
export type hashMetadata = (ipfsPinHash: string, metadata: PinataMetadata) => Promise<any>;
|
|
101
|
-
/**
|
|
102
|
-
* Pin by hash
|
|
103
|
-
*/
|
|
104
|
-
export type pinByHash = (hashToPin: string, options?: PinataPinByHashPinOptions | undefined) => Promise<PinataPinByHashResponse>;
|
|
105
|
-
/**
|
|
106
|
-
* Pin file to IPFS
|
|
107
|
-
*/
|
|
108
|
-
export type pinFileToIPFS = (readableStream: any, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
|
|
109
|
-
/**
|
|
110
|
-
* Pin from FS
|
|
111
|
-
*/
|
|
112
|
-
export type pinFromFS = (sourcePath: string, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
|
|
113
|
-
/**
|
|
114
|
-
* Pin Jobs
|
|
115
|
-
*/
|
|
116
|
-
export type pinJobs = (filters?: PinataPinJobsFilterOptions | undefined) => Promise<PinataPinJobsResponse>;
|
|
117
|
-
/**
|
|
118
|
-
* Pin JSON to IPFS
|
|
119
|
-
*/
|
|
120
|
-
export type pinJSONToIPFS = (body: Object, options?: PinataPinOptions | undefined) => Promise<PinataPinResponse>;
|
|
121
|
-
/**
|
|
122
|
-
* Unpin
|
|
123
|
-
*/
|
|
124
|
-
export type unpin = (hashToUnpin: string) => Promise<any>;
|
|
125
|
-
/**
|
|
126
|
-
* Test Authentication
|
|
127
|
-
*/
|
|
128
|
-
export type testAuthentication = () => Promise<{
|
|
129
|
-
authenticated: boolean;
|
|
130
|
-
}>;
|
|
131
|
-
/**
|
|
132
|
-
* Pin List
|
|
133
|
-
*/
|
|
134
|
-
export type pinList = (filters?: PinataPinListFilterOptions | undefined) => Promise<PinataPinListResponse>;
|
|
135
|
-
/**
|
|
136
|
-
* User Pinned Data Total
|
|
137
|
-
*/
|
|
138
|
-
export type userPinnedDataTotal = () => Promise<number>;
|
|
139
|
-
export type PinataConfig = {
|
|
140
|
-
pinataApiKey?: string | undefined;
|
|
141
|
-
pinataSecretApiKey?: string | undefined;
|
|
142
|
-
pinataJWTKey?: string | undefined;
|
|
143
|
-
};
|
|
144
|
-
export type PinataClient = {
|
|
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 {
|
|
145
11
|
config: PinataConfig;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
pinList:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
import
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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,36 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @param {string} pinataApiKey
|
|
4
|
-
* @param {string} pinataSecretApiKey
|
|
5
|
-
*/
|
|
6
|
-
export function validateApiKeys(pinataApiKey: string, pinataSecretApiKey: string): void;
|
|
7
|
-
export function createConfigForAxiosHeaders(config: any): {
|
|
8
|
-
withCredentials: boolean;
|
|
9
|
-
headers: {
|
|
10
|
-
pinata_api_key: any;
|
|
11
|
-
pinata_secret_api_key: any;
|
|
12
|
-
Authorization?: undefined;
|
|
13
|
-
};
|
|
14
|
-
} | {
|
|
15
|
-
headers: {
|
|
16
|
-
Authorization: string;
|
|
17
|
-
pinata_api_key?: undefined;
|
|
18
|
-
pinata_secret_api_key?: undefined;
|
|
19
|
-
};
|
|
20
|
-
withCredentials?: undefined;
|
|
21
|
-
};
|
|
22
|
-
export function createConfigForAxiosHeadersWithFormData(config: any, boundaryValue: any): {
|
|
1
|
+
import { PinataConfig } from '..';
|
|
2
|
+
export interface axiosHeaders {
|
|
23
3
|
maxContentLength: number;
|
|
24
4
|
maxBodyLength: number;
|
|
5
|
+
headers: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
withCredentials?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function validateApiKeys(pinataApiKey?: string, pinataSecretApiKey?: string): void;
|
|
11
|
+
export declare function createConfigForAxiosHeaders(config: PinataConfig): {
|
|
25
12
|
withCredentials: boolean;
|
|
26
13
|
headers: {
|
|
27
|
-
pinata_api_key:
|
|
28
|
-
pinata_secret_api_key:
|
|
14
|
+
pinata_api_key: string;
|
|
15
|
+
pinata_secret_api_key: string;
|
|
29
16
|
Authorization?: undefined;
|
|
30
17
|
};
|
|
31
18
|
} | {
|
|
32
|
-
maxContentLength: number;
|
|
33
|
-
maxBodyLength: number;
|
|
34
19
|
headers: {
|
|
35
20
|
Authorization: string;
|
|
36
21
|
pinata_api_key?: undefined;
|
|
@@ -38,23 +23,15 @@ export function createConfigForAxiosHeadersWithFormData(config: any, boundaryVal
|
|
|
38
23
|
};
|
|
39
24
|
withCredentials?: undefined;
|
|
40
25
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* @param {*} pinPolicy
|
|
54
|
-
*/
|
|
55
|
-
export function validatePinPolicyStructure(pinPolicy: any): void;
|
|
56
|
-
/**
|
|
57
|
-
* Validate Pinata Options
|
|
58
|
-
* @param {*} options
|
|
59
|
-
*/
|
|
60
|
-
export function validatePinataOptions(options: any): void;
|
|
26
|
+
export declare function createConfigForAxiosHeadersWithFormData(config: PinataConfig, boundaryValue: string): axiosHeaders;
|
|
27
|
+
export declare function validateHostNodes(hostNodes: any): void;
|
|
28
|
+
export declare function validateMetadata(metadata: any): void;
|
|
29
|
+
export declare function validatePinPolicyStructure(pinPolicy: {
|
|
30
|
+
regions: any[];
|
|
31
|
+
}): void;
|
|
32
|
+
export declare function validatePinataOptions(options: {
|
|
33
|
+
cidVersion?: number;
|
|
34
|
+
wrapWithDirectory?: boolean;
|
|
35
|
+
hostNodes?: any;
|
|
36
|
+
customPinPolicy?: any;
|
|
37
|
+
}): 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,34 +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
|
-
|
|
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(config, filters = {}) {
|
|
15
|
-
filters = {...filters, ...{includeCount: 'false' }};
|
|
16
|
-
|
|
17
|
-
const baseEndpoint = `${baseUrl}/data/pinList`;
|
|
18
|
-
const endpoint = queryBuilder(baseEndpoint, filters);
|
|
19
|
-
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
axios.get(
|
|
22
|
-
endpoint,
|
|
23
|
-
{...createConfigForAxiosHeaders(config)})
|
|
24
|
-
.then(function (result) {
|
|
25
|
-
if (result.status !== 200) {
|
|
26
|
-
reject(new Error(`unknown server response while attempting to retrieve user pin list: ${result}`));
|
|
27
|
-
}
|
|
28
|
-
resolve(result.data);
|
|
29
|
-
}).catch(function (error) {
|
|
30
|
-
const formattedError = handleError(error);
|
|
31
|
-
reject(formattedError);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { baseUrl } from './../../constants';
|
|
3
|
-
import { createConfigForAxiosHeaders, validatePinPolicyStructure } from '../../util/validators';
|
|
4
|
-
import isIPFS from 'is-ipfs';
|
|
5
|
-
import { handleError } from '../../util/errorResponse';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Hash Pin Policy
|
|
9
|
-
* @param {string} pinataApiKey
|
|
10
|
-
* @param {string} pinataSecretApiKey
|
|
11
|
-
* @param {*} ipfsPinHash
|
|
12
|
-
* @param {*} newPinPolicy
|
|
13
|
-
* @returns {Promise<unknown>}
|
|
14
|
-
*/
|
|
15
|
-
export default function hashPinPolicy(config, ipfsPinHash, newPinPolicy) {
|
|
16
|
-
validatePinPolicyStructure(newPinPolicy);
|
|
17
|
-
|
|
18
|
-
if (!ipfsPinHash) {
|
|
19
|
-
throw new Error('ipfsPinHash value is required for changing the pin policy of a pin');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!isIPFS.cid(ipfsPinHash)) {
|
|
23
|
-
throw new Error('ipfsPinHash value is an invalid IPFS CID');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!newPinPolicy) {
|
|
27
|
-
throw new Error('newPinPolicy is required for changing the pin policy of a pin');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const endpoint = `${baseUrl}/pinning/hashPinPolicy`;
|
|
31
|
-
const body = {
|
|
32
|
-
ipfsPinHash: ipfsPinHash,
|
|
33
|
-
newPinPolicy: newPinPolicy
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
axios.put(
|
|
38
|
-
endpoint,
|
|
39
|
-
body,
|
|
40
|
-
{...createConfigForAxiosHeaders(config)})
|
|
41
|
-
.then(function (result) {
|
|
42
|
-
if (result.status !== 200) {
|
|
43
|
-
reject(new Error(`unknown server response while changing pin policy for hash: ${result}`));
|
|
44
|
-
}
|
|
45
|
-
resolve(result.data);
|
|
46
|
-
}).catch(function (error) {
|
|
47
|
-
const formattedError = handleError(error);
|
|
48
|
-
reject(formattedError);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
@@ -1,53 +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 {createConfigForAxiosHeadersWithFormData, validateMetadata, validatePinataOptions} from '../../util/validators';
|
|
6
|
-
import { handleError } from '../../util/errorResponse';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Pin File to IPFS
|
|
10
|
-
* @param {string} pinataApiKey
|
|
11
|
-
* @param {string} pinataSecretApiKey
|
|
12
|
-
* @param {*} readStream
|
|
13
|
-
* @param {*} options
|
|
14
|
-
* @returns {Promise<unknown>}
|
|
15
|
-
*/
|
|
16
|
-
export default function pinFileToIPFS(config, readStream, options) {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
|
|
19
|
-
const data = new NodeFormData();
|
|
20
|
-
|
|
21
|
-
data.append('file', readStream);
|
|
22
|
-
|
|
23
|
-
const endpoint = `${baseUrl}/pinning/pinFileToIPFS`;
|
|
24
|
-
|
|
25
|
-
if (!(readStream instanceof stream.Readable || readStream instanceof NodeFormData)) {
|
|
26
|
-
reject(new Error('readStream is not a readable stream or form data'));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (options) {
|
|
30
|
-
if (options.pinataMetadata) {
|
|
31
|
-
validateMetadata(options.pinataMetadata);
|
|
32
|
-
data.append('pinataMetadata', JSON.stringify(options.pinataMetadata));
|
|
33
|
-
}
|
|
34
|
-
if (options.pinataOptions) {
|
|
35
|
-
validatePinataOptions(options.pinataOptions);
|
|
36
|
-
data.append('pinataOptions', JSON.stringify(options.pinataOptions));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
axios.post(
|
|
40
|
-
endpoint,
|
|
41
|
-
readStream instanceof NodeFormData ? readStream : data,
|
|
42
|
-
createConfigForAxiosHeadersWithFormData(config, data._boundary)
|
|
43
|
-
).then(function (result) {
|
|
44
|
-
if (result.status !== 200) {
|
|
45
|
-
reject(new Error(`unknown server response while pinning File to IPFS: ${result}`));
|
|
46
|
-
}
|
|
47
|
-
resolve(result.data);
|
|
48
|
-
}).catch(function (error) {
|
|
49
|
-
const formattedError = handleError(error);
|
|
50
|
-
reject(formattedError);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|