@payloadcms/storage-s3 4.0.0-internal.5b1e7cd → 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 (41) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/adapter.d.ts +3 -3
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +32 -18
  6. package/dist/adapter.js.map +1 -1
  7. package/dist/deleteFile.d.ts +2 -5
  8. package/dist/deleteFile.d.ts.map +1 -1
  9. package/dist/deleteFile.js +2 -9
  10. package/dist/deleteFile.js.map +1 -1
  11. package/dist/generateURL.js +4 -4
  12. package/dist/generateURL.js.map +1 -1
  13. package/dist/generateUploadInstructions.d.ts +13 -0
  14. package/dist/generateUploadInstructions.d.ts.map +1 -0
  15. package/dist/generateUploadInstructions.js +70 -0
  16. package/dist/generateUploadInstructions.js.map +1 -0
  17. package/dist/getFile.d.ts +5 -4
  18. package/dist/getFile.d.ts.map +1 -1
  19. package/dist/getFile.js +22 -22
  20. package/dist/getFile.js.map +1 -1
  21. package/dist/index.d.ts +14 -23
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +64 -82
  24. package/dist/index.js.map +1 -1
  25. package/dist/uploadFile.d.ts +2 -5
  26. package/dist/uploadFile.d.ts.map +1 -1
  27. package/dist/uploadFile.js +3 -10
  28. package/dist/uploadFile.js.map +1 -1
  29. package/package.json +5 -10
  30. package/dist/client/S3ClientUploadHandler.d.ts +0 -9
  31. package/dist/client/S3ClientUploadHandler.d.ts.map +0 -1
  32. package/dist/client/S3ClientUploadHandler.js +0 -44
  33. package/dist/client/S3ClientUploadHandler.js.map +0 -1
  34. package/dist/exports/client.d.ts +0 -2
  35. package/dist/exports/client.d.ts.map +0 -1
  36. package/dist/exports/client.js +0 -3
  37. package/dist/exports/client.js.map +0 -1
  38. package/dist/generateSignedURL.d.ts +0 -15
  39. package/dist/generateSignedURL.d.ts.map +0 -1
  40. package/dist/generateSignedURL.js +0 -61
  41. package/dist/generateSignedURL.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,22 +1,12 @@
