pinata 1.3.0 → 1.4.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/dist/index.d.mts CHANGED
@@ -116,6 +116,7 @@ type SignedUrlOptions = {
116
116
  cid: string;
117
117
  date?: number;
118
118
  expires: number;
119
+ gateway?: string;
119
120
  };
120
121
  type GatewayAnalyticsQuery = {
121
122
  gateway_domain: string;
package/dist/index.d.ts CHANGED
@@ -116,6 +116,7 @@ type SignedUrlOptions = {
116
116
  cid: string;
117
117
  date?: number;
118
118
  expires: number;
119
+ gateway?: string;
119
120
  };
120
121
  type GatewayAnalyticsQuery = {
121
122
  gateway_domain: string;
package/dist/index.js CHANGED
@@ -385,7 +385,7 @@ var deleteFile = async (config, files) => {
385
385
  } else {
386
386
  headers = {
387
387
  Authorization: `Bearer ${config.pinataJwt}`,
388
- Source: "sdk/unpin"
388
+ Source: "sdk/deleteFile"
389
389
  };
390
390
  }
391
391
  let endpoint = "https://api.pinata.cloud/v3";
@@ -613,12 +613,19 @@ var getCid = async (config, cid, options) => {
613
613
  if (config.endpointUrl) {
614
614
  endpoint = config.endpointUrl;
615
615
  }
616
+ let headers;
617
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
618
+ headers = { ...config.customHeaders };
619
+ } else {
620
+ headers = {
621
+ "Content-Type": "application/json",
622
+ Authorization: `Bearer ${config.pinataJwt}`,
623
+ Source: "sdk/getCid"
624
+ };
625
+ }
616
626
  const signedUrlRequest = await fetch(`${endpoint}/files/sign`, {
617
627
  method: "POST",
618
- headers: {
619
- "Content-Type": "application/json",
620
- Authorization: `Bearer ${config?.pinataJwt}`
621
- },
628
+ headers,
622
629
  body: payload
623
630
  });
624
631
  const signedUrl = await signedUrlRequest.json();
@@ -1355,7 +1362,13 @@ var createSignedURL = async (config, options, imgOpts) => {
1355
1362
  if (!config) {
1356
1363
  throw new ValidationError("Pinata configuration is missing");
1357
1364
  }
1358
- let newUrl = `${config?.pinataGateway}/files/${options.cid}`;
1365
+ let baseUrl;
1366
+ if (options?.gateway) {
1367
+ baseUrl = options.gateway.startsWith("https://") ? options.gateway : `https://${options.gateway}`;
1368
+ } else {
1369
+ baseUrl = config.pinataGateway;
1370
+ }
1371
+ let newUrl = `${baseUrl}/files/${options.cid}`;
1359
1372
  const params = new URLSearchParams();
1360
1373
  if (imgOpts) {
1361
1374
  if (imgOpts.width)
@@ -1396,13 +1409,20 @@ var createSignedURL = async (config, options, imgOpts) => {
1396
1409
  if (config.endpointUrl) {
1397
1410
  endpoint = config.endpointUrl;
1398
1411
  }
1412
+ let headers;
1413
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1414
+ headers = { ...config.customHeaders };
1415
+ } else {
1416
+ headers = {
1417
+ "Content-Type": "application/json",
1418
+ Authorization: `Bearer ${config.pinataJwt}`,
1419
+ Source: "sdk/createSignURL"
1420
+ };
1421
+ }
1399
1422
  try {
1400
1423
  const request = await fetch(`${endpoint}/files/sign`, {
1401
1424
  method: "POST",
1402
- headers: {
1403
- "Content-Type": "application/json",
1404
- Authorization: `Bearer ${config?.pinataJwt}`
1405
- },
1425
+ headers,
1406
1426
  body: payload
1407
1427
  });
1408
1428
  if (!request.ok) {