shogun-relay-sdk 1.2.3 → 1.2.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.
@@ -4,7 +4,28 @@ export declare class IpfsModule {
4
4
  constructor(client: ApiClient);
5
5
  getStatus(): Promise<any>;
6
6
  uploadFile(fileBuffer: Buffer, filename: string, contentType: string, userAddress?: string): Promise<any>;
7
+ /**
8
+ * Upload multiple files as a directory to IPFS
9
+ * Maintains directory structure using relative paths
10
+ *
11
+ * @param files Array of file objects with buffer, filename, path, and contentType
12
+ * @param userAddress Optional user address for authentication
13
+ * @returns Promise with directory CID and file information
14
+ */
15
+ uploadDirectory(files: Array<{
16
+ buffer: Buffer;
17
+ filename: string;
18
+ path: string;
19
+ contentType?: string;
20
+ }>, userAddress?: string): Promise<any>;
7
21
  cat(cid: string): Promise<Buffer>;
22
+ /**
23
+ * Cat a file from an IPFS directory using a relative path
24
+ * @param directoryCid The CID of the directory
25
+ * @param filePath The relative path to the file within the directory (e.g., "index.html" or "css/style.css")
26
+ * @returns Promise with file content as Buffer
27
+ */
28
+ catFromDirectory(directoryCid: string, filePath: string): Promise<Buffer>;
8
29
  pinAdd(cid: string): Promise<any>;
9
30
  pinRm(cid: string): Promise<any>;
10
31
  pinLs(): Promise<any>;
@@ -26,11 +26,54 @@ class IpfsModule {
26
26
  headers: headers,
27
27
  });
28
28
  }
29
+ /**
30
+ * Upload multiple files as a directory to IPFS
31
+ * Maintains directory structure using relative paths
32
+ *
33
+ * @param files Array of file objects with buffer, filename, path, and contentType
34
+ * @param userAddress Optional user address for authentication
35
+ * @returns Promise with directory CID and file information
36
+ */
37
+ async uploadDirectory(files, userAddress) {
38
+ if (!files || files.length === 0) {
39
+ throw new Error("At least one file is required for directory upload");
40
+ }
41
+ const form = new form_data_1.default();
42
+ // Add all files to FormData maintaining directory structure
43
+ files.forEach((file) => {
44
+ form.append("files", file.buffer, {
45
+ filename: file.path, // Use path to maintain directory structure
46
+ contentType: file.contentType || "application/octet-stream",
47
+ });
48
+ });
49
+ const headers = form.getHeaders();
50
+ if (userAddress) {
51
+ headers["x-user-address"] = userAddress;
52
+ }
53
+ return this.client.post("/api/v1/ipfs/upload-directory", form, {
54
+ headers: headers,
55
+ });
56
+ }
29
57
  async cat(cid) {
30
58
  return this.client.get(`/api/v1/ipfs/cat/${cid}`, {
31
59
  responseType: "arraybuffer",
32
60
  });
33
61
  }
62
+ /**
63
+ * Cat a file from an IPFS directory using a relative path
64
+ * @param directoryCid The CID of the directory
65
+ * @param filePath The relative path to the file within the directory (e.g., "index.html" or "css/style.css")
66
+ * @returns Promise with file content as Buffer
67
+ */
68
+ async catFromDirectory(directoryCid, filePath) {
69
+ const fullPath = `${directoryCid}/${filePath}`;
70
+ return this.client.post(`/api/v1/ipfs/api/v0/cat?arg=${encodeURIComponent(fullPath)}`, null, {
71
+ responseType: "arraybuffer",
72
+ headers: {
73
+ "Content-Length": "0",
74
+ },
75
+ });
76
+ }
34
77
  async pinAdd(cid) {
35
78
  return this.client.post("/api/v1/ipfs/pin/add", { cid });
36
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-relay-sdk",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "SDK for interacting with Shogun Relay API - HTTP client for IPFS, deals, registry, and network operations",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",