@storagehub-sdk/msp-client 0.0.3 → 0.0.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.
@@ -1,2 +1,2 @@
1
- import{HttpClient as R}from"@storagehub-sdk/core";var y=class m{config;http;token;constructor(e,n){this.config=e,this.http=n}static async connect(e){if(!e?.baseUrl)throw new Error("MspClient.connect: baseUrl is required");let n=new R({baseUrl:e.baseUrl,...e.timeoutMs!==void 0&&{timeoutMs:e.timeoutMs},...e.defaultHeaders!==void 0&&{defaultHeaders:e.defaultHeaders},...e.fetchImpl!==void 0&&{fetchImpl:e.fetchImpl}});return new m(e,n)}getHealth(e){return this.http.get("/health",{...e?.signal!==void 0&&{signal:e.signal}})}getNonce(e,n,t){return this.http.post("/auth/nonce",{body:{address:e,chainId:n},headers:{"Content-Type":"application/json"},...t?.signal!==void 0&&{signal:t.signal}})}verify(e,n,t){return this.http.post("/auth/verify",{body:{message:e,signature:n},headers:{"Content-Type":"application/json"},...t?.signal!==void 0&&{signal:t.signal}})}setToken(e){this.token=e}withAuth(e){return this.token?{...e??{},Authorization:`Bearer ${this.token}`}:e}listBuckets(e){let n=this.withAuth();return this.http.get("/buckets",{...n?{headers:n}:{},...e?.signal?{signal:e.signal}:{}})}getBucket(e,n){let t=this.withAuth(),a=`/buckets/${encodeURIComponent(e)}`;return this.http.get(a,{...t?{headers:t}:{},...n?.signal?{signal:n.signal}:{}})}getFiles(e,n){let t=this.withAuth(),a=`/buckets/${encodeURIComponent(e)}/files`;return this.http.get(a,{...t?{headers:t}:{},...n?.signal?{signal:n.signal}:{},...n?.path?{query:{path:n.path.replace(/^\/+/,"")}}:{}})}async uploadFile(e,n,t,a){let i=`/buckets/${encodeURIComponent(e)}/upload/${encodeURIComponent(n)}`,o=this.withAuth();if(t instanceof ReadableStream)return await this.http.put(i,o?{body:t,headers:{...o,"Content-Type":"application/octet-stream"}}:{body:t,headers:{"Content-Type":"application/octet-stream"}});let s=new FormData,l=await this.coerceToFormPart(t);return s.append("file",l,"file"),await this.http.put(i,o?{body:s,headers:o}:{body:s})}async coerceToFormPart(e){return typeof Blob<"u"&&e instanceof Blob?e:e instanceof Uint8Array?new Blob([e]):typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer?new Blob([e]):new Blob([e])}async downloadByKey(e,n,t){let a=`/buckets/${encodeURIComponent(e)}/download/${encodeURIComponent(n)}`,i={Accept:"*/*"};if(t?.range){let{start:d,end:h}=t.range,g=`bytes=${d}-${h??""}`;i.Range=g}let o=this.withAuth(i),s=await this.http.getRaw(a,{...o?{headers:o}:{},...t?.signal?{signal:t.signal}:{}});if(!s.body)throw new Error("Response body is null - unable to create stream");let l=s.headers.get("content-type"),r=s.headers.get("content-range"),c=s.headers.get("content-length"),p=c!==null?Number(c):void 0,u=typeof p=="number"&&Number.isFinite(p)?p:null;return{stream:s.body,status:s.status,contentType:l,contentRange:r,contentLength:u}}async downloadByLocation(e,n,t){let i=n.replace(/^\/+/,"").split("/").map(encodeURIComponent).join("/"),o=`/buckets/${encodeURIComponent(e)}/download/path/${i}`,s={Accept:"*/*"};if(t?.range){let{start:g,end:b}=t.range,f=`bytes=${g}-${b??""}`;s.Range=f}let l=this.withAuth(s),r=await this.http.getRaw(o,{...l?{headers:l}:{},...t?.signal?{signal:t.signal}:{}});if(!r.body)throw new Error("Response body is null - unable to create stream");let c=r.headers.get("content-type"),p=r.headers.get("content-range"),u=r.headers.get("content-length"),d=u!==null?Number(u):void 0,h=typeof d=="number"&&Number.isFinite(d)?d:null;return{stream:r.body,status:r.status,contentType:c,contentRange:p,contentLength:h}}};export{y as MspClient};
1
+ import{HttpClient as R}from"@storagehub-sdk/core";var y=class m{config;http;token;constructor(t,n){this.config=t,this.http=n}static async connect(t){if(!t?.baseUrl)throw new Error("MspClient.connect: baseUrl is required");let n=new R({baseUrl:t.baseUrl,...t.timeoutMs!==void 0&&{timeoutMs:t.timeoutMs},...t.defaultHeaders!==void 0&&{defaultHeaders:t.defaultHeaders},...t.fetchImpl!==void 0&&{fetchImpl:t.fetchImpl}});return new m(t,n)}getHealth(t){return this.http.get("/health",{...t?.signal!==void 0&&{signal:t.signal}})}getNonce(t,n,e){return this.http.post("/auth/nonce",{body:{address:t,chainId:n},headers:{"Content-Type":"application/json"},...e?.signal!==void 0&&{signal:e.signal}})}verify(t,n,e){return this.http.post("/auth/verify",{body:{message:t,signature:n},headers:{"Content-Type":"application/json"},...e?.signal!==void 0&&{signal:e.signal}})}setToken(t){this.token=t}withAuth(t){return this.token?{...t??{},Authorization:`Bearer ${this.token}`}:t}listBuckets(t){let n=this.withAuth();return this.http.get("/buckets",{...n?{headers:n}:{},...t?.signal?{signal:t.signal}:{}})}getBucket(t,n){let e=this.withAuth(),a=`/buckets/${encodeURIComponent(t)}`;return this.http.get(a,{...e?{headers:e}:{},...n?.signal?{signal:n.signal}:{}})}getFiles(t,n){let e=this.withAuth(),a=`/buckets/${encodeURIComponent(t)}/files`;return this.http.get(a,{...e?{headers:e}:{},...n?.signal?{signal:n.signal}:{},...n?.path?{query:{path:n.path.replace(/^\/+/,"")}}:{}})}async uploadFile(t,n,e,a){let i=`/buckets/${encodeURIComponent(t)}/upload/${encodeURIComponent(n)}`,o=this.withAuth();if(e instanceof ReadableStream)return await this.http.put(i,o?{body:e,headers:{...o,"Content-Type":"application/octet-stream"}}:{body:e,headers:{"Content-Type":"application/octet-stream"}});let s=new FormData,l=await this.coerceToFormPart(e);return s.append("file",l,"file"),await this.http.put(i,o?{body:s,headers:o}:{body:s})}async coerceToFormPart(t){return typeof Blob<"u"&&t instanceof Blob?t:t instanceof Uint8Array?new Blob([t]):typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer?new Blob([t]):new Blob([t])}async downloadByKey(t,n,e){let a=`/buckets/${encodeURIComponent(t)}/download/${encodeURIComponent(n)}`,i={Accept:"*/*"};if(e?.range){let{start:d,end:h}=e.range,g=`bytes=${d}-${h??""}`;i.Range=g}let o=this.withAuth(i),s=await this.http.getRaw(a,{...o?{headers:o}:{},...e?.signal?{signal:e.signal}:{}});if(!s.body)throw new Error("Response body is null - unable to create stream");let l=s.headers.get("content-type"),r=s.headers.get("content-range"),c=s.headers.get("content-length"),p=c!==null?Number(c):void 0,u=typeof p=="number"&&Number.isFinite(p)?p:null;return{stream:s.body,status:s.status,contentType:l,contentRange:r,contentLength:u}}async downloadByLocation(t,n,e){let i=n.replace(/^\/+/,"").split("/").map(encodeURIComponent).join("/"),o=`/buckets/${encodeURIComponent(t)}/download/path/${i}`,s={Accept:"*/*"};if(e?.range){let{start:g,end:b}=e.range,f=`bytes=${g}-${b??""}`;s.Range=f}let l=this.withAuth(s),r=await this.http.getRaw(o,{...l?{headers:l}:{},...e?.signal?{signal:e.signal}:{}});if(!r.body)throw new Error("Response body is null - unable to create stream");let c=r.headers.get("content-type"),p=r.headers.get("content-range"),u=r.headers.get("content-length"),d=u!==null?Number(u):void 0,h=typeof d=="number"&&Number.isFinite(d)?d:null;return{stream:r.body,status:r.status,contentType:c,contentRange:p,contentLength:h}}};export{y as MspClient};
2
2
  //# sourceMappingURL=index.browser.js.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { MspClient } from './MspClient.js';
