@pinata/sdk 1.2.0 → 1.2.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.
Files changed (50) hide show
  1. package/README.md +21 -5
  2. package/lib/pinata-sdk.js +305 -155
  3. package/lib/pinata-sdk.min.js +5 -5
  4. package/package.json +1 -1
  5. package/src/commands/data/getFilesByCount/getFilesByCount.js +2 -5
  6. package/src/commands/data/pinList/pinList.js +4 -11
  7. package/src/commands/data/testAuthentication.js +4 -11
  8. package/src/commands/data/userPinnedDataTotal.js +4 -11
  9. package/src/commands/pinning/hashMetadata.js +4 -11
  10. package/src/commands/pinning/hashPinPolicy.js +4 -10
  11. package/src/commands/pinning/pinByHash.js +4 -11
  12. package/src/commands/pinning/pinFileToIPFS.js +5 -16
  13. package/src/commands/pinning/pinFromFS.js +6 -23
  14. package/src/commands/pinning/pinJSONToIPFS.js +4 -10
  15. package/src/commands/pinning/pinJobs/pinJobs.js +4 -10
  16. package/src/commands/pinning/unpin.js +4 -11
  17. package/src/commands/pinning/userPinPolicy.js +4 -10
  18. package/src/constants.js +3 -0
  19. package/src/index.js +60 -15
  20. package/src/util/validators.js +88 -12
  21. package/test/commands/data/getFilesByCount/getFilesByCount.test.js +17 -21
  22. package/test/commands/data/pinList/pinList.test.js +20 -15
  23. package/test/commands/data/testAuthentication.test.js +17 -13
  24. package/test/commands/data/userPinnedDataTotal.test.js +3 -3
  25. package/test/commands/pinning/hashMetadata.test.js +7 -7
  26. package/test/commands/pinning/hashPinPolicy.test.js +6 -6
  27. package/test/commands/pinning/pinByHash.test.js +4 -4
  28. package/test/commands/pinning/pinFileToIPFS.test.js +5 -5
  29. package/test/commands/pinning/pinFromFS.js +3 -3
  30. package/test/commands/pinning/pinJSONToIPFS.test.js +4 -4
  31. package/test/commands/pinning/pinJobs/pinJobs.test.js +3 -3
  32. package/test/commands/pinning/unpin.test.js +5 -5
  33. package/test/commands/pinning/userPinPolicy.test.js +51 -22
  34. package/test/util/validators.test.js +114 -72
  35. package/types/commands/data/getFilesByCount/getFilesByCount.d.ts +1 -1
  36. package/types/commands/data/pinList/pinList.d.ts +1 -1
  37. package/types/commands/data/testAuthentication.d.ts +1 -1
  38. package/types/commands/data/userPinnedDataTotal.d.ts +1 -1
  39. package/types/commands/pinning/hashMetadata.d.ts +1 -1
  40. package/types/commands/pinning/hashPinPolicy.d.ts +1 -1
  41. package/types/commands/pinning/pinByHash.d.ts +1 -1
  42. package/types/commands/pinning/pinFileToIPFS.d.ts +1 -1
  43. package/types/commands/pinning/pinFromFS.d.ts +1 -1
  44. package/types/commands/pinning/pinJSONToIPFS.d.ts +1 -1
  45. package/types/commands/pinning/pinJobs/pinJobs.d.ts +1 -1
  46. package/types/commands/pinning/unpin.d.ts +1 -1
  47. package/types/commands/pinning/userPinPolicy.d.ts +1 -1
  48. package/types/constants.d.ts +1 -0
  49. package/types/index.d.ts +9 -174
  50. package/types/util/validators.d.ts +34 -0
package/types/index.d.ts CHANGED
@@ -1,182 +1,11 @@
1
- /**
2
- * @typedef {Record<string, string | number | null>} PinataMetadata
3
- */
4
- /**
5
- * @typedef PinataMetadataFilter
6
- * @property {string} [name]
7
- * @property {Record<string, {value: string, op: string}>} keyvalues
8
- */
9
- /**
10
- * @typedef {{id: string, desiredReplicationCount: number}} PinataPinPolicyItem
11
- */
12
- /**
13
- * @typedef PinataPinByHashOptions
14
- * @property {string[]} [hostNodes]
15
- * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
16
- */
17
- /**
18
- * @typedef PinataPinByHashPinOptions
19
- * @property {PinataMetadata} [pinataMetadata]
20
- * @property {PinataPinByHashOptions} [pinataOptions]
21
- */
22
- /**
23
- * @typedef PinataOptions
24
- * @property {0 | 1} [cidVersion]
25
- * @property {boolean} [wrapWithDirectory]
26
- * @property {{regions: PinataPinPolicyItem[]}} [customPinPolicy]
27
- */
28
- /**
29
- * @typedef PinataPinOptions
30
- * @property {PinataMetadata} [pinataMetadata]
31
- * @property {PinataOptions} [pinataOptions]
32
- */
33
- /**
34
- * @typedef PinataPinJobsFilterOptions
35
- * @property {'ASC' | 'DESC'} sort
36
- * @property {string} [status]
37
- * @property {string} [ipfs_pin_hash]
38
- * @property {number} [limit]
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
1
  /**
173
2
  * Pinata Client
174
3
  *
175
- * @param {string} pinataApiKey
176
- * @param {string} pinataSecretApiKey
4
+ * @param {string | PinataConfig} [pinataApiKey]
5
+ * @param {string} [pinataSecretApiKey]
177
6
  * @returns {PinataClient}
178
7
  */
179
- export default function pinataClient(pinataApiKey: string, pinataSecretApiKey: string): PinataClient;
8
+ export default function pinataClient(pinataApiKey?: string | PinataConfig | undefined, pinataSecretApiKey?: string | undefined): PinataClient;
180
9
  export type PinataMetadata = Record<string, string | number | null>;
181
10
  export type PinataMetadataFilter = {
182
11
  name?: string | undefined;
@@ -307,7 +136,13 @@ export type pinList = (filters?: PinataPinListFilterOptions | undefined) => Prom
307
136
  * User Pinned Data Total
308
137
  */
309
138
  export type userPinnedDataTotal = () => Promise<number>;
139
+ export type PinataConfig = {
140
+ pinataApiKey?: string | undefined;
141
+ pinataSecretApiKey?: string | undefined;
142
+ pinataJWTKey?: string | undefined;
143
+ };
310
144
  export type PinataClient = {
145
+ config: PinataConfig;
311
146
  pinByHash: pinByHash;
312
147
  hashMetadata: hashMetadata;
313
148
  pinFileToIPFS: pinFileToIPFS;
@@ -4,6 +4,40 @@
4
4
  * @param {string} pinataSecretApiKey
5
5
  */
6
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): {
23
+ maxContentLength: number;
24
+ maxBodyLength: number;
25
+ withCredentials: boolean;
26
+ headers: {
27
+ pinata_api_key: any;
28
+ pinata_secret_api_key: any;
29
+ Authorization?: undefined;
30
+ };
31
+ } | {
32
+ maxContentLength: number;
33
+ maxBodyLength: number;
34
+ headers: {
35
+ Authorization: string;
36
+ pinata_api_key?: undefined;
37
+ pinata_secret_api_key?: undefined;
38
+ };
39
+ withCredentials?: undefined;
40
+ };
7
41
  /**
8
42
  * Validate host Nodes
9
43
  * @param {*} hostNodes