@payloadcms/storage-vercel-blob 3.0.0-alpha.63 → 3.0.0-alpha.64

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/index.ts +0 -133
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-vercel-blob",
3
- "version": "3.0.0-alpha.63",
3
+ "version": "3.0.0-alpha.64",
4
4
  "description": "Payload storage adapter for Vercel Blob Storage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,14 +21,14 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@payloadcms/plugin-cloud-storage": "3.0.0-alpha.63"
24
+ "@payloadcms/plugin-cloud-storage": "3.0.0-alpha.64"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@vercel/blob": "^0.22.3",
28
- "payload": "3.0.0-alpha.63"
28
+ "payload": "3.0.0-alpha.64"
29
29
  },
30
30
  "peerDependencies": {
31
- "payload": "3.0.0-alpha.63"
31
+ "payload": "3.0.0-alpha.64"
32
32
  },
33
33
  "engines": {
34
34
  "node": ">=18.20.2"
package/src/index.ts DELETED
@@ -1,133 +0,0 @@
1
- import type {
2
- PluginOptions as CloudStoragePluginOptions,
3
- CollectionOptions,
4
- } from '@payloadcms/plugin-cloud-storage/types'
5
- import type { Adapter, GeneratedAdapter } from '@payloadcms/plugin-cloud-storage/types'
6
- import type { Config, Plugin } from 'payload/config'
7
-
8
- import { cloudStorage } from '@payloadcms/plugin-cloud-storage'
9
-
10
- import { getGenerateUrl } from './generateURL.js'
11
- import { getHandleDelete } from './handleDelete.js'
12
- import { getHandleUpload } from './handleUpload.js'
13
- import { getStaticHandler } from './staticHandler.js'
14
-
15
- export type VercelBlobStorageOptions = {
16
- /**
17
- * Access control level
18
- *
19
- * @default 'public'
20
- */
21
- access?: 'public'
22
-
23
- /**
24
- * Add a random suffix to the uploaded file name
25
- *
26
- * @default false
27
- */
28
- addRandomSuffix?: boolean
29
-
30
- /**
31
- * Cache-Control max-age in seconds
32
- *
33
- * @default 31536000 (1 year)
34
- */
35
- cacheControlMaxAge?: number
36
-
37
- /**
38
- * Collections to apply the Vercel Blob adapter to
39
- */
40
- collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>
41
-
42
- /**
43
- * Whether or not to enable the plugin
44
- *
45
- * Default: true
46
- */
47
- enabled?: boolean
48
-
49
- /**
50
- * Vercel Blob storage read/write token
51
- *
52
- * Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel
53
- */
54
- token: string
55
- }
56
-
57
- const defaultUploadOptions: Partial<VercelBlobStorageOptions> = {
58
- access: 'public',
59
- addRandomSuffix: false,
60
- cacheControlMaxAge: 60 * 60 * 24 * 365, // 1 year
61
- enabled: true,
62
- }
63
-
64
- type VercelBlobStoragePlugin = (vercelBlobStorageOpts: VercelBlobStorageOptions) => Plugin
65
-
66
- export const vercelBlobStorage: VercelBlobStoragePlugin =
67
- (options: VercelBlobStorageOptions) =>
68
- (incomingConfig: Config): Config => {
69
- if (options.enabled === false) {
70
- return incomingConfig
71
- }
72
-
73
- if (!options.token) {
74
- throw new Error('The token argument is required for the Vercel Blob adapter.')
75
- }
76
-
77
- // Parse storeId from token
78
- const storeId = options.token.match(/^vercel_blob_rw_([a-z\d]+)_[a-z\d]+$/i)?.[1]?.toLowerCase()
79
-
80
- if (!storeId) {
81
- throw new Error(
82
- 'Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.',
83
- )
84
- }
85
-
86
- const optionsWithDefaults = {
87
- ...defaultUploadOptions,
88
- ...options,
89
- }
90
-
91
- const baseUrl = `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`
92
-
93
- const adapter = vercelBlobStorageInternal({ ...optionsWithDefaults, baseUrl })
94
-
95
- // Add adapter to each collection option object
96
- const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(
97
- options.collections,
98
- ).reduce(
99
- (acc, [slug, collOptions]) => ({
100
- ...acc,
101
- [slug]: {
102
- ...(collOptions === true ? {} : collOptions),
103
- adapter,
104
- },
105
- }),
106
- {} as Record<string, CollectionOptions>,
107
- )
108
-
109
- return cloudStorage({
110
- collections: collectionsWithAdapter,
111
- })(incomingConfig)
112
- }
113
-
114
- function vercelBlobStorageInternal(
115
- options: VercelBlobStorageOptions & { baseUrl: string },
116
- ): Adapter {
117
- return ({ collection, prefix }): GeneratedAdapter => {
118
- const { access, addRandomSuffix, baseUrl, cacheControlMaxAge, token } = options
119
- return {
120
- generateURL: getGenerateUrl({ baseUrl, prefix }),
121
- handleDelete: getHandleDelete({ baseUrl, prefix, token: options.token }),
122
- handleUpload: getHandleUpload({
123
- access,
124
- addRandomSuffix,
125
- baseUrl,
126
- cacheControlMaxAge,
127
- prefix,
128
- token,
129
- }),
130
- staticHandler: getStaticHandler({ baseUrl, token }, collection),
131
- }
132
- }
133
- }