2
- export type { Bucket, FileEntry, FileListResponse, HealthStatus, NonceResponse, UploadOptions, UploadReceipt, VerifyResponse, } from './types.js';
2
+ export type { Bucket, FileEntry, FileListResponse, HealthStatus, NonceResponse, DownloadOptions, DownloadResult, UploadOptions, UploadReceipt, VerifyResponse, } from './types.js';
@@ -1,2 +1,2 @@
1
- import{HttpClient as R}from"@storagehub-sdk/core";var y=class m{config;http;token;constructor(e,n){this.config=e,this.http=n}static async connect(e){if(!e?.baseUrl)throw new Error("MspClient.connect: baseUrl is required");let n=new R({baseUrl:e.baseUrl,...e.timeoutMs!==void 0&&{timeoutMs:e.timeoutMs},...e.defaultHeaders!==void 0&&{defaultHeaders:e.defaultHeaders},...e.fetchImpl!==void 0&&{fetchImpl:e.fetchImpl}});return new m(e,n)}getHealth(e){return this.http.get("/health",{...e?.signal!==void 0&&{signal:e.signal}})}getNonce(e,n,t){return this.http.post("/auth/nonce",{body:{address:e,chainId:n},headers:{"Content-Type":"application/json"},...t?.signal!==void 0&&{signal:t.signal}})}verify(e,n,t){return this.http.post("/auth/verify",{body:{message:e,signature:n},headers:{"Content-Type":"application/json"},...t?.signal!==void 0&&{signal:t.signal}})}setToken(e){this.token=e}withAuth(e){return this.token?{...e??{},Authorization:`Bearer ${this.token}`}:e}listBuckets(e){let n=this.withAuth();return this.http.get("/buckets",{...n?{headers:n}:{},...e?.signal?{signal:e.signal}:{}})}getBucket(e,n){let t=this.withAuth(),a=`/buckets/${encodeURIComponent(e)}`;return this.http.get(a,{...t?{headers:t}:{},...n?.signal?{signal:n.signal}:{}})}getFiles(e,n){let t=this.withAuth(),a=`/buckets/${encodeURIComponent(e)}/files`;return this.http.get(a,{...t?{headers:t}:{},...n?.signal?{signal:n.signal}:{},...n?.path?{query:{path:n.path.replace(/^\/+/,"")}}:{}})}async uploadFile(e,n,t,a){let i=`/buckets/${encodeURIComponent(e)}/upload/${encodeURIComponent(n)}`,o=this.withAuth();if(t instanceof ReadableStream)return await this.http.put(i,o?{body:t,headers:{...o,"Content-Type":"application/octet-stream"}}:{body:t,headers:{"Content-Type":"application/octet-stream"}});let s=new FormData,l=await this.coerceToFormPart(t);return s.append("file",l,"file"),await this.http.put(i,o?{body:s,headers:o}:{body:s})}async coerceToFormPart(e){return typeof Blob<"u"&&e instanceof Blob?e:e instanceof Uint8Array?new Blob([e]):typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer?new Blob([e]):new Blob([e])}async downloadByKey(e,n,t){let a=`/buckets/${encodeURIComponent(e)}/download/${encodeURIComponent(n)}`,i={Accept:"*/*"};if(t?.range){let{start:d,end:h}=t.range,g=`bytes=${d}-${h??""}`;i.Range=g}let o=this.withAuth(i),s=await this.http.getRaw(a,{...o?{headers:o}:{},...t?.signal?{signal:t.signal}:{}});if(!s.body)throw new Error("Response body is null - unable to create stream");let l=s.headers.get("content-type"),r=s.headers.get("content-range"),c=s.headers.get("content-length"),p=c!==null?Number(c):void 0,u=typeof p=="number"&&Number.isFinite(p)?p:null;return{stream:s.body,status:s.status,contentType:l,contentRange:r,contentLength:u}}async downloadByLocation(e,n,t){let i=n.replace(/^\/+/,"").split("/").map(encodeURIComponent).join("/"),o=`/buckets/${encodeURIComponent(e)}/download/path/${i}`,s={Accept:"*/*"};if(t?.range){let{start:g,end:b}=t.range,f=`bytes=${g}-${b??""}`;s.Range=f}let l=this.withAuth(s),r=await this.http.getRaw(o,{...l?{headers:l}:{},...t?.signal?{signal:t.signal}:{}});if(!r.body)throw new Error("Response body is null - unable to create stream");let c=r.headers.get("content-type"),p=r.headers.get("content-range"),u=r.headers.get("content-length"),d=u!==null?Number(u):void 0,h=typeof d=="number"&&Number.isFinite(d)?d:null;return{stream:r.body,status:r.status,contentType:c,contentRange:p,contentLength:h}}};export{y as MspClient};
1
+ import{HttpClient as R}from"@storagehub-sdk/core";var y=class m{config;http;token;constructor(t,n){this.config=t,this.http=n}static async connect(t){if(!t?.baseUrl)throw new Error("MspClient.connect: baseUrl is required");let n=new R({baseUrl:t.baseUrl,...t.timeoutMs!==void 0&&{timeoutMs:t.timeoutMs},...t.defaultHeaders!==void 0&&{defaultHeaders:t.defaultHeaders},...t.fetchImpl!==void 0&&{fetchImpl:t.fetchImpl}});return new m(t,n)}getHealth(t){return this.http.get("/health",{...t?.signal!==void 0&&{signal:t.signal}})}getNonce(t,n,e){return this.http.post("/auth/nonce",{body:{address:t,chainId:n},headers:{"Content-Type":"application/json"},...e?.signal!==void 0&&{signal:e.signal}})}verify(t,n,e){return this.http.post("/auth/verify",{body:{message:t,signature:n},headers:{"Content-Type":"application/json"},...e?.signal!==void 0&&{signal:e.signal}})}setToken(t){this.token=t}withAuth(t){return this.token?{...t??{},Authorization:`Bearer ${this.token}`}:t}listBuckets(t){let n=this.withAuth();return this.http.get("/buckets",{...n?{headers:n}:{},...t?.signal?{signal:t.signal}:{}})}getBucket(t,n){let e=this.withAuth(),a=`/buckets/${encodeURIComponent(t)}`;return this.http.get(a,{...e?{headers:e}:{},...n?.signal?{signal:n.signal}:{}})}getFiles(t,n){let e=this.withAuth(),a=`/buckets/${encodeURIComponent(t)}/files`;return this.http.get(a,{...e?{headers:e}:{},...n?.signal?{signal:n.signal}:{},...n?.path?{query:{path:n.path.replace(/^\/+/,"")}}:{}})}async uploadFile(t,n,e,a){let i=`/buckets/${encodeURIComponent(t)}/upload/${encodeURIComponent(n)}`,o=this.withAuth();if(e instanceof ReadableStream)return await this.http.put(i,o?{body:e,headers:{...o,"Content-Type":"application/octet-stream"}}:{body:e,headers:{"Content-Type":"application/octet-stream"}});let s=new FormData,l=await this.coerceToFormPart(e);return s.append("file",l,"file"),await this.http.put(i,o?{body:s,headers:o}:{body:s})}async coerceToFormPart(t){return typeof Blob<"u"&&t instanceof Blob?t:t instanceof Uint8Array?new Blob([t]):typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer?new Blob([t]):new Blob([t])}async downloadByKey(t,n,e){let a=`/buckets/${encodeURIComponent(t)}/download/${encodeURIComponent(n)}`,i={Accept:"*/*"};if(e?.range){let{start:d,end:h}=e.range,g=`bytes=${d}-${h??""}`;i.Range=g}let o=this.withAuth(i),s=await this.http.getRaw(a,{...o?{headers:o}:{},...e?.signal?{signal:e.signal}:{}});if(!s.body)throw new Error("Response body is null - unable to create stream");let l=s.headers.get("content-type"),r=s.headers.get("content-range"),c=s.headers.get("content-length"),p=c!==null?Number(c):void 0,u=typeof p=="number"&&Number.isFinite(p)?p:null;return{stream:s.body,status:s.status,contentType:l,contentRange:r,contentLength:u}}async downloadByLocation(t,n,e){let i=n.replace(/^\/+/,"").split("/").map(encodeURIComponent).join("/"),o=`/buckets/${encodeURIComponent(t)}/download/path/${i}`,s={Accept:"*/*"};if(e?.range){let{start:g,end:b}=e.range,f=`bytes=${g}-${b??""}`;s.Range=f}let l=this.withAuth(s),r=await this.http.getRaw(o,{...l?{headers:l}:{},...e?.signal?{signal:e.signal}:{}});if(!r.body)throw new Error("Response body is null - unable to create stream");let c=r.headers.get("content-type"),p=r.headers.get("content-range"),u=r.headers.get("content-length"),d=u!==null?Number(u):void 0,h=typeof d=="number"&&Number.isFinite(d)?d:null;return{stream:r.body,status:r.status,contentType:c,contentRange:p,contentLength:h}}};export{y as MspClient};
2
2
  //# sourceMappingURL=index.node.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storagehub-sdk/msp-client",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "High-level TypeScript client for StorageHub MSP: simple file upload/download, SIWE-style auth, health checks, and bucket browsing built on top of @storagehub-sdk/core.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.node.js",
@@ -35,8 +35,8 @@
35
35
  "test": "vitest",
36
36
  "typecheck": "tsc --noEmit"
37
37
  },
38
- "dependencies": {
39
- "@storagehub-sdk/core": "workspace:*"
38
+ "peerDependencies": {
39
+ "@storagehub-sdk/core": ">=0.0.4"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=22"