@vercel/blob
Advanced tools
Comparing version
@@ -7,2 +7,3 @@ import { Readable } from 'node:stream'; | ||
interface HeadBlobResult { | ||
url: string; | ||
size: string; | ||
@@ -16,2 +17,12 @@ uploadedAt: Date; | ||
} | ||
interface ListBlobResult { | ||
blobs: HeadBlobResult[]; | ||
cursor?: string; | ||
hasMore: boolean; | ||
} | ||
interface ListCommandOptions extends BlobCommandOptions { | ||
limit?: number; | ||
prefix?: string; | ||
cursor?: string; | ||
} | ||
interface BlobCommandOptions { | ||
@@ -29,3 +40,4 @@ token?: string; | ||
declare function head(url: string, options?: BlobCommandOptions): Promise<HeadBlobResult>; | ||
declare function list(options?: ListCommandOptions): Promise<ListBlobResult>; | ||
export { HeadBlobResult, PutBlobResult, del, head, put }; | ||
export { BlobCommandOptions, HeadBlobResult, ListBlobResult, ListCommandOptions, PutBlobResult, PutCommandOptions, del, head, list, put }; |
@@ -1,1 +0,1 @@ | ||
import{fetch as r}from"undici";async function c(e,o,t){if(!e)throw new Error("vercelBlob.put: pathname is required");if(!o)throw new Error("vercelBlob.put: body is required");if(!t||t.access!=="public")throw new Error('vercelBlob.put: access must be "public"');return(await r(`${n()}/${e}`,{method:"PUT",body:o,headers:{authorization:`Bearer ${s(t)}`},duplex:"half"})).json()}async function d(e,o){let t=new URL(n());t.searchParams.set("url",e),await r(t,{method:"DELETE",headers:{authorization:`Bearer ${s(o)}`}})}async function u(e,o){let t=new URL(n());t.searchParams.set("url",e);let i=await(await r(t,{method:"GET",headers:{authorization:`Bearer ${s(o)}`}})).json();return{...i,uploadedAt:new Date(i.uploadedAt)}}function n(){return process.env.VERCEL_BLOB_API_URL||"https://blob.vercel-storage.com"}function s(e){if(e!=null&&e.token)return e.token;if(!process.env.BLOB_READ_WRITE_TOKEN)throw new Error("BLOB_READ_WRITE_TOKEN environment variable is not set. Please set it to your write token.");return process.env.BLOB_READ_WRITE_TOKEN}export{d as del,u as head,c as put}; | ||
import{fetch as n}from"undici";async function c(e,t,r){if(!e)throw new Error("vercelBlob.put: pathname is required");if(!t)throw new Error("vercelBlob.put: body is required");if(!r||r.access!=="public")throw new Error('vercelBlob.put: access must be "public"');return(await n(`${a()}/${e}`,{method:"PUT",body:t,headers:{authorization:`Bearer ${i(r)}`},duplex:"half"})).json()}async function u(e,t){let r=new URL(a());r.searchParams.set("url",e),await n(r,{method:"DELETE",headers:{authorization:`Bearer ${i(t)}`}})}async function d(e,t){let r=new URL(a());r.searchParams.set("url",e);let s=await(await n(r,{method:"GET",headers:{authorization:`Bearer ${i(t)}`}})).json();return{...s,uploadedAt:new Date(s.uploadedAt)}}async function b(e){let t=new URL(a());e!=null&&e.limit&&t.searchParams.set("limit",e.limit.toString()),e!=null&&e.prefix&&t.searchParams.set("prefix",e.prefix),e!=null&&e.cursor&&t.searchParams.set("cursor",e.cursor);let o=await(await n(t,{method:"GET",headers:{authorization:`Bearer ${i(e)}`}})).json();return{...o,blobs:o.blobs.map(s=>({...s,uploadedAt:new Date(s.uploadedAt)}))}}function a(){return process.env.VERCEL_BLOB_API_URL||"https://blob.vercel-storage.com"}function i(e){if(e!=null&&e.token)return e.token;if(!process.env.BLOB_READ_WRITE_TOKEN)throw new Error("BLOB_READ_WRITE_TOKEN environment variable is not set. Please set it to your write token.");return process.env.BLOB_READ_WRITE_TOKEN}export{u as del,d as head,b as list,c as put}; |
{ | ||
"name": "@vercel/blob", | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"description": "The Vercel Blob JavaScript API client", | ||
@@ -5,0 +5,0 @@ "homepage": "https://vercel.com/blob", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8835
22.86%66
37.5%