@payloadcms/storage-vercel-blob 4.0.0-internal.5b1e7cd → 4.0.0-internal.5f0cd13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"VercelBlobClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,kCAAkC,GAAG;IAC/C,eAAe,EAAE,OAAO,CAAA;IACxB,oBAAoB,EAAE,OAAO,CAAA;CAC9B,CAAA;AASD,eAAO,MAAM,6BAA6B;;;;;;;aAMpB,OAAO,aAmCzB,CAAA"}
1
+ {"version":3,"file":"VercelBlobClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,kCAAkC,GAAG;IAC/C,eAAe,EAAE,OAAO,CAAA;IACxB,oBAAoB,EAAE,OAAO,CAAA;CAC9B,CAAA;AASD,eAAO,MAAM,6BAA6B;;;;;;;iCAyCtC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getClientUploadRoute.d.ts","sourceRoot":"","sources":["../src/getClientUploadRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAKnF,KAAK,IAAI,GAAG;IACV,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE;QACd,cAAc,EAAE,oBAAoB,CAAA;QACpC,GAAG,EAAE,cAAc,CAAA;KACpB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAChC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAID,eAAO,MAAM,oBAAoB,2DAC0C,IAAI,KAAG,cA+B/E,CAAA"}
1
+ {"version":3,"file":"getClientUploadRoute.d.ts","sourceRoot":"","sources":["../src/getClientUploadRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAKnF,KAAK,IAAI,GAAG;IACV,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE;QACd,cAAc,EAAE,oBAAoB,CAAA;QACpC,GAAG,EAAE,cAAc,CAAA;KACpB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAChC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAID,eAAO,MAAM,oBAAoB,GAC9B,wDAAwE,IAAI,KAAG,cA+B/E,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ClientUploadsConfig, CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
2
- import type { Plugin, UploadCollectionSlug } from 'payload';
2
+ import type { StorageAdapter, UploadCollectionSlug } from 'payload';
3
3
  export type VercelBlobStorageOptions = {
4
4
  /**
5
5
  * Access control level. Currently, only 'public' is supported.
@@ -67,7 +67,7 @@ export type VercelBlobStorageOptions = {
67
67
  */
68
68
  useCompositePrefixes?: boolean;
69
69
  };
70
- type VercelBlobStoragePlugin = (vercelBlobStorageOpts: VercelBlobStorageOptions) => Plugin;
71
- export declare const vercelBlobStorage: VercelBlobStoragePlugin;
70
+ type VercelBlobStorageFactory = (vercelBlobStorageOpts: VercelBlobStorageOptions) => StorageAdapter;
71
+ export declare const vercelBlobStorage: VercelBlobStorageFactory;
72
72
  export {};
73
73
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MA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E,OAAO,CAAA;IAE5B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IAEnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAE7F;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAEzB;;;;;;;;;;;;OAYG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AASD,KAAK,wBAAwB,GAAG,CAAC,qBAAqB,EAAE,wBAAwB,KAAK,cAAc,CAAA;AAEnG,eAAO,MAAM,iBAAiB,EAAE,wBA0H9B,CAAA"}
package/dist/index.js CHANGED
@@ -8,94 +8,98 @@ const defaultUploadOptions = {
8
8
  cacheControlMaxAge: 60 * 60 * 24 * 365,
9
9
  enabled: true
10
10
  };
11
- export const vercelBlobStorage = (options)=>(incomingConfig)=>{
12
- // Parse storeId from token
13
- const storeId = options.token?.match(/^vercel_blob_rw_([a-z\d]+)_[a-z\d]+$/i)?.[1]?.toLowerCase();
14
- const isPluginDisabled = options.enabled === false || !options.token;
15
- // Don't throw if the plugin is disabled
16
- if (!storeId && !isPluginDisabled) {
17
- throw new Error('Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.');
18
- }
19
- const optionsWithDefaults = {
20
- ...defaultUploadOptions,
21
- ...options
22
- };
23
- // support overriding the base URL for emulator https://github.com/payloadcms/vercel-blob-emulator
24
- const baseUrl = process.env.STORAGE_VERCEL_BLOB_BASE_URL || `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`;
25
- initClientUploads({
26
- clientHandler: '@payloadcms/storage-vercel-blob/client#VercelBlobClientUploadHandler',
27
- collections: options.collections,
28
- config: incomingConfig,
29
- enabled: !isPluginDisabled && Boolean(options.clientUploads),
30
- extraClientHandlerProps: ()=>({
31
- addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
32
- useCompositePrefixes: !!options.useCompositePrefixes
11
+ export const vercelBlobStorage = (options)=>({
12
+ name: 'vercel-blob',
13
+ collections: Object.keys(options.collections),
14
+ init: (incomingConfig)=>{
15
+ // Parse storeId from token
16
+ const storeId = options.token?.match(/^vercel_blob_rw_([a-z\d]+)_[a-z\d]+$/i)?.[1]?.toLowerCase();
17
+ const isPluginDisabled = options.enabled === false || !options.token;
18
+ // Don't throw if the plugin is disabled
19
+ if (!storeId && !isPluginDisabled) {
20
+ throw new Error('Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.');
21
+ }
22
+ const optionsWithDefaults = {
23
+ ...defaultUploadOptions,
24
+ ...options
25
+ };
26
+ // support overriding the base URL for emulator https://github.com/payloadcms/vercel-blob-emulator
27
+ const baseUrl = process.env.STORAGE_VERCEL_BLOB_BASE_URL || `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`;
28
+ initClientUploads({
29
+ clientHandler: '@payloadcms/storage-vercel-blob/client#VercelBlobClientUploadHandler',
30
+ collections: options.collections,
31
+ config: incomingConfig,
32
+ enabled: !isPluginDisabled && Boolean(options.clientUploads),
33
+ extraClientHandlerProps: ()=>({
34
+ addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
35
+ useCompositePrefixes: !!options.useCompositePrefixes
36
+ }),
37
+ serverHandler: getClientUploadRoute({
38
+ access: typeof options.clientUploads === 'object' ? options.clientUploads.access : undefined,
39
+ addRandomSuffix: optionsWithDefaults.addRandomSuffix,
40
+ cacheControlMaxAge: options.cacheControlMaxAge,
41
+ token: options.token ?? ''
33
42
  }),
34
- serverHandler: getClientUploadRoute({
35
- access: typeof options.clientUploads === 'object' ? options.clientUploads.access : undefined,
43
+ serverHandlerPath: '/vercel-blob-client-upload-route'
44
+ });
45
+ // If the plugin is disabled or no token is provided, do not enable the plugin
46
+ if (isPluginDisabled) {
47
+ if (options.alwaysInsertFields) {
48
+ const collectionsWithoutAdapter = Object.entries(options.collections).reduce((acc, [slug, collOptions])=>({
49
+ ...acc,
50
+ [slug]: {
51
+ ...collOptions === true ? {} : collOptions,
52
+ adapter: null
53
+ }
54
+ }), {});
55
+ return cloudStoragePlugin({
56
+ alwaysInsertFields: true,
57
+ collections: collectionsWithoutAdapter,
58
+ enabled: false,
59
+ useCompositePrefixes: options.useCompositePrefixes
60
+ })(incomingConfig);
61
+ }
62
+ return incomingConfig;
63
+ }
64
+ const adapter = createVercelBlobAdapter({
65
+ access: optionsWithDefaults.access ?? 'public',
36
66
  addRandomSuffix: optionsWithDefaults.addRandomSuffix,
37
- cacheControlMaxAge: options.cacheControlMaxAge,
38
- token: options.token ?? ''
39
- }),
40
- serverHandlerPath: '/vercel-blob-client-upload-route'
41
- });
42
- // If the plugin is disabled or no token is provided, do not enable the plugin
43
- if (isPluginDisabled) {
44
- if (options.alwaysInsertFields) {
45
- const collectionsWithoutAdapter = Object.entries(options.collections).reduce((acc, [slug, collOptions])=>({
46
- ...acc,
47
- [slug]: {
48
- ...collOptions === true ? {} : collOptions,
49
- adapter: null
67
+ baseUrl,
68
+ cacheControlMaxAge: optionsWithDefaults.cacheControlMaxAge ?? 60 * 60 * 24 * 365,
69
+ clientUploads: optionsWithDefaults.clientUploads,
70
+ token: options.token,
71
+ useCompositePrefixes: options.useCompositePrefixes
72
+ });
73
+ // Add adapter to each collection option object
74
+ const collectionsWithAdapter = Object.entries(options.collections).reduce((acc, [slug, collOptions])=>({
75
+ ...acc,
76
+ [slug]: {
77
+ ...collOptions === true ? {} : collOptions,
78
+ adapter
79
+ }
80
+ }), {});
81
+ // Set disableLocalStorage: true for collections specified in the plugin options
82
+ const config = {
83
+ ...incomingConfig,
84
+ collections: (incomingConfig.collections || []).map((collection)=>{
85
+ if (!collectionsWithAdapter[collection.slug]) {
86
+ return collection;
87
+ }
88
+ return {
89
+ ...collection,
90
+ upload: {
91
+ ...typeof collection.upload === 'object' ? collection.upload : {},
92
+ disableLocalStorage: true
50
93
  }
51
- }), {});
52
- return cloudStoragePlugin({
53
- alwaysInsertFields: true,
54
- collections: collectionsWithoutAdapter,
55
- enabled: false,
56
- useCompositePrefixes: options.useCompositePrefixes
57
- })(incomingConfig);
58
- }
59
- return incomingConfig;
94
+ };
95
+ })
96
+ };
97
+ return cloudStoragePlugin({
98
+ alwaysInsertFields: options.alwaysInsertFields,
99
+ collections: collectionsWithAdapter,
100
+ useCompositePrefixes: options.useCompositePrefixes
101
+ })(config);
60
102
  }
61
- const adapter = createVercelBlobAdapter({
62
- access: optionsWithDefaults.access ?? 'public',
63
- addRandomSuffix: optionsWithDefaults.addRandomSuffix,
64
- baseUrl,
65
- cacheControlMaxAge: optionsWithDefaults.cacheControlMaxAge ?? 60 * 60 * 24 * 365,
66
- clientUploads: optionsWithDefaults.clientUploads,
67
- token: options.token,
68
- useCompositePrefixes: options.useCompositePrefixes
69
- });
70
- // Add adapter to each collection option object
71
- const collectionsWithAdapter = Object.entries(options.collections).reduce((acc, [slug, collOptions])=>({
72
- ...acc,
73
- [slug]: {
74
- ...collOptions === true ? {} : collOptions,
75
- adapter
76
- }
77
- }), {});
78
- // Set disableLocalStorage: true for collections specified in the plugin options
79
- const config = {
80
- ...incomingConfig,
81
- collections: (incomingConfig.collections || []).map((collection)=>{
82
- if (!collectionsWithAdapter[collection.slug]) {
83
- return collection;
84
- }
85
- return {
86
- ...collection,
87
- upload: {
88
- ...typeof collection.upload === 'object' ? collection.upload : {},
89
- disableLocalStorage: true
90
- }
91
- };
92
- })
93
- };
94
- return cloudStoragePlugin({
95
- alwaysInsertFields: options.alwaysInsertFields,
96
- collections: collectionsWithAdapter,
97
- useCompositePrefixes: options.useCompositePrefixes
98
- })(config);
99
- };
103
+ });
100
104
 
101
105
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport type { VercelBlobClientUploadHandlerExtra } from './client/VercelBlobClientUploadHandler.js'\n\nimport { createVercelBlobAdapter } from './adapter.js'\nimport { getClientUploadRoute } from './getClientUploadRoute.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 * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n\n /**\n * Cache-Control max-age in seconds\n *\n * @default 365 * 24 * 60 * 60 // (1 Year)\n */\n cacheControlMaxAge?: number\n\n /**\n * Do uploads directly on the client, to bypass limits on Vercel.\n */\n clientUploads?: ClientUploadsConfig\n\n /**\n * Collections to apply the Vercel Blob adapter to\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Vercel Blob storage read/write token\n *\n * Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel\n *\n * If unset, the plugin will be disabled and will fallback to local storage\n */\n token: string | undefined\n\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), document prefix overrides collection\n * prefix entirely.\n *\n * Example:\n * - collection prefix: `collection-prefix/`\n * - document prefix: `document-prefix/`\n * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`\n * - resulting prefix with useCompositePrefixes=false: `document-prefix/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\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 // Parse storeId from token\n const storeId = options.token\n ?.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]\n ?.toLowerCase()\n\n const isPluginDisabled = options.enabled === false || !options.token\n\n // Don't throw if the plugin is disabled\n if (!storeId && !isPluginDisabled) {\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 // support overriding the base URL for emulator https://github.com/payloadcms/vercel-blob-emulator\n const baseUrl =\n process.env.STORAGE_VERCEL_BLOB_BASE_URL ||\n `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`\n\n initClientUploads<\n VercelBlobClientUploadHandlerExtra,\n VercelBlobStorageOptions['collections'][string]\n >({\n clientHandler: '@payloadcms/storage-vercel-blob/client#VercelBlobClientUploadHandler',\n collections: options.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(options.clientUploads),\n extraClientHandlerProps: () => ({\n addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,\n useCompositePrefixes: !!options.useCompositePrefixes,\n }),\n serverHandler: getClientUploadRoute({\n access:\n typeof options.clientUploads === 'object' ? options.clientUploads.access : undefined,\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n cacheControlMaxAge: options.cacheControlMaxAge,\n token: options.token ?? '',\n }),\n serverHandlerPath: '/vercel-blob-client-upload-route',\n })\n\n // If the plugin is disabled or no token is provided, do not enable the plugin\n if (isPluginDisabled) {\n if (options.alwaysInsertFields) {\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: { ...(collOptions === true ? {} : collOptions), adapter: null },\n }),\n {} as Record<string, CollectionOptions>,\n )\n return cloudStoragePlugin({\n alwaysInsertFields: true,\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: options.useCompositePrefixes,\n })(incomingConfig)\n }\n return incomingConfig\n }\n\n const adapter = createVercelBlobAdapter({\n access: optionsWithDefaults.access ?? 'public',\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n baseUrl,\n cacheControlMaxAge: optionsWithDefaults.cacheControlMaxAge ?? 60 * 60 * 24 * 365,\n clientUploads: optionsWithDefaults.clientUploads,\n token: options.token!,\n useCompositePrefixes: options.useCompositePrefixes,\n })\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 cloudStoragePlugin({\n alwaysInsertFields: options.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: options.useCompositePrefixes,\n })(config)\n }\n"],"names":["cloudStoragePlugin","initClientUploads","createVercelBlobAdapter","getClientUploadRoute","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","incomingConfig","storeId","token","match","toLowerCase","isPluginDisabled","Error","optionsWithDefaults","baseUrl","process","env","STORAGE_VERCEL_BLOB_BASE_URL","clientHandler","collections","config","Boolean","clientUploads","extraClientHandlerProps","useCompositePrefixes","serverHandler","undefined","serverHandlerPath","alwaysInsertFields","collectionsWithoutAdapter","Object","entries","reduce","acc","slug","collOptions","adapter","collectionsWithAdapter","map","collection","upload","disableLocalStorage"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAI9E,SAASC,uBAAuB,QAAQ,eAAc;AACtD,SAASC,oBAAoB,QAAQ,4BAA2B;AA6EhE,MAAMC,uBAA0D;IAC9DC,QAAQ;IACRC,iBAAiB;IACjBC,oBAAoB,KAAK,KAAK,KAAK;IACnCC,SAAS;AACX;AAIA,OAAO,MAAMC,oBACX,CAACC,UACD,CAACC;QACC,2BAA2B;QAC3B,MAAMC,UAAUF,QAAQG,KAAK,EACzBC,MAAM,0CAA0C,CAAC,EAAE,EACnDC;QAEJ,MAAMC,mBAAmBN,QAAQF,OAAO,KAAK,SAAS,CAACE,QAAQG,KAAK;QAEpE,wCAAwC;QACxC,IAAI,CAACD,WAAW,CAACI,kBAAkB;YACjC,MAAM,IAAIC,MACR;QAEJ;QAEA,MAAMC,sBAAsB;YAC1B,GAAGd,oBAAoB;YACvB,GAAGM,OAAO;QACZ;QAEA,kGAAkG;QAClG,MAAMS,UACJC,QAAQC,GAAG,CAACC,4BAA4B,IACxC,CAAC,QAAQ,EAAEV,QAAQ,CAAC,EAAEM,oBAAoBb,MAAM,CAAC,wBAAwB,CAAC;QAE5EJ,kBAGE;YACAsB,eAAe;YACfC,aAAad,QAAQc,WAAW;YAChCC,QAAQd;YACRH,SAAS,CAACQ,oBAAoBU,QAAQhB,QAAQiB,aAAa;YAC3DC,yBAAyB,IAAO,CAAA;oBAC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A;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CC;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMhB,SAAS;YACb,GAAGd,cAAc;YACjBa,aAAa,AAACb,CAAAA,eAAea,WAAW,IAAI,EAAE,AAAD,EAAGmB,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACF,sBAAsB,CAACE,WAAWL,IAAI,CAAC,EAAE;oBAC5C,OAAOK;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAO9C,mBAAmB;YACxBiC,oBAAoBvB,QAAQuB,kBAAkB;YAC9CT,aAAakB;YACbb,sBAAsBnB,QAAQmB,oBAAoB;QACpD,GAAGJ;IACL,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport type { VercelBlobClientUploadHandlerExtra } from './client/VercelBlobClientUploadHandler.js'\n\nimport { createVercelBlobAdapter } from './adapter.js'\nimport { getClientUploadRoute } from './getClientUploadRoute.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 * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n\n /**\n * Cache-Control max-age in seconds\n *\n * @default 365 * 24 * 60 * 60 // (1 Year)\n */\n cacheControlMaxAge?: number\n\n /**\n * Do uploads directly on the client, to bypass limits on Vercel.\n */\n clientUploads?: ClientUploadsConfig\n\n /**\n * Collections to apply the Vercel Blob adapter to\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Vercel Blob storage read/write token\n *\n * Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel\n *\n * If unset, the plugin will be disabled and will fallback to local storage\n */\n token: string | undefined\n\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), document prefix overrides collection\n * prefix entirely.\n *\n * Example:\n * - collection prefix: `collection-prefix/`\n * - document prefix: `document-prefix/`\n * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`\n * - resulting prefix with useCompositePrefixes=false: `document-prefix/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\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 VercelBlobStorageFactory = (vercelBlobStorageOpts: VercelBlobStorageOptions) => StorageAdapter\n\nexport const vercelBlobStorage: VercelBlobStorageFactory = (\n options: VercelBlobStorageOptions,\n): StorageAdapter => ({\n name: 'vercel-blob',\n collections: Object.keys(options.collections),\n init: (incomingConfig: Config): Config => {\n // Parse storeId from token\n const storeId = options.token\n ?.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]\n ?.toLowerCase()\n\n const isPluginDisabled = options.enabled === false || !options.token\n\n // Don't throw if the plugin is disabled\n if (!storeId && !isPluginDisabled) {\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 // support overriding the base URL for emulator https://github.com/payloadcms/vercel-blob-emulator\n const baseUrl =\n process.env.STORAGE_VERCEL_BLOB_BASE_URL ||\n `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`\n\n initClientUploads<\n VercelBlobClientUploadHandlerExtra,\n VercelBlobStorageOptions['collections'][string]\n >({\n clientHandler: '@payloadcms/storage-vercel-blob/client#VercelBlobClientUploadHandler',\n collections: options.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(options.clientUploads),\n extraClientHandlerProps: () => ({\n addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,\n useCompositePrefixes: !!options.useCompositePrefixes,\n }),\n serverHandler: getClientUploadRoute({\n access:\n typeof options.clientUploads === 'object' ? options.clientUploads.access : undefined,\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n cacheControlMaxAge: options.cacheControlMaxAge,\n token: options.token ?? '',\n }),\n serverHandlerPath: '/vercel-blob-client-upload-route',\n })\n\n // If the plugin is disabled or no token is provided, do not enable the plugin\n if (isPluginDisabled) {\n if (options.alwaysInsertFields) {\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: { ...(collOptions === true ? {} : collOptions), adapter: null },\n }),\n {} as Record<string, CollectionOptions>,\n )\n return cloudStoragePlugin({\n alwaysInsertFields: true,\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: options.useCompositePrefixes,\n })(incomingConfig)\n }\n return incomingConfig\n }\n\n const adapter = createVercelBlobAdapter({\n access: optionsWithDefaults.access ?? 'public',\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n baseUrl,\n cacheControlMaxAge: optionsWithDefaults.cacheControlMaxAge ?? 60 * 60 * 24 * 365,\n clientUploads: optionsWithDefaults.clientUploads,\n token: options.token!,\n useCompositePrefixes: options.useCompositePrefixes,\n })\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 cloudStoragePlugin({\n alwaysInsertFields: options.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: options.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["cloudStoragePlugin","initClientUploads","createVercelBlobAdapter","getClientUploadRoute","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","name","collections","Object","keys","init","incomingConfig","storeId","token","match","toLowerCase","isPluginDisabled","Error","optionsWithDefaults","baseUrl","process","env","STORAGE_VERCEL_BLOB_BASE_URL","clientHandler","config","Boolean","clientUploads","extraClientHandlerProps","useCompositePrefixes","serverHandler","undefined","serverHandlerPath","alwaysInsertFields","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","collectionsWithAdapter","map","collection","upload","disableLocalStorage"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAI9E,SAASC,uBAAuB,QAAQ,eAAc;AACtD,SAASC,oBAAoB,QAAQ,4BAA2B;AA6EhE,MAAMC,uBAA0D;IAC9DC,QAAQ;IACRC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AAGA,UAAU;wBACbC,QAAQ;4BACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;4BAClEC,qBAAqB;wBACvB;oBACF;gBACF;YACF;YAEA,OAAOjD,mBAAmB;gBACxBqC,oBAAoB3B,QAAQ2B,kBAAkB;gBAC9CzB,aAAaiC;gBACbZ,sBAAsBvB,QAAQuB,oBAAoB;YACpD,GAAGJ;QACL;IACF,CAAA,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-vercel-blob",
3
- "version": "4.0.0-internal.5b1e7cd",
3
+ "version": "4.0.0-internal.5f0cd13",
4
4
  "description": "Payload storage adapter for Vercel Blob Storage",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -38,16 +38,16 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@vercel/blob": "2.3.1",
41
- "@payloadcms/plugin-cloud-storage": "4.0.0-internal.5b1e7cd"
41
+ "@payloadcms/plugin-cloud-storage": "4.0.0-internal.5f0cd13"
42
42
  },
43
43
  "devDependencies": {
44
- "payload": "4.0.0-internal.5b1e7cd"
44
+ "payload": "4.0.0-internal.5f0cd13"
45
45
  },
46
46
  "peerDependencies": {
47
- "payload": "4.0.0-internal.5b1e7cd"
47
+ "payload": "4.0.0-internal.5f0cd13"
48
48
  },
49
49
  "engines": {
50
- "node": "^18.20.2 || >=20.9.0"
50
+ "node": ">=24.15.0"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "pnpm build:types && pnpm build:swc",