shogun-relay-sdk 1.2.7 → 1.2.9
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/modules/ipfs.d.ts +30 -1
- package/dist/modules/ipfs.js +72 -0
- package/dist/modules/system.d.ts +6 -1
- package/dist/modules/system.js +7 -0
- package/dist/modules/uploads.d.ts +41 -0
- package/dist/modules/uploads.js +29 -0
- package/package.json +2 -2
- package/dist/modules/oracle.d.ts +0 -20
- package/dist/modules/oracle.js +0 -35
package/dist/modules/ipfs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiClient } from "../client";
|
|
2
2
|
export declare class IpfsModule {
|
|
3
|
-
private client;
|
|
3
|
+
private readonly client;
|
|
4
4
|
constructor(client: ApiClient);
|
|
5
5
|
getStatus(): Promise<any>;
|
|
6
6
|
uploadFile(fileBuffer: Buffer, filename: string, contentType: string, userAddress?: string): Promise<any>;
|
|
@@ -34,4 +34,33 @@ export declare class IpfsModule {
|
|
|
34
34
|
repoGC(): Promise<any>;
|
|
35
35
|
repoStat(): Promise<any>;
|
|
36
36
|
getVersion(): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Upload a file using browser FormData (for browser environments)
|
|
39
|
+
* @param file File object from browser File API
|
|
40
|
+
* @param userAddress Optional user address for authentication
|
|
41
|
+
* @returns Promise with upload result
|
|
42
|
+
*/
|
|
43
|
+
uploadFileBrowser(file: File, userAddress?: string): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Upload multiple files as a directory using browser FormData (for browser environments)
|
|
46
|
+
* Maintains directory structure using relative paths from File.webkitRelativePath or file.name
|
|
47
|
+
*
|
|
48
|
+
* @param files Array of File objects from browser File API
|
|
49
|
+
* @param userAddress Optional user address for authentication
|
|
50
|
+
* @returns Promise with directory CID and file information
|
|
51
|
+
*/
|
|
52
|
+
uploadDirectoryBrowser(files: File[], userAddress?: string): Promise<any>;
|
|
53
|
+
/**
|
|
54
|
+
* Cat a file and return as Blob (for browser environments)
|
|
55
|
+
* @param cid The CID of the file
|
|
56
|
+
* @returns Promise with file content as Blob
|
|
57
|
+
*/
|
|
58
|
+
catBlob(cid: string): Promise<Blob>;
|
|
59
|
+
/**
|
|
60
|
+
* Cat a file from directory and return as Blob (for browser environments)
|
|
61
|
+
* @param directoryCid The CID of the directory
|
|
62
|
+
* @param filePath The relative path to the file within the directory
|
|
63
|
+
* @returns Promise with file content as Blob
|
|
64
|
+
*/
|
|
65
|
+
catFromDirectoryBlob(directoryCid: string, filePath: string): Promise<Blob>;
|
|
37
66
|
}
|
package/dist/modules/ipfs.js
CHANGED
|
@@ -118,5 +118,77 @@ class IpfsModule {
|
|
|
118
118
|
async getVersion() {
|
|
119
119
|
return this.client.get("/api/v1/ipfs/version");
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Upload a file using browser FormData (for browser environments)
|
|
123
|
+
* @param file File object from browser File API
|
|
124
|
+
* @param userAddress Optional user address for authentication
|
|
125
|
+
* @returns Promise with upload result
|
|
126
|
+
*/
|
|
127
|
+
async uploadFileBrowser(file, userAddress) {
|
|
128
|
+
const formData = new form_data_1.default();
|
|
129
|
+
formData.append("file", file, file.name);
|
|
130
|
+
const headers = {};
|
|
131
|
+
if (userAddress) {
|
|
132
|
+
headers["x-user-address"] = userAddress;
|
|
133
|
+
}
|
|
134
|
+
return this.client.post("/api/v1/ipfs/upload", formData, {
|
|
135
|
+
headers: headers,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Upload multiple files as a directory using browser FormData (for browser environments)
|
|
140
|
+
* Maintains directory structure using relative paths from File.webkitRelativePath or file.name
|
|
141
|
+
*
|
|
142
|
+
* @param files Array of File objects from browser File API
|
|
143
|
+
* @param userAddress Optional user address for authentication
|
|
144
|
+
* @returns Promise with directory CID and file information
|
|
145
|
+
*/
|
|
146
|
+
async uploadDirectoryBrowser(files, userAddress) {
|
|
147
|
+
if (!files || files.length === 0) {
|
|
148
|
+
throw new Error("At least one file is required for directory upload");
|
|
149
|
+
}
|
|
150
|
+
const formData = new form_data_1.default();
|
|
151
|
+
// Add all files to FormData maintaining directory structure
|
|
152
|
+
files.forEach((file) => {
|
|
153
|
+
// Use webkitRelativePath if available (from folder input), otherwise use file.name
|
|
154
|
+
const relativePath = file.webkitRelativePath || file.name;
|
|
155
|
+
formData.append("files", file, relativePath);
|
|
156
|
+
});
|
|
157
|
+
const headers = {};
|
|
158
|
+
if (userAddress) {
|
|
159
|
+
headers["x-user-address"] = userAddress;
|
|
160
|
+
}
|
|
161
|
+
return this.client.post("/api/v1/ipfs/upload-directory", formData, {
|
|
162
|
+
headers: headers,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Cat a file and return as Blob (for browser environments)
|
|
167
|
+
* @param cid The CID of the file
|
|
168
|
+
* @returns Promise with file content as Blob
|
|
169
|
+
*/
|
|
170
|
+
async catBlob(cid) {
|
|
171
|
+
return this.client.get(`/api/v1/ipfs/cat/${cid}`, {
|
|
172
|
+
responseType: "blob",
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Cat a file from directory and return as Blob (for browser environments)
|
|
177
|
+
* @param directoryCid The CID of the directory
|
|
178
|
+
* @param filePath The relative path to the file within the directory
|
|
179
|
+
* @returns Promise with file content as Blob
|
|
180
|
+
*/
|
|
181
|
+
async catFromDirectoryBlob(directoryCid, filePath) {
|
|
182
|
+
const fullPath = `${directoryCid}/${filePath}`;
|
|
183
|
+
const encodedPath = fullPath.includes('/')
|
|
184
|
+
? `${encodeURIComponent(directoryCid)}/${filePath.split('/').map(p => encodeURIComponent(p)).join('/')}`
|
|
185
|
+
: encodeURIComponent(fullPath);
|
|
186
|
+
return this.client.post(`/api/v1/ipfs/api/v0/cat?arg=${encodedPath}`, "", {
|
|
187
|
+
responseType: "blob",
|
|
188
|
+
headers: {
|
|
189
|
+
"Content-Type": "application/octet-stream",
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
}
|
|
121
193
|
}
|
|
122
194
|
exports.IpfsModule = IpfsModule;
|
package/dist/modules/system.d.ts
CHANGED
|
@@ -9,8 +9,13 @@ export interface HealthResponse {
|
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
export declare class SystemModule {
|
|
12
|
-
private client;
|
|
12
|
+
private readonly client;
|
|
13
13
|
constructor(client: ApiClient);
|
|
14
14
|
getHealth(): Promise<HealthResponse>;
|
|
15
15
|
getStats(): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Simple health check endpoint
|
|
18
|
+
* @returns Promise with health status
|
|
19
|
+
*/
|
|
20
|
+
health(): Promise<any>;
|
|
16
21
|
}
|
package/dist/modules/system.js
CHANGED
|
@@ -12,5 +12,12 @@ class SystemModule {
|
|
|
12
12
|
async getStats() {
|
|
13
13
|
return this.client.get("/api/v1/system/stats");
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Simple health check endpoint
|
|
17
|
+
* @returns Promise with health status
|
|
18
|
+
*/
|
|
19
|
+
async health() {
|
|
20
|
+
return this.client.get("/health");
|
|
21
|
+
}
|
|
15
22
|
}
|
|
16
23
|
exports.SystemModule = SystemModule;
|
|
@@ -5,4 +5,45 @@ export declare class UploadsModule {
|
|
|
5
5
|
getUserUploads(identifier: string): Promise<any>;
|
|
6
6
|
deleteUpload(identifier: string, hash: string): Promise<any>;
|
|
7
7
|
getSystemHashes(): Promise<any>;
|
|
8
|
+
/**
|
|
9
|
+
* Get the complete system hashes map with metadata for all files
|
|
10
|
+
* @returns Promise with system hashes map object
|
|
11
|
+
*/
|
|
12
|
+
getSystemHashesMap(): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Save file metadata to system hash map
|
|
15
|
+
* @param metadata Metadata object containing hash, userAddress, fileName, etc.
|
|
16
|
+
* @returns Promise with save result
|
|
17
|
+
*/
|
|
18
|
+
saveSystemHash(metadata: {
|
|
19
|
+
hash: string;
|
|
20
|
+
userAddress?: string;
|
|
21
|
+
fileName?: string;
|
|
22
|
+
displayName?: string;
|
|
23
|
+
originalName?: string;
|
|
24
|
+
fileSize?: number;
|
|
25
|
+
contentType?: string;
|
|
26
|
+
isEncrypted?: boolean;
|
|
27
|
+
isDirectory?: boolean;
|
|
28
|
+
fileCount?: number;
|
|
29
|
+
files?: Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
size?: number;
|
|
33
|
+
mimetype?: string;
|
|
34
|
+
originalName?: string;
|
|
35
|
+
isEncrypted?: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
relayUrl?: string;
|
|
38
|
+
uploadedAt?: number;
|
|
39
|
+
timestamp?: number;
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}): Promise<any>;
|
|
42
|
+
/**
|
|
43
|
+
* Remove a hash from system hash map
|
|
44
|
+
* @param cid The CID/hash to remove
|
|
45
|
+
* @param userAddress User address (defaults to "drive-user")
|
|
46
|
+
* @returns Promise with removal result
|
|
47
|
+
*/
|
|
48
|
+
removeSystemHash(cid: string, userAddress?: string): Promise<any>;
|
|
8
49
|
}
|
package/dist/modules/uploads.js
CHANGED
|
@@ -14,5 +14,34 @@ class UploadsModule {
|
|
|
14
14
|
async getSystemHashes() {
|
|
15
15
|
return this.client.get("/api/v1/user-uploads/system-hashes");
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the complete system hashes map with metadata for all files
|
|
19
|
+
* @returns Promise with system hashes map object
|
|
20
|
+
*/
|
|
21
|
+
async getSystemHashesMap() {
|
|
22
|
+
return this.client.get("/api/v1/user-uploads/system-hashes-map");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Save file metadata to system hash map
|
|
26
|
+
* @param metadata Metadata object containing hash, userAddress, fileName, etc.
|
|
27
|
+
* @returns Promise with save result
|
|
28
|
+
*/
|
|
29
|
+
async saveSystemHash(metadata) {
|
|
30
|
+
return this.client.post("/api/v1/user-uploads/save-system-hash", metadata);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Remove a hash from system hash map
|
|
34
|
+
* @param cid The CID/hash to remove
|
|
35
|
+
* @param userAddress User address (defaults to "drive-user")
|
|
36
|
+
* @returns Promise with removal result
|
|
37
|
+
*/
|
|
38
|
+
async removeSystemHash(cid, userAddress = "drive-user") {
|
|
39
|
+
return this.client.delete(`/api/v1/user-uploads/remove-system-hash/${cid}`, {
|
|
40
|
+
data: { userAddress },
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
17
46
|
}
|
|
18
47
|
exports.UploadsModule = UploadsModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogun-relay-sdk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"axios": "^1.6.0",
|
|
46
|
-
"form-data": "^4.0.
|
|
46
|
+
"form-data": "^4.0.5"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@eslint/js": "^9.15.0",
|
package/dist/modules/oracle.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ApiClient } from "../client";
|
|
2
|
-
import { OracleFeedsResponse, OracleDataResponse, OracleGlobalStatsResponse } from "../types";
|
|
3
|
-
export declare class OracleModule {
|
|
4
|
-
private client;
|
|
5
|
-
constructor(client: ApiClient);
|
|
6
|
-
/**
|
|
7
|
-
* Get list of available oracle feeds
|
|
8
|
-
*/
|
|
9
|
-
getFeeds(): Promise<OracleFeedsResponse>;
|
|
10
|
-
/**
|
|
11
|
-
* Get signed oracle data
|
|
12
|
-
* @param feedId Feed ID
|
|
13
|
-
* @param payment Optional x402 payment string (if feed is paid)
|
|
14
|
-
*/
|
|
15
|
-
getData(feedId: string, payment?: string): Promise<OracleDataResponse>;
|
|
16
|
-
/**
|
|
17
|
-
* Get global oracle stats
|
|
18
|
-
*/
|
|
19
|
-
getGlobalStats(): Promise<OracleGlobalStatsResponse>;
|
|
20
|
-
}
|
package/dist/modules/oracle.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OracleModule = void 0;
|
|
4
|
-
class OracleModule {
|
|
5
|
-
constructor(client) {
|
|
6
|
-
this.client = client;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Get list of available oracle feeds
|
|
10
|
-
*/
|
|
11
|
-
async getFeeds() {
|
|
12
|
-
return this.client.get("/api/v1/oracle/feeds");
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Get signed oracle data
|
|
16
|
-
* @param feedId Feed ID
|
|
17
|
-
* @param payment Optional x402 payment string (if feed is paid)
|
|
18
|
-
*/
|
|
19
|
-
async getData(feedId, payment) {
|
|
20
|
-
const config = {};
|
|
21
|
-
if (payment) {
|
|
22
|
-
config.headers = {
|
|
23
|
-
"X-Payment": payment
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return this.client.get(`/api/v1/oracle/data/${feedId}`, config);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Get global oracle stats
|
|
30
|
-
*/
|
|
31
|
-
async getGlobalStats() {
|
|
32
|
-
return this.client.get("/api/v1/oracle/stats/global");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.OracleModule = OracleModule;
|