1
+ import type { S3ClientConfig } from '@aws-sdk/client-s3';
1
2
  import type { ClientUploadsConfig, CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
2
- import type { Plugin, UploadCollectionSlug } from 'payload';
3
- import * as AWS from '@aws-sdk/client-s3';
3
+ import type { StorageAdapter, UploadCollectionSlug } from 'payload';
4
4
  import type { SignedDownloadsConfig } from './getFile.js';
5
5
  export type S3StorageOptions = {
6
6
  /**
7
7
  * Access control list for uploaded files.
8
8
  */
9
9
  acl?: 'private' | 'public-read';
10
- /**
11
- * When enabled, fields (like the prefix field) will always be inserted into
12
- * the collection schema regardless of whether the plugin is enabled. This
13
- * ensures a consistent schema across all environments.
14
- *
15
- * This will be enabled by default in Payload v4.
16
- *
17
- * @default false
18
- */
19
- alwaysInsertFields?: boolean;
20
10
  /**
21
11
  * Bucket name to upload files to.
22
12
  *
@@ -31,7 +21,7 @@ export type S3StorageOptions = {
31
21
  */
32
22
  clientCacheKey?: string;
33
23
  /**
34
- * Do uploads directly on the client to bypass limits on Vercel. You must allow CORS PUT method for the bucket to your website.
24
+ * Upload directly to S3 instead of through Payload. You must allow CORS PUT requests from your website.
35
25
  */
36
26
  clientUploads?: ClientUploadsConfig;
37
27
  /**
@@ -45,7 +35,7 @@ export type S3StorageOptions = {
45
35
  *
46
36
  * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)
47
37
  */
48
- config: AWS.S3ClientConfig;
38
+ config: S3ClientConfig;
49
39
  /**
50
40
  * Whether or not to disable local storage
51
41
  *
@@ -64,20 +54,21 @@ export type S3StorageOptions = {
64
54
  signedDownloads?: SignedDownloadsConfig;
65
55
  /**
66
56
  * When true, the collection-level prefix and document-level prefix are combined
67
- * (compositional). When false (default), document prefix overrides collection
68
- * prefix entirely.
57
+ * (compositional). When false (default), a document prefix already within the
58
+ * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.
59
+ * Existing files retain their stored prefixes for reads, URLs, and cleanup.
69
60
  *
70
- * Example:
71
- * - collection prefix: `collection-prefix/`
72
- * - document prefix: `document-prefix/`
73
- * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`
74
- * - resulting prefix with useCompositePrefixes=false: `document-prefix/`
61
+ * Example with a document prefix already contained by the collection prefix:
62
+ * - collection prefix: `uploads/`
63
+ * - document prefix: `uploads/documents/`
64
+ * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`
65
+ * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`
75
66
  *
76
67
  * @default false
77
68
  */
78
69
  useCompositePrefixes?: boolean;
79
70
  };
80
- type S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin;
81
- export declare const s3Storage: S3StoragePlugin;
71
+ type S3StorageFactory = (storageS3Args: S3StorageOptions) => StorageAdapter;
72
+ export declare const s3Storage: S3StorageFactory;
82
73
  export {};
83
74
  //# 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,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAU,MAAM,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnE,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAIzC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAKzD,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAE/B;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;;OAIG;IAEH,MAAM,EAAE,MAAM,CAAA;IAE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,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAClB,MAAM,CACJ,oBAAoB,EAClB,CAAC;QACC,eAAe,CAAC,EAAE,qBAAqB,CAAA;KACxC,GAAG,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC,GACvC,IAAI,CACP,CACF,CAAA;IACD;;;;OAIG;IACH,MAAM,EAAE,cAAc,CAAA;IAEtB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAA;IACvC;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,gBAAgB,GAAG,CAAC,aAAa,EAAE,gBAAgB,KAAK,cAAc,CAAA;AAe3E,eAAO,MAAM,SAAS,EAAE,gBA8GtB,CAAA"}
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
- import * as AWS from '@aws-sdk/client-s3';
1
+ import { S3 } from '@aws-sdk/client-s3';
2
2
  import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
3
- import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
4
3
  import { createS3Adapter } from './adapter.js';
5
- import { getGenerateSignedURLHandler } from './generateSignedURL.js';
6
4
  const s3Clients = new Map();
7
5
  const defaultRequestHandlerOpts = {
8
6
  httpAgent: {
@@ -14,38 +12,25 @@ const defaultRequestHandlerOpts = {
14
12
  maxSockets: 100
15
13
  }
16
14
  };
17
- export const s3Storage = (s3StorageOptions)=>(incomingConfig)=>{
18
- const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`;
19
- const getStorageClient = ()=>{
20
- if (s3Clients.has(cacheKey)) {
15
+ export const s3Storage = (s3StorageOptions)=>({
16
+ name: 's3',
17
+ collections: Object.keys(s3StorageOptions.collections),
18
+ init: (incomingConfig)=>{
19
+ const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`;
20
+ const isPluginDisabled = s3StorageOptions.enabled === false;
21
+ const getStorageClient = ()=>{
22
+ if (s3Clients.has(cacheKey)) {
23
+ return s3Clients.get(cacheKey);
24
+ }
25
+ s3Clients.set(cacheKey, new S3({
26
+ requestHandler: defaultRequestHandlerOpts,
27
+ ...s3StorageOptions.config ?? {}
28
+ }));
21
29
  return s3Clients.get(cacheKey);
22
- }
23
- s3Clients.set(cacheKey, new AWS.S3({
24
- requestHandler: defaultRequestHandlerOpts,
25
- ...s3StorageOptions.config ?? {}
26
- }));
27
- return s3Clients.get(cacheKey);
28
- };
29
- const isPluginDisabled = s3StorageOptions.enabled === false;
30
- initClientUploads({
31
- clientHandler: '@payloadcms/storage-s3/client#S3ClientUploadHandler',
32
- collections: s3StorageOptions.collections,
33
- config: incomingConfig,
34
- enabled: !isPluginDisabled && Boolean(s3StorageOptions.clientUploads),
35
- serverHandler: getGenerateSignedURLHandler({
36
- access: typeof s3StorageOptions.clientUploads === 'object' ? s3StorageOptions.clientUploads.access : undefined,
37
- acl: s3StorageOptions.acl,
38
- bucket: s3StorageOptions.bucket,
39
- collections: s3StorageOptions.collections,
40
- getStorageClient,
41
- useCompositePrefixes: s3StorageOptions.useCompositePrefixes
42
- }),
43
- serverHandlerPath: '/storage-s3-generate-signed-url'
44
- });
45
- if (isPluginDisabled) {
46
- // If alwaysInsertFields is true, still call cloudStoragePlugin to insert fields
47
- if (s3StorageOptions.alwaysInsertFields) {
48
- // Build collections with adapter: null since plugin is disabled
30
+ };
31
+ if (isPluginDisabled) {
32
+ // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are
33
+ // inserted into the schema, keeping it consistent across environments.
49
34
  const collectionsWithoutAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
50
35
  ...acc,
51
36
  [slug]: {
@@ -54,60 +39,57 @@ export const s3Storage = (s3StorageOptions)=>(incomingConfig)=>{
54
39
  }
55
40
  }), {});
56
41
  return cloudStoragePlugin({
57
- alwaysInsertFields: true,
58
42
  collections: collectionsWithoutAdapter,
59
43
  enabled: false,
60
44
  useCompositePrefixes: s3StorageOptions.useCompositePrefixes
61
45
  })(incomingConfig);
62
46
  }
63
- return incomingConfig;
64
- }
65
- // Determine signedDownloads for this collection
66
- const resolveSignedDownloads = (slug)=>{
67
- const collectionStorageConfig = s3StorageOptions.collections[slug];
68
- let signedDownloads = typeof collectionStorageConfig === 'object' ? collectionStorageConfig.signedDownloads ?? false : null;
69
- if (signedDownloads === null) {
70
- signedDownloads = s3StorageOptions.signedDownloads ?? false;
71
- }
72
- return signedDownloads;
73
- };
74
- // Add adapter to each collection option object
75
- const collectionsWithAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
76
- ...acc,
77
- [slug]: {
78
- ...collOptions === true ? {} : collOptions,
79
- adapter: createS3Adapter({
80
- acl: s3StorageOptions.acl,
81
- bucket: s3StorageOptions.bucket,
82
- clientUploads: s3StorageOptions.clientUploads,
83
- config: s3StorageOptions.config,
84
- getStorageClient,
85
- signedDownloads: resolveSignedDownloads(slug),
86
- useCompositePrefixes: s3StorageOptions.useCompositePrefixes
87
- })
47
+ // Determine signedDownloads for this collection
48
+ const resolveSignedDownloads = (slug)=>{
49
+ const collectionStorageConfig = s3StorageOptions.collections[slug];
50
+ let signedDownloads = typeof collectionStorageConfig === 'object' ? collectionStorageConfig.signedDownloads ?? false : null;
51
+ if (signedDownloads === null) {
52
+ signedDownloads = s3StorageOptions.signedDownloads ?? false;
88
53
  }
89
- }), {});
90
- // Set disableLocalStorage: true for collections specified in the plugin options
91
- const config = {
92
- ...incomingConfig,
93
- collections: (incomingConfig.collections || []).map((collection)=>{
94
- if (!collectionsWithAdapter[collection.slug]) {
95
- return collection;
96
- }
97
- return {
98
- ...collection,
99
- upload: {
100
- ...typeof collection.upload === 'object' ? collection.upload : {},
101
- disableLocalStorage: true
54
+ return signedDownloads;
55
+ };
56
+ // Add adapter to each collection option object
57
+ const collectionsWithAdapter = Object.entries(s3StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
58
+ ...acc,
59
+ [slug]: {
60
+ ...collOptions === true ? {} : collOptions,
61
+ adapter: createS3Adapter({
62
+ acl: s3StorageOptions.acl,
63
+ bucket: s3StorageOptions.bucket,
64
+ clientUploads: s3StorageOptions.clientUploads,
65
+ config: s3StorageOptions.config,
66
+ getStorageClient,
67
+ signedDownloads: resolveSignedDownloads(slug),
68
+ useCompositePrefixes: s3StorageOptions.useCompositePrefixes
69
+ })
70
+ }
71
+ }), {});
72
+ // Set disableLocalStorage: true for collections specified in the plugin options
73
+ const config = {
74
+ ...incomingConfig,
75
+ collections: (incomingConfig.collections || []).map((collection)=>{
76
+ if (!collectionsWithAdapter[collection.slug]) {
77
+ return collection;
102
78
  }
103
- };
104
- })
105
- };
106
- return cloudStoragePlugin({
107
- alwaysInsertFields: s3StorageOptions.alwaysInsertFields,
108
- collections: collectionsWithAdapter,
109
- useCompositePrefixes: s3StorageOptions.useCompositePrefixes
110
- })(config);
111
- };
79
+ return {
80
+ ...collection,
81
+ upload: {
82
+ ...typeof collection.upload === 'object' ? collection.upload : {},
83
+ disableLocalStorage: true
84
+ }
85
+ };
86
+ })
87
+ };
88
+ return cloudStoragePlugin({
89
+ collections: collectionsWithAdapter,
90
+ useCompositePrefixes: s3StorageOptions.useCompositePrefixes
91
+ })(config);
92
+ }
93
+ });
112
94
 
