pinata 0.1.3 → 0.1.5

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Krasimir Tsonev
3
+ Copyright (c) 2024 Pinata Cloud Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
-
package/README.md CHANGED
@@ -1,32 +1,107 @@
1
1
  # Pinata
2
2
 
3
+ ![cover-image](https://docs.mypinata.cloud/ipfs/bafkreidv5iptnieh6eijei7enqc4mdhxpte3ries23heqf7s2hu3gdu6ru)
4
+
3
5
  The new all-in-one Pinata SDK
4
6
 
5
- ## Installation
7
+ ## Quickstart
8
+
9
+ [View the full documentation here](https://docs.pinata.cloud/sdk-beta/getting-started)
6
10
 
7
- Clone, install, and build
11
+ ### 1. Install
8
12
 
9
13
  ```bash
10
- git clone https://github.com/PinataCloud/pinata
11
- cd pinata
12
- npm install && npm run build
14
+ npm i pinata
15
+ ```
16
+
17
+ Import and initialize the SDK in your codebase with the following variables
18
+ - [Pinata API Key JWT](https://docs.pinata.cloud/account-management/api-keys)
19
+ - [Pinata Dedicated Gateway Domain](https://docs.pinata.cloud/gateways/dedicated-ipfs-gateways)
20
+
21
+ ```typescript
22
+ import { PinataSDK } from "pinata";
23
+
24
+ const pinata = new PinataSDK({
25
+ pinataJwt: "PINATA_JWT",
26
+ pinataGateway: "example-gateway.mypinata.cloud",
27
+ });
28
+ ```
29
+
30
+ <Note>The `PINATA_JWT` is a secret key, be sure to initialize the SDK in a secure environment and practice basic variable security practices. If you need to upload from a client environment, consider using signed JWTs</Note>
31
+
32
+ ### 2. Upload a File
33
+
34
+ ```typescript
35
+ import { PinataSDK } from "pinata";
36
+
37
+ const pinata = new PinataSDK({
38
+ pinataJwt: process.env.PINATA_JWT!,
39
+ pinataGateway: "example-gateway.mypinata.cloud",
40
+ });
41
+
42
+ async function main() {
43
+ try {
44
+ const file = new File(["hello"], "Testing.txt", { type: "text/plain" });
45
+ const upload = await pinata.upload.file(file);
46
+ console.log(upload);
47
+ } catch (error) {
48
+ console.log(error);
49
+ }
50
+ }
51
+
52
+ await main();
13
53
  ```
14
54
 
15
- Import into your project with the `dist` directory from build
55
+ This will return an object like the following
16
56
 
17
57
  ```typescript
18
- import { PinataSDK } from "../dist"
58
+ {
59
+ IpfsHash: "bafkreibm6jg3ux5qumhcn2b3flc3tyu6dmlb4xa7u5bf44yegnrjhc4yeq",
60
+ PinSize: 5,
61
+ Timestamp: "2024-07-11T23:33:27.665Z",
62
+ }
19
63
  ```
20
64
 
21
- ## Initialization
65
+ ### 3. Retrieve a File
66
+
67
+ Use the CID or `IpfsHash` from the upload to fetch a file
22
68
 
23
69
  ```typescript
24
- import { PinataSDK } from "../dist";
70
+ import { PinataSDK } from "pinata";
25
71
 
26
72
  const pinata = new PinataSDK({
27
- pinataJwt: `PINATA_JWT`,
28
- pinataGateway: `example-sub-domain.mypinata.cloud`,
73
+ pinataJwt: process.env.PINATA_JWT!,
74
+ pinataGateway: "example-gateway.mypinata.cloud",
29
75
  });
76
+
77
+ async function main() {
78
+ try {
79
+ const data = await pinata.gateways.get("bafkreibm6jg3ux5qumhcn2b3flc3tyu6dmlb4xa7u5bf44yegnrjhc4yeq");
80
+ console.log(data)
81
+ } catch (error) {
82
+ console.log(error);
83
+ }
84
+ }
85
+
86
+ main();
87
+ ```
88
+
89
+ [View the full documentation here](https://docs.pinata.cloud/sdk-beta/getting-started)
90
+
91
+ ## Developing
92
+
93
+ ```bash
94
+ git clone https://github.com/PinataCloud/pinata
95
+ cd pinata
96
+ npm install
30
97
  ```
31
98
 
32
- ## [Full Docs](https://docs.pinata.cloud/sdk-beta/getting-started)
99
+ Run Build
100
+ ```bash
101
+ npm run build
102
+ ```
103
+
104
+ Run Tests
105
+ ```bash
106
+ npm run test
107
+ ```
package/dist/index.d.mts CHANGED
@@ -222,6 +222,14 @@ type GroupCIDOptions = {
222
222
  groupId: string;
223
223
  cids: string[];
224
224
  };
225
+ type SignatureOptions = {
226
+ cid: string;
227
+ signature: string;
228
+ };
229
+ type SignatureResponse = {
230
+ cid: string;
231
+ signature: string;
232
+ };
225
233
 
226
234
  declare class PinataSDK {
227
235
  config: PinataConfig | undefined;
@@ -230,6 +238,7 @@ declare class PinataSDK {
230
238
  usage: Usage;
231
239
  keys: Keys;
232
240
  groups: Groups;
241
+ signatures: Signatures;
233
242
  constructor(config?: PinataConfig);
234
243
  testAuthentication(): Promise<AuthTestResponse>;
235
244
  unpin(files: string[]): Promise<UnpinResponse[]>;
@@ -369,5 +378,12 @@ declare class FilterGroups {
369
378
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
370
379
  all(): Promise<GroupResponseItem[]>;
371
380
  }
381
+ declare class Signatures {
382
+ config: PinataConfig | undefined;
383
+ constructor(config?: PinataConfig);
384
+ add(options: SignatureOptions): Promise<SignatureResponse>;
385
+ get(cid: string): Promise<SignatureResponse>;
386
+ delete(cid: string): Promise<string>;
387
+ }
372
388
 
373
- export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
389
+ export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
package/dist/index.d.ts CHANGED
@@ -222,6 +222,14 @@ type GroupCIDOptions = {
222
222
  groupId: string;
223
223
  cids: string[];
224
224
  };
225
+ type SignatureOptions = {
226
+ cid: string;
227
+ signature: string;
228
+ };
229
+ type SignatureResponse = {
230
+ cid: string;
231
+ signature: string;
232
+ };
225
233
 
226
234
  declare class PinataSDK {
227
235
  config: PinataConfig | undefined;
@@ -230,6 +238,7 @@ declare class PinataSDK {
230
238
  usage: Usage;
231
239
  keys: Keys;
232
240
  groups: Groups;
241
+ signatures: Signatures;
233
242
  constructor(config?: PinataConfig);
234
243
  testAuthentication(): Promise<AuthTestResponse>;
235
244
  unpin(files: string[]): Promise<UnpinResponse[]>;
@@ -369,5 +378,12 @@ declare class FilterGroups {
369
378
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
370
379
  all(): Promise<GroupResponseItem[]>;
371
380
  }
381
+ declare class Signatures {
382
+ config: PinataConfig | undefined;
383
+ constructor(config?: PinataConfig);
384
+ add(options: SignatureOptions): Promise<SignatureResponse>;
385
+ get(cid: string): Promise<SignatureResponse>;
386
+ delete(cid: string): Promise<string>;
387
+ }
372
388
 
373
- export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
389
+ export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
package/dist/index.js CHANGED
@@ -1484,6 +1484,130 @@ var deleteGroup = async (config, options) => {
1484
1484
  }
1485
1485
  };
1486
1486
 
1487
+ // src/core/signatures/addSignature.ts
1488
+ var addSignature = async (config, options) => {
1489
+ if (!config || !config.pinataJwt) {
1490
+ throw new ValidationError("Pinata configuration or JWT is missing");
1491
+ }
1492
+ const data = JSON.stringify({
1493
+ signature: options.signature
1494
+ });
1495
+ try {
1496
+ const request = await fetch(
1497
+ `https://api.pinata.cloud/v3/ipfs/signature/${options.cid}`,
1498
+ {
1499
+ method: "POST",
1500
+ headers: {
1501
+ "Content-Type": "application/json",
1502
+ Authorization: `Bearer ${config?.pinataJwt}`
1503
+ },
1504
+ body: data
1505
+ }
1506
+ );
1507
+ if (!request.ok) {
1508
+ const errorData = await request.json();
1509
+ if (request.status === 401) {
1510
+ throw new AuthenticationError("Authentication failed", request.status, errorData);
1511
+ }
1512
+ if (request.status === 403) {
1513
+ throw new PinataError(
1514
+ "Unauthorized signing, you must be the original owner of the file and it must not have a signature",
1515
+ request.status,
1516
+ errorData
1517
+ );
1518
+ }
1519
+ throw new NetworkError(
1520
+ `HTTP error! status: ${request.status}`,
1521
+ request.status,
1522
+ errorData
1523
+ );
1524
+ }
1525
+ const res = await request.json();
1526
+ return res.data;
1527
+ } catch (error) {
1528
+ if (error instanceof PinataError) {
1529
+ throw error;
1530
+ }
1531
+ if (error instanceof Error) {
1532
+ throw new PinataError(`Error processing addSignature: ${error.message}`);
1533
+ }
1534
+ throw new PinataError("An unknown error occurred while adding signature to CID");
1535
+ }
1536
+ };
1537
+
1538
+ // src/core/signatures/getSignature.ts
1539
+ var getSignature = async (config, cid2) => {
1540
+ if (!config || !config.pinataJwt) {
1541
+ throw new ValidationError("Pinata configuration or JWT is missing");
1542
+ }
1543
+ try {
1544
+ const request = await fetch(`https://api.pinata.cloud/v3/ipfs/signature/${cid2}`, {
1545
+ method: "GET",
1546
+ headers: {
1547
+ "Content-Type": "application/json",
1548
+ Authorization: `Bearer ${config?.pinataJwt}`
1549
+ }
1550
+ });
1551
+ if (!request.ok) {
1552
+ const errorData = await request.json();
1553
+ if (request.status === 401) {
1554
+ throw new AuthenticationError("Authentication failed", request.status, errorData);
1555
+ }
1556
+ throw new NetworkError(
1557
+ `HTTP error! status: ${request.status}`,
1558
+ request.status,
1559
+ errorData
1560
+ );
1561
+ }
1562
+ const res = await request.json();
1563
+ return res.data;
1564
+ } catch (error) {
1565
+ if (error instanceof PinataError) {
1566
+ throw error;
1567
+ }
1568
+ if (error instanceof Error) {
1569
+ throw new PinataError(`Error processing getSignature: ${error.message}`);
1570
+ }
1571
+ throw new PinataError("An unknown error occurred while fetching signature for CID");
1572
+ }
1573
+ };
1574
+
1575
+ // src/core/signatures/removeSignature.ts
1576
+ var removeSignature = async (config, cid2) => {
1577
+ if (!config || !config.pinataJwt) {
1578
+ throw new ValidationError("Pinata configuration or JWT is missing");
1579
+ }
1580
+ try {
1581
+ const request = await fetch(`https://api.pinata.cloud/v3/ipfs/signature/${cid2}`, {
1582
+ method: "DELETE",
1583
+ headers: {
1584
+ "Content-Type": "application/json",
1585
+ Authorization: `Bearer ${config?.pinataJwt}`
1586
+ }
1587
+ });
1588
+ if (!request.ok) {
1589
+ const errorData = await request.json();
1590
+ if (request.status === 401) {
1591
+ throw new AuthenticationError("Authentication failed", request.status, errorData);
1592
+ }
1593
+ throw new NetworkError(
1594
+ `HTTP error! status: ${request.status}`,
1595
+ request.status,
1596
+ errorData
1597
+ );
1598
+ }
1599
+ return "OK";
1600
+ } catch (error) {
1601
+ if (error instanceof PinataError) {
1602
+ throw error;
1603
+ }
1604
+ if (error instanceof Error) {
1605
+ throw new PinataError(`Error processing addSignature: ${error.message}`);
1606
+ }
1607
+ throw new PinataError("An unknown error occurred while adding signature to CID");
1608
+ }
1609
+ };
1610
+
1487
1611
  // src/core/pinataSDK.ts
1488
1612
  var formatConfig = (config) => {
1489
1613
  let gateway = config?.pinataGateway;
@@ -1503,6 +1627,7 @@ var PinataSDK = class {
1503
1627
  this.usage = new Usage(this.config);
1504
1628
  this.keys = new Keys(this.config);
1505
1629
  this.groups = new Groups(this.config);
1630
+ this.signatures = new Signatures(this.config);
1506
1631
  }
1507
1632
  testAuthentication() {
1508
1633
  return testAuthentication(this.config);
@@ -1565,10 +1690,7 @@ var UploadBuilder = class {
1565
1690
  options.peerAddresses = this.peerAddresses;
1566
1691
  }
1567
1692
  this.args[this.args.length - 1] = options;
1568
- return this.uploadFunction(this.config, ...this.args).then(
1569
- onfulfilled,
1570
- onrejected
1571
- );
1693
+ return this.uploadFunction(this.config, ...this.args).then(onfulfilled, onrejected);
1572
1694
  }
1573
1695
  };
1574
1696
  var Upload = class {
@@ -1964,6 +2086,20 @@ var FilterGroups = class {
1964
2086
  return allItems;
1965
2087
  }
1966
2088
  };
2089
+ var Signatures = class {
2090
+ constructor(config) {
2091
+ this.config = formatConfig(config);
2092
+ }
2093
+ add(options) {
2094
+ return addSignature(this.config, options);
2095
+ }
2096
+ get(cid2) {
2097
+ return getSignature(this.config, cid2);
2098
+ }
2099
+ delete(cid2) {
2100
+ return removeSignature(this.config, cid2);
2101
+ }
2102
+ };
1967
2103
  // Annotate the CommonJS export names for ESM import in node:
1968
2104
  0 && (module.exports = {
1969
2105
  PinataSDK