@vercel/blob 2.1.0-371428d-20260119152220 → 2.1.0-454414f-20260204161813
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.
- package/dist/{chunk-4ACRCP3X.cjs → chunk-23VLASYP.cjs} +21 -8
- package/dist/chunk-23VLASYP.cjs.map +1 -0
- package/dist/{chunk-XABT64U6.js → chunk-NUG4TPYD.js} +20 -7
- package/dist/chunk-NUG4TPYD.js.map +1 -0
- package/dist/client.cjs +26 -24
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +17 -12
- package/dist/client.d.ts +17 -12
- package/dist/client.js +5 -3
- package/dist/client.js.map +1 -1
- package/dist/{create-folder-Dfl_PTiT.d.cts → create-folder-Bmttf9ub.d.cts} +13 -5
- package/dist/{create-folder-Dfl_PTiT.d.ts → create-folder-Bmttf9ub.d.ts} +13 -5
- package/dist/index.cjs +36 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -8
- package/dist/index.d.ts +23 -8
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/dist/chunk-4ACRCP3X.cjs.map +0 -1
- package/dist/chunk-XABT64U6.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
var _chunk23VLASYPcjs = require('./chunk-23VLASYP.cjs');
|
|
26
27
|
|
|
27
28
|
// src/del.ts
|
|
28
29
|
async function del(urlOrPathname, options) {
|
|
29
|
-
await
|
|
30
|
+
await _chunk23VLASYPcjs.requestApi.call(void 0,
|
|
30
31
|
"/delete",
|
|
31
32
|
{
|
|
32
33
|
method: "POST",
|
|
@@ -43,7 +44,7 @@ async function del(urlOrPathname, options) {
|
|
|
43
44
|
// src/head.ts
|
|
44
45
|
async function head(urlOrPathname, options) {
|
|
45
46
|
const searchParams = new URLSearchParams({ url: urlOrPathname });
|
|
46
|
-
const response = await
|
|
47
|
+
const response = await _chunk23VLASYPcjs.requestApi.call(void 0,
|
|
47
48
|
`?${searchParams.toString()}`,
|
|
48
49
|
// HEAD can't have body as a response, so we use GET
|
|
49
50
|
{
|
|
@@ -60,7 +61,8 @@ async function head(urlOrPathname, options) {
|
|
|
60
61
|
contentType: response.contentType,
|
|
61
62
|
contentDisposition: response.contentDisposition,
|
|
62
63
|
cacheControl: response.cacheControl,
|
|
63
|
-
uploadedAt: new Date(response.uploadedAt)
|
|
64
|
+
uploadedAt: new Date(response.uploadedAt),
|
|
65
|
+
etag: response.etag
|
|
64
66
|
};
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -80,7 +82,7 @@ async function list(options) {
|
|
|
80
82
|
if (options == null ? void 0 : options.mode) {
|
|
81
83
|
searchParams.set("mode", options.mode);
|
|
82
84
|
}
|
|
83
|
-
const response = await
|
|
85
|
+
const response = await _chunk23VLASYPcjs.requestApi.call(void 0,
|
|
84
86
|
`?${searchParams.toString()}`,
|
|
85
87
|
{
|
|
86
88
|
method: "GET",
|
|
@@ -108,32 +110,32 @@ function mapBlobResult(blobResult) {
|
|
|
108
110
|
downloadUrl: blobResult.downloadUrl,
|
|
109
111
|
pathname: blobResult.pathname,
|
|
110
112
|
size: blobResult.size,
|
|
111
|
-
uploadedAt: new Date(blobResult.uploadedAt)
|
|
113
|
+
uploadedAt: new Date(blobResult.uploadedAt),
|
|
114
|
+
etag: blobResult.etag
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
// src/copy.ts
|
|
116
119
|
async function copy(fromUrlOrPathname, toPathname, options) {
|
|
117
120
|
if (!options) {
|
|
118
|
-
throw new (0,
|
|
121
|
+
throw new (0, _chunk23VLASYPcjs.BlobError)("missing options, see usage");
|
|
119
122
|
}
|
|
120
|
-
if (options.access !== "public"
|
|
121
|
-
throw new (0,
|
|
123
|
+
if (options.access !== "public") {
|
|
124
|
+
throw new (0, _chunk23VLASYPcjs.BlobError)('access must be "public"');
|
|
122
125
|
}
|
|
123
|
-
if (toPathname.length >
|
|
124
|
-
throw new (0,
|
|
125
|
-
`pathname is too long, maximum length is ${
|
|
126
|
+
if (toPathname.length > _chunk23VLASYPcjs.MAXIMUM_PATHNAME_LENGTH) {
|
|
127
|
+
throw new (0, _chunk23VLASYPcjs.BlobError)(
|
|
128
|
+
`pathname is too long, maximum length is ${_chunk23VLASYPcjs.MAXIMUM_PATHNAME_LENGTH}`
|
|
126
129
|
);
|
|
127
130
|
}
|
|
128
|
-
for (const invalidCharacter of
|
|
131
|
+
for (const invalidCharacter of _chunk23VLASYPcjs.disallowedPathnameCharacters) {
|
|
129
132
|
if (toPathname.includes(invalidCharacter)) {
|
|
130
|
-
throw new (0,
|
|
133
|
+
throw new (0, _chunk23VLASYPcjs.BlobError)(
|
|
131
134
|
`pathname cannot contain "${invalidCharacter}", please encode it if needed`
|
|
132
135
|
);
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
const headers = {};
|
|
136
|
-
headers["x-vercel-blob-access"] = options.access;
|
|
137
139
|
if (options.addRandomSuffix !== void 0) {
|
|
138
140
|
headers["x-add-random-suffix"] = options.addRandomSuffix ? "1" : "0";
|
|
139
141
|
}
|
|
@@ -146,11 +148,14 @@ async function copy(fromUrlOrPathname, toPathname, options) {
|
|
|
146
148
|
if (options.cacheControlMaxAge !== void 0) {
|
|
147
149
|
headers["x-cache-control-max-age"] = options.cacheControlMaxAge.toString();
|
|
148
150
|
}
|
|
151
|
+
if (options.ifMatch) {
|
|
152
|
+
headers["x-if-match"] = options.ifMatch;
|
|
153
|
+
}
|
|
149
154
|
const params = new URLSearchParams({
|
|
150
155
|
pathname: toPathname,
|
|
151
156
|
fromUrl: fromUrlOrPathname
|
|
152
157
|
});
|
|
153
|
-
const response = await
|
|
158
|
+
const response = await _chunk23VLASYPcjs.requestApi.call(void 0,
|
|
154
159
|
`?${params.toString()}`,
|
|
155
160
|
{
|
|
156
161
|
method: "PUT",
|
|
@@ -164,36 +169,40 @@ async function copy(fromUrlOrPathname, toPathname, options) {
|
|
|
164
169
|
downloadUrl: response.downloadUrl,
|
|
165
170
|
pathname: response.pathname,
|
|
166
171
|
contentType: response.contentType,
|
|
167
|
-
contentDisposition: response.contentDisposition
|
|
172
|
+
contentDisposition: response.contentDisposition,
|
|
173
|
+
etag: response.etag
|
|
168
174
|
};
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
// src/index.ts
|
|
172
|
-
var put =
|
|
178
|
+
var put = _chunk23VLASYPcjs.createPutMethod.call(void 0, {
|
|
173
179
|
allowedOptions: [
|
|
174
180
|
"cacheControlMaxAge",
|
|
175
181
|
"addRandomSuffix",
|
|
176
182
|
"allowOverwrite",
|
|
177
|
-
"contentType"
|
|
183
|
+
"contentType",
|
|
184
|
+
"ifMatch"
|
|
178
185
|
]
|
|
179
186
|
});
|
|
180
|
-
var createMultipartUpload =
|
|
187
|
+
var createMultipartUpload = _chunk23VLASYPcjs.createCreateMultipartUploadMethod.call(void 0, {
|
|
181
188
|
allowedOptions: [
|
|
182
189
|
"cacheControlMaxAge",
|
|
183
190
|
"addRandomSuffix",
|
|
184
191
|
"allowOverwrite",
|
|
185
|
-
"contentType"
|
|
192
|
+
"contentType",
|
|
193
|
+
"ifMatch"
|
|
186
194
|
]
|
|
187
195
|
});
|
|
188
|
-
var createMultipartUploader =
|
|
196
|
+
var createMultipartUploader = _chunk23VLASYPcjs.createCreateMultipartUploaderMethod.call(void 0, {
|
|
189
197
|
allowedOptions: [
|
|
190
198
|
"cacheControlMaxAge",
|
|
191
199
|
"addRandomSuffix",
|
|
192
200
|
"allowOverwrite",
|
|
193
|
-
"contentType"
|
|
201
|
+
"contentType",
|
|
202
|
+
"ifMatch"
|
|
194
203
|
]
|
|
195
204
|
});
|
|
196
|
-
var uploadPart =
|
|
205
|
+
var uploadPart = _chunk23VLASYPcjs.createUploadPartMethod.call(void 0, {
|
|
197
206
|
allowedOptions: [
|
|
198
207
|
"cacheControlMaxAge",
|
|
199
208
|
"addRandomSuffix",
|
|
@@ -201,7 +210,7 @@ var uploadPart = _chunk4ACRCP3Xcjs.createUploadPartMethod.call(void 0, {
|
|
|
201
210
|
"contentType"
|
|
202
211
|
]
|
|
203
212
|
});
|
|
204
|
-
var completeMultipartUpload =
|
|
213
|
+
var completeMultipartUpload = _chunk23VLASYPcjs.createCompleteMultipartUploadMethod.call(void 0, {
|
|
205
214
|
allowedOptions: [
|
|
206
215
|
"cacheControlMaxAge",
|
|
207
216
|
"addRandomSuffix",
|
|
@@ -234,5 +243,6 @@ var completeMultipartUpload = _chunk4ACRCP3Xcjs.createCompleteMultipartUploadMet
|
|
|
234
243
|
|
|
235
244
|
|
|
236
245
|
|
|
237
|
-
|
|
246
|
+
|
|
247
|
+
exports.BlobAccessError = _chunk23VLASYPcjs.BlobAccessError; exports.BlobClientTokenExpiredError = _chunk23VLASYPcjs.BlobClientTokenExpiredError; exports.BlobContentTypeNotAllowedError = _chunk23VLASYPcjs.BlobContentTypeNotAllowedError; exports.BlobError = _chunk23VLASYPcjs.BlobError; exports.BlobFileTooLargeError = _chunk23VLASYPcjs.BlobFileTooLargeError; exports.BlobNotFoundError = _chunk23VLASYPcjs.BlobNotFoundError; exports.BlobPathnameMismatchError = _chunk23VLASYPcjs.BlobPathnameMismatchError; exports.BlobPreconditionFailedError = _chunk23VLASYPcjs.BlobPreconditionFailedError; exports.BlobRequestAbortedError = _chunk23VLASYPcjs.BlobRequestAbortedError; exports.BlobServiceNotAvailable = _chunk23VLASYPcjs.BlobServiceNotAvailable; exports.BlobServiceRateLimited = _chunk23VLASYPcjs.BlobServiceRateLimited; exports.BlobStoreNotFoundError = _chunk23VLASYPcjs.BlobStoreNotFoundError; exports.BlobStoreSuspendedError = _chunk23VLASYPcjs.BlobStoreSuspendedError; exports.BlobUnknownError = _chunk23VLASYPcjs.BlobUnknownError; exports.completeMultipartUpload = completeMultipartUpload; exports.copy = copy; exports.createFolder = _chunk23VLASYPcjs.createFolder; exports.createMultipartUpload = createMultipartUpload; exports.createMultipartUploader = createMultipartUploader; exports.del = del; exports.getDownloadUrl = _chunk23VLASYPcjs.getDownloadUrl; exports.head = head; exports.list = list; exports.put = put; exports.uploadPart = uploadPart;
|
|
238
248
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/storage/storage/packages/blob/dist/index.cjs","../src/del.ts","../src/head.ts","../src/list.ts","../src/copy.ts","../src/index.ts"],"names":[],"mappings":"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","file":"/home/runner/work/storage/storage/packages/blob/dist/index.cjs","sourcesContent":[null,"import { requestApi } from './api';\nimport type { BlobCommandOptions } from './helpers';\n\n/**\n * Deletes one or multiple blobs from your store.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#delete-a-blob\n *\n * @param urlOrPathname - Blob url (or pathname) to delete. You can pass either a single value or an array of values. You can only delete blobs that are located in a store, that your 'BLOB_READ_WRITE_TOKEN' has access to.\n * @param options - Additional options for the request.\n */\nexport async function del(\n urlOrPathname: string[] | string,\n options?: BlobCommandOptions,\n): Promise<void> {\n await requestApi(\n '/delete',\n {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n urls: Array.isArray(urlOrPathname) ? urlOrPathname : [urlOrPathname],\n }),\n signal: options?.abortSignal,\n },\n options,\n );\n}\n","import { requestApi } from './api';\nimport type { BlobCommandOptions } from './helpers';\n\n/**\n * Result of the head method containing metadata about a blob.\n */\nexport interface HeadBlobResult {\n /**\n * The size of the blob in bytes.\n */\n size: number;\n\n /**\n * The date when the blob was uploaded.\n */\n uploadedAt: Date;\n\n /**\n * The pathname of the blob within the store.\n */\n pathname: string;\n\n /**\n * The content type of the blob.\n */\n contentType: string;\n\n /**\n * The content disposition header value.\n */\n contentDisposition: string;\n\n /**\n * The URL of the blob.\n */\n url: string;\n\n /**\n * A URL that will cause browsers to download the file instead of displaying it inline.\n */\n downloadUrl: string;\n\n /**\n * The cache control header value.\n */\n cacheControl: string;\n}\n\ninterface HeadBlobApiResponse extends Omit<HeadBlobResult, 'uploadedAt'> {\n uploadedAt: string; // when receiving data from our API, uploadedAt is a string\n}\n\n/**\n * Fetches metadata of a blob object.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#get-blob-metadata\n *\n * @param urlOrPathname - Blob url or pathname to lookup.\n * @param options - Additional options for the request.\n */\nexport async function head(\n urlOrPathname: string,\n options?: BlobCommandOptions,\n): Promise<HeadBlobResult> {\n const searchParams = new URLSearchParams({ url: urlOrPathname });\n\n const response = await requestApi<HeadBlobApiResponse>(\n `?${searchParams.toString()}`,\n // HEAD can't have body as a response, so we use GET\n {\n method: 'GET',\n signal: options?.abortSignal,\n },\n options,\n );\n\n return {\n url: response.url,\n downloadUrl: response.downloadUrl,\n pathname: response.pathname,\n size: response.size,\n contentType: response.contentType,\n contentDisposition: response.contentDisposition,\n cacheControl: response.cacheControl,\n uploadedAt: new Date(response.uploadedAt),\n };\n}\n","import { requestApi } from './api';\nimport type { BlobCommandOptions } from './helpers';\n\n/**\n * Basic blob object information returned by the list method.\n */\nexport interface ListBlobResultBlob {\n /**\n * The URL of the blob.\n */\n url: string;\n\n /**\n * A URL that will cause browsers to download the file instead of displaying it inline.\n */\n downloadUrl: string;\n\n /**\n * The pathname of the blob within the store.\n */\n pathname: string;\n\n /**\n * The size of the blob in bytes.\n */\n size: number;\n\n /**\n * The date when the blob was uploaded.\n */\n uploadedAt: Date;\n}\n\n/**\n * Result of the list method in expanded mode (default).\n */\nexport interface ListBlobResult {\n /**\n * Array of blob objects in the store.\n */\n blobs: ListBlobResultBlob[];\n\n /**\n * Pagination cursor for the next set of results, if hasMore is true.\n */\n cursor?: string;\n\n /**\n * Indicates if there are more results available.\n */\n hasMore: boolean;\n}\n\n/**\n * Result of the list method in folded mode.\n */\nexport interface ListFoldedBlobResult extends ListBlobResult {\n /**\n * Array of folder paths in the store.\n */\n folders: string[];\n}\n\n/**\n * @internal Internal interface for the API response blob structure.\n * Maps the API response format where uploadedAt is a string, not a Date.\n */\ninterface ListBlobApiResponseBlob\n extends Omit<ListBlobResultBlob, 'uploadedAt'> {\n uploadedAt: string;\n}\n\n/**\n * @internal Internal interface for the API response structure.\n */\ninterface ListBlobApiResponse extends Omit<ListBlobResult, 'blobs'> {\n blobs: ListBlobApiResponseBlob[];\n folders?: string[];\n}\n\n/**\n * Options for the list method.\n */\nexport interface ListCommandOptions<\n M extends 'expanded' | 'folded' | undefined = undefined,\n> extends BlobCommandOptions {\n /**\n * The maximum number of blobs to return.\n * @defaultvalue 1000\n */\n limit?: number;\n\n /**\n * Filters the result to only include blobs that start with this prefix.\n * If used together with `mode: 'folded'`, make sure to include a trailing slash after the foldername.\n */\n prefix?: string;\n\n /**\n * The cursor to use for pagination. Can be obtained from the response of a previous `list` request.\n */\n cursor?: string;\n\n /**\n * Defines how the blobs are listed\n * - `expanded` the blobs property contains all blobs.\n * - `folded` the blobs property contains only the blobs at the root level of your store. Blobs that are located inside a folder get merged into a single entry in the folder response property.\n * @defaultvalue 'expanded'\n */\n mode?: M;\n}\n\n/**\n * @internal Type helper to determine the return type based on the mode parameter.\n */\ntype ListCommandResult<\n M extends 'expanded' | 'folded' | undefined = undefined,\n> = M extends 'folded' ? ListFoldedBlobResult : ListBlobResult;\n\n/**\n * Fetches a paginated list of blob objects from your store.\n *\n * @param options - Configuration options including:\n * - token - (Optional) A string specifying the read-write token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - limit - (Optional) The maximum number of blobs to return. Defaults to 1000.\n * - prefix - (Optional) Filters the result to only include blobs that start with this prefix. If used with mode: 'folded', include a trailing slash after the folder name.\n * - cursor - (Optional) The cursor to use for pagination. Can be obtained from the response of a previous list request.\n * - mode - (Optional) Defines how the blobs are listed. Can be 'expanded' (default) or 'folded'. In folded mode, blobs located inside a folder are merged into a single entry in the folders response property.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to an object containing:\n * - blobs: An array of blob objects with size, uploadedAt, pathname, url, and downloadUrl properties\n * - cursor: A string for pagination (if hasMore is true)\n * - hasMore: A boolean indicating if there are more results available\n * - folders: (Only in 'folded' mode) An array of folder paths\n */\nexport async function list<\n M extends 'expanded' | 'folded' | undefined = undefined,\n>(options?: ListCommandOptions<M>): Promise<ListCommandResult<M>> {\n const searchParams = new URLSearchParams();\n\n if (options?.limit) {\n searchParams.set('limit', options.limit.toString());\n }\n if (options?.prefix) {\n searchParams.set('prefix', options.prefix);\n }\n if (options?.cursor) {\n searchParams.set('cursor', options.cursor);\n }\n if (options?.mode) {\n searchParams.set('mode', options.mode);\n }\n\n const response = await requestApi<ListBlobApiResponse>(\n `?${searchParams.toString()}`,\n {\n method: 'GET',\n signal: options?.abortSignal,\n },\n options,\n );\n\n if (options?.mode === 'folded') {\n return {\n folders: response.folders ?? [],\n cursor: response.cursor,\n hasMore: response.hasMore,\n blobs: response.blobs.map(mapBlobResult),\n } as ListCommandResult<M>;\n }\n\n return {\n cursor: response.cursor,\n hasMore: response.hasMore,\n blobs: response.blobs.map(mapBlobResult),\n } as ListCommandResult<M>;\n}\n\n/**\n * @internal Helper function to map API response blob format to the expected return type.\n * Converts the uploadedAt string into a Date object.\n */\nfunction mapBlobResult(\n blobResult: ListBlobApiResponseBlob,\n): ListBlobResultBlob {\n return {\n url: blobResult.url,\n downloadUrl: blobResult.downloadUrl,\n pathname: blobResult.pathname,\n size: blobResult.size,\n uploadedAt: new Date(blobResult.uploadedAt),\n };\n}\n","import { MAXIMUM_PATHNAME_LENGTH, requestApi } from './api';\nimport type { CommonCreateBlobOptions } from './helpers';\nimport { BlobError, disallowedPathnameCharacters } from './helpers';\n\nexport type CopyCommandOptions = CommonCreateBlobOptions;\n\nexport interface CopyBlobResult {\n url: string;\n downloadUrl: string;\n pathname: string;\n contentType: string;\n contentDisposition: string;\n}\n\n/**\n * Copies a blob to another location in your store.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#copy-a-blob\n *\n * @param fromUrlOrPathname - The blob URL (or pathname) to copy. You can only copy blobs that are in the store, that your 'BLOB_READ_WRITE_TOKEN' has access to.\n * @param toPathname - The pathname to copy the blob to. This includes the filename.\n * @param options - Additional options. The copy method will not preserve any metadata configuration (e.g.: 'cacheControlMaxAge') of the source blob. If you want to copy the metadata, you need to define it here again.\n */\nexport async function copy(\n fromUrlOrPathname: string,\n toPathname: string,\n options: CopyCommandOptions,\n): Promise<CopyBlobResult> {\n if (!options) {\n throw new BlobError('missing options, see usage');\n }\n\n if (options.access !== 'public' && options.access !== 'private') {\n throw new BlobError('access must be \"public\" or \"private\"');\n }\n\n if (toPathname.length > MAXIMUM_PATHNAME_LENGTH) {\n throw new BlobError(\n `pathname is too long, maximum length is ${MAXIMUM_PATHNAME_LENGTH}`,\n );\n }\n\n for (const invalidCharacter of disallowedPathnameCharacters) {\n if (toPathname.includes(invalidCharacter)) {\n throw new BlobError(\n `pathname cannot contain \"${invalidCharacter}\", please encode it if needed`,\n );\n }\n }\n\n const headers: Record<string, string> = {};\n\n // access is always required, so always add it to headers\n headers['x-vercel-blob-access'] = options.access;\n\n if (options.addRandomSuffix !== undefined) {\n headers['x-add-random-suffix'] = options.addRandomSuffix ? '1' : '0';\n }\n\n if (options.allowOverwrite !== undefined) {\n headers['x-allow-overwrite'] = options.allowOverwrite ? '1' : '0';\n }\n\n if (options.contentType) {\n headers['x-content-type'] = options.contentType;\n }\n\n if (options.cacheControlMaxAge !== undefined) {\n headers['x-cache-control-max-age'] = options.cacheControlMaxAge.toString();\n }\n\n const params = new URLSearchParams({\n pathname: toPathname,\n fromUrl: fromUrlOrPathname,\n });\n\n const response = await requestApi<CopyBlobResult>(\n `?${params.toString()}`,\n {\n method: 'PUT',\n headers,\n signal: options.abortSignal,\n },\n options,\n );\n\n return {\n url: response.url,\n downloadUrl: response.downloadUrl,\n pathname: response.pathname,\n contentType: response.contentType,\n contentDisposition: response.contentDisposition,\n };\n}\n","import type { CommonCreateBlobOptions } from './helpers';\nimport type { CompleteMultipartUploadCommandOptions } from './multipart/complete';\nimport { createCompleteMultipartUploadMethod } from './multipart/complete';\nimport { createCreateMultipartUploadMethod } from './multipart/create';\nimport { createCreateMultipartUploaderMethod } from './multipart/create-uploader';\nimport type { UploadPartCommandOptions } from './multipart/upload';\nimport { createUploadPartMethod } from './multipart/upload';\nimport type { PutCommandOptions } from './put';\nimport { createPutMethod } from './put';\n\n// expose api BlobErrors\nexport {\n BlobAccessError,\n BlobClientTokenExpiredError,\n BlobContentTypeNotAllowedError,\n BlobFileTooLargeError,\n BlobNotFoundError,\n BlobPathnameMismatchError,\n BlobRequestAbortedError,\n BlobServiceNotAvailable,\n BlobServiceRateLimited,\n BlobStoreNotFoundError,\n BlobStoreSuspendedError,\n BlobUnknownError,\n} from './api';\n// expose generic BlobError and download url util\nexport {\n BlobError,\n getDownloadUrl,\n type OnUploadProgressCallback,\n type UploadProgressEvent,\n} from './helpers';\n\n// vercelBlob.put()\n\nexport type { PutBlobResult } from './put-helpers';\nexport type { PutCommandOptions };\n\n/**\n * Uploads a blob into your store from your server.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#upload-a-blob\n *\n * If you want to upload from the browser directly, or if you're hitting Vercel upload limits, check out the documentation for client uploads: https://vercel.com/docs/vercel-blob/using-blob-sdk#client-uploads\n *\n * @param pathname - The pathname to upload the blob to, including the extension. This will influence the URL of your blob like https://$storeId.public.blob.vercel-storage.com/$pathname.\n * @param body - The content of your blob, can be a: string, File, Blob, Buffer or Stream. We support almost everything fetch supports: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' or 'private'. Public blobs are accessible via URL, private blobs require authentication.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to false. We recommend using this option to ensure there are no conflicts in your blob filenames.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.\n * - contentType - (Optional) A string indicating the media type. By default, it's extracted from the pathname's extension.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure how long Blobs are cached. Defaults to one month. Cannot be set to a value lower than 1 minute.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - multipart - (Optional) Whether to use multipart upload for large files. It will split the file into multiple parts, upload them in parallel and retry failed parts.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * - onUploadProgress - (Optional) Callback to track upload progress: onUploadProgress(\\{loaded: number, total: number, percentage: number\\})\n * @returns A promise that resolves to the blob information, including pathname, contentType, contentDisposition, url, and downloadUrl.\n */\nexport const put = createPutMethod<PutCommandOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n ],\n});\n\n// vercelBlob.del()\n\nexport { del } from './del';\n\n// vercelBlob.head()\n\nexport type { HeadBlobResult } from './head';\nexport { head } from './head';\n\n// vercelBlob.list()\n\nexport type {\n ListBlobResult,\n ListBlobResultBlob,\n ListCommandOptions,\n ListFoldedBlobResult,\n} from './list';\nexport { list } from './list';\n\n// vercelBlob.copy()\n\nexport type { CopyBlobResult, CopyCommandOptions } from './copy';\nexport { copy } from './copy';\n\n// vercelBlob. createMultipartUpload()\n// vercelBlob. uploadPart()\n// vercelBlob. completeMultipartUpload()\n// vercelBlob. createMultipartUploader()\n\n/**\n * Creates a multipart upload. This is the first step in the manual multipart upload process.\n *\n * @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' or 'private'. Public blobs are accessible via URL, private blobs require authentication.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.\n * - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to an object containing:\n * - key: A string that identifies the blob object.\n * - uploadId: A string that identifies the multipart upload. Both are needed for subsequent uploadPart calls.\n */\nexport const createMultipartUpload =\n createCreateMultipartUploadMethod<CommonCreateBlobOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n ],\n });\n\n/**\n * Creates a multipart uploader that simplifies the multipart upload process.\n * This is a wrapper around the manual multipart upload process that provides a more convenient API.\n *\n * @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' or 'private'. Public blobs are accessible via URL, private blobs require authentication.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.\n * - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to an uploader object with the following properties and methods:\n * - key: A string that identifies the blob object.\n * - uploadId: A string that identifies the multipart upload.\n * - uploadPart: A method to upload a part of the file.\n * - complete: A method to complete the multipart upload process.\n */\nexport const createMultipartUploader =\n createCreateMultipartUploaderMethod<CommonCreateBlobOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n ],\n });\n\nexport type { UploadPartCommandOptions };\n\n/**\n * Uploads a part of a multipart upload.\n * Used as part of the manual multipart upload process.\n *\n * @param pathname - Same value as the pathname parameter passed to createMultipartUpload. This will influence the final URL of your blob.\n * @param body - A blob object as ReadableStream, String, ArrayBuffer or Blob based on these supported body types. Each part must be a minimum of 5MB, except the last one which can be smaller.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' or 'private'. Public blobs are accessible via URL, private blobs require authentication.\n * - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.\n * - key - (Required) A string returned from createMultipartUpload which identifies the blob object.\n * - partNumber - (Required) A number identifying which part is uploaded (1-based index).\n * - contentType - (Optional) The media type for the blob. By default, it's derived from the pathname.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure how long Blobs are cached.\n * - abortSignal - (Optional) AbortSignal to cancel the running request.\n * - onUploadProgress - (Optional) Callback to track upload progress: onUploadProgress(\\{loaded: number, total: number, percentage: number\\})\n * @returns A promise that resolves to the uploaded part information containing etag and partNumber, which will be needed for the completeMultipartUpload call.\n */\nexport const uploadPart = createUploadPartMethod<UploadPartCommandOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n ],\n});\n\nexport type { CompleteMultipartUploadCommandOptions };\n\n/**\n * Completes a multipart upload by combining all uploaded parts.\n * This is the final step in the manual multipart upload process.\n *\n * @param pathname - Same value as the pathname parameter passed to createMultipartUpload.\n * @param parts - An array containing all the uploaded parts information from previous uploadPart calls. Each part must have properties etag and partNumber.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' or 'private'. Public blobs are accessible via URL, private blobs require authentication.\n * - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.\n * - key - (Required) A string returned from createMultipartUpload which identifies the blob object.\n * - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to the finalized blob information, including pathname, contentType, contentDisposition, url, and downloadUrl.\n */\nexport const completeMultipartUpload =\n createCompleteMultipartUploadMethod<CompleteMultipartUploadCommandOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n ],\n });\n\nexport { createFolder } from './create-folder';\nexport type { Part, PartInput } from './multipart/helpers';\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/storage/storage/packages/blob/dist/index.cjs","../src/del.ts","../src/head.ts","../src/list.ts","../src/copy.ts","../src/index.ts"],"names":[],"mappings":"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","file":"/home/runner/work/storage/storage/packages/blob/dist/index.cjs","sourcesContent":[null,"import { requestApi } from './api';\nimport type { BlobCommandOptions } from './helpers';\n\n/**\n * Deletes one or multiple blobs from your store.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#delete-a-blob\n *\n * @param urlOrPathname - Blob url (or pathname) to delete. You can pass either a single value or an array of values. You can only delete blobs that are located in a store, that your 'BLOB_READ_WRITE_TOKEN' has access to.\n * @param options - Additional options for the request.\n */\nexport async function del(\n urlOrPathname: string[] | string,\n options?: BlobCommandOptions,\n): Promise<void> {\n await requestApi(\n '/delete',\n {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n urls: Array.isArray(urlOrPathname) ? urlOrPathname : [urlOrPathname],\n }),\n signal: options?.abortSignal,\n },\n options,\n );\n}\n","import { requestApi } from './api';\nimport type { BlobCommandOptions } from './helpers';\n\n/**\n * Result of the head method containing metadata about a blob.\n */\nexport interface HeadBlobResult {\n /**\n * The size of the blob in bytes.\n */\n size: number;\n\n /**\n * The date when the blob was uploaded.\n */\n uploadedAt: Date;\n\n /**\n * The pathname of the blob within the store.\n */\n pathname: string;\n\n /**\n * The content type of the blob.\n */\n contentType: string;\n\n /**\n * The content disposition header value.\n */\n contentDisposition: string;\n\n /**\n * The URL of the blob.\n */\n url: string;\n\n /**\n * A URL that will cause browsers to download the file instead of displaying it inline.\n */\n downloadUrl: string;\n\n /**\n * The cache control header value.\n */\n cacheControl: string;\n\n /**\n * The ETag of the blob. Can be used with `ifMatch` for conditional writes.\n */\n etag: string;\n}\n\ninterface HeadBlobApiResponse extends Omit<HeadBlobResult, 'uploadedAt'> {\n uploadedAt: string; // when receiving data from our API, uploadedAt is a string\n}\n\n/**\n * Fetches metadata of a blob object.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#get-blob-metadata\n *\n * @param urlOrPathname - Blob url or pathname to lookup.\n * @param options - Additional options for the request.\n */\nexport async function head(\n urlOrPathname: string,\n options?: BlobCommandOptions,\n): Promise<HeadBlobResult> {\n const searchParams = new URLSearchParams({ url: urlOrPathname });\n\n const response = await requestApi<HeadBlobApiResponse>(\n `?${searchParams.toString()}`,\n // HEAD can't have body as a response, so we use GET\n {\n method: 'GET',\n signal: options?.abortSignal,\n },\n options,\n );\n\n return {\n url: response.url,\n downloadUrl: response.downloadUrl,\n pathname: response.pathname,\n size: response.size,\n contentType: response.contentType,\n contentDisposition: response.contentDisposition,\n cacheControl: response.cacheControl,\n uploadedAt: new Date(response.uploadedAt),\n etag: response.etag,\n };\n}\n","import { requestApi } from './api';\nimport type { BlobCommandOptions } from './helpers';\n\n/**\n * Basic blob object information returned by the list method.\n */\nexport interface ListBlobResultBlob {\n /**\n * The URL of the blob.\n */\n url: string;\n\n /**\n * A URL that will cause browsers to download the file instead of displaying it inline.\n */\n downloadUrl: string;\n\n /**\n * The pathname of the blob within the store.\n */\n pathname: string;\n\n /**\n * The size of the blob in bytes.\n */\n size: number;\n\n /**\n * The date when the blob was uploaded.\n */\n uploadedAt: Date;\n\n /**\n * The ETag of the blob. Can be used with `ifMatch` for conditional writes.\n */\n etag: string;\n}\n\n/**\n * Result of the list method in expanded mode (default).\n */\nexport interface ListBlobResult {\n /**\n * Array of blob objects in the store.\n */\n blobs: ListBlobResultBlob[];\n\n /**\n * Pagination cursor for the next set of results, if hasMore is true.\n */\n cursor?: string;\n\n /**\n * Indicates if there are more results available.\n */\n hasMore: boolean;\n}\n\n/**\n * Result of the list method in folded mode.\n */\nexport interface ListFoldedBlobResult extends ListBlobResult {\n /**\n * Array of folder paths in the store.\n */\n folders: string[];\n}\n\n/**\n * @internal Internal interface for the API response blob structure.\n * Maps the API response format where uploadedAt is a string, not a Date.\n */\ninterface ListBlobApiResponseBlob\n extends Omit<ListBlobResultBlob, 'uploadedAt'> {\n uploadedAt: string;\n}\n\n/**\n * @internal Internal interface for the API response structure.\n */\ninterface ListBlobApiResponse extends Omit<ListBlobResult, 'blobs'> {\n blobs: ListBlobApiResponseBlob[];\n folders?: string[];\n}\n\n/**\n * Options for the list method.\n */\nexport interface ListCommandOptions<\n M extends 'expanded' | 'folded' | undefined = undefined,\n> extends BlobCommandOptions {\n /**\n * The maximum number of blobs to return.\n * @defaultvalue 1000\n */\n limit?: number;\n\n /**\n * Filters the result to only include blobs that start with this prefix.\n * If used together with `mode: 'folded'`, make sure to include a trailing slash after the foldername.\n */\n prefix?: string;\n\n /**\n * The cursor to use for pagination. Can be obtained from the response of a previous `list` request.\n */\n cursor?: string;\n\n /**\n * Defines how the blobs are listed\n * - `expanded` the blobs property contains all blobs.\n * - `folded` the blobs property contains only the blobs at the root level of your store. Blobs that are located inside a folder get merged into a single entry in the folder response property.\n * @defaultvalue 'expanded'\n */\n mode?: M;\n}\n\n/**\n * @internal Type helper to determine the return type based on the mode parameter.\n */\ntype ListCommandResult<\n M extends 'expanded' | 'folded' | undefined = undefined,\n> = M extends 'folded' ? ListFoldedBlobResult : ListBlobResult;\n\n/**\n * Fetches a paginated list of blob objects from your store.\n *\n * @param options - Configuration options including:\n * - token - (Optional) A string specifying the read-write token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - limit - (Optional) The maximum number of blobs to return. Defaults to 1000.\n * - prefix - (Optional) Filters the result to only include blobs that start with this prefix. If used with mode: 'folded', include a trailing slash after the folder name.\n * - cursor - (Optional) The cursor to use for pagination. Can be obtained from the response of a previous list request.\n * - mode - (Optional) Defines how the blobs are listed. Can be 'expanded' (default) or 'folded'. In folded mode, blobs located inside a folder are merged into a single entry in the folders response property.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to an object containing:\n * - blobs: An array of blob objects with size, uploadedAt, pathname, url, and downloadUrl properties\n * - cursor: A string for pagination (if hasMore is true)\n * - hasMore: A boolean indicating if there are more results available\n * - folders: (Only in 'folded' mode) An array of folder paths\n */\nexport async function list<\n M extends 'expanded' | 'folded' | undefined = undefined,\n>(options?: ListCommandOptions<M>): Promise<ListCommandResult<M>> {\n const searchParams = new URLSearchParams();\n\n if (options?.limit) {\n searchParams.set('limit', options.limit.toString());\n }\n if (options?.prefix) {\n searchParams.set('prefix', options.prefix);\n }\n if (options?.cursor) {\n searchParams.set('cursor', options.cursor);\n }\n if (options?.mode) {\n searchParams.set('mode', options.mode);\n }\n\n const response = await requestApi<ListBlobApiResponse>(\n `?${searchParams.toString()}`,\n {\n method: 'GET',\n signal: options?.abortSignal,\n },\n options,\n );\n\n if (options?.mode === 'folded') {\n return {\n folders: response.folders ?? [],\n cursor: response.cursor,\n hasMore: response.hasMore,\n blobs: response.blobs.map(mapBlobResult),\n } as ListCommandResult<M>;\n }\n\n return {\n cursor: response.cursor,\n hasMore: response.hasMore,\n blobs: response.blobs.map(mapBlobResult),\n } as ListCommandResult<M>;\n}\n\n/**\n * @internal Helper function to map API response blob format to the expected return type.\n * Converts the uploadedAt string into a Date object.\n */\nfunction mapBlobResult(\n blobResult: ListBlobApiResponseBlob,\n): ListBlobResultBlob {\n return {\n url: blobResult.url,\n downloadUrl: blobResult.downloadUrl,\n pathname: blobResult.pathname,\n size: blobResult.size,\n uploadedAt: new Date(blobResult.uploadedAt),\n etag: blobResult.etag,\n };\n}\n","import { MAXIMUM_PATHNAME_LENGTH, requestApi } from './api';\nimport type { CommonCreateBlobOptions } from './helpers';\nimport { BlobError, disallowedPathnameCharacters } from './helpers';\n\nexport type CopyCommandOptions = CommonCreateBlobOptions;\n\nexport interface CopyBlobResult {\n url: string;\n downloadUrl: string;\n pathname: string;\n contentType: string;\n contentDisposition: string;\n /**\n * The ETag of the blob. Can be used with `ifMatch` for conditional writes.\n */\n etag: string;\n}\n\n/**\n * Copies a blob to another location in your store.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#copy-a-blob\n *\n * @param fromUrlOrPathname - The blob URL (or pathname) to copy. You can only copy blobs that are in the store, that your 'BLOB_READ_WRITE_TOKEN' has access to.\n * @param toPathname - The pathname to copy the blob to. This includes the filename.\n * @param options - Additional options. The copy method will not preserve any metadata configuration (e.g.: 'cacheControlMaxAge') of the source blob. If you want to copy the metadata, you need to define it here again.\n */\nexport async function copy(\n fromUrlOrPathname: string,\n toPathname: string,\n options: CopyCommandOptions,\n): Promise<CopyBlobResult> {\n if (!options) {\n throw new BlobError('missing options, see usage');\n }\n\n if (options.access !== 'public') {\n throw new BlobError('access must be \"public\"');\n }\n\n if (toPathname.length > MAXIMUM_PATHNAME_LENGTH) {\n throw new BlobError(\n `pathname is too long, maximum length is ${MAXIMUM_PATHNAME_LENGTH}`,\n );\n }\n\n for (const invalidCharacter of disallowedPathnameCharacters) {\n if (toPathname.includes(invalidCharacter)) {\n throw new BlobError(\n `pathname cannot contain \"${invalidCharacter}\", please encode it if needed`,\n );\n }\n }\n\n const headers: Record<string, string> = {};\n\n if (options.addRandomSuffix !== undefined) {\n headers['x-add-random-suffix'] = options.addRandomSuffix ? '1' : '0';\n }\n\n if (options.allowOverwrite !== undefined) {\n headers['x-allow-overwrite'] = options.allowOverwrite ? '1' : '0';\n }\n\n if (options.contentType) {\n headers['x-content-type'] = options.contentType;\n }\n\n if (options.cacheControlMaxAge !== undefined) {\n headers['x-cache-control-max-age'] = options.cacheControlMaxAge.toString();\n }\n\n if (options.ifMatch) {\n headers['x-if-match'] = options.ifMatch;\n }\n\n const params = new URLSearchParams({\n pathname: toPathname,\n fromUrl: fromUrlOrPathname,\n });\n\n const response = await requestApi<CopyBlobResult>(\n `?${params.toString()}`,\n {\n method: 'PUT',\n headers,\n signal: options.abortSignal,\n },\n options,\n );\n\n return {\n url: response.url,\n downloadUrl: response.downloadUrl,\n pathname: response.pathname,\n contentType: response.contentType,\n contentDisposition: response.contentDisposition,\n etag: response.etag,\n };\n}\n","import type { CommonCreateBlobOptions } from './helpers';\nimport type { CompleteMultipartUploadCommandOptions } from './multipart/complete';\nimport { createCompleteMultipartUploadMethod } from './multipart/complete';\nimport { createCreateMultipartUploadMethod } from './multipart/create';\nimport { createCreateMultipartUploaderMethod } from './multipart/create-uploader';\nimport type { UploadPartCommandOptions } from './multipart/upload';\nimport { createUploadPartMethod } from './multipart/upload';\nimport type { PutCommandOptions } from './put';\nimport { createPutMethod } from './put';\n\n// expose api BlobErrors\nexport {\n BlobAccessError,\n BlobClientTokenExpiredError,\n BlobContentTypeNotAllowedError,\n BlobFileTooLargeError,\n BlobNotFoundError,\n BlobPathnameMismatchError,\n BlobPreconditionFailedError,\n BlobRequestAbortedError,\n BlobServiceNotAvailable,\n BlobServiceRateLimited,\n BlobStoreNotFoundError,\n BlobStoreSuspendedError,\n BlobUnknownError,\n} from './api';\n// expose generic BlobError and download url util\nexport {\n BlobError,\n getDownloadUrl,\n type OnUploadProgressCallback,\n type UploadProgressEvent,\n} from './helpers';\n\n// vercelBlob.put()\n\nexport type { PutBlobResult } from './put-helpers';\nexport type { PutCommandOptions };\n\n/**\n * Uploads a blob into your store from your server.\n * Detailed documentation can be found here: https://vercel.com/docs/vercel-blob/using-blob-sdk#upload-a-blob\n *\n * If you want to upload from the browser directly, or if you're hitting Vercel upload limits, check out the documentation for client uploads: https://vercel.com/docs/vercel-blob/using-blob-sdk#client-uploads\n *\n * @param pathname - The pathname to upload the blob to, including the extension. This will influence the URL of your blob like https://$storeId.public.blob.vercel-storage.com/$pathname.\n * @param body - The content of your blob, can be a: string, File, Blob, Buffer or Stream. We support almost everything fetch supports: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' as blobs are publicly accessible.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to false. We recommend using this option to ensure there are no conflicts in your blob filenames.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.\n * - contentType - (Optional) A string indicating the media type. By default, it's extracted from the pathname's extension.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure how long Blobs are cached. Defaults to one month. Cannot be set to a value lower than 1 minute.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - multipart - (Optional) Whether to use multipart upload for large files. It will split the file into multiple parts, upload them in parallel and retry failed parts.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * - onUploadProgress - (Optional) Callback to track upload progress: onUploadProgress(\\{loaded: number, total: number, percentage: number\\})\n * @returns A promise that resolves to the blob information, including pathname, contentType, contentDisposition, url, and downloadUrl.\n */\nexport const put = createPutMethod<PutCommandOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n 'ifMatch',\n ],\n});\n\n// vercelBlob.del()\n\nexport { del } from './del';\n\n// vercelBlob.head()\n\nexport type { HeadBlobResult } from './head';\nexport { head } from './head';\n\n// vercelBlob.list()\n\nexport type {\n ListBlobResult,\n ListBlobResultBlob,\n ListCommandOptions,\n ListFoldedBlobResult,\n} from './list';\nexport { list } from './list';\n\n// vercelBlob.copy()\n\nexport type { CopyBlobResult, CopyCommandOptions } from './copy';\nexport { copy } from './copy';\n\n// vercelBlob. createMultipartUpload()\n// vercelBlob. uploadPart()\n// vercelBlob. completeMultipartUpload()\n// vercelBlob. createMultipartUploader()\n\n/**\n * Creates a multipart upload. This is the first step in the manual multipart upload process.\n *\n * @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' as blobs are publicly accessible.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.\n * - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to an object containing:\n * - key: A string that identifies the blob object.\n * - uploadId: A string that identifies the multipart upload. Both are needed for subsequent uploadPart calls.\n */\nexport const createMultipartUpload =\n createCreateMultipartUploadMethod<CommonCreateBlobOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n 'ifMatch',\n ],\n });\n\n/**\n * Creates a multipart uploader that simplifies the multipart upload process.\n * This is a wrapper around the manual multipart upload process that provides a more convenient API.\n *\n * @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' as blobs are publicly accessible.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.\n * - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to an uploader object with the following properties and methods:\n * - key: A string that identifies the blob object.\n * - uploadId: A string that identifies the multipart upload.\n * - uploadPart: A method to upload a part of the file.\n * - complete: A method to complete the multipart upload process.\n */\nexport const createMultipartUploader =\n createCreateMultipartUploaderMethod<CommonCreateBlobOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n 'ifMatch',\n ],\n });\n\nexport type { UploadPartCommandOptions };\n\n/**\n * Uploads a part of a multipart upload.\n * Used as part of the manual multipart upload process.\n *\n * @param pathname - Same value as the pathname parameter passed to createMultipartUpload. This will influence the final URL of your blob.\n * @param body - A blob object as ReadableStream, String, ArrayBuffer or Blob based on these supported body types. Each part must be a minimum of 5MB, except the last one which can be smaller.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' as blobs are publicly accessible.\n * - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.\n * - key - (Required) A string returned from createMultipartUpload which identifies the blob object.\n * - partNumber - (Required) A number identifying which part is uploaded (1-based index).\n * - contentType - (Optional) The media type for the blob. By default, it's derived from the pathname.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure how long Blobs are cached.\n * - abortSignal - (Optional) AbortSignal to cancel the running request.\n * - onUploadProgress - (Optional) Callback to track upload progress: onUploadProgress(\\{loaded: number, total: number, percentage: number\\})\n * @returns A promise that resolves to the uploaded part information containing etag and partNumber, which will be needed for the completeMultipartUpload call.\n */\nexport const uploadPart = createUploadPartMethod<UploadPartCommandOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n ],\n});\n\nexport type { CompleteMultipartUploadCommandOptions };\n\n/**\n * Completes a multipart upload by combining all uploaded parts.\n * This is the final step in the manual multipart upload process.\n *\n * @param pathname - Same value as the pathname parameter passed to createMultipartUpload.\n * @param parts - An array containing all the uploaded parts information from previous uploadPart calls. Each part must have properties etag and partNumber.\n * @param options - Configuration options including:\n * - access - (Required) Must be 'public' as blobs are publicly accessible.\n * - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.\n * - key - (Required) A string returned from createMultipartUpload which identifies the blob object.\n * - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension.\n * - token - (Optional) A string specifying the token to use when making requests. It defaults to process.env.BLOB_READ_WRITE_TOKEN when deployed on Vercel.\n * - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.\n * - allowOverwrite - (Optional) A boolean to allow overwriting blobs.\n * - cacheControlMaxAge - (Optional) A number in seconds to configure the edge and browser cache. Defaults to one year.\n * - abortSignal - (Optional) AbortSignal to cancel the operation.\n * @returns A promise that resolves to the finalized blob information, including pathname, contentType, contentDisposition, url, and downloadUrl.\n */\nexport const completeMultipartUpload =\n createCompleteMultipartUploadMethod<CompleteMultipartUploadCommandOptions>({\n allowedOptions: [\n 'cacheControlMaxAge',\n 'addRandomSuffix',\n 'allowOverwrite',\n 'contentType',\n ],\n });\n\nexport { createFolder } from './create-folder';\nexport type { Part, PartInput } from './multipart/helpers';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as CommonCreateBlobOptions, W as WithUploadProgress, f as BlobError, B as BlobCommandOptions,
|
|
2
|
-
export { O as OnUploadProgressCallback,
|
|
1
|
+
import { e as CommonCreateBlobOptions, W as WithUploadProgress, f as BlobError, B as BlobCommandOptions, a as Part, g as CompleteMultipartUploadCommandOptions, P as PutBlobResult, b as PutBody, U as UploadPartCommandOptions } from './create-folder-Bmttf9ub.cjs';
|
|
2
|
+
export { O as OnUploadProgressCallback, h as PartInput, i as UploadProgressEvent, d as createFolder, j as getDownloadUrl } from './create-folder-Bmttf9ub.cjs';
|
|
3
3
|
import 'stream';
|
|
4
4
|
import 'undici';
|
|
5
5
|
|
|
@@ -48,6 +48,9 @@ declare class BlobServiceRateLimited extends BlobError {
|
|
|
48
48
|
declare class BlobRequestAbortedError extends BlobError {
|
|
49
49
|
constructor();
|
|
50
50
|
}
|
|
51
|
+
declare class BlobPreconditionFailedError extends BlobError {
|
|
52
|
+
constructor();
|
|
53
|
+
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
56
|
* Deletes one or multiple blobs from your store.
|
|
@@ -94,6 +97,10 @@ interface HeadBlobResult {
|
|
|
94
97
|
* The cache control header value.
|
|
95
98
|
*/
|
|
96
99
|
cacheControl: string;
|
|
100
|
+
/**
|
|
101
|
+
* The ETag of the blob. Can be used with `ifMatch` for conditional writes.
|
|
102
|
+
*/
|
|
103
|
+
etag: string;
|
|
97
104
|
}
|
|
98
105
|
/**
|
|
99
106
|
* Fetches metadata of a blob object.
|
|
@@ -128,6 +135,10 @@ interface ListBlobResultBlob {
|
|
|
128
135
|
* The date when the blob was uploaded.
|
|
129
136
|
*/
|
|
130
137
|
uploadedAt: Date;
|
|
138
|
+
/**
|
|
139
|
+
* The ETag of the blob. Can be used with `ifMatch` for conditional writes.
|
|
140
|
+
*/
|
|
141
|
+
etag: string;
|
|
131
142
|
}
|
|
132
143
|
/**
|
|
133
144
|
* Result of the list method in expanded mode (default).
|
|
@@ -210,6 +221,10 @@ interface CopyBlobResult {
|
|
|
210
221
|
pathname: string;
|
|
211
222
|
contentType: string;
|
|
212
223
|
contentDisposition: string;
|
|
224
|
+
/**
|
|
225
|
+
* The ETag of the blob. Can be used with `ifMatch` for conditional writes.
|
|
226
|
+
*/
|
|
227
|
+
etag: string;
|
|
213
228
|
}
|
|
214
229
|
/**
|
|
215
230
|
* Copies a blob to another location in your store.
|
|
@@ -230,7 +245,7 @@ declare function copy(fromUrlOrPathname: string, toPathname: string, options: Co
|
|
|
230
245
|
* @param pathname - The pathname to upload the blob to, including the extension. This will influence the URL of your blob like https://$storeId.public.blob.vercel-storage.com/$pathname.
|
|
231
246
|
* @param body - The content of your blob, can be a: string, File, Blob, Buffer or Stream. We support almost everything fetch supports: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body.
|
|
232
247
|
* @param options - Configuration options including:
|
|
233
|
-
* - access - (Required) Must be 'public'
|
|
248
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
234
249
|
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to false. We recommend using this option to ensure there are no conflicts in your blob filenames.
|
|
235
250
|
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
|
|
236
251
|
* - contentType - (Optional) A string indicating the media type. By default, it's extracted from the pathname's extension.
|
|
@@ -248,7 +263,7 @@ declare const put: (pathname: string, body: PutBody, optionsInput: PutCommandOpt
|
|
|
248
263
|
*
|
|
249
264
|
* @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.
|
|
250
265
|
* @param options - Configuration options including:
|
|
251
|
-
* - access - (Required) Must be 'public'
|
|
266
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
252
267
|
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.
|
|
253
268
|
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
|
|
254
269
|
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.
|
|
@@ -269,7 +284,7 @@ declare const createMultipartUpload: (pathname: string, optionsInput: CommonCrea
|
|
|
269
284
|
*
|
|
270
285
|
* @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.
|
|
271
286
|
* @param options - Configuration options including:
|
|
272
|
-
* - access - (Required) Must be 'public'
|
|
287
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
273
288
|
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.
|
|
274
289
|
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
|
|
275
290
|
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.
|
|
@@ -299,7 +314,7 @@ declare const createMultipartUploader: (pathname: string, optionsInput: CommonCr
|
|
|
299
314
|
* @param pathname - Same value as the pathname parameter passed to createMultipartUpload. This will influence the final URL of your blob.
|
|
300
315
|
* @param body - A blob object as ReadableStream, String, ArrayBuffer or Blob based on these supported body types. Each part must be a minimum of 5MB, except the last one which can be smaller.
|
|
301
316
|
* @param options - Configuration options including:
|
|
302
|
-
* - access - (Required) Must be 'public'
|
|
317
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
303
318
|
* - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.
|
|
304
319
|
* - key - (Required) A string returned from createMultipartUpload which identifies the blob object.
|
|
305
320
|
* - partNumber - (Required) A number identifying which part is uploaded (1-based index).
|
|
@@ -321,7 +336,7 @@ declare const uploadPart: (pathname: string, body: PutBody, optionsInput: Upload
|
|
|
321
336
|
* @param pathname - Same value as the pathname parameter passed to createMultipartUpload.
|
|
322
337
|
* @param parts - An array containing all the uploaded parts information from previous uploadPart calls. Each part must have properties etag and partNumber.
|
|
323
338
|
* @param options - Configuration options including:
|
|
324
|
-
* - access - (Required) Must be 'public'
|
|
339
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
325
340
|
* - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.
|
|
326
341
|
* - key - (Required) A string returned from createMultipartUpload which identifies the blob object.
|
|
327
342
|
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension.
|
|
@@ -334,4 +349,4 @@ declare const uploadPart: (pathname: string, body: PutBody, optionsInput: Upload
|
|
|
334
349
|
*/
|
|
335
350
|
declare const completeMultipartUpload: (pathname: string, parts: Part[], optionsInput: CompleteMultipartUploadCommandOptions) => Promise<PutBlobResult>;
|
|
336
351
|
|
|
337
|
-
export { BlobAccessError, BlobClientTokenExpiredError, BlobContentTypeNotAllowedError, BlobError, BlobFileTooLargeError, BlobNotFoundError, BlobPathnameMismatchError, BlobRequestAbortedError, BlobServiceNotAvailable, BlobServiceRateLimited, BlobStoreNotFoundError, BlobStoreSuspendedError, BlobUnknownError, CompleteMultipartUploadCommandOptions, type CopyBlobResult, type CopyCommandOptions, type HeadBlobResult, type ListBlobResult, type ListBlobResultBlob, type ListCommandOptions, type ListFoldedBlobResult, Part, PutBlobResult, type PutCommandOptions, UploadPartCommandOptions, completeMultipartUpload, copy, createMultipartUpload, createMultipartUploader, del, head, list, put, uploadPart };
|
|
352
|
+
export { BlobAccessError, BlobClientTokenExpiredError, BlobContentTypeNotAllowedError, BlobError, BlobFileTooLargeError, BlobNotFoundError, BlobPathnameMismatchError, BlobPreconditionFailedError, BlobRequestAbortedError, BlobServiceNotAvailable, BlobServiceRateLimited, BlobStoreNotFoundError, BlobStoreSuspendedError, BlobUnknownError, CompleteMultipartUploadCommandOptions, type CopyBlobResult, type CopyCommandOptions, type HeadBlobResult, type ListBlobResult, type ListBlobResultBlob, type ListCommandOptions, type ListFoldedBlobResult, Part, PutBlobResult, type PutCommandOptions, UploadPartCommandOptions, completeMultipartUpload, copy, createMultipartUpload, createMultipartUploader, del, head, list, put, uploadPart };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as CommonCreateBlobOptions, W as WithUploadProgress, f as BlobError, B as BlobCommandOptions,
|
|
2
|
-
export { O as OnUploadProgressCallback,
|
|
1
|
+
import { e as CommonCreateBlobOptions, W as WithUploadProgress, f as BlobError, B as BlobCommandOptions, a as Part, g as CompleteMultipartUploadCommandOptions, P as PutBlobResult, b as PutBody, U as UploadPartCommandOptions } from './create-folder-Bmttf9ub.js';
|
|
2
|
+
export { O as OnUploadProgressCallback, h as PartInput, i as UploadProgressEvent, d as createFolder, j as getDownloadUrl } from './create-folder-Bmttf9ub.js';
|
|
3
3
|
import 'stream';
|
|
4
4
|
import 'undici';
|
|
5
5
|
|
|
@@ -48,6 +48,9 @@ declare class BlobServiceRateLimited extends BlobError {
|
|
|
48
48
|
declare class BlobRequestAbortedError extends BlobError {
|
|
49
49
|
constructor();
|
|
50
50
|
}
|
|
51
|
+
declare class BlobPreconditionFailedError extends BlobError {
|
|
52
|
+
constructor();
|
|
53
|
+
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
56
|
* Deletes one or multiple blobs from your store.
|
|
@@ -94,6 +97,10 @@ interface HeadBlobResult {
|
|
|
94
97
|
* The cache control header value.
|
|
95
98
|
*/
|
|
96
99
|
cacheControl: string;
|
|
100
|
+
/**
|
|
101
|
+
* The ETag of the blob. Can be used with `ifMatch` for conditional writes.
|
|
102
|
+
*/
|
|
103
|
+
etag: string;
|
|
97
104
|
}
|
|
98
105
|
/**
|
|
99
106
|
* Fetches metadata of a blob object.
|
|
@@ -128,6 +135,10 @@ interface ListBlobResultBlob {
|
|
|
128
135
|
* The date when the blob was uploaded.
|
|
129
136
|
*/
|
|
130
137
|
uploadedAt: Date;
|
|
138
|
+
/**
|
|
139
|
+
* The ETag of the blob. Can be used with `ifMatch` for conditional writes.
|
|
140
|
+
*/
|
|
141
|
+
etag: string;
|
|
131
142
|
}
|
|
132
143
|
/**
|
|
133
144
|
* Result of the list method in expanded mode (default).
|
|
@@ -210,6 +221,10 @@ interface CopyBlobResult {
|
|
|
210
221
|
pathname: string;
|
|
211
222
|
contentType: string;
|
|
212
223
|
contentDisposition: string;
|
|
224
|
+
/**
|
|
225
|
+
* The ETag of the blob. Can be used with `ifMatch` for conditional writes.
|
|
226
|
+
*/
|
|
227
|
+
etag: string;
|
|
213
228
|
}
|
|
214
229
|
/**
|
|
215
230
|
* Copies a blob to another location in your store.
|
|
@@ -230,7 +245,7 @@ declare function copy(fromUrlOrPathname: string, toPathname: string, options: Co
|
|
|
230
245
|
* @param pathname - The pathname to upload the blob to, including the extension. This will influence the URL of your blob like https://$storeId.public.blob.vercel-storage.com/$pathname.
|
|
231
246
|
* @param body - The content of your blob, can be a: string, File, Blob, Buffer or Stream. We support almost everything fetch supports: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body.
|
|
232
247
|
* @param options - Configuration options including:
|
|
233
|
-
* - access - (Required) Must be 'public'
|
|
248
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
234
249
|
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to false. We recommend using this option to ensure there are no conflicts in your blob filenames.
|
|
235
250
|
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
|
|
236
251
|
* - contentType - (Optional) A string indicating the media type. By default, it's extracted from the pathname's extension.
|
|
@@ -248,7 +263,7 @@ declare const put: (pathname: string, body: PutBody, optionsInput: PutCommandOpt
|
|
|
248
263
|
*
|
|
249
264
|
* @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.
|
|
250
265
|
* @param options - Configuration options including:
|
|
251
|
-
* - access - (Required) Must be 'public'
|
|
266
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
252
267
|
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.
|
|
253
268
|
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
|
|
254
269
|
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.
|
|
@@ -269,7 +284,7 @@ declare const createMultipartUpload: (pathname: string, optionsInput: CommonCrea
|
|
|
269
284
|
*
|
|
270
285
|
* @param pathname - A string specifying the path inside the blob store. This will be the base value of the return URL and includes the filename and extension.
|
|
271
286
|
* @param options - Configuration options including:
|
|
272
|
-
* - access - (Required) Must be 'public'
|
|
287
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
273
288
|
* - addRandomSuffix - (Optional) A boolean specifying whether to add a random suffix to the pathname. It defaults to true.
|
|
274
289
|
* - allowOverwrite - (Optional) A boolean to allow overwriting blobs. By default an error will be thrown if you try to overwrite a blob by using the same pathname for multiple blobs.
|
|
275
290
|
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension. Falls back to application/octet-stream when no extension exists or can't be matched.
|
|
@@ -299,7 +314,7 @@ declare const createMultipartUploader: (pathname: string, optionsInput: CommonCr
|
|
|
299
314
|
* @param pathname - Same value as the pathname parameter passed to createMultipartUpload. This will influence the final URL of your blob.
|
|
300
315
|
* @param body - A blob object as ReadableStream, String, ArrayBuffer or Blob based on these supported body types. Each part must be a minimum of 5MB, except the last one which can be smaller.
|
|
301
316
|
* @param options - Configuration options including:
|
|
302
|
-
* - access - (Required) Must be 'public'
|
|
317
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
303
318
|
* - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.
|
|
304
319
|
* - key - (Required) A string returned from createMultipartUpload which identifies the blob object.
|
|
305
320
|
* - partNumber - (Required) A number identifying which part is uploaded (1-based index).
|
|
@@ -321,7 +336,7 @@ declare const uploadPart: (pathname: string, body: PutBody, optionsInput: Upload
|
|
|
321
336
|
* @param pathname - Same value as the pathname parameter passed to createMultipartUpload.
|
|
322
337
|
* @param parts - An array containing all the uploaded parts information from previous uploadPart calls. Each part must have properties etag and partNumber.
|
|
323
338
|
* @param options - Configuration options including:
|
|
324
|
-
* - access - (Required) Must be 'public'
|
|
339
|
+
* - access - (Required) Must be 'public' as blobs are publicly accessible.
|
|
325
340
|
* - uploadId - (Required) A string returned from createMultipartUpload which identifies the multipart upload.
|
|
326
341
|
* - key - (Required) A string returned from createMultipartUpload which identifies the blob object.
|
|
327
342
|
* - contentType - (Optional) The media type for the file. If not specified, it's derived from the file extension.
|
|
@@ -334,4 +349,4 @@ declare const uploadPart: (pathname: string, body: PutBody, optionsInput: Upload
|
|
|
334
349
|
*/
|
|
335
350
|
declare const completeMultipartUpload: (pathname: string, parts: Part[], optionsInput: CompleteMultipartUploadCommandOptions) => Promise<PutBlobResult>;
|
|
336
351
|
|
|
337
|
-
export { BlobAccessError, BlobClientTokenExpiredError, BlobContentTypeNotAllowedError, BlobError, BlobFileTooLargeError, BlobNotFoundError, BlobPathnameMismatchError, BlobRequestAbortedError, BlobServiceNotAvailable, BlobServiceRateLimited, BlobStoreNotFoundError, BlobStoreSuspendedError, BlobUnknownError, CompleteMultipartUploadCommandOptions, type CopyBlobResult, type CopyCommandOptions, type HeadBlobResult, type ListBlobResult, type ListBlobResultBlob, type ListCommandOptions, type ListFoldedBlobResult, Part, PutBlobResult, type PutCommandOptions, UploadPartCommandOptions, completeMultipartUpload, copy, createMultipartUpload, createMultipartUploader, del, head, list, put, uploadPart };
|
|
352
|
+
export { BlobAccessError, BlobClientTokenExpiredError, BlobContentTypeNotAllowedError, BlobError, BlobFileTooLargeError, BlobNotFoundError, BlobPathnameMismatchError, BlobPreconditionFailedError, BlobRequestAbortedError, BlobServiceNotAvailable, BlobServiceRateLimited, BlobStoreNotFoundError, BlobStoreSuspendedError, BlobUnknownError, CompleteMultipartUploadCommandOptions, type CopyBlobResult, type CopyCommandOptions, type HeadBlobResult, type ListBlobResult, type ListBlobResultBlob, type ListCommandOptions, type ListFoldedBlobResult, Part, PutBlobResult, type PutCommandOptions, UploadPartCommandOptions, completeMultipartUpload, copy, createMultipartUpload, createMultipartUploader, del, head, list, put, uploadPart };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
BlobFileTooLargeError,
|
|
7
7
|
BlobNotFoundError,
|
|
8
8
|
BlobPathnameMismatchError,
|
|
9
|
+
BlobPreconditionFailedError,
|
|
9
10
|
BlobRequestAbortedError,
|
|
10
11
|
BlobServiceNotAvailable,
|
|
11
12
|
BlobServiceRateLimited,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
disallowedPathnameCharacters,
|
|
23
24
|
getDownloadUrl,
|
|
24
25
|
requestApi
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-NUG4TPYD.js";
|
|
26
27
|
|
|
27
28
|
// src/del.ts
|
|
28
29
|
async function del(urlOrPathname, options) {
|
|
@@ -60,7 +61,8 @@ async function head(urlOrPathname, options) {
|
|
|
60
61
|
contentType: response.contentType,
|
|
61
62
|
contentDisposition: response.contentDisposition,
|
|
62
63
|
cacheControl: response.cacheControl,
|
|
63
|
-
uploadedAt: new Date(response.uploadedAt)
|
|
64
|
+
uploadedAt: new Date(response.uploadedAt),
|
|
65
|
+
etag: response.etag
|
|
64
66
|
};
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -108,7 +110,8 @@ function mapBlobResult(blobResult) {
|
|
|
108
110
|
downloadUrl: blobResult.downloadUrl,
|
|
109
111
|
pathname: blobResult.pathname,
|
|
110
112
|
size: blobResult.size,
|
|
111
|
-
uploadedAt: new Date(blobResult.uploadedAt)
|
|
113
|
+
uploadedAt: new Date(blobResult.uploadedAt),
|
|
114
|
+
etag: blobResult.etag
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
|
|
@@ -117,8 +120,8 @@ async function copy(fromUrlOrPathname, toPathname, options) {
|
|
|
117
120
|
if (!options) {
|
|
118
121
|
throw new BlobError("missing options, see usage");
|
|
119
122
|
}
|
|
120
|
-
if (options.access !== "public"
|
|
121
|
-
throw new BlobError('access must be "public"
|
|
123
|
+
if (options.access !== "public") {
|
|
124
|
+
throw new BlobError('access must be "public"');
|
|
122
125
|
}
|
|
123
126
|
if (toPathname.length > MAXIMUM_PATHNAME_LENGTH) {
|
|
124
127
|
throw new BlobError(
|
|
@@ -133,7 +136,6 @@ async function copy(fromUrlOrPathname, toPathname, options) {
|
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
const headers = {};
|
|
136
|
-
headers["x-vercel-blob-access"] = options.access;
|
|
137
139
|
if (options.addRandomSuffix !== void 0) {
|
|
138
140
|
headers["x-add-random-suffix"] = options.addRandomSuffix ? "1" : "0";
|
|
139
141
|
}
|
|
@@ -146,6 +148,9 @@ async function copy(fromUrlOrPathname, toPathname, options) {
|
|
|
146
148
|
if (options.cacheControlMaxAge !== void 0) {
|
|
147
149
|
headers["x-cache-control-max-age"] = options.cacheControlMaxAge.toString();
|
|
148
150
|
}
|
|
151
|
+
if (options.ifMatch) {
|
|
152
|
+
headers["x-if-match"] = options.ifMatch;
|
|
153
|
+
}
|
|
149
154
|
const params = new URLSearchParams({
|
|
150
155
|
pathname: toPathname,
|
|
151
156
|
fromUrl: fromUrlOrPathname
|
|
@@ -164,7 +169,8 @@ async function copy(fromUrlOrPathname, toPathname, options) {
|
|
|
164
169
|
downloadUrl: response.downloadUrl,
|
|
165
170
|
pathname: response.pathname,
|
|
166
171
|
contentType: response.contentType,
|
|
167
|
-
contentDisposition: response.contentDisposition
|
|
172
|
+
contentDisposition: response.contentDisposition,
|
|
173
|
+
etag: response.etag
|
|
168
174
|
};
|
|
169
175
|
}
|
|
170
176
|
|
|
@@ -174,7 +180,8 @@ var put = createPutMethod({
|
|
|
174
180
|
"cacheControlMaxAge",
|
|
175
181
|
"addRandomSuffix",
|
|
176
182
|
"allowOverwrite",
|
|
177
|
-
"contentType"
|
|
183
|
+
"contentType",
|
|
184
|
+
"ifMatch"
|
|
178
185
|
]
|
|
179
186
|
});
|
|
180
187
|
var createMultipartUpload = createCreateMultipartUploadMethod({
|
|
@@ -182,7 +189,8 @@ var createMultipartUpload = createCreateMultipartUploadMethod({
|
|
|
182
189
|
"cacheControlMaxAge",
|
|
183
190
|
"addRandomSuffix",
|
|
184
191
|
"allowOverwrite",
|
|
185
|
-
"contentType"
|
|
192
|
+
"contentType",
|
|
193
|
+
"ifMatch"
|
|
186
194
|
]
|
|
187
195
|
});
|
|
188
196
|
var createMultipartUploader = createCreateMultipartUploaderMethod({
|
|
@@ -190,7 +198,8 @@ var createMultipartUploader = createCreateMultipartUploaderMethod({
|
|
|
190
198
|
"cacheControlMaxAge",
|
|
191
199
|
"addRandomSuffix",
|
|
192
200
|
"allowOverwrite",
|
|
193
|
-
"contentType"
|
|
201
|
+
"contentType",
|
|
202
|
+
"ifMatch"
|
|
194
203
|
]
|
|
195
204
|
});
|
|
196
205
|
var uploadPart = createUploadPartMethod({
|
|
@@ -217,6 +226,7 @@ export {
|
|
|
217
226
|
BlobFileTooLargeError,
|
|
218
227
|
BlobNotFoundError,
|
|
219
228
|
BlobPathnameMismatchError,
|
|
229
|
+
BlobPreconditionFailedError,
|
|
220
230
|
BlobRequestAbortedError,
|
|
221
231
|
BlobServiceNotAvailable,
|
|
222
232
|
BlobServiceRateLimited,
|