113
95
  //# 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 { NodeHttpHandlerOptions } from '@smithy/node-http-handler'\nimport type { Config, Plugin, UploadCollectionSlug } from 'payload'\n\nimport * as AWS from '@aws-sdk/client-s3'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport type { SignedDownloadsConfig } from './getFile.js'\n\nimport { createS3Adapter } from './adapter.js'\nimport { getGenerateSignedURLHandler } from './generateSignedURL.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n acl?: 'private' | 'public-read'\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 * Bucket name to upload files to.\n *\n * Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).\n */\n\n bucket: string\n\n /**\n * Optional cache key to identify the S3 storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `s3:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Do uploads directly on the client to bypass limits on Vercel. You must allow CORS PUT method for the bucket to your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<\n Record<\n UploadCollectionSlug,\n | ({\n signedDownloads?: SignedDownloadsConfig\n } & Omit<CollectionOptions, 'adapter'>)\n | true\n >\n >\n /**\n * AWS S3 client configuration. Highly dependent on your AWS setup.\n *\n * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)\n */\n config: AWS.S3ClientConfig\n\n /**\n * Whether or not to disable local storage\n *\n * @default true\n */\n disableLocalStorage?: boolean\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Use pre-signed URLs for files downloading. Can be overriden per-collection.\n */\n signedDownloads?: SignedDownloadsConfig\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\ntype S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin\n\nconst s3Clients = new Map<string, AWS.S3>()\n\nconst defaultRequestHandlerOpts: NodeHttpHandlerOptions = {\n httpAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n httpsAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n}\n\nexport const s3Storage: S3StoragePlugin =\n (s3StorageOptions: S3StorageOptions) =>\n (incomingConfig: Config): Config => {\n const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`\n\n const getStorageClient: () => AWS.S3 = () => {\n if (s3Clients.has(cacheKey)) {\n return s3Clients.get(cacheKey)!\n }\n\n s3Clients.set(\n cacheKey,\n new AWS.S3({\n requestHandler: defaultRequestHandlerOpts,\n ...(s3StorageOptions.config ?? {}),\n }),\n )\n\n return s3Clients.get(cacheKey)!\n }\n\n const isPluginDisabled = s3StorageOptions.enabled === false\n\n initClientUploads({\n clientHandler: '@payloadcms/storage-s3/client#S3ClientUploadHandler',\n collections: s3StorageOptions.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(s3StorageOptions.clientUploads),\n serverHandler: getGenerateSignedURLHandler({\n access:\n typeof s3StorageOptions.clientUploads === 'object'\n ? s3StorageOptions.clientUploads.access\n : undefined,\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n collections: s3StorageOptions.collections,\n getStorageClient,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\n serverHandlerPath: '/storage-s3-generate-signed-url',\n })\n\n if (isPluginDisabled) {\n // If alwaysInsertFields is true, still call cloudStoragePlugin to insert fields\n if (s3StorageOptions.alwaysInsertFields) {\n // Build collections with adapter: null since plugin is disabled\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: null,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n alwaysInsertFields: true,\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\n\n return incomingConfig\n }\n\n // Determine signedDownloads for this collection\n const resolveSignedDownloads = (slug: string): SignedDownloadsConfig => {\n const collectionStorageConfig = s3StorageOptions.collections[slug]\n\n let signedDownloads: null | SignedDownloadsConfig =\n typeof collectionStorageConfig === 'object'\n ? (collectionStorageConfig.signedDownloads ?? false)\n : null\n\n if (signedDownloads === null) {\n signedDownloads = s3StorageOptions.signedDownloads ?? false\n }\n\n return signedDownloads\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: createS3Adapter({\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n clientUploads: s3StorageOptions.clientUploads,\n config: s3StorageOptions.config,\n getStorageClient,\n signedDownloads: resolveSignedDownloads(slug),\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\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: s3StorageOptions.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(config)\n }\n"],"names":["AWS","cloudStoragePlugin","initClientUploads","createS3Adapter","getGenerateSignedURLHandler","s3Clients","Map","defaultRequestHandlerOpts","httpAgent","keepAlive","maxSockets","httpsAgent","s3Storage","s3StorageOptions","incomingConfig","cacheKey","clientCacheKey","bucket","getStorageClient","has","get","set","S3","requestHandler","config","isPluginDisabled","enabled","clientHandler","collections","Boolean","clientUploads","serverHandler","access","undefined","acl","useCompositePrefixes","serverHandlerPath","alwaysInsertFields","collectionsWithoutAdapter","Object","entries","reduce","acc","slug","collOptions","adapter","resolveSignedDownloads","collectionStorageConfig","signedDownloads","collectionsWithAdapter","map","collection","upload","disableLocalStorage"],"mappings":"AAQA,YAAYA,SAAS,qBAAoB;AACzC,SAASC,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAI9E,SAASC,eAAe,QAAQ,eAAc;AAC9C,SAASC,2BAA2B,QAAQ,yBAAwB;AA6FpE,MAAMC,YAAY,IAAIC;AAEtB,MAAMC,4BAAoD;IACxDC,WAAW;QACTC,WAAW;QACXC,YAAY;IACd;IACAC,YAAY;QACVF,WAAW;QACXC,YAAY;IACd;AACF;AAEA,OAAO,MAAME,YACX,CAACC,mBACD,CAACC;QACC,MAAMC,WAAWF,iBAAiBG,cAAc,IAAI,CAAC,GAAG,EAAEH,iBAAiBI,MAAM,EAAE;QAEnF,MAAMC,mBAAiC;YACrC,IAAIb,UAAUc,GAAG,CAACJ,WAAW;gBAC3B,OAAOV,UAAUe,GAAG,CAACL;YACvB;YAEAV,UAAUgB,GAAG,CACXN,UACA,IAAIf,IAAIsB,EAAE,CAAC;gBACTC,gBAAgBhB;gBAChB,GAAIM,iBAAiBW,MAAM,IAAI,CAAC,CAAC;YACnC;YAGF,OAAOnB,UAAUe,GAAG,CAACL;QACvB;QAEA,MAAMU,mBAAmBZ,iBAAiBa,OA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AAOC,OAAO,CACrF3B,iBAAiBe,WAAW,EAC5Ba,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CC,SAAS1C,gBAAgB;wBACvB+B,KAAKrB,iBAAiBqB,GAAG;wBACzBjB,QAAQJ,iBAAiBI,MAAM;wBAC/Ba,eAAejB,iBAAiBiB,aAAa;wBAC7CN,QAAQX,iBAAiBW,MAAM;wBAC/BN;wBACA8B,iBAAiBF,uBAAuBH;wBACxCR,sBAAsBtB,iBAAiBsB,oBAAoB;oBAC7D;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMX,SAAS;YACb,GAAGV,cAAc;YACjBc,aAAa,AAACd,CAAAA,eAAec,WAAW,IAAI,EAAE,AAAD,EAAGsB,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACF,sBAAsB,CAACE,WAAWR,IAAI,CAAC,EAAE;oBAC5C,OAAOQ;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,OAAOpD,mBAAmB;YACxBoC,oBAAoBxB,iBAAiBwB,kBAAkB;YACvDT,aAAaqB;YACbd,sBAAsBtB,iBAAiBsB,oBAAoB;QAC7D,GAAGX;IACL,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { S3ClientConfig } from '@aws-sdk/client-s3'\nimport type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { NodeHttpHandlerOptions } from '@smithy/node-http-handler'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { S3 } from '@aws-sdk/client-s3'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport type { SignedDownloadsConfig } from './getFile.js'\n\nimport { createS3Adapter } from './adapter.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n acl?: 'private' | 'public-read'\n\n /**\n * Bucket name to upload files to.\n *\n * Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).\n */\n\n bucket: string\n\n /**\n * Optional cache key to identify the S3 storage client instance.\n * If not provided, a default key will be used.\n *\n * @default `s3:containerName`\n */\n clientCacheKey?: string\n\n /**\n * Upload directly to S3 instead of through Payload. You must allow CORS PUT requests from your website.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Partial<\n Record<\n UploadCollectionSlug,\n | ({\n signedDownloads?: SignedDownloadsConfig\n } & Omit<CollectionOptions, 'adapter'>)\n | true\n >\n >\n /**\n * AWS S3 client configuration. Highly dependent on your AWS setup.\n *\n * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)\n */\n config: S3ClientConfig\n\n /**\n * Whether or not to disable local storage\n *\n * @default true\n */\n disableLocalStorage?: boolean\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * Use pre-signed URLs for files downloading. Can be overriden per-collection.\n */\n signedDownloads?: SignedDownloadsConfig\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), a document prefix already within the\n * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.\n * Existing files retain their stored prefixes for reads, URLs, and cleanup.\n *\n * Example with a document prefix already contained by the collection prefix:\n * - collection prefix: `uploads/`\n * - document prefix: `uploads/documents/`\n * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`\n * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype S3StorageFactory = (storageS3Args: S3StorageOptions) => StorageAdapter\n\nconst s3Clients = new Map<string, S3>()\n\nconst defaultRequestHandlerOpts: NodeHttpHandlerOptions = {\n httpAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n httpsAgent: {\n keepAlive: true,\n maxSockets: 100,\n },\n}\n\nexport const s3Storage: S3StorageFactory = (\n s3StorageOptions: S3StorageOptions,\n): StorageAdapter => ({\n name: 's3',\n collections: Object.keys(s3StorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const cacheKey = s3StorageOptions.clientCacheKey || `s3:${s3StorageOptions.bucket}`\n\n const isPluginDisabled = s3StorageOptions.enabled === false\n\n const getStorageClient: () => S3 = () => {\n if (s3Clients.has(cacheKey)) {\n return s3Clients.get(cacheKey)!\n }\n\n s3Clients.set(\n cacheKey,\n new S3({\n requestHandler: defaultRequestHandlerOpts,\n ...(s3StorageOptions.config ?? {}),\n }),\n )\n\n return s3Clients.get(cacheKey)!\n }\n\n if (isPluginDisabled) {\n // Still call cloudStoragePlugin with adapter: null so fields (like prefix) are\n // inserted into the schema, keeping it consistent across environments.\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: null,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n return cloudStoragePlugin({\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(incomingConfig)\n }\n\n // Determine signedDownloads for this collection\n const resolveSignedDownloads = (slug: string): SignedDownloadsConfig => {\n const collectionStorageConfig = s3StorageOptions.collections[slug]\n\n let signedDownloads: null | SignedDownloadsConfig =\n typeof collectionStorageConfig === 'object'\n ? (collectionStorageConfig.signedDownloads ?? false)\n : null\n\n if (signedDownloads === null) {\n signedDownloads = s3StorageOptions.signedDownloads ?? false\n }\n\n return signedDownloads\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter: createS3Adapter({\n acl: s3StorageOptions.acl,\n bucket: s3StorageOptions.bucket,\n clientUploads: s3StorageOptions.clientUploads,\n config: s3StorageOptions.config,\n getStorageClient,\n signedDownloads: resolveSignedDownloads(slug),\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n }),\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 collections: collectionsWithAdapter,\n useCompositePrefixes: s3StorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["S3","cloudStoragePlugin","createS3Adapter","s3Clients","Map","defaultRequestHandlerOpts","httpAgent","keepAlive","maxSockets","httpsAgent","s3Storage","s3StorageOptions","name","collections","Object","keys","init","incomingConfig","cacheKey","clientCacheKey","bucket","isPluginDisabled","enabled","getStorageClient","has","get","set","requestHandler","config","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","resolveSignedDownloads","collectionStorageConfig","signedDownloads","collectionsWithAdapter","acl","clientUploads","map","collection","upload","disableLocalStorage"],"mappings":"AASA,SAASA,EAAE,QAAQ,qBAAoB;AACvC,SAASC,kBAAkB,QAAQ,mCAAkC;AAIrE,SAASC,eAAe,QAAQ,eAAc;AAmF9C,MAAMC,YAAY,IAAIC;AAEtB,MAAMC,4BAAoD;IACx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BAAoB,MAAM;oBAC5BA,kBAAkB5B,iBAAiB4B,eAAe,IAAI;gBACxD;gBAEA,OAAOA;YACT;YAEA,+CAA+C;YAC/C,MAAMC,yBAAmE1B,OAAOgB,OAAO,CACrFnB,iBAAiBE,WAAW,EAC5BkB,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;oBAC7B,GAAGF,GAAG;oBACN,CAACC,KAAK,EAAE;wBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;wBAC3CC,SAASjC,gBAAgB;4BACvBuC,KAAK9B,iBAAiB8B,GAAG;4BACzBrB,QAAQT,iBAAiBS,MAAM;4BAC/BsB,eAAe/B,iBAAiB+B,aAAa;4BAC7Cd,QAAQjB,iBAAiBiB,MAAM;4BAC/BL;4BACAgB,iBAAiBF,uBAAuBJ;4BACxCG,sBAAsBzB,iBAAiByB,oBAAoB;wBAC7D;oBACF;gBACF,CAAA,GACA,CAAC;YAGH,gFAAgF;YAChF,MAAMR,SAAS;gBACb,GAAGX,cAAc;gBACjBJ,aAAa,AAACI,CAAAA,eAAeJ,WAAW,IAAI,EAAE,AAAD,EAAG8B,GAAG,CAAC,CAACC;oBACnD,IAAI,CAACJ,sBAAsB,CAACI,WAAWX,IAAI,CAAC,EAAE;wBAC5C,OAAOW;oBACT;oBAEA,OAAO;wBACL,GAAGA,UAAU;wBACbC,QAAQ;4BACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;4BAClEC,qBAAqB;wBACvB;oBACF;gBACF;YACF;YAEA,OAAO7C,mBAAmB;gBACxBY,aAAa2B;gBACbJ,sBAAsBzB,iBAAiByB,oBAAoB;YAC7D,GAAGR;QACL;IACF,CAAA,EAAE"}
