@payloadcms/storage-vercel-blob 3.0.0-beta.18 → 3.0.0-beta.20
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/README.md +49 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
# Vercel Blob Storage
|
|
1
|
+
# Vercel Blob Storage for Payload
|
|
2
|
+
|
|
3
|
+
This package provides a simple way to use [Vercel Blob](https://vercel.com/docs/storage/vercel-blob) storage with Payload.
|
|
4
|
+
|
|
5
|
+
**NOTE:** This package removes the need to use `@payloadcms/plugin-cloud-storage` as was needed in Payload 2.x.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @payloadcms/storage-vercel-blob
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
- Configure the `collections` object to specify which collections should use the Vercel Blob adapter. The slug _must_ match one of your existing collection slugs.
|
|
16
|
+
- Ensure you have `BLOB_READ_WRITE_TOKEN` set in your Vercel environment variables. This is usually set by Vercel automatically after adding blob storage to your project.
|
|
17
|
+
- When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'
|
|
21
|
+
import { Media } from './collections/Media'
|
|
22
|
+
import { MediaWithPrefix } from './collections/MediaWithPrefix'
|
|
23
|
+
|
|
24
|
+
export default buildConfig({
|
|
25
|
+
collections: [Media, MediaWithPrefix],
|
|
26
|
+
plugins: [
|
|
27
|
+
vercelBlobStorage({
|
|
28
|
+
enabled: true, // Optional, defaults to true
|
|
29
|
+
// Specify which collections should use Vercel Blob
|
|
30
|
+
collections: {
|
|
31
|
+
[Media.slug]: true,
|
|
32
|
+
[MediaWithPrefix.slug]: {
|
|
33
|
+
prefix: 'my-prefix',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
// Token provided by Vercel once Blob storage is added to your Vercel project
|
|
37
|
+
token: process.env.BLOB_READ_WRITE_TOKEN,
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Option | Description | Default |
|
|
44
|
+
| -------------------- | -------------------------------------------------------------------- | ----------------------------- |
|
|
45
|
+
| `enabled` | Whether or not to enable the plugin | `true` |
|
|
46
|
+
| `collections` | Collections to apply the Vercel Blob adapter to | |
|
|
47
|
+
| `addRandomSuffix` | Add a random suffix to the uploaded file name in Vercel Blob storage | `false` |
|
|
48
|
+
| `cacheControlMaxAge` | Cache-Control max-age in seconds | `365 * 24 * 60 * 60` (1 Year) |
|
|
49
|
+
| `token` | Vercel Blob storage read/write token | `''` |
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
|
2
2
|
import type { Plugin } from 'payload/config';
|
|
3
3
|
export type VercelBlobStorageOptions = {
|
|
4
4
|
/**
|
|
5
|
-
* Access control level
|
|
5
|
+
* Access control level. Currently, only 'public' is supported.
|
|
6
|
+
* Vercel plans on adding support for private blobs in the future.
|
|
6
7
|
*
|
|
7
8
|
* @default 'public'
|
|
8
9
|
*/
|
|
9
10
|
access?: 'public';
|
|
10
11
|
/**
|
|
11
|
-
* Add a random suffix to the uploaded file name
|
|
12
|
+
* Add a random suffix to the uploaded file name in Vercel Blob storage
|
|
12
13
|
*
|
|
13
14
|
* @default false
|
|
14
15
|
*/
|
|
@@ -16,7 +17,7 @@ export type VercelBlobStorageOptions = {
|
|
|
16
17
|
/**
|
|
17
18
|
* Cache-Control max-age in seconds
|
|
18
19
|
*
|
|
19
|
-
* @
|
|
20
|
+
* @defaultvalue 365 * 24 * 60 * 60 (1 Year)
|
|
20
21
|
*/
|
|
21
22
|
cacheControlMaxAge?: number;
|
|
22
23
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AASpD,MAAM,MAAM,wBAAwB,GAAG;IACrC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,gBAAgB,CAAA;AASpD,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IAEjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAEtE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AASD,KAAK,uBAAuB,GAAG,CAAC,qBAAqB,EAAE,wBAAwB,KAAK,MAAM,CAAA;AAE1F,eAAO,MAAM,iBAAiB,EAAE,uBAgE7B,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Adapter, GeneratedAdapter } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateUrl } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getStaticHandler } from './staticHandler.js'\n\nexport type VercelBlobStorageOptions = {\n /**\n * Access control level
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Adapter, GeneratedAdapter } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateUrl } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getStaticHandler } from './staticHandler.js'\n\nexport type VercelBlobStorageOptions = {\n /**\n * Access control level. Currently, only 'public' is supported.\n * Vercel plans on adding support for private blobs in the future.\n *\n * @default 'public'\n */\n access?: 'public'\n\n /**\n * Add a random suffix to the uploaded file name in Vercel Blob storage\n *\n * @default false\n */\n addRandomSuffix?: boolean\n\n /**\n * Cache-Control max-age in seconds\n *\n * @defaultvalue 365 * 24 * 60 * 60 (1 Year)\n */\n cacheControlMaxAge?: number\n\n /**\n * Collections to apply the Vercel Blob adapter to\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Vercel Blob storage read/write token\n *\n * Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel\n */\n token: string\n}\n\nconst defaultUploadOptions: Partial<VercelBlobStorageOptions> = {\n access: 'public',\n addRandomSuffix: false,\n cacheControlMaxAge: 60 * 60 * 24 * 365, // 1 year\n enabled: true,\n}\n\ntype VercelBlobStoragePlugin = (vercelBlobStorageOpts: VercelBlobStorageOptions) => Plugin\n\nexport const vercelBlobStorage: VercelBlobStoragePlugin =\n (options: VercelBlobStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (options.enabled === false) {\n return incomingConfig\n }\n\n if (!options.token) {\n throw new Error('The token argument is required for the Vercel Blob adapter.')\n }\n\n // Parse storeId from token\n const storeId = options.token.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]?.toLowerCase()\n\n if (!storeId) {\n throw new Error(\n 'Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.',\n )\n }\n\n const optionsWithDefaults = {\n ...defaultUploadOptions,\n ...options,\n }\n\n const baseUrl = `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`\n\n const adapter = vercelBlobStorageInternal({ ...optionsWithDefaults, baseUrl })\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction vercelBlobStorageInternal(\n options: VercelBlobStorageOptions & { baseUrl: string },\n): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n const { access, addRandomSuffix, baseUrl, cacheControlMaxAge, token } = options\n return {\n name: 'vercel-blob',\n generateURL: getGenerateUrl({ baseUrl, prefix }),\n handleDelete: getHandleDelete({ baseUrl, prefix, token: options.token }),\n handleUpload: getHandleUpload({\n access,\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n prefix,\n token,\n }),\n staticHandler: getStaticHandler({ baseUrl, token }, collection),\n }\n }\n}\n"],"names":["cloudStorage","getGenerateUrl","getHandleDelete","getHandleUpload","getStaticHandler","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","incomingConfig","token","Error","storeId","match","toLowerCase","optionsWithDefaults","baseUrl","adapter","vercelBlobStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","prefix","name","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAOA,SAASA,YAAY,QAAQ,mCAAkC;AAE/D,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,gBAAgB,QAAQ,qBAAoB;AA6CrD,MAAMC,uBAA0D;IAC9DC,QAAQ;IACRC,iBAAiB;IACjBC,oBAAoB,KAAK,KAAK,KAAK;IACnCC,SAAS;AACX;AAIA,OAAO,MAAMC,oBACX,CAACC,UACD,CAACC;QACC,IAAID,QAAQF,OAAO,KAAK,OAAO;YAC7B,OAAOG;QACT;QAEA,IAAI,CAACD,QAAQE,KAAK,EAAE;YAClB,MAAM,IAAIC,MAAM;QAClB;QAEA,2BAA2B;QAC3B,MAAMC,UAAUJ,QAAQE,KAAK,CAACG,KAAK,CAAC,0CAA0C,CAAC,EAAE,EAAEC;QAEnF,IAAI,CAACF,SAAS;YACZ,MAAM,IAAID,MACR;QAEJ;QAEA,MAAMI,sBAAsB;YAC1B,GAAGb,oBAAoB;YACvB,GAAGM,OAAO;QACZ;QAE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gBACAY;gBACAX;gBACA2B;gBACAtB;YACF;YACA2B,eAAepC,iBAAiB;gBAAEe;gBAASN;YAAM,GAAGmB;QACtD;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-vercel-blob",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.20",
|
|
4
4
|
"description": "Payload storage adapter for Vercel Blob Storage",
|
|
5
|
+
"homepage": "https://payloadcms.com",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/payloadcms/payload.git",
|
|
8
9
|
"directory": "packages/storage-vercel-blob"
|
|
9
10
|
},
|
|
10
11
|
"license": "MIT",
|
|
11
|
-
"homepage": "https://payloadcms.com",
|
|
12
12
|
"author": "Payload CMS, Inc.",
|
|
13
|
-
"main": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
13
|
"type": "module",
|
|
16
14
|
"exports": {
|
|
17
15
|
".": {
|
|
@@ -20,27 +18,29 @@
|
|
|
20
18
|
"types": "./dist/index.d.ts"
|
|
21
19
|
}
|
|
22
20
|
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
23
26
|
"dependencies": {
|
|
24
27
|
"@vercel/blob": "^0.22.3",
|
|
25
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.
|
|
28
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.20"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"payload": "3.0.0-beta.
|
|
31
|
+
"payload": "3.0.0-beta.20"
|
|
29
32
|
},
|
|
30
33
|
"peerDependencies": {
|
|
31
|
-
"payload": "3.0.0-beta.
|
|
34
|
+
"payload": "3.0.0-beta.20"
|
|
32
35
|
},
|
|
33
36
|
"engines": {
|
|
34
37
|
"node": ">=18.20.2"
|
|
35
38
|
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "pnpm build:swc && pnpm build:types",
|
|
41
|
+
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
41
42
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
42
43
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
43
|
-
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
44
44
|
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
45
45
|
}
|
|
46
46
|
}
|