@nhost/nhost-js
Version:
Nhost JavaScript SDK
2 lines • 5.79 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../fetch-B_MCWy66.cjs");exports.createAPIClient=(e,s=[])=>{let a=t.createEnhancedFetch(s);return{baseURL:e,pushChainFunction:e=>{s.push(e),a=t.createEnhancedFetch(s)},uploadFiles:async(s,r)=>{const n=`${e}/files`,d=new FormData,o="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==s["bucket-id"]&&d.append("bucket-id",s["bucket-id"]),void 0!==s["metadata[]"]&&s["metadata[]"].forEach((t=>{o?d.append("metadata[]",{string:JSON.stringify(t),type:"application/json",name:""}):d.append("metadata[]",new Blob([JSON.stringify(t)],{type:"application/json"}),"")})),void 0!==s["file[]"]&&s["file[]"].forEach((t=>{d.append("file[]",t)}));const i=await a(n,{...r,method:"POST",body:d});if(i.status>=300){const e=[412].includes(i.status)?null:await i.text();throw new t.FetchError(e?JSON.parse(e):{},i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},deleteFile:async(s,r)=>{const n=`${e}/files/${s}`,d=await a(n,{...r,method:"DELETE",headers:{...r?.headers}});if(d.status>=300){const e=[412].includes(d.status)?null:await d.text();throw new t.FetchError(e?JSON.parse(e):{},d.status,d.headers)}return{body:void 0,status:d.status,headers:d.headers}},getFile:async(s,r,n)=>{const d=r&&Object.entries(r).flatMap((([t,e])=>{const s=Array.isArray(e)?e.join(","):"object"==typeof e&&null!==e?JSON.stringify(e):String(e);return[`${t}=${encodeURIComponent(s)}`]})).join("&"),o=d?`${e}/files/${s}?${d}`:`${e}/files/${s}`,i=await a(o,{...n,method:"GET",headers:{...n?.headers}});if(i.status>=300){const e=[412].includes(i.status)?null:await i.text();throw new t.FetchError(e?JSON.parse(e):{},i.status,i.headers)}return{body:await i.blob(),status:i.status,headers:i.headers}},getFileMetadataHeaders:async(s,r,n)=>{const d=r&&Object.entries(r).flatMap((([t,e])=>{const s=Array.isArray(e)?e.join(","):"object"==typeof e&&null!==e?JSON.stringify(e):String(e);return[`${t}=${encodeURIComponent(s)}`]})).join("&"),o=d?`${e}/files/${s}?${d}`:`${e}/files/${s}`,i=await a(o,{...n,method:"HEAD",headers:{...n?.headers}});if(i.status>=300){const e=[412].includes(i.status)?null:await i.text();throw new t.FetchError(e?JSON.parse(e):{},i.status,i.headers)}return{body:void 0,status:i.status,headers:i.headers}},replaceFile:async(s,r,n)=>{const d=`${e}/files/${s}`,o=new FormData,i="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==r.metadata&&(i?o.append("metadata",{string:JSON.stringify(r.metadata),type:"application/json",name:""}):o.append("metadata",new Blob([JSON.stringify(r.metadata)],{type:"application/json"}),"")),void 0!==r.file&&o.append("file",r.file);const u=await a(d,{...n,method:"PUT",body:o});if(u.status>=300){const e=[412].includes(u.status)?null:await u.text();throw new t.FetchError(e?JSON.parse(e):{},u.status,u.headers)}const l=[204,205,304].includes(u.status)?null:await u.text();return{body:l?JSON.parse(l):{},status:u.status,headers:u.headers}},getFilePresignedURL:async(s,r)=>{const n=`${e}/files/${s}/presignedurl`,d=await a(n,{...r,method:"GET",headers:{...r?.headers}});if(d.status>=300){const e=[412].includes(d.status)?null:await d.text();throw new t.FetchError(e?JSON.parse(e):{},d.status,d.headers)}const o=[204,205,304].includes(d.status)?null:await d.text();return{body:o?JSON.parse(o):{},status:d.status,headers:d.headers}},deleteBrokenMetadata:async s=>{const r=`${e}/ops/delete-broken-metadata`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},deleteOrphanedFiles:async s=>{const r=`${e}/ops/delete-orphans`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},listBrokenMetadata:async s=>{const r=`${e}/ops/list-broken-metadata`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},listFilesNotUploaded:async s=>{const r=`${e}/ops/list-not-uploaded`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},listOrphanedFiles:async s=>{const r=`${e}/ops/list-orphans`,n=await a(r,{...s,method:"POST",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}},getVersion:async s=>{const r=`${e}/version`,n=await a(r,{...s,method:"GET",headers:{...s?.headers}});if(n.status>=300){const e=[412].includes(n.status)?null:await n.text();throw new t.FetchError(e?JSON.parse(e):{},n.status,n.headers)}const d=[204,205,304].includes(n.status)?null:await n.text();return{body:d?JSON.parse(d):{},status:n.status,headers:n.headers}}}};
//# sourceMappingURL=storage.cjs.map