@@ -4,13 +4,10 @@ interface UploadArgs {
4
4
  bucket: string;
5
5
  buffer: Buffer;
6
6
  client: AWS.S3;
7
- collectionPrefix?: string;
8
- docPrefix?: string;
9
- filename: string;
10
7
  mimeType: string;
8
+ storageFilePath: string;
11
9
  tempFilePath?: string;
12
- useCompositePrefixes?: boolean;
13
10
  }
14
- export declare function uploadFile({ acl, bucket, buffer, client, collectionPrefix, docPrefix, filename, mimeType, tempFilePath, useCompositePrefixes, }: UploadArgs): Promise<void>;
11
+ export declare function uploadFile({ acl, bucket, buffer, client, mimeType, storageFilePath, tempFilePath, }: UploadArgs): Promise<void>;
15
12
  export {};
16
13
  //# sourceMappingURL=uploadFile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAM9C,UAAU,UAAU;IAClB,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAID,wBAAsB,UAAU,CAAC,EAC/B,GAAG,EACH,MAAM,EACN,MAAM,EACN,MAAM,EACN,gBAAqB,EACrB,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,oBAA4B,GAC7B,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAoC5B"}
1
+ {"version":3,"file":"uploadFile.d.ts","sourceRoot":"","sources":["../src/uploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAK9C,UAAU,UAAU;IAClB,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAID,wBAAsB,UAAU,CAAC,EAC/B,GAAG,EACH,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,eAAe,EACf,YAAY,GACb,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA6B5B"}
@@ -1,15 +1,8 @@
1
1
  import { Upload } from '@aws-sdk/lib-storage';
2
- import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
3
2
  import fs from 'fs';
4
3
  const multipartThreshold = 1024 * 1024 * 50 // 50MB
5
4
  ;
6
- export async function uploadFile({ acl, bucket, buffer, client, collectionPrefix = '', docPrefix, filename, mimeType, tempFilePath, useCompositePrefixes = false }) {
7
- const { fileKey } = getFileKey({
8
- collectionPrefix,
9
- docPrefix,
10
- filename,
11
- useCompositePrefixes
12
- });
5
+ export async function uploadFile({ acl, bucket, buffer, client, mimeType, storageFilePath, tempFilePath }) {
13
6
  const fileBufferOrStream = tempFilePath ? fs.createReadStream(tempFilePath) : buffer;
14
7
  if (buffer.length > 0 && buffer.length < multipartThreshold) {
15
8
  await client.putObject({
@@ -17,7 +10,7 @@ export async function uploadFile({ acl, bucket, buffer, client, collectionPrefix
17
10
  Body: fileBufferOrStream,
18
11
  Bucket: bucket,
19
12
  ContentType: mimeType,
20
- Key: fileKey
13
+ Key: storageFilePath
21
14
  });
22
15
  return;
23
16
  }
@@ -28,7 +21,7 @@ export async function uploadFile({ acl, bucket, buffer, client, collectionPrefix
28
21
  Body: fileBufferOrStream,
29
22
  Bucket: bucket,
30
23
  ContentType: mimeType,
31
- Key: fileKey
24
+ Key: storageFilePath
32
25
  },
33
26
  partSize: multipartThreshold,
34
27
  queueSize: 4
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\n\nimport { Upload } from '@aws-sdk/lib-storage'\nimport { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport fs from 'fs'\n\ninterface UploadArgs {\n acl?: 'private' | 'public-read'\n bucket: string\n buffer: Buffer\n client: AWS.S3\n collectionPrefix?: string\n docPrefix?: string\n filename: string\n mimeType: string\n tempFilePath?: string\n useCompositePrefixes?: boolean\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\n\nexport async function uploadFile({\n acl,\n bucket,\n buffer,\n client,\n collectionPrefix = '',\n docPrefix,\n filename,\n mimeType,\n tempFilePath,\n useCompositePrefixes = false,\n}: UploadArgs): Promise<void> {\n const { fileKey } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n const fileBufferOrStream = tempFilePath ? fs.createReadStream(tempFilePath) : buffer\n\n if (buffer.length > 0 && buffer.length < multipartThreshold) {\n await client.putObject({\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: fileKey,\n })\n\n return\n }\n\n const parallelUploadS3 = new Upload({\n client,\n params: {\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: fileKey,\n },\n partSize: multipartThreshold,\n queueSize: 4,\n })\n\n await parallelUploadS3.done()\n}\n"],"names":["Upload","getFileKey","fs","multipartThreshold","uploadFile","acl","bucket","buffer","client","collectionPrefix","docPrefix","filename","mimeType","tempFilePath","useCompositePrefixes","fileKey","fileBufferOrStream","createReadStream","length","putObject","ACL","Body","Bucket","ContentType","Key","parallelUploadS3","params","partSize","queueSize","done"],"mappings":"AAEA,SAASA,MAAM,QAAQ,uBAAsB;AAC7C,SAASC,UAAU,QAAQ,6CAA4C;AACvE,OAAOC,QAAQ,KAAI;AAenB,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AAEnD,OAAO,eAAeC,WAAW,EAC/BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,mBAAmB,EAAE,EACrBC,SAAS,EACTC,QAAQ,EACRC,QAAQ,EACRC,YAAY,EACZC,uBAAuB,KAAK,EACjB;IACX,MAAM,EAAEC,OAAO,EAAE,GAAGd,WAAW;QAC7BQ;QACAC;QACAC;QACAG;IACF;IAEA,MAAME,qBAAqBH,eAAeX,GAAGe,gBAAgB,CAACJ,gBAAgBN;IAE9E,IAAIA,OAAOW,MAAM,GAAG,KAAKX,OAAOW,MAAM,GAAGf,oBAAoB;QAC3D,MAAMK,OAAOW,SAAS,CAAC;YACrBC,KAAKf;YACLgB,MAAML;YACNM,QAAQhB;YACRiB,aAAaX;YACbY,KAAKT;QACP;QAEA;IACF;IAEA,MAAMU,mBAAmB,IAAIzB,OAAO;QAClCQ;QACAkB,QAAQ;YACNN,KAAKf;YACLgB,MAAML;YACNM,QAAQhB;YACRiB,aAAaX;YACbY,KAAKT;QACP;QACAY,UAAUxB;QACVyB,WAAW;IACb;IAEA,MAAMH,iBAAiBI,IAAI;AAC7B"}
1
+ {"version":3,"sources":["../src/uploadFile.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\n\nimport { Upload } from '@aws-sdk/lib-storage'\nimport fs from 'fs'\n\ninterface UploadArgs {\n acl?: 'private' | 'public-read'\n bucket: string\n buffer: Buffer\n client: AWS.S3\n mimeType: string\n storageFilePath: string\n tempFilePath?: string\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\n\nexport async function uploadFile({\n acl,\n bucket,\n buffer,\n client,\n mimeType,\n storageFilePath,\n tempFilePath,\n}: UploadArgs): Promise<void> {\n const fileBufferOrStream = tempFilePath ? fs.createReadStream(tempFilePath) : buffer\n\n if (buffer.length > 0 && buffer.length < multipartThreshold) {\n await client.putObject({\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: storageFilePath,\n })\n\n return\n }\n\n const parallelUploadS3 = new Upload({\n client,\n params: {\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: mimeType,\n Key: storageFilePath,\n },\n partSize: multipartThreshold,\n queueSize: 4,\n })\n\n await parallelUploadS3.done()\n}\n"],"names":["Upload","fs","multipartThreshold","uploadFile","acl","bucket","buffer","client","mimeType","storageFilePath","tempFilePath","fileBufferOrStream","createReadStream","length","putObject","ACL","Body","Bucket","ContentType","Key","parallelUploadS3","params","partSize","queueSize","done"],"mappings":"AAEA,SAASA,MAAM,QAAQ,uBAAsB;AAC7C,OAAOC,QAAQ,KAAI;AAYnB,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AAEnD,OAAO,eAAeC,WAAW,EAC/BC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,eAAe,EACfC,YAAY,EACD;IACX,MAAMC,qBAAqBD,eAAeT,GAAGW,gBAAgB,CAACF,gBAAgBJ;IAE9E,IAAIA,OAAOO,MAAM,GAAG,KAAKP,OAAOO,MAAM,GAAGX,oBAAoB;QAC3D,MAAMK,OAAOO,SAAS,CAAC;YACrBC,KAAKX;YACLY,MAAML;YACNM,QAAQZ;YACRa,aAAaV;YACbW,KAAKV;QACP;QAEA;IACF;IAEA,MAAMW,mBAAmB,IAAIpB,OAAO;QAClCO;QACAc,QAAQ;YACNN,KAAKX;YACLY,MAAML;YACNM,QAAQZ;YACRa,aAAaV;YACbW,KAAKV;QACP;QACAa,UAAUpB;QACVqB,WAAW;IACb;IAEA,MAAMH,iBAAiBI,IAAI;AAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-s3",
3
- "version": "4.0.0-internal.5b1e7cd",
3
+ "version": "4.0.0-internal.5e065b3",
4
4
  "description": "Payload storage adapter for Amazon S3",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -24,11 +24,6 @@
24
24
  "import": "./dist/index.js",
25
25
  "types": "./dist/index.d.ts",
26
26
  "default": "./dist/index.js"
27
- },
28
- "./client": {
29
- "import": "./dist/exports/client.js",
30
- "types": "./dist/exports/client.d.ts",
31
- "default": "./dist/exports/client.js"
32
27
  }
33
28
  },
34
29
  "main": "./dist/index.js",
@@ -40,17 +35,17 @@
40
35
  "@aws-sdk/client-s3": "^3.614.0",
41
36
  "@aws-sdk/lib-storage": "^3.614.0",
42
37
  "@aws-sdk/s3-request-presigner": "^3.614.0",
43
- "@payloadcms/plugin-cloud-storage": "4.0.0-internal.5b1e7cd"
38
+ "@payloadcms/plugin-cloud-storage": "4.0.0-internal.5e065b3"
44
39
  },
45
40
  "devDependencies": {
46
41
  "@smithy/node-http-handler": "4.0.3",
47
- "payload": "4.0.0-internal.5b1e7cd"
42
+ "payload": "4.0.0-internal.5e065b3"
48
43
  },
49
44
  "peerDependencies": {
50
- "payload": "4.0.0-internal.5b1e7cd"
45
+ "payload": "4.0.0-internal.5e065b3"
51
46
  },
52
47
  "engines": {
53
- "node": "^18.20.2 || >=20.9.0"
48
+ "node": ">=24.15.0"
54
49
  },
55
50
  "scripts": {
56
51
  "build": "pnpm build:types && pnpm build:swc",
@@ -1,9 +0,0 @@
1
- export declare const S3ClientUploadHandler: ({ children, collectionSlug, enabled, extra, prefix, serverHandlerPath, }: {
2
- children: import("react").ReactNode;
3
- collectionSlug: import("payload").UploadCollectionSlug;
4
- enabled?: boolean;
5
- extra: Record<string, unknown>;
6
- prefix?: string;
7
- serverHandlerPath: `/${string}`;
8
- }) => import("react").JSX.Element;
9
- //# sourceMappingURL=S3ClientUploadHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"S3ClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/S3ClientUploadHandler.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,qBAAqB;;;;;;;aA0B5B,OAAM,aAkBV,CAAA"}
@@ -1,44 +0,0 @@
1
- 'use client';
2
- import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client';
3
- import { formatAdminURL } from 'payload/shared';
4
- export const S3ClientUploadHandler = createClientUploadHandler({
5
- handler: async ({ apiRoute, collectionSlug, docPrefix, file, serverHandlerPath, serverURL })=>{
6
- const endpointRoute = formatAdminURL({
7
- apiRoute,
8
- path: serverHandlerPath,
9
- serverURL
10
- });
11
- // get the signed URL from the server
12
- const response = await fetch(endpointRoute, {
13
- body: JSON.stringify({
14
- collectionSlug,
15
- docPrefix,
16
- filename: file.name,
17
- filesize: file.size,
18
- mimeType: file.type
19
- }),
20
- credentials: 'include',
21
- method: 'POST'
22
- });
23
- if (!response.ok) {
24
- const { errors } = await response.json();
25
- throw new Error(errors.reduce((acc, err)=>`${acc ? `${acc}, ` : ''}${err.message}`, ''));
26
- }
27
- const { docPrefix: sanitizedDocPrefix, url } = await response.json();
28
- // upload the file directly to S3 using the signed URL
29
- await fetch(url, {
30
- body: file,
31
- headers: {
32
- 'Content-Length': file.size.toString(),
33
- 'Content-Type': file.type
34
- },
35
- method: 'PUT'
36
- });
37
- // return the docPrefix so the client can update the field value accordingly
38
- return {
39
- prefix: sanitizedDocPrefix
40
- };
41
- }
42
- });
43
-
44
- //# sourceMappingURL=S3ClientUploadHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/client/S3ClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\nimport { formatAdminURL } from 'payload/shared'\n\nexport const S3ClientUploadHandler = createClientUploadHandler({\n handler: async ({ apiRoute, collectionSlug, docPrefix, file, serverHandlerPath, serverURL }) => {\n const endpointRoute = formatAdminURL({\n apiRoute,\n path: serverHandlerPath,\n serverURL,\n })\n\n // get the signed URL from the server\n const response = await fetch(endpointRoute, {\n body: JSON.stringify({\n collectionSlug,\n docPrefix,\n filename: file.name,\n filesize: file.size,\n mimeType: file.type,\n }),\n credentials: 'include',\n method: 'POST',\n })\n\n if (!response.ok) {\n const { errors } = (await response.json()) as {\n errors: { message: string }[]\n }\n\n throw new Error(errors.reduce((acc, err) => `${acc ? `${acc}, ` : ''}${err.message}`, ''))\n }\n\n const { docPrefix: sanitizedDocPrefix, url } = (await response.json()) as {\n docPrefix: string\n url: string\n }\n\n // upload the file directly to S3 using the signed URL\n await fetch(url, {\n body: file,\n headers: { 'Content-Length': file.size.toString(), 'Content-Type': file.type },\n method: 'PUT',\n })\n\n // return the docPrefix so the client can update the field value accordingly\n return { prefix: sanitizedDocPrefix }\n },\n})\n"],"names":["createClientUploadHandler","formatAdminURL","S3ClientUploadHandler","handler","apiRoute","collectionSlug","docPrefix","file","serverHandlerPath","serverURL","endpointRoute","path","response","fetch","body","JSON","stringify","filename","name","filesize","size","mimeType","type","credentials","method","ok","errors","json","Error","reduce","acc","err","message","sanitizedDocPrefix","url","headers","toString","prefix"],"mappings":"AAAA;AACA,SAASA,yBAAyB,QAAQ,0CAAyC;AACnF,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,OAAO,MAAMC,wBAAwBF,0BAA0B;IAC7DG,SAAS,OAAO,EAAEC,QAAQ,EAAEC,cAAc,EAAEC,SAAS,EAAEC,IAAI,EAAEC,iBAAiB,EAAEC,SAAS,EAAE;QACzF,MAAMC,gBAAgBT,eAAe;YACnCG;YACAO,MAAMH;YACNC;QACF;QAEA,qCAAqC;QACrC,MAAMG,WAAW,MAAMC,MAAMH,eAAe;YAC1CI,MAAMC,KAAKC,SAAS,CAAC;gBACnBX;gBACAC;gBACAW,UAAUV,KAAKW,IAAI;gBACnBC,UAAUZ,KAAKa,IAAI;gBACnBC,UAAUd,KAAKe,IAAI;YACrB;YACAC,aAAa;YACbC,QAAQ;QACV;QAEA,IAAI,CAACZ,SAASa,EAAE,EAAE;YAChB,MAAM,EAAEC,MAAM,EAAE,GAAI,MAAMd,SAASe,IAAI;YAIvC,MAAM,IAAIC,MAAMF,OAAOG,MAAM,CAAC,CAACC,KAAKC,MAAQ,GAAGD,MAAM,GAAGA,IAAI,EAAE,CAAC,GAAG,KAAKC,IAAIC,OAAO,EAAE,EAAE;QACxF;QAEA,MAAM,EAAE1B,WAAW2B,kBAAkB,EAAEC,GAAG,EAAE,GAAI,MAAMtB,SAASe,IAAI;QAKnE,sDAAsD;QACtD,MAAMd,MAAMqB,KAAK;YACfpB,MAAMP;YACN4B,SAAS;gBAAE,kBAAkB5B,KAAKa,IAAI,CAACgB,QAAQ;gBAAI,gBAAgB7B,KAAKe,IAAI;YAAC;YAC7EE,QAAQ;QACV;QAEA,4EAA4E;QAC5E,OAAO;YAAEa,QAAQJ;QAAmB;IACtC;AACF,GAAE"}
@@ -1,2 +0,0 @@
1
- export { S3ClientUploadHandler } from '../client/S3ClientUploadHandler.js';
2
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA"}
@@ -1,3 +0,0 @@
1
- export { S3ClientUploadHandler } from '../client/S3ClientUploadHandler.js';
2
-
3
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { S3ClientUploadHandler } from '../client/S3ClientUploadHandler.js'\n"],"names":["S3ClientUploadHandler"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,qCAAoC"}
@@ -1,15 +0,0 @@
1
- import type { ClientUploadsAccess } from '@payloadcms/plugin-cloud-storage/types';
2
- import type { PayloadHandler } from 'payload';
3
- import * as AWS from '@aws-sdk/client-s3';
4
- import type { S3StorageOptions } from './index.js';
5
- interface Args {
6
- access?: ClientUploadsAccess;
7
- acl?: 'private' | 'public-read';
8
- bucket: string;
9
- collections: S3StorageOptions['collections'];
10
- getStorageClient: () => AWS.S3;
11
- useCompositePrefixes?: boolean;
12
- }
13
- export declare const getGenerateSignedURLHandler: ({ access, acl, bucket, collections, getStorageClient, useCompositePrefixes, }: Args) => PayloadHandler;
14
- export {};
15
- //# sourceMappingURL=generateSignedURL.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateSignedURL.d.ts","sourceRoot":"","sources":["../src/generateSignedURL.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAKzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAMlD,UAAU,IAAI;IACZ,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAC5C,gBAAgB,EAAE,MAAM,GAAG,CAAC,EAAE,CAAA;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAID,eAAO,MAAM,2BAA2B,kFAOrC,IAAI,KAAG,cAyET,CAAA"}
@@ -1,61 +0,0 @@
1
- import * as AWS from '@aws-sdk/client-s3';
2
- import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
3
- import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
4
- import { APIError, Forbidden } from 'payload';
5
- const bytesToMB = (bytes)=>{
6
- return bytes / 1024 / 1024;
7
- };
8
- const defaultAccess = ({ req })=>!!req.user;
9
- export const getGenerateSignedURLHandler = ({ access = defaultAccess, acl, bucket, collections, getStorageClient, useCompositePrefixes = false })=>{
10
- return async (req)=>{
11
- if (!req.json) {
12
- throw new APIError('Content-Type expected to be application/json', 400);
13
- }
14
- let filesizeLimit = req.payload.config.upload.limits?.fileSize;
15
- if (filesizeLimit === Infinity) {
16
- filesizeLimit = undefined;
17
- }
18
- const { collectionSlug, docPrefix, filename, filesize, mimeType } = await req.json();
19
- const collectionS3Config = collections[collectionSlug];
20
- if (!collectionS3Config) {
21
- throw new APIError(`Collection ${collectionSlug} was not found in S3 options`);
22
- }
23
- const collectionPrefix = typeof collectionS3Config === 'object' && collectionS3Config.prefix || '';
24
- if (!await access({
25
- collectionSlug,
26
- req
27
- })) {
28
- throw new Forbidden();
29
- }
30
- const { fileKey, sanitizedDocPrefix } = getFileKey({
31
- collectionPrefix,
32
- docPrefix,
33
- filename,
34
- useCompositePrefixes
35
- });
36
- const signableHeaders = new Set();
37
- if (filesizeLimit) {
38
- if (filesize > filesizeLimit) {
39
- throw new APIError(`Exceeded file size limit. Limit: ${bytesToMB(filesizeLimit).toFixed(2)}MB, got: ${bytesToMB(filesize).toFixed(2)}MB`, 400);
40
- }
41
- // Still force S3 to validate
42
- signableHeaders.add('content-length');
43
- }
44
- const url = await getSignedUrl(getStorageClient(), new AWS.PutObjectCommand({
45
- ACL: acl,
46
- Bucket: bucket,
47
- ContentLength: filesizeLimit ? Math.min(filesize, filesizeLimit) : undefined,
48
- ContentType: mimeType,
49
- Key: fileKey
50
- }), {
51
- expiresIn: 600,
52
- signableHeaders
53
- });
54
- return Response.json({
55
- docPrefix: sanitizedDocPrefix,
56
- url
57
- });
58
- };
59
- };
60
-
61
- //# sourceMappingURL=generateSignedURL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generateSignedURL.ts"],"sourcesContent":["import type { ClientUploadsAccess } from '@payloadcms/plugin-cloud-storage/types'\nimport type { PayloadHandler } from 'payload'\n\nimport * as AWS from '@aws-sdk/client-s3'\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner'\nimport { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { APIError, Forbidden } from 'payload'\n\nimport type { S3StorageOptions } from './index.js'\n\nconst bytesToMB = (bytes: number) => {\n return bytes / 1024 / 1024\n}\n\ninterface Args {\n access?: ClientUploadsAccess\n acl?: 'private' | 'public-read'\n bucket: string\n collections: S3StorageOptions['collections']\n getStorageClient: () => AWS.S3\n useCompositePrefixes?: boolean\n}\n\nconst defaultAccess: Args['access'] = ({ req }) => !!req.user\n\nexport const getGenerateSignedURLHandler = ({\n access = defaultAccess,\n acl,\n bucket,\n collections,\n getStorageClient,\n useCompositePrefixes = false,\n}: Args): PayloadHandler => {\n return async (req) => {\n if (!req.json) {\n throw new APIError('Content-Type expected to be application/json', 400)\n }\n\n let filesizeLimit = req.payload.config.upload.limits?.fileSize\n\n if (filesizeLimit === Infinity) {\n filesizeLimit = undefined\n }\n\n const { collectionSlug, docPrefix, filename, filesize, mimeType } = (await req.json()) as {\n collectionSlug: string\n docPrefix?: string\n filename: string\n filesize: number\n mimeType: string\n }\n\n const collectionS3Config = collections[collectionSlug]\n if (!collectionS3Config) {\n throw new APIError(`Collection ${collectionSlug} was not found in S3 options`)\n }\n\n const collectionPrefix =\n (typeof collectionS3Config === 'object' && collectionS3Config.prefix) || ''\n\n if (!(await access({ collectionSlug, req }))) {\n throw new Forbidden()\n }\n\n const { fileKey, sanitizedDocPrefix } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n\n const signableHeaders = new Set<string>()\n\n if (filesizeLimit) {\n if (filesize > filesizeLimit) {\n throw new APIError(\n `Exceeded file size limit. Limit: ${bytesToMB(filesizeLimit).toFixed(2)}MB, got: ${bytesToMB(filesize).toFixed(2)}MB`,\n 400,\n )\n }\n\n // Still force S3 to validate\n signableHeaders.add('content-length')\n }\n\n const url = await getSignedUrl(\n getStorageClient(),\n new AWS.PutObjectCommand({\n ACL: acl,\n Bucket: bucket,\n ContentLength: filesizeLimit ? Math.min(filesize, filesizeLimit) : undefined,\n ContentType: mimeType,\n Key: fileKey,\n }),\n {\n expiresIn: 600,\n signableHeaders,\n },\n )\n\n return Response.json({\n docPrefix: sanitizedDocPrefix,\n url,\n })\n }\n}\n"],"names":["AWS","getSignedUrl","getFileKey","APIError","Forbidden","bytesToMB","bytes","defaultAccess","req","user","getGenerateSignedURLHandler","access","acl","bucket","collections","getStorageClient","useCompositePrefixes","json","filesizeLimit","payload","config","upload","limits","fileSize","Infinity","undefined","collectionSlug","docPrefix","filename","filesize","mimeType","collectionS3Config","collectionPrefix","prefix","fileKey","sanitizedDocPrefix","signableHeaders","Set","toFixed","add","url","PutObjectCommand","ACL","Bucket","ContentLength","Math","min","ContentType","Key","expiresIn","Response"],"mappings":"AAGA,YAAYA,SAAS,qBAAoB;AACzC,SAASC,YAAY,QAAQ,gCAA+B;AAC5D,SAASC,UAAU,QAAQ,6CAA4C;AACvE,SAASC,QAAQ,EAAEC,SAAS,QAAQ,UAAS;AAI7C,MAAMC,YAAY,CAACC;IACjB,OAAOA,QAAQ,OAAO;AACxB;AAWA,MAAMC,gBAAgC,CAAC,EAAEC,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;AAE7D,OAAO,MAAMC,8BAA8B,CAAC,EAC1CC,SAASJ,aAAa,EACtBK,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,gBAAgB,EAChBC,uBAAuB,KAAK,EACvB;IACL,OAAO,OAAOR;QACZ,IAAI,CAACA,IAAIS,IAAI,EAAE;YACb,MAAM,IAAId,SAAS,gDAAgD;QACrE;QAEA,IAAIe,gBAAgBV,IAAIW,OAAO,CAACC,MAAM,CAACC,MAAM,CAACC,MAAM,EAAEC;QAEtD,IAAIL,kBAAkBM,UAAU;YAC9BN,gBAAgBO;QAClB;QAEA,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAI,MAAMtB,IAAIS,IAAI;QAQnF,MAAMc,qBAAqBjB,WAAW,CAACY,eAAe;QACtD,IAAI,CAACK,oBAAoB;YACvB,MAAM,IAAI5B,SAAS,CAAC,WAAW,EAAEuB,eAAe,4BAA4B,CAAC;QAC/E;QAEA,MAAMM,mBACJ,AAAC,OAAOD,uBAAuB,YAAYA,mBAAmBE,MAAM,IAAK;QAE3E,IAA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