Skip to content

Commit 1d332bd

Browse files
committed
update functions to latest type changes
1 parent 86337e0 commit 1d332bd

File tree

2 files changed

+102
-5
lines changed

2 files changed

+102
-5
lines changed
Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,108 @@
11
import type { Bucket, FileListResponse, GetFilesOptions } from "../types.js";
22
import { ModuleBase } from "../base.js";
3+
import { ensure0xPrefix } from "@storagehub-sdk/core";
34

45
export class BucketsModule extends ModuleBase {
6+
/** Recursively fix hex prefixes in FileTree structures */
7+
private fixFileTree(item: any): any {
8+
if (item.type === "file") {
9+
return {
10+
name: item.name,
11+
type: item.type,
12+
sizeBytes: item.sizeBytes,
13+
fileKey: ensure0xPrefix(item.fileKey),
14+
status: item.status
15+
};
16+
} else {
17+
return {
18+
name: item.name,
19+
type: item.type,
20+
children: item.children?.map((child: any) => this.fixFileTree(child)) || []
21+
};
22+
}
23+
}
524
/** List all buckets for the current authenticated user */
625
async listBuckets(signal?: AbortSignal): Promise<Bucket[]> {
726
const headers = await this.withAuth();
8-
return this.ctx.http.get<Bucket[]>("/buckets", {
27+
const wire = await this.ctx.http.get<
28+
Array<{
29+
bucketId: string;
30+
name: string;
31+
root: string;
32+
isPublic: boolean;
33+
sizeBytes: number;
34+
valuePropId: string;
35+
fileCount: number;
36+
}>
37+
>("/buckets", {
938
...(headers ? { headers } : {}),
1039
...(signal ? { signal } : {})
1140
});
41+
42+
return wire.map((bucket) => ({
43+
bucketId: ensure0xPrefix(bucket.bucketId),
44+
name: bucket.name,
45+
root: ensure0xPrefix(bucket.root),
46+
isPublic: bucket.isPublic,
47+
sizeBytes: bucket.sizeBytes,
48+
valuePropId: bucket.valuePropId, // "unknown" string, not hex
49+
fileCount: bucket.fileCount
50+
}));
1251
}
1352

1453
/** Get a specific bucket's metadata by its bucket ID */
1554
async getBucket(bucketId: string, signal?: AbortSignal): Promise<Bucket> {
1655
const headers = await this.withAuth();
1756
const path = `/buckets/${encodeURIComponent(bucketId)}`;
18-
return this.ctx.http.get<Bucket>(path, {
57+
58+
const wire = await this.ctx.http.get<{
59+
bucketId: string;
60+
name: string;
61+
root: string;
62+
isPublic: boolean;
63+
sizeBytes: number;
64+
valuePropId: string;
65+
fileCount: number;
66+
}>(path, {
1967
...(headers ? { headers } : {}),
2068
...(signal ? { signal } : {})
2169
});
70+
71+
return {
72+
bucketId: ensure0xPrefix(wire.bucketId),
73+
name: wire.name,
74+
root: ensure0xPrefix(wire.root),
75+
isPublic: wire.isPublic,
76+
sizeBytes: wire.sizeBytes,
77+
valuePropId: wire.valuePropId, // "unknown" string, not hex
78+
fileCount: wire.fileCount
79+
};
2280
}
2381

2482
/** List files/folders under a path for a bucket (root if no path) */
2583
async getFiles(bucketId: string, options?: GetFilesOptions): Promise<FileListResponse> {
2684
const headers = await this.withAuth();
2785
const path = `/buckets/${encodeURIComponent(bucketId)}/files`;
28-
return this.ctx.http.get<FileListResponse>(path, {
86+
87+
const wire = await this.ctx.http.get<{
88+
bucketId: string;
89+
files: Array<{
90+
name: string;
91+
type: "file" | "folder";
92+
sizeBytes?: number;
93+
fileKey?: string;
94+
status?: string;
95+
children?: Array<any>;
96+
}>;
97+
}>(path, {
2998
...(headers ? { headers } : {}),
3099
...(options?.signal ? { signal: options.signal } : {}),
31100
...(options?.path ? { query: { path: this.normalizePath(options.path) } } : {})
32101
});
102+
103+
return {
104+
bucketId: ensure0xPrefix(wire.bucketId),
105+
files: wire.files.map((file) => this.fixFileTree(file))
106+
};
33107
}
34108
}

sdk/msp-client/src/modules/info.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
StatsResponse,
77
ValueProp
88
} from "../types.js";
9+
import { ensure0xPrefix } from "@storagehub-sdk/core";
910

1011
export class InfoModule extends ModuleBase {
1112
getHealth(signal?: AbortSignal): Promise<HealthStatus> {
@@ -15,10 +16,32 @@ export class InfoModule extends ModuleBase {
1516
}
1617

1718
/** Get general MSP information */
18-
getInfo(signal?: AbortSignal): Promise<InfoResponse> {
19-
return this.ctx.http.get<InfoResponse>("/info", {
19+
async getInfo(signal?: AbortSignal): Promise<InfoResponse> {
20+
const wire = await this.ctx.http.get<{
21+
client: string;
22+
version: string;
23+
mspId: string;
24+
multiaddresses: string[];
25+
ownerAccount: string;
26+
paymentAccount: string;
27+
status: string;
28+
activeSince: number;
29+
uptime: string;
30+
}>("/info", {
2031
...(signal ? { signal } : {})
2132
});
33+
34+
return {
35+
client: wire.client,
36+
version: wire.version,
37+
mspId: ensure0xPrefix(wire.mspId),
38+
multiaddresses: wire.multiaddresses,
39+
ownerAccount: ensure0xPrefix(wire.ownerAccount), // Ensure 0x prefix (backend has it, but TypeScript needs guarantee)
40+
paymentAccount: ensure0xPrefix(wire.paymentAccount), // Ensure 0x prefix (backend has it, but TypeScript needs guarantee)
41+
status: wire.status,
42+
activeSince: wire.activeSince,
43+
uptime: wire.uptime
44+
};
2245
}
2346

2447
/** Get MSP statistics */

0 commit comments

Comments
 (0)