@payloadcms/plugin-cloud-storage 4.0.0-internal.5d5a2b2 → 4.0.0-internal.5e065b3

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 (85) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +2 -0
  3. package/dist/client/createClientUploadHandler.d.ts +8 -7
  4. package/dist/client/createClientUploadHandler.d.ts.map +1 -1
  5. package/dist/client/createClientUploadHandler.js +26 -22
  6. package/dist/client/createClientUploadHandler.js.map +1 -1
  7. package/dist/exports/client.d.ts +2 -0
  8. package/dist/exports/client.d.ts.map +1 -1
  9. package/dist/exports/client.js +2 -0
  10. package/dist/exports/client.js.map +1 -1
  11. package/dist/exports/utilities.d.ts +1 -2
  12. package/dist/exports/utilities.d.ts.map +1 -1
  13. package/dist/exports/utilities.js +1 -2
  14. package/dist/exports/utilities.js.map +1 -1
  15. package/dist/fields/getFields.d.ts +1 -5
  16. package/dist/fields/getFields.d.ts.map +1 -1
  17. package/dist/fields/getFields.js +54 -22
  18. package/dist/fields/getFields.js.map +1 -1
  19. package/dist/hooks/afterChange.d.ts +3 -1
  20. package/dist/hooks/afterChange.d.ts.map +1 -1
  21. package/dist/hooks/afterChange.js +82 -24
  22. package/dist/hooks/afterChange.js.map +1 -1
  23. package/dist/hooks/afterDelete.d.ts +3 -1
  24. package/dist/hooks/afterDelete.d.ts.map +1 -1
  25. package/dist/hooks/afterDelete.js +17 -3
  26. package/dist/hooks/afterDelete.js.map +1 -1
  27. package/dist/hooks/afterRead.d.ts.map +1 -1
  28. package/dist/hooks/afterRead.js +16 -3
  29. package/dist/hooks/afterRead.js.map +1 -1
  30. package/dist/hooks/beforeChange.d.ts.map +1 -1
  31. package/dist/hooks/beforeChange.js +14 -3
  32. package/dist/hooks/beforeChange.js.map +1 -1
  33. package/dist/hooks/normalizeUploadPrefix.d.ts +11 -0
  34. package/dist/hooks/normalizeUploadPrefix.d.ts.map +1 -0
  35. package/dist/hooks/normalizeUploadPrefix.js +42 -0
  36. package/dist/hooks/normalizeUploadPrefix.js.map +1 -0
  37. package/dist/plugin.d.ts.map +1 -1
  38. package/dist/plugin.js +178 -128
  39. package/dist/plugin.js.map +1 -1
  40. package/dist/types.d.ts +37 -21
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/types.js.map +1 -1
  43. package/dist/utilities/buildPrefixWithObjectKey.d.ts +8 -0
  44. package/dist/utilities/buildPrefixWithObjectKey.d.ts.map +1 -0
  45. package/dist/utilities/buildPrefixWithObjectKey.js +13 -0
  46. package/dist/utilities/buildPrefixWithObjectKey.js.map +1 -0
  47. package/dist/utilities/buildStoragePathData.d.ts +49 -0
  48. package/dist/utilities/buildStoragePathData.d.ts.map +1 -0
  49. package/dist/utilities/buildStoragePathData.js +67 -0
  50. package/dist/utilities/buildStoragePathData.js.map +1 -0
  51. package/dist/utilities/getFilePrefix.d.ts +19 -11
  52. package/dist/utilities/getFilePrefix.d.ts.map +1 -1
  53. package/dist/utilities/getFilePrefix.js +71 -31
  54. package/dist/utilities/getFilePrefix.js.map +1 -1
  55. package/dist/utilities/getIncomingFiles.js +4 -4
  56. package/dist/utilities/getIncomingFiles.js.map +1 -1
  57. package/dist/utilities/resolveSignedURLKey.d.ts +13 -2
  58. package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
  59. package/dist/utilities/resolveSignedURLKey.js +43 -9
  60. package/dist/utilities/resolveSignedURLKey.js.map +1 -1
  61. package/dist/utilities/sanitizePrefix.d.ts +1 -9
  62. package/dist/utilities/sanitizePrefix.d.ts.map +1 -1
  63. package/dist/utilities/sanitizePrefix.js +1 -21
  64. package/dist/utilities/sanitizePrefix.js.map +1 -1
  65. package/package.json +6 -6
  66. package/dist/admin/fields/getFields.d.ts +0 -17
  67. package/dist/admin/fields/getFields.d.ts.map +0 -1
  68. package/dist/admin/fields/getFields.js +0 -98
  69. package/dist/admin/fields/getFields.js.map +0 -1
  70. package/dist/admin/index.d.ts +0 -4
  71. package/dist/admin/index.d.ts.map +0 -1
  72. package/dist/admin/index.js +0 -34
  73. package/dist/admin/index.js.map +0 -1
  74. package/dist/utilities/getFileKey.d.ts +0 -22
  75. package/dist/utilities/getFileKey.d.ts.map +0 -1
  76. package/dist/utilities/getFileKey.js +0 -23
  77. package/dist/utilities/getFileKey.js.map +0 -1
  78. package/dist/utilities/getFileKey.spec.js +0 -174
  79. package/dist/utilities/getFileKey.spec.js.map +0 -1
  80. package/dist/utilities/getFilePrefix.spec.js +0 -105
  81. package/dist/utilities/getFilePrefix.spec.js.map +0 -1
  82. package/dist/utilities/initClientUploads.d.ts +0 -13
  83. package/dist/utilities/initClientUploads.d.ts.map +0 -1
  84. package/dist/utilities/initClientUploads.js +0 -63
  85. package/dist/utilities/initClientUploads.js.map +0 -1
package/dist/plugin.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { getFields } from './fields/getFields.js';
2
2
  import { getAfterChangeHook } from './hooks/afterChange.js';
3
3
  import { getAfterDeleteHook } from './hooks/afterDelete.js';
4
+ import { getNormalizeUploadPrefixHook } from './hooks/normalizeUploadPrefix.js';
4
5
  import { getPreserveFileDataHook } from './hooks/preserveFileData.js';
5
6
  // This plugin extends all targeted collections by offloading uploaded files
6
7
  // to cloud storage instead of solely storing files locally.
@@ -9,148 +10,197 @@ import { getPreserveFileDataHook } from './hooks/preserveFileData.js';
9
10
  // 1. handleUpload, 2. handleDelete, 3. generateURL, 4. staticHandler
10
11
  // Optionally, the adapter can specify any Webpack config overrides if they are necessary.
