diff --git a/src/core/data/listFiles.ts b/src/core/data/listFiles.ts index dab1668..013586b 100644 --- a/src/core/data/listFiles.ts +++ b/src/core/data/listFiles.ts @@ -133,7 +133,10 @@ export const listFiles = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/data/pinJobs.ts b/src/core/data/pinJobs.ts index f381026..3143b11 100644 --- a/src/core/data/pinJobs.ts +++ b/src/core/data/pinJobs.ts @@ -74,7 +74,11 @@ export const pinJobs = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/data/pinnedFileUsage.ts b/src/core/data/pinnedFileUsage.ts index 5200285..1c0daa2 100644 --- a/src/core/data/pinnedFileUsage.ts +++ b/src/core/data/pinnedFileUsage.ts @@ -48,7 +48,10 @@ export const pinnedFileCount = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/data/totalStorageUsage.ts b/src/core/data/totalStorageUsage.ts index c458945..78fd15e 100644 --- a/src/core/data/totalStorageUsage.ts +++ b/src/core/data/totalStorageUsage.ts @@ -49,7 +49,10 @@ export const totalStorageUsage = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/data/updateMetadata.ts b/src/core/data/updateMetadata.ts index 2fcfaeb..271f3ea 100644 --- a/src/core/data/updateMetadata.ts +++ b/src/core/data/updateMetadata.ts @@ -58,7 +58,11 @@ export const updateMetadata = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/gateway/analyticsDateInterval.ts b/src/core/gateway/analyticsDateInterval.ts index 7a68cab..77c00bd 100644 --- a/src/core/gateway/analyticsDateInterval.ts +++ b/src/core/gateway/analyticsDateInterval.ts @@ -109,7 +109,10 @@ export const analyticsDateInterval = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/gateway/analyticsTopUsage.ts b/src/core/gateway/analyticsTopUsage.ts index 043c7e7..afe8451 100644 --- a/src/core/gateway/analyticsTopUsage.ts +++ b/src/core/gateway/analyticsTopUsage.ts @@ -112,7 +112,10 @@ export const analyticsTopUsage = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/gateway/deleteSwap.ts b/src/core/gateway/deleteSwap.ts index 3f22bd8..9cb40ff 100644 --- a/src/core/gateway/deleteSwap.ts +++ b/src/core/gateway/deleteSwap.ts @@ -46,7 +46,11 @@ export const deleteSwap = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/gateway/swapCid.ts b/src/core/gateway/swapCid.ts index f181523..6d046d3 100644 --- a/src/core/gateway/swapCid.ts +++ b/src/core/gateway/swapCid.ts @@ -55,7 +55,11 @@ export const swapCid = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/gateway/swapHistory.ts b/src/core/gateway/swapHistory.ts index 0c0950d..41fe4da 100644 --- a/src/core/gateway/swapHistory.ts +++ b/src/core/gateway/swapHistory.ts @@ -55,7 +55,11 @@ export const swapHistory = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/groups/addToGroup.ts b/src/core/groups/addToGroup.ts index ec19ae9..f5032d4 100644 --- a/src/core/groups/addToGroup.ts +++ b/src/core/groups/addToGroup.ts @@ -53,7 +53,11 @@ export const addToGroup = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/groups/createGroup.ts b/src/core/groups/createGroup.ts index 37fc28f..47785c5 100644 --- a/src/core/groups/createGroup.ts +++ b/src/core/groups/createGroup.ts @@ -50,7 +50,11 @@ export const createGroup = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/groups/deleteGroup.ts b/src/core/groups/deleteGroup.ts index 00fcf3b..24df957 100644 --- a/src/core/groups/deleteGroup.ts +++ b/src/core/groups/deleteGroup.ts @@ -49,7 +49,11 @@ export const deleteGroup = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/groups/getGroup.ts b/src/core/groups/getGroup.ts index d370c6f..d5ca9ee 100644 --- a/src/core/groups/getGroup.ts +++ b/src/core/groups/getGroup.ts @@ -52,7 +52,11 @@ export const getGroup = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/groups/listGroups.ts b/src/core/groups/listGroups.ts index 3c22119..68bfc3c 100644 --- a/src/core/groups/listGroups.ts +++ b/src/core/groups/listGroups.ts @@ -54,7 +54,11 @@ export const listGroups = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/groups/removeFromGroup.ts b/src/core/groups/removeFromGroup.ts index db8bf59..237b503 100644 --- a/src/core/groups/removeFromGroup.ts +++ b/src/core/groups/removeFromGroup.ts @@ -50,7 +50,11 @@ export const removeFromGroup = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/groups/updateGroup.ts b/src/core/groups/updateGroup.ts index b890fe7..a5716c1 100644 --- a/src/core/groups/updateGroup.ts +++ b/src/core/groups/updateGroup.ts @@ -58,7 +58,11 @@ export const updateGroup = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/keys/createKey.ts b/src/core/keys/createKey.ts index a14052c..9a16145 100644 --- a/src/core/keys/createKey.ts +++ b/src/core/keys/createKey.ts @@ -55,7 +55,11 @@ export const createKey = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/keys/listKeys.ts b/src/core/keys/listKeys.ts index 00950e0..345c8b4 100644 --- a/src/core/keys/listKeys.ts +++ b/src/core/keys/listKeys.ts @@ -58,7 +58,11 @@ export const listKeys = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/keys/revokeKeys.ts b/src/core/keys/revokeKeys.ts index e9c08fa..ed29630 100644 --- a/src/core/keys/revokeKeys.ts +++ b/src/core/keys/revokeKeys.ts @@ -54,7 +54,11 @@ export const revokeKeys = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/pinataSDK.ts b/src/core/pinataSDK.ts index eebb82c..629fa03 100644 --- a/src/core/pinataSDK.ts +++ b/src/core/pinataSDK.ts @@ -119,6 +119,21 @@ export class PinataSDK { this.signatures.updateConfig(this.config); } + setNewJwt(jwt: string): void { + if (!this.config) { + this.config = { pinataJwt: "" }; + } + this.config.pinataJwt = jwt; + + // Update headers for all sub-modules + this.upload.updateConfig(this.config); + this.gateways.updateConfig(this.config); + this.usage.updateConfig(this.config); + this.keys.updateConfig(this.config); + this.groups.updateConfig(this.config); + this.signatures.updateConfig(this.config); + } + testAuthentication(): Promise { return testAuthentication(this.config); } diff --git a/src/core/pinning/base64.ts b/src/core/pinning/base64.ts index 4c53107..f837e81 100644 --- a/src/core/pinning/base64.ts +++ b/src/core/pinning/base64.ts @@ -83,7 +83,10 @@ export const uploadBase64 = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${jwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${jwt}`, diff --git a/src/core/pinning/cid.ts b/src/core/pinning/cid.ts index 2bd7ca7..9cec5e2 100644 --- a/src/core/pinning/cid.ts +++ b/src/core/pinning/cid.ts @@ -60,7 +60,11 @@ export const uploadCid = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${jwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${jwt}`, diff --git a/src/core/pinning/file.ts b/src/core/pinning/file.ts index 744efec..28e9779 100644 --- a/src/core/pinning/file.ts +++ b/src/core/pinning/file.ts @@ -74,7 +74,10 @@ export const uploadFile = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${jwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${jwt}`, diff --git a/src/core/pinning/fileArray.ts b/src/core/pinning/fileArray.ts index 6dbc1d4..d535544 100644 --- a/src/core/pinning/fileArray.ts +++ b/src/core/pinning/fileArray.ts @@ -81,7 +81,10 @@ export const uploadFileArray = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${jwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${jwt}`, diff --git a/src/core/pinning/json.ts b/src/core/pinning/json.ts index 75749f4..459825f 100644 --- a/src/core/pinning/json.ts +++ b/src/core/pinning/json.ts @@ -78,7 +78,11 @@ export const uploadJson = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${jwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${jwt}`, diff --git a/src/core/pinning/stream.ts b/src/core/pinning/stream.ts index b77bc57..cde8f6d 100644 --- a/src/core/pinning/stream.ts +++ b/src/core/pinning/stream.ts @@ -90,7 +90,10 @@ export const uploadStream = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${jwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${jwt}`, diff --git a/src/core/pinning/unpin.ts b/src/core/pinning/unpin.ts index 89f2c32..813fc3b 100644 --- a/src/core/pinning/unpin.ts +++ b/src/core/pinning/unpin.ts @@ -55,7 +55,10 @@ export const unpinFile = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/pinning/url.ts b/src/core/pinning/url.ts index 6979477..e0c544c 100644 --- a/src/core/pinning/url.ts +++ b/src/core/pinning/url.ts @@ -94,7 +94,10 @@ export const uploadUrl = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${jwt}`, + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${jwt}`, diff --git a/src/core/signatures/addSignature.ts b/src/core/signatures/addSignature.ts index 0695199..f64e53a 100644 --- a/src/core/signatures/addSignature.ts +++ b/src/core/signatures/addSignature.ts @@ -59,7 +59,11 @@ export const addSignature = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/signatures/getSignature.ts b/src/core/signatures/getSignature.ts index 80241df..cb04578 100644 --- a/src/core/signatures/getSignature.ts +++ b/src/core/signatures/getSignature.ts @@ -47,7 +47,11 @@ export const getSignature = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`, diff --git a/src/core/signatures/removeSignature.ts b/src/core/signatures/removeSignature.ts index 17d684a..e061a7f 100644 --- a/src/core/signatures/removeSignature.ts +++ b/src/core/signatures/removeSignature.ts @@ -47,7 +47,11 @@ export const removeSignature = async ( let headers: Record; if (config.customHeaders && Object.keys(config.customHeaders).length > 0) { - headers = { ...config.customHeaders }; + headers = { + Authorization: `Bearer ${config.pinataJwt}`, + "Content-Type": "application/json", + ...config.customHeaders, + }; } else { headers = { Authorization: `Bearer ${config.pinataJwt}`,