@vercel/blob
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -6,2 +6,11 @@ import { Readable } from 'node:stream'; | ||
} | ||
declare class BlobError extends Error { | ||
constructor(message: string); | ||
} | ||
declare class BlobAccessError extends Error { | ||
constructor(); | ||
} | ||
declare class BlobUnknownError extends Error { | ||
constructor(); | ||
} | ||
interface HeadBlobResult { | ||
@@ -41,2 +50,2 @@ url: string; | ||
export { BlobCommandOptions, HeadBlobResult, ListBlobResult, ListCommandOptions, PutBlobResult, PutCommandOptions, del, head, list, put }; | ||
export { BlobAccessError, BlobCommandOptions, BlobError, BlobUnknownError, HeadBlobResult, ListBlobResult, ListCommandOptions, PutBlobResult, PutCommandOptions, del, head, list, put }; |
@@ -1,1 +0,1 @@ | ||
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 d(e,t){let r=new URL(a());r.searchParams.set("url",e);let s=await n(r,{method:"DELETE",headers:{authorization:`Bearer ${i(t)}`}});if(s.status!==200)throw s.status===403?new Error("vercelBlob.del: failed to delete blob, access denied"):new Error("vercelBlob.del: failed to delete blob")}async function u(e,t){let r=new URL(a());r.searchParams.set("url",e);let o=await(await n(r,{method:"GET",headers:{authorization:`Bearer ${i(t)}`}})).json();return{...o,uploadedAt:new Date(o.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 s=await(await n(t,{method:"GET",headers:{authorization:`Bearer ${i(e)}`}})).json();return{...s,blobs:s.blobs.map(o=>({...o,uploadedAt:new Date(o.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{d as del,u as head,b as list,c as put}; | ||
import{fetch as l}from"undici";var i=class extends Error{constructor(t){super(`Vercel Blob: ${t}`)}},o=class extends Error{constructor(){super("Vercel Blob: Access denied, please provide a valid token")}},n=class extends Error{constructor(){super("Vercel Blob: Unknown error, please contact support@vercel.com")}};async function m(e,t,r){if(!e)throw new i("pathname is required");if(!t)throw new i("body is required");if(!r||r.access!=="public")throw new i('access must be "public"');let s=await l(`${c()}/${e}`,{method:"PUT",body:t,headers:{authorization:`Bearer ${u(r)}`},duplex:"half"});if(s.status!==200)throw s.status===403?new o:new n;return s.json()}async function b(e,t){let r=new URL(c());r.searchParams.set("url",e);let s=await l(r,{method:"DELETE",headers:{authorization:`Bearer ${u(t)}`}});if(s.status!==200)throw s.status===403?new o:new n}async function p(e,t){let r=new URL(c());r.searchParams.set("url",e);let s=await l(r,{method:"GET",headers:{authorization:`Bearer ${u(t)}`}});if(s.status!==200)throw s.status===403?new o:new n;let a=await s.json();return{...a,uploadedAt:new Date(a.uploadedAt)}}async function f(e){let t=new URL(c());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 r=await l(t,{method:"GET",headers:{authorization:`Bearer ${u(e)}`}});if(r.status!==200)throw r.status===403?new o:new n;let s=await r.json();return{...s,blobs:s.blobs.map(a=>({...a,uploadedAt:new Date(a.uploadedAt)}))}}function c(){return process.env.VERCEL_BLOB_API_URL||"https://blob.vercel-storage.com"}function u(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{o as BlobAccessError,i as BlobError,n as BlobUnknownError,b as del,p as head,f as list,m as put}; |
{ | ||
"name": "@vercel/blob", | ||
"version": "0.3.2", | ||
"version": "0.4.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
10877
81