11
12
  export const cloudStoragePlugin = (pluginOptions)=>(incomingConfig)=>{
12
- const { alwaysInsertFields, collections: allCollectionOptions, enabled, useCompositePrefixes } = pluginOptions;
13
+ const { collections: allCollectionOptions, enabled, useCompositePrefixes } = pluginOptions;
13
14
  const config = {
14
15
  ...incomingConfig
15
16
  };
16
- // If disabled but alwaysInsertFields is true, only insert fields without full plugin functionality
17
+ // If disabled, only insert fields (e.g. prefix) without full plugin functionality,
18
+ // so the collection schema stays consistent across environments.
17
19
  if (enabled === false) {
18
- if (alwaysInsertFields) {
20
+ return {
21
+ ...config,
22
+ collections: (config.collections || []).map((existingCollection)=>{
23
+ const options = allCollectionOptions[existingCollection.slug];
24
+ if (options) {
25
+ // If adapter is provided, use it to get fields
26
+ const adapter = options.adapter ? options.adapter({
27
+ collection: existingCollection,
28
+ prefix: options.prefix
29
+ }) : undefined;
30
+ const fields = getFields({
31
+ adapter,
32
+ collection: existingCollection,
33
+ disablePayloadAccessControl: options.disablePayloadAccessControl,
34
+ generateFileURL: options.generateFileURL,
35
+ prefix: options.prefix,
36
+ useCompositePrefixes
37
+ });
38
+ return {
39
+ ...existingCollection,
40
+ fields
41
+ };
42
+ }
43
+ return existingCollection;
44
+ })
45
+ };
46
+ }
47
+ const initFunctions = [];
48
+ const endpointPaths = new Map();
49
+ const collections = (config.collections || []).map((existingCollection)=>{
50
+ const options = allCollectionOptions[existingCollection.slug];
51
+ if (options?.adapter) {
52
+ const adapter = options.adapter({
53
+ collection: existingCollection,
54
+ prefix: options.prefix
55
+ });
56
+ if (adapter.onInit) {
57
+ initFunctions.push(adapter.onInit);
58
+ }
59
+ let uploadInstructions;
60
+ if (adapter.uploadInstructions) {
61
+ const { adminHandler, enabled, endpoint, ...instructions } = adapter.uploadInstructions;
62
+ let endpointPath = endpointPaths.get(options.adapter);
63
+ if (enabled && endpoint && !endpointPath) {
64
+ const endpointCount = config.endpoints?.filter(({ path })=>path?.startsWith(endpoint.path)).length || 0;
65
+ endpointPath = endpointCount ? `${endpoint.path}-${endpointCount}` : endpoint.path;
66
+ config.endpoints ??= [];
67
+ config.endpoints.push({
68
+ handler: endpoint.handler,
69
+ method: 'post',
70
+ path: endpointPath
71
+ });
72
+ endpointPaths.set(options.adapter, endpointPath);
73
+ }
74
+ if (enabled && adminHandler) {
75
+ config.admin ??= {};
76
+ config.admin.components ??= {};
77
+ config.admin.components.providers ??= [];
78
+ config.admin.components.providers.push({
79
+ clientProps: {
80
+ collectionSlug: existingCollection.slug,
81
+ endpointPath,
82
+ prefix: options.prefix,
83
+ props: adminHandler.props || {}
84
+ },
85
+ path: adminHandler.path
86
+ });
87
+ }
88
+ if (enabled) {
89
+ uploadInstructions = instructions;
90
+ } else if (adminHandler) {
91
+ /** Avoid importMap.js differences when client uploads vary between dev and production. */ config.admin ??= {};
92
+ config.admin.dependencies ??= {};
93
+ config.admin.dependencies[adminHandler.path] = {
94
+ type: 'component',
95
+ path: adminHandler.path
96
+ };
97
+ }
98
+ }
99
+ const fields = getFields({
100
+ adapter,
101
+ collection: existingCollection,
102
+ disablePayloadAccessControl: options.disablePayloadAccessControl,
103
+ generateFileURL: options.generateFileURL,
104
+ prefix: options.prefix,
105
+ useCompositePrefixes
106
+ });
107
+ const handlers = [
108
+ ...typeof existingCollection.upload === 'object' && Array.isArray(existingCollection.upload.handlers) ? existingCollection.upload.handlers : []
109
+ ];
110
+ if (!options.disablePayloadAccessControl) {
111
+ handlers.push(adapter.staticHandler);
112
+ // Else if disablePayloadAccessControl: true and upload instructions are used
113
+ // Build the "proxied" handler that responds only when addDataAndFileToRequest fetches the uploaded file
114
+ } else if (uploadInstructions) {
115
+ handlers.push((req, args)=>{
116
+ if ('uploadReference' in args.params) {
117
+ return adapter.staticHandler(req, args);
118
+ }
119
+ });
120
+ }
121
+ const getSkipSafeFetchSetting = ()=>{
122
+ const isBooleanTrueSkipSafeFetch = typeof existingCollection.upload === 'object' && existingCollection.upload.skipSafeFetch === true;
123
+ const isAllowListSkipSafeFetch = typeof existingCollection.upload === 'object' && Array.isArray(existingCollection.upload.skipSafeFetch);
124
+ if (isBooleanTrueSkipSafeFetch) {
125
+ return true;
126
+ } else if (isAllowListSkipSafeFetch) {
127
+ const existingSkipSafeFetch = typeof existingCollection.upload === 'object' && Array.isArray(existingCollection.upload.skipSafeFetch) ? existingCollection.upload.skipSafeFetch : [];
128
+ const hasExactLocalhostMatch = existingSkipSafeFetch.some((entry)=>{
129
+ const entryKeys = Object.keys(entry);
130
+ return entryKeys.length === 1 && entry.hostname === 'localhost';
131
+ });
132
+ const localhostEntry = process.env.NODE_ENV !== 'production' && !hasExactLocalhostMatch ? [
133
+ {
134
+ hostname: 'localhost'
135
+ }
136
+ ] : [];
137
+ return [
138
+ ...existingSkipSafeFetch,
139
+ ...localhostEntry
140
+ ];
141
+ }
142
+ if (process.env.NODE_ENV !== 'production') {
143
+ return [
144
+ {
145
+ hostname: 'localhost'
146
+ }
147
+ ];
148
+ }
149
+ return false;
150
+ };
19
151
  return {
20
- ...config,
21
- collections: (config.collections || []).map((existingCollection)=>{
22
- const options = allCollectionOptions[existingCollection.slug];
23
- if (options) {
24
- // If adapter is provided, use it to get fields
25
- const adapter = options.adapter ? options.adapter({
152
+ ...existingCollection,
153
+ fields,
154
+ hooks: {
155
+ ...existingCollection.hooks || {},
156
+ afterChange: [
157
+ ...existingCollection.hooks?.afterChange || [],
158
+ getAfterChangeHook({
159
+ adapter,
26
160
  collection: existingCollection,
27
- prefix: options.prefix
28
- }) : undefined;
29
- const fields = getFields({
161
+ collectionPrefix: options.prefix,
162
+ useCompositePrefixes
163
+ })
164
+ ],
165
+ afterDelete: [
166
+ ...existingCollection.hooks?.afterDelete || [],
167
+ getAfterDeleteHook({
30
168
  adapter,
31
- alwaysInsertFields: true,
32
169
  collection: existingCollection,
33
- disablePayloadAccessControl: options.disablePayloadAccessControl,
34
- generateFileURL: options.generateFileURL,
35
- prefix: options.prefix,
170
+ collectionPrefix: options.prefix,
36
171
  useCompositePrefixes
37
- });
38
- return {
39
- ...existingCollection,
40
- fields
41
- };
42
- }
43
- return existingCollection;
44
- })
172
+ })
173
+ ],
174
+ beforeChange: [
175
+ ...existingCollection.hooks?.beforeChange || [],
176
+ getNormalizeUploadPrefixHook({
177
+ collectionPrefix: options.prefix,
178
+ useCompositePrefixes
179
+ }),
180
+ getPreserveFileDataHook()
181
+ ]
182
+ },
183
+ upload: {
184
+ ...typeof existingCollection.upload === 'object' ? existingCollection.upload : {},
185
+ adapter: adapter.name,
186
+ ...uploadInstructions && {
187
+ uploadInstructions
188
+ },
189
+ disableLocalStorage: typeof options.disableLocalStorage === 'boolean' ? options.disableLocalStorage : true,
190
+ handlers,
191
+ skipSafeFetch: getSkipSafeFetchSetting()
192
+ }
45
193
  };
46
194
  }
47
- return config;
48
- }
49
- const initFunctions = [];
195
+ return existingCollection;
196
+ });
50
197
  return {
51
198
  ...config,
52
- collections: (config.collections || []).map((existingCollection)=>{
53
- const options = allCollectionOptions[existingCollection.slug];
54
- if (options?.adapter) {
55
- const adapter = options.adapter({
56
- collection: existingCollection,
57
- prefix: options.prefix
58
- });
59
- if (adapter.onInit) {
60
- initFunctions.push(adapter.onInit);
61
- }
62
- const fields = getFields({
63
- adapter,
64
- collection: existingCollection,
65
- disablePayloadAccessControl: options.disablePayloadAccessControl,
66
- generateFileURL: options.generateFileURL,
67
- prefix: options.prefix,
68
- useCompositePrefixes
69
- });
70
- const handlers = [
71
- ...typeof existingCollection.upload === 'object' && Array.isArray(existingCollection.upload.handlers) ? existingCollection.upload.handlers : []
72
- ];
73
- if (!options.disablePayloadAccessControl) {
74
- handlers.push(adapter.staticHandler);
75
- // Else if disablePayloadAccessControl: true and clientUploads is used
76
- // Build the "proxied" handler that responses only when the file was requested by client upload in addDataAndFileToRequest
77
- } else if (adapter.clientUploads) {
78
- handlers.push((req, args)=>{
79
- if ('clientUploadContext' in args.params) {
80
- return adapter.staticHandler(req, args);
81
- }
82
- });
83
- }
84
- const getSkipSafeFetchSetting = ()=>{
85
- if (options.disablePayloadAccessControl) {
86
- return true;
87
- }
88
- const isBooleanTrueSkipSafeFetch = typeof existingCollection.upload === 'object' && existingCollection.upload.skipSafeFetch === true;
89
- const isAllowListSkipSafeFetch = typeof existingCollection.upload === 'object' && Array.isArray(existingCollection.upload.skipSafeFetch);
90
- if (isBooleanTrueSkipSafeFetch) {
91
- return true;
92
- } else if (isAllowListSkipSafeFetch) {
93
- const existingSkipSafeFetch = typeof existingCollection.upload === 'object' && Array.isArray(existingCollection.upload.skipSafeFetch) ? existingCollection.upload.skipSafeFetch : [];
94
- const hasExactLocalhostMatch = existingSkipSafeFetch.some((entry)=>{
95
- const entryKeys = Object.keys(entry);
96
- return entryKeys.length === 1 && entry.hostname === 'localhost';
97
- });
98
- const localhostEntry = process.env.NODE_ENV !== 'production' && !hasExactLocalhostMatch ? [
99
- {
100
- hostname: 'localhost'
101
- }
102
- ] : [];
103
- return [
104
- ...existingSkipSafeFetch,
105
- ...localhostEntry
106
- ];
107
- }
108
- if (process.env.NODE_ENV !== 'production') {
109
- return [
110
- {
111
- hostname: 'localhost'
112
- }
113
- ];
114
- }
115
- return false;
116
- };
117
- return {
118
- ...existingCollection,
119
- fields,
120
- hooks: {
121
- ...existingCollection.hooks || {},
122
- afterChange: [
123
- ...existingCollection.hooks?.afterChange || [],
124
- getAfterChangeHook({
125
- adapter,
126
- collection: existingCollection
127
- })
128
- ],
129
- afterDelete: [
130
- ...existingCollection.hooks?.afterDelete || [],
131
- getAfterDeleteHook({
132
- adapter,
133
- collection: existingCollection
134
- })
135
- ],
136
- beforeChange: [
137
- ...existingCollection.hooks?.beforeChange || [],
138
- getPreserveFileDataHook()
139
- ]
140
- },
141
- upload: {
142
- ...typeof existingCollection.upload === 'object' ? existingCollection.upload : {},
143
- adapter: adapter.name,
144
- disableLocalStorage: typeof options.disableLocalStorage === 'boolean' ? options.disableLocalStorage : true,
145
- handlers,
146
- skipSafeFetch: getSkipSafeFetchSetting()
147
- }
148
- };
149
- }
150
- return existingCollection;
151
- }),
199
+ collections,
152
200
  onInit: async (payload)=>{
153
- initFunctions.forEach((fn)=>fn());
201
+ // Await each init so a provisioning failure fails Payload startup
202
+ // instead of becoming an unhandled rejection.
203
+ await Promise.all(initFunctions.map((fn)=>fn()));
154
204
  if (config.onInit) {
155
205
  await config.onInit(payload);
156
206
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { AllowList, PluginOptions } from './types.js'\n\nimport { getFields } from './fields/getFields.js'\nimport { getAfterChangeHook } from './hooks/afterChange.js'\nimport { getAfterDeleteHook } from './hooks/afterDelete.js'\nimport { getPreserveFileDataHook } from './hooks/preserveFileData.js'\n\n// This plugin extends all targeted collections by offloading uploaded files\n// to cloud storage instead of solely storing files locally.\n\n// It is based on an adapter approach, where adapters can be written for any cloud provider.\n// Adapters are responsible for providing four actions that this plugin will use:\n// 1. handleUpload, 2. handleDelete, 3. generateURL, 4. staticHandler\n\n// Optionally, the adapter can specify any Webpack config overrides if they are necessary.\n\nexport const cloudStoragePlugin =\n (pluginOptions: PluginOptions) =>\n (incomingConfig: Config): Config => {\n const {\n alwaysInsertFields,\n collections: allCollectionOptions,\n enabled,\n useCompositePrefixes,\n } = pluginOptions\n const config = { ...incomingConfig }\n\n // If disabled but alwaysInsertFields is true, only insert fields without full plugin functionality\n if (enabled === false) {\n if (alwaysInsertFields) {\n return {\n ...config,\n collections: (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options) {\n // If adapter is provided, use it to get fields\n const adapter = options.adapter\n ? options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n : undefined\n\n const fields = getFields({\n adapter,\n alwaysInsertFields: true,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n return {\n ...existingCollection,\n fields,\n }\n }\n\n return existingCollection\n }),\n }\n }\n\n return config\n }\n\n const initFunctions: Array<() => void> = []\n\n return {\n ...config,\n collections: (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options?.adapter) {\n const adapter = options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n\n if (adapter.onInit) {\n initFunctions.push(adapter.onInit)\n }\n\n const fields = getFields({\n adapter,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n const handlers = [\n ...(typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.handlers)\n ? existingCollection.upload.handlers\n : []),\n ]\n\n if (!options.disablePayloadAccessControl) {\n handlers.push(adapter.staticHandler)\n // Else if disablePayloadAccessControl: true and clientUploads is used\n // Build the \"proxied\" handler that responses only when the file was requested by client upload in addDataAndFileToRequest\n } else if (adapter.clientUploads) {\n handlers.push((req, args) => {\n if ('clientUploadContext' in args.params) {\n return adapter.staticHandler(req, args)\n }\n })\n }\n\n const getSkipSafeFetchSetting = (): AllowList | boolean => {\n if (options.disablePayloadAccessControl) {\n return true\n }\n const isBooleanTrueSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n existingCollection.upload.skipSafeFetch === true\n\n const isAllowListSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n\n if (isBooleanTrueSkipSafeFetch) {\n return true\n } else if (isAllowListSkipSafeFetch) {\n const existingSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n ? existingCollection.upload.skipSafeFetch\n : []\n\n const hasExactLocalhostMatch = existingSkipSafeFetch.some((entry) => {\n const entryKeys = Object.keys(entry)\n return entryKeys.length === 1 && entry.hostname === 'localhost'\n })\n\n const localhostEntry =\n process.env.NODE_ENV !== 'production' && !hasExactLocalhostMatch\n ? [{ hostname: 'localhost' }]\n : []\n\n return [...existingSkipSafeFetch, ...localhostEntry]\n }\n\n if (process.env.NODE_ENV !== 'production') {\n return [{ hostname: 'localhost' }]\n }\n\n return false\n }\n\n return {\n ...existingCollection,\n fields,\n hooks: {\n ...(existingCollection.hooks || {}),\n afterChange: [\n ...(existingCollection.hooks?.afterChange || []),\n getAfterChangeHook({ adapter, collection: existingCollection }),\n ],\n afterDelete: [\n ...(existingCollection.hooks?.afterDelete || []),\n getAfterDeleteHook({ adapter, collection: existingCollection }),\n ],\n beforeChange: [\n ...(existingCollection.hooks?.beforeChange || []),\n getPreserveFileDataHook(),\n ],\n },\n upload: {\n ...(typeof existingCollection.upload === 'object' ? existingCollection.upload : {}),\n adapter: adapter.name,\n disableLocalStorage:\n typeof options.disableLocalStorage === 'boolean'\n ? options.disableLocalStorage\n : true,\n handlers,\n skipSafeFetch: getSkipSafeFetchSetting(),\n },\n }\n }\n\n return existingCollection\n }),\n onInit: async (payload) => {\n initFunctions.forEach((fn) => fn())\n if (config.onInit) {\n await config.onInit(payload)\n }\n },\n }\n }\n"],"names":["getFields","getAfterChangeHook","getAfterDeleteHook","getPreserveFileDataHook","cloudStoragePlugin","pluginOptions","incomingConfig","alwaysInsertFields","collections","allCollectionOptions","enabled","useCompositePrefixes","config","map","existingCollection","options","slug","adapter","collection","prefix","undefined","fields","disablePayloadAccessControl","generateFileURL","initFunctions","onInit","push","handlers","upload","Array","isArray","staticHandler","clientUploads","req","args","params","getSkipSafeFetchSetting","isBooleanTrueSkipSafeFetch","skipSafeFetch","isAllowListSkipSafeFetch","existingSkipSafeFetch","hasExactLocalhostMatch","some","entry","entryKeys","Object","keys","length","hostname","localhostEntry","process","env","NODE_ENV","hooks","afterChange","afterDelete","beforeChange","name","disableLocalStorage","payload","forEach","fn"],"mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AACjD,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,uBAAuB,QAAQ,8BAA6B;AAErE,4EAA4E;AAC5E,4DAA4D;AAE5D,4FAA4F;AAC5F,iFAAiF;AACjF,qEAAqE;AAErE,0FAA0F;AAE1F,OAAO,MAAMC,qBACX,CAACC,gBACD,CAACC;QACC,MAAM,EACJC,kBAAkB,EAClBC,aAAaC,oBAAoB,EACjCC,OAAO,EACPC,oBAAoB,EACrB,GAAGN;QACJ,MAAMO,SAAS;YAAE,GAAGN,cAAc;QAAC;QAEnC,mGAAmG;QACnG,IAAII,YA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GAC3B,EAAE;4BAER,OAAO;mCAAIR;mCAA0BS;6BAAe;wBACtD;wBAEA,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;4BACzC,OAAO;gCAAC;oCAAEJ,UAAU;gCAAY;6BAAE;wBACpC;wBAEA,OAAO;oBACT;oBAEA,OAAO;wBACL,GAAGlC,kBAAkB;wBACrBO;wBACAgC,OAAO;4BACL,GAAIvC,mBAAmBuC,KAAK,IAAI,CAAC,CAAC;4BAClCC,aAAa;mCACPxC,mBAAmBuC,KAAK,EAAEC,eAAe,EAAE;gCAC/CrD,mBAAmB;oCAAEgB;oCAASC,YAAYJ;gCAAmB;6BAC9D;4BACDyC,aAAa;mCACPzC,mBAAmBuC,KAAK,EAAEE,eAAe,EAAE;gCAC/CrD,mBAAmB;oCAAEe;oCAASC,YAAYJ;gCAAmB;6BAC9D;4BACD0C,cAAc;mCACR1C,mBAAmBuC,KAAK,EAAEG,gBAAgB,EAAE;gCAChDrD;6BACD;wBACH;wBACAyB,QAAQ;4BACN,GAAI,OAAOd,mBAAmBc,MAAM,KAAK,WAAWd,mBAAmBc,MAAM,GAAG,CAAC,CAAC;4BAClFX,SAASA,QAAQwC,IAAI;4BACrBC,qBACE,OAAO3C,QAAQ2C,mBAAmB,KAAK,YACnC3C,QAAQ2C,mBAAmB,GAC3B;4BACN/B;4BACAW,eAAeF;wBACjB;oBACF;gBACF;gBAEA,OAAOtB;YACT;YACAW,QAAQ,OAAOkC;gBACbnC,cAAcoC,OAAO,CAAC,CAACC,KAAOA;gBAC9B,IAAIjD,OAAOa,MAAM,EAAE;oBACjB,MAAMb,OAAOa,MAAM,CAACkC;gBACtB;YACF;QACF;IACF,EAAC"}
1
+ {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { Adapter, AllowList, PluginOptions } from './types.js'\n\nimport { getFields } from './fields/getFields.js'\nimport { getAfterChangeHook } from './hooks/afterChange.js'\nimport { getAfterDeleteHook } from './hooks/afterDelete.js'\nimport { getNormalizeUploadPrefixHook } from './hooks/normalizeUploadPrefix.js'\nimport { getPreserveFileDataHook } from './hooks/preserveFileData.js'\n\n// This plugin extends all targeted collections by offloading uploaded files\n// to cloud storage instead of solely storing files locally.\n\n// It is based on an adapter approach, where adapters can be written for any cloud provider.\n// Adapters are responsible for providing four actions that this plugin will use:\n// 1. handleUpload, 2. handleDelete, 3. generateURL, 4. staticHandler\n\n// Optionally, the adapter can specify any Webpack config overrides if they are necessary.\n\nexport const cloudStoragePlugin =\n (pluginOptions: PluginOptions) =>\n (incomingConfig: Config): Config => {\n const { collections: allCollectionOptions, enabled, useCompositePrefixes } = pluginOptions\n const config = { ...incomingConfig }\n\n // If disabled, only insert fields (e.g. prefix) without full plugin functionality,\n // so the collection schema stays consistent across environments.\n if (enabled === false) {\n return {\n ...config,\n collections: (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options) {\n // If adapter is provided, use it to get fields\n const adapter = options.adapter\n ? options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n : undefined\n\n const fields = getFields({\n adapter,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n return {\n ...existingCollection,\n fields,\n }\n }\n\n return existingCollection\n }),\n }\n }\n\n const initFunctions: Array<() => Promise<void> | void> = []\n const endpointPaths = new Map<Adapter, string>()\n\n const collections = (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options?.adapter) {\n const adapter = options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n\n if (adapter.onInit) {\n initFunctions.push(adapter.onInit)\n }\n\n let uploadInstructions\n\n if (adapter.uploadInstructions) {\n const { adminHandler, enabled, endpoint, ...instructions } = adapter.uploadInstructions\n let endpointPath = endpointPaths.get(options.adapter)\n\n if (enabled && endpoint && !endpointPath) {\n const endpointCount =\n config.endpoints?.filter(({ path }) => path?.startsWith(endpoint.path)).length || 0\n\n endpointPath = endpointCount ? `${endpoint.path}-${endpointCount}` : endpoint.path\n config.endpoints ??= []\n config.endpoints.push({\n handler: endpoint.handler,\n method: 'post',\n path: endpointPath,\n })\n endpointPaths.set(options.adapter, endpointPath)\n }\n\n if (enabled && adminHandler) {\n config.admin ??= {}\n config.admin.components ??= {}\n config.admin.components.providers ??= []\n config.admin.components.providers.push({\n clientProps: {\n collectionSlug: existingCollection.slug,\n endpointPath,\n prefix: options.prefix,\n props: adminHandler.props || {},\n },\n path: adminHandler.path,\n })\n }\n\n if (enabled) {\n uploadInstructions = instructions\n } else if (adminHandler) {\n /** Avoid importMap.js differences when client uploads vary between dev and production. */\n config.admin ??= {}\n config.admin.dependencies ??= {}\n config.admin.dependencies[adminHandler.path] = {\n type: 'component',\n path: adminHandler.path,\n }\n }\n }\n\n const fields = getFields({\n adapter,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n const handlers = [\n ...(typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.handlers)\n ? existingCollection.upload.handlers\n : []),\n ]\n\n if (!options.disablePayloadAccessControl) {\n handlers.push(adapter.staticHandler)\n // Else if disablePayloadAccessControl: true and upload instructions are used\n // Build the \"proxied\" handler that responds only when addDataAndFileToRequest fetches the uploaded file\n } else if (uploadInstructions) {\n handlers.push((req, args) => {\n if ('uploadReference' in args.params) {\n return adapter.staticHandler(req, args)\n }\n })\n }\n\n const getSkipSafeFetchSetting = (): AllowList | boolean => {\n const isBooleanTrueSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n existingCollection.upload.skipSafeFetch === true\n\n const isAllowListSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n\n if (isBooleanTrueSkipSafeFetch) {\n return true\n } else if (isAllowListSkipSafeFetch) {\n const existingSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n ? existingCollection.upload.skipSafeFetch\n : []\n\n const hasExactLocalhostMatch = existingSkipSafeFetch.some((entry) => {\n const entryKeys = Object.keys(entry)\n return entryKeys.length === 1 && entry.hostname === 'localhost'\n })\n\n const localhostEntry =\n process.env.NODE_ENV !== 'production' && !hasExactLocalhostMatch\n ? [{ hostname: 'localhost' }]\n : []\n\n return [...existingSkipSafeFetch, ...localhostEntry]\n }\n\n if (process.env.NODE_ENV !== 'production') {\n return [{ hostname: 'localhost' }]\n }\n\n return false\n }\n\n return {\n ...existingCollection,\n fields,\n hooks: {\n ...(existingCollection.hooks || {}),\n afterChange: [\n ...(existingCollection.hooks?.afterChange || []),\n getAfterChangeHook({\n adapter,\n collection: existingCollection,\n collectionPrefix: options.prefix,\n useCompositePrefixes,\n }),\n ],\n afterDelete: [\n ...(existingCollection.hooks?.afterDelete || []),\n getAfterDeleteHook({\n adapter,\n collection: existingCollection,\n collectionPrefix: options.prefix,\n useCompositePrefixes,\n }),\n ],\n beforeChange: [\n ...(existingCollection.hooks?.beforeChange || []),\n getNormalizeUploadPrefixHook({\n collectionPrefix: options.prefix,\n useCompositePrefixes,\n }),\n getPreserveFileDataHook(),\n ],\n },\n upload: {\n ...(typeof existingCollection.upload === 'object' ? existingCollection.upload : {}),\n adapter: adapter.name,\n ...(uploadInstructions && {\n uploadInstructions,\n }),\n disableLocalStorage:\n typeof options.disableLocalStorage === 'boolean' ? options.disableLocalStorage : true,\n handlers,\n skipSafeFetch: getSkipSafeFetchSetting(),\n },\n }\n }\n\n return existingCollection\n })\n\n return {\n ...config,\n collections,\n onInit: async (payload) => {\n // Await each init so a provisioning failure fails Payload startup\n // instead of becoming an unhandled rejection.\n await Promise.all(initFunctions.map((fn) => fn()))\n if (config.onInit) {\n await config.onInit(payload)\n }\n },\n }\n }\n"],"names":["getFields","getAfterChangeHook","getAfterDeleteHook","getNormalizeUploadPrefixHook","getPreserveFileDataHook","cloudStoragePlugin","pluginOptions","incomingConfig","collections","allCollectionOptions","enabled","useCompositePrefixes","config","map","existingCollection","options","slug","adapter","collection","prefix","undefined","fields","disablePayloadAccessControl","generateFileURL","initFunctions","endpointPaths","Map","onInit","push","uploadInstructions","adminHandler","endpoint","instructions","endpointPath","get","endpointCount","endpoints","filter","path","startsWith","length","handler","method","set","admin","components","providers","clientProps","collectionSlug","props","dependencies","type","handlers","upload","Array","isArray","staticHandler","req","args","params","getSkipSafeFetchSetting","isBooleanTrueSkipSafeFetch","skipSafeFetch","isAllowListSkipSafeFetch","existingSkipSafeFetch","hasExactLocalhostMatch","some","entry","entryKeys","Object","keys","hostname","localhostEntry","process","env","NODE_ENV","hooks","afterChange","collectionPrefix","afterDelete","beforeChange","name","disableLocalStorage","payload","Promise","all","fn"],"mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AACjD,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,4BAA4B,QAAQ,mCAAkC;AAC/E,SAASC,uBAAuB,QAAQ,8BAA6B;AAErE,4EAA4E;AAC5E,4DAA4D;AAE5D,4FAA4F;AAC5F,iFAAiF;AACjF,qEAAqE;AAErE,0FAA0F;AAE1F,OAAO,MAAMC,qBACX,CAACC,gBACD,CAACC;QACC,MAAM,EAAEC,aAAaC,oBAAoB,EAAEC,OAAO,EAAEC,oBAAoB,EAAE,GAAGL;QAC7E,MAAMM,SAAS;YAAE,GAAGL,cAAc;QAAC;QAEnC,mFAAmF;QACnF,iEAAiE;QACjE,IAAIG,YAAY,OAAO;YACrB,OAAO;gBACL,GAAGE,MAAM;gBACTJ,aAAa,AAACI,CAAAA,OAAOJ,WAAW,IAAI,EAAE,AAAD,EAAGK,GAAG,CAAC,CAACC;oBAC3C,MAAMC,UAAUN,oBAAoB,CAACK,mBAAmBE,IAAI,CAAC;oBAE7D,IAAID,SAAS;wBACX,+C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ig, Field, FileData, ImageSize, PayloadRequest, TypeWithID, UploadCollectionSlug } from 'payload';
1
+ import type { CollectionConfig, Field, FileData, FileHandlerOperation, ImageSize, PayloadHandler, PayloadRequest, TypeWithID, UploadCollectionSlug, UploadInstructionsAccess, UploadInstructionsCapability } from 'payload';
2
+ export type { FileHandlerOperation } from 'payload';
2
3
  export interface File {
3
4
  buffer: Buffer;
4
- clientUploadContext?: unknown;
5
5
  filename: string;
6
6
  filesize: number;
7
7
  mimeType: string;
8
8
  tempFilePath?: string;
9
+ uploadReference?: unknown;
9
10
  }
10
- export type ClientUploadsAccess = (args: {
11
- collectionSlug: UploadCollectionSlug;
12
- req: PayloadRequest;
13
- }) => boolean | Promise<boolean>;
14
11
  export type ClientUploadsConfig = {
15
- access?: ClientUploadsAccess;
12
+ access?: UploadInstructionsAccess;
16
13
  } | boolean;
14
+ /**
15
+ * Reference to a client-uploaded object, returned by an upload handler and
16
+ * submitted with the document. Always carries the signed receipt; `prefix`
17
+ * locates the stored object.
18
+ */
19
+ export type UploadReference = {
20
+ _objectKey?: string;
21
+ prefix: string;
22
+ signedReceipt: `${string}.${string}`;
23
+ };
17
24
  export type HandleUpload = (args: {
18
- clientUploadContext: unknown;
19
25
  collection: CollectionConfig;
20
26
  data: any;
21
27
  file: File;
22
28
  req: PayloadRequest;
29
+ /**
30
+ * Pre-resolved storage path (`_objectKey` folded in, contained beneath the collection prefix).
31
+ */
32
+ storageFilePath: string;
23
33
  }) => Partial<FileData & TypeWithID> | Promise<Partial<FileData & TypeWithID>> | Promise<void> | void;
24
34
  export interface TypeWithPrefix {
25
35
  prefix?: string;
@@ -29,6 +39,10 @@ export type HandleDelete = (args: {
29
39
  doc: FileData & TypeWithID & TypeWithPrefix;
30
40
  filename: string;
31
41
  req: PayloadRequest;
42
+ /**
43
+ * Pre-resolved storage path of the object to delete.
44
+ */
45
+ storageFilePath: string;
32
46
  }) => Promise<void> | void;
33
47
  export type GenerateURL = (args: {
34
48
  collection: CollectionConfig;
@@ -40,14 +54,14 @@ export type StaticHandler = (req: PayloadRequest, args: {
40
54
  doc?: TypeWithID;
41
55
  headers?: Headers;
42
56
  params: {
43
- clientUploadContext?: unknown;
44
57
  collection: string;
45
58
  filename: string;
59
+ operation?: FileHandlerOperation;
46
60
  prefix?: string;
61
+ uploadReference?: unknown;
47
62
  };
48
63
  }) => Promise<Response> | Response;
49
64
  export interface GeneratedAdapter {
50
- clientUploads?: ClientUploadsConfig;
51
65
  /**
52
66
  * Additional fields to be injected into the base collection and image sizes
53
67
  */
@@ -59,8 +73,20 @@ export interface GeneratedAdapter {
59
73
  handleDelete: HandleDelete;
60
74
  handleUpload: HandleUpload;
61
75
  name: string;
62
- onInit?: () => void;
76
+ onInit?: () => Promise<void> | void;
63
77
  staticHandler: StaticHandler;
78
+ /** Generates upload instructions when supported. */
79
+ uploadInstructions?: {
80
+ adminHandler?: {
81
+ path: string;
82
+ props?: Record<string, unknown>;
83
+ };
84
+ enabled: boolean;
85
+ endpoint?: {
86
+ handler: PayloadHandler;
87
+ path: `/${string}`;
88
+ };
89
+ } & UploadInstructionsCapability;
64
90
  }
65
91
  export type Adapter = (args: {
66
92
  collection: CollectionConfig;
@@ -87,16 +113,6 @@ export interface CollectionOptions {
87
113
  prefix?: string;
88
114
  }
89
115
  export interface PluginOptions {
90
- /**
91
- * When enabled, fields (like the prefix field) will always be inserted into
92
- * the collection schema regardless of whether the plugin is enabled. This
93
- * ensures a consistent schema across all environments.
94
- *
95
- * This will be enabled by default in Payload v4.
96
- *
97
- * @default false
98
- */
99
- alwaysInsertFields?: boolean;
100
116
  collections: Partial<Record<UploadCollectionSlug, CollectionOptions>>;
101
117
  /**
102
118
  * Whether or not to enable the plugin
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACR,SAAS,EACT,cAAc,EACd,UAAU,EACV,oBAAoB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;IAAE,UAAU,EAAE,gBAAgB,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,gBAAgB,CAAA;AAEnG,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAC,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IACnC,UAAU,EAAE,gBAAgB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;AAE9B,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,2BAA2B,CAAC,EAAE,IAAI,CAAA;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAC,CAAA;IACrE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n FileData,\n ImageSize,\n PayloadRequest,\n TypeWithID,\n UploadCollectionSlug,\n} from 'payload'\n\nexport interface File {\n buffer: Buffer\n clientUploadContext?: unknown\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n}\n\nexport type ClientUploadsAccess = (args: {\n collectionSlug: UploadCollectionSlug\n req: PayloadRequest\n}) => boolean | Promise<boolean>\n\nexport type ClientUploadsConfig =\n | {\n access?: ClientUploadsAccess\n }\n | boolean\n\nexport type HandleUpload = (args: {\n clientUploadContext: unknown\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequest\n}) =>\n | Partial<FileData & TypeWithID>\n | Promise<Partial<FileData & TypeWithID>>\n | Promise<void>\n | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: FileData & TypeWithID & TypeWithPrefix\n filename: string\n req: PayloadRequest\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n data: any\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequest,\n args: {\n doc?: TypeWithID\n headers?: Headers\n params: { clientUploadContext?: unknown; collection: string; filename: string; prefix?: string }\n },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n clientUploads?: ClientUploadsConfig\n /**\n * Additional fields to be injected into the base collection and image sizes\n */\n fields?: Field[]\n /**\n * Generates the public URL for a file\n */\n generateURL?: GenerateURL\n handleDelete: HandleDelete\n handleUpload: HandleUpload\n name: string\n onInit?: () => void\n staticHandler: StaticHandler\n}\n\nexport type Adapter = (args: { collection: CollectionConfig; prefix?: string }) => GeneratedAdapter\n\nexport type AllowList = Array<{\n hostname: string\n pathname?: string\n port?: string\n protocol?: 'http' | 'https'\n search?: string\n}>\n\nexport type GenerateFileURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n size?: ImageSize\n}) => Promise<string> | string\n\nexport interface CollectionOptions {\n adapter: Adapter | null\n disableLocalStorage?: boolean\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport interface PluginOptions {\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 collections: Partial<Record<UploadCollectionSlug, CollectionOptions>>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * When true (compositional prefixes), the stored `prefix` field is only the\n * document-level segment; the collection prefix comes from plugin options and\n * must not be pre-filled as the field default.\n *\n * Set by storage adapters that support compositional prefixes (e.g. S3, Azure, R2, Vercel Blob, GCS).\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n"],"names":[],"mappings":"AA+GA,WA4BC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n FileData,\n FileHandlerOperation,\n ImageSize,\n PayloadHandler,\n PayloadRequest,\n TypeWithID,\n UploadCollectionSlug,\n UploadInstructionsAccess,\n UploadInstructionsCapability,\n} from 'payload'\n\nexport type { FileHandlerOperation } from 'payload'\n\nexport interface File {\n buffer: Buffer\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n uploadReference?: unknown\n}\n\nexport type ClientUploadsConfig = { access?: UploadInstructionsAccess } | boolean\n\n/**\n * Reference to a client-uploaded object, returned by an upload handler and\n * submitted with the document. Always carries the signed receipt; `prefix`\n * locates the stored object.\n */\nexport type UploadReference = {\n _objectKey?: string\n prefix: string\n signedReceipt: `${string}.${string}`\n}\n\nexport type HandleUpload = (args: {\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequest\n /**\n * Pre-resolved storage path (`_objectKey` folded in, contained beneath the collection prefix).\n */\n storageFilePath: string\n}) =>\n | Partial<FileData & TypeWithID>\n | Promise<Partial<FileData & TypeWithID>>\n | Promise<void>\n | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: FileData & TypeWithID & TypeWithPrefix\n filename: string\n req: PayloadRequest\n /**\n * Pre-resolved storage path of the object to delete.\n */\n storageFilePath: string\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n data: any\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequest,\n args: {\n doc?: TypeWithID\n headers?: Headers\n params: {\n collection: string\n filename: string\n operation?: FileHandlerOperation\n prefix?: string\n uploadReference?: unknown\n }\n },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n /**\n * Additional fields to be injected into the base collection and image sizes\n */\n fields?: Field[]\n /**\n * Generates the public URL for a file\n */\n generateURL?: GenerateURL\n handleDelete: HandleDelete\n handleUpload: HandleUpload\n name: string\n onInit?: () => Promise<void> | void\n staticHandler: StaticHandler\n /** Generates upload instructions when supported. */\n uploadInstructions?: {\n adminHandler?: {\n path: string\n props?: Record<string, unknown>\n }\n enabled: boolean\n endpoint?: {\n handler: PayloadHandler\n path: `/${string}`\n }\n } & UploadInstructionsCapability\n}\n\nexport type Adapter = (args: { collection: CollectionConfig; prefix?: string }) => GeneratedAdapter\n\nexport type AllowList = Array<{\n hostname: string\n pathname?: string\n port?: string\n protocol?: 'http' | 'https'\n search?: string\n}>\n\nexport type GenerateFileURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n size?: ImageSize\n}) => Promise<string> | string\n\nexport interface CollectionOptions {\n adapter: Adapter | null\n disableLocalStorage?: boolean\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport interface PluginOptions {\n collections: Partial<Record<UploadCollectionSlug, CollectionOptions>>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * When true (compositional prefixes), the stored `prefix` field is only the\n * document-level segment; the collection prefix comes from plugin options and\n * must not be pre-filled as the field default.\n *\n * Set by storage adapters that support compositional prefixes (e.g. S3, Azure, R2, Vercel Blob, GCS).\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n"],"names":[],"mappings":"AA+IA,WAkBC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.
3
+ */
4
+ export declare const buildPrefixWithObjectKey: ({ objectKey, prefix, }: {
5
+ objectKey?: string;
6
+ prefix?: string;
7
+ }) => string;
8
+ //# sourceMappingURL=buildPrefixWithObjectKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildPrefixWithObjectKey.d.ts","sourceRoot":"","sources":["../../src/utilities/buildPrefixWithObjectKey.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,wBAAwB,2BAGlC;IACD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAG,MASH,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { sanitizePrefix } from './sanitizePrefix.js';
2
+ /**
3
+ * Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.
4
+ */ export const buildPrefixWithObjectKey = ({ objectKey, prefix })=>{
5
+ const safePrefix = sanitizePrefix(prefix ?? '');
6
+ const safeObjectKey = sanitizePrefix(objectKey ?? '');
7
+ if (safePrefix && safeObjectKey) {
8
+ return `${safePrefix}/${safeObjectKey}`;
9
+ }
10
+ return safePrefix || safeObjectKey;
11
+ };
12
+
13
+ //# sourceMappingURL=buildPrefixWithObjectKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/buildPrefixWithObjectKey.ts"],"sourcesContent":["import { sanitizePrefix } from './sanitizePrefix.js'\n\n/**\n * Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.\n */\nexport const buildPrefixWithObjectKey = ({\n objectKey,\n prefix,\n}: {\n objectKey?: string\n prefix?: string\n}): string => {\n const safePrefix = sanitizePrefix(prefix ?? '')\n const safeObjectKey = sanitizePrefix(objectKey ?? '')\n\n if (safePrefix && safeObjectKey) {\n return `${safePrefix}/${safeObjectKey}`\n }\n\n return safePrefix || safeObjectKey\n}\n"],"names":["sanitizePrefix","buildPrefixWithObjectKey","objectKey","prefix","safePrefix","safeObjectKey"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD;;CAEC,GACD,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,SAAS,EACTC,MAAM,EAIP;IACC,MAAMC,aAAaJ,eAAeG,UAAU;IAC5C,MAAME,gBAAgBL,eAAeE,aAAa;IAElD,IAAIE,cAAcC,eAAe;QAC/B,OAAO,GAAGD,WAAW,CAAC,EAAEC,eAAe;IACzC;IAEA,OAAOD,cAAcC;AACvB,EAAC"}
@@ -0,0 +1,49 @@
1
+ type BuildFilePathDataArgs = {
2
+ collectionPrefix?: string;
3
+ docPrefix?: string;
4
+ filename: string;
5
+ useCompositePrefixes?: boolean;
6
+ };
7
+ type BuildFilePathDataResult = {
8
+ sanitizedCollectionPrefix: string;
9
+ sanitizedDocPrefix: string;
10
+ sanitizedFilename: string;
11
+ /**
12
+ * The full path to the file within the storage backend.
13
+ */
14
+ storageFilePath: string;
15
+ };
16
+ export declare function isStoragePathWithinCollectionPrefix({ collectionPrefix, docPrefix, }: {
17
+ collectionPrefix?: string;
18
+ docPrefix: string;
19
+ }): boolean;
20
+ /**
21
+ * Resolves where a new upload must be stored, without needing a filename.
22
+ *
23
+ * In non-composite mode (useCompositePrefixes: false), docPrefix is treated as a complete prefix
24
+ * when it is already within collectionPrefix and is otherwise nested beneath collectionPrefix.
25
+ * In composite mode (useCompositePrefixes: true), the collection prefix is joined when the key is
26
+ * built, so the persisted document prefix stays relative to it.
27
+ *
28
+ * Prefix-only callers (such as the upload prefix hooks) use this directly; use
29
+ * {@link buildUploadStoragePathData} when a full object key is needed.
30
+ */
31
+ export declare function buildUploadPrefix({ collectionPrefix, docPrefix, useCompositePrefixes, }: Omit<BuildFilePathDataArgs, 'filename'>): {
32
+ sanitizedCollectionPrefix: string;
33
+ sanitizedDocPrefix: string;
34
+ uploadPrefix: string;
35
+ };
36
+ /**
37
+ * Resolves a new upload destination beneath the configured collection prefix.
38
+ * Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.
39
+ */
40
+ export declare function buildUploadStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes, }: BuildFilePathDataArgs): BuildFilePathDataResult;
41
+ /**
42
+ * Resolves the exact location represented by persisted upload metadata.
43
+ * Non-composite document prefixes historically override the collection prefix;
44
+ * keep that behavior for reads, URLs, and cleanup of pre-upgrade files.
45
+ * New writes must use buildUploadStoragePathData instead.
46
+ */
47
+ export declare function buildStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes, }: BuildFilePathDataArgs): BuildFilePathDataResult;
48
+ export {};
49
+ //# sourceMappingURL=buildStoragePathData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildStoragePathData.d.ts","sourceRoot":"","sources":["../../src/utilities/buildStoragePathData.ts"],"names":[],"mappings":"AAKA,KAAK,qBAAqB,GAAG;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC7B,yBAAyB,EAAE,MAAM,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,wBAAgB,mCAAmC,CAAC,EAClD,gBAAgB,EAChB,SAAS,GACV,EAAE;IACD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,OAAO,CAQV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,SAAS,EACT,oBAA4B,GAC7B,EAAE,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,GAAG;IAC3C,yBAAyB,EAAE,MAAM,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;CACrB,CAiBA;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,qBAAqB,GAAG,uBAAuB,CAkBjD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,qBAAqB,GAAG,uBAAuB,CAcjD"}