@payloadcms/storage-s3 3.0.0-beta.18 → 3.0.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,50 @@
1
- # Nodemailer Email Adapter
1
+ # S3 Storage for Payload
2
+
3
+ This package provides a simple way to use S3 with Payload.
4
+
5
+ **NOTE:** This package removes the need to use `@payloadcms/plugin-cloud-storage` as was needed in Payload 2.x.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @payloadcms/storage-s3
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ - Configure the `collections` object to specify which collections should use the Vercel Blob adapter. The slug _must_ match one of your existing collection slugs.
16
+ - The `config` object can be any [`S3ClientConfig`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3) object (from [`@aws-sdk/client-s3`](https://github.com/aws/aws-sdk-js-v3)). _This is highly dependent on your AWS setup_. Check the AWS documentation for more information.
17
+ - When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
18
+
19
+ ```ts
20
+ import { s3Storage } from '@payloadcms/storage-s3'
21
+ import { Media } from './collections/Media'
22
+ import { MediaWithPrefix } from './collections/MediaWithPrefix'
23
+
24
+ export default buildConfig({
25
+ collections: [Media, MediaWithPrefix],
26
+ plugins: [
27
+ s3Storage({
28
+ collections: {
29
+ [mediaSlug]: true,
30
+ [mediaWithPrefixSlug]: {
31
+ prefix,
32
+ },
33
+ },
34
+ bucket: process.env.S3_BUCKET,
35
+ config: {
36
+ credentials: {
37
+ accessKeyId: process.env.S3_ACCESS_KEY_ID,
38
+ secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
39
+ },
40
+ region: process.env.S3_REGION,
41
+ // ... Other S3 configuration
42
+ },
43
+ }),
44
+ ],
45
+ })
46
+ ```
47
+
48
+ ### Configuration Options
49
+
50
+ See the the [AWS SDK Package](https://github.com/aws/aws-sdk-js-v3) and [`S3ClientConfig`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3) object for guidance on AWS S3 configuration.
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ function s3StorageInternal({ acl, bucket, config = {} }) {
46
46
  return storageClient;
47
47
  };
48
48
  return {
49
+ name: 's3',
49
50
  generateURL: getGenerateURL({
50
51
  bucket,
51
52
  config
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport * as AWS from '@aws-sdk/client-s3'\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n\n acl?: 'private' | 'public-read'\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 * Collection options to apply the S3 adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\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\ntype S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin\n\nexport const s3Storage: S3StoragePlugin =\n (s3StorageOptions: S3StorageOptions) =>\n (incomingConfig: Config): Config => {\n if (s3StorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = s3StorageInternal(s3StorageOptions)\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,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction s3StorageInternal({ acl, bucket, config = {} }: S3StorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: AWS.S3 | null = null\n const getStorageClient: () => AWS.S3 = () => {\n if (storageClient) return storageClient\n storageClient = new AWS.S3(config)\n return storageClient\n }\n\n return {\n generateURL: getGenerateURL({ bucket, config }),\n handleDelete: getHandleDelete({ bucket, getStorageClient }),\n handleUpload: getHandleUpload({\n acl,\n bucket,\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection, getStorageClient }),\n }\n }\n}\n"],"names":["AWS","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","s3Storage","s3StorageOptions","incomingConfig","enabled","adapter","s3StorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","acl","bucket","prefix","storageClient","getStorageClient","S3","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,YAAYA,S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BAAgB,IAAI5B,IAAI8B,EAAE,CAACV;YAC3B,OAAOQ;QACT;QAEA,OAAO;YACLG,aAAa7B,eAAe;gBAAEwB;gBAAQN;YAAO;YAC7CY,cAAc7B,gBAAgB;gBAAEuB;gBAAQG;YAAiB;YACzDI,cAAc7B,gBAAgB;gBAC5BqB;gBACAC;gBACAJ;gBACAO;gBACAF;YACF;YACAO,eAAe7B,WAAW;gBAAEqB;gBAAQJ;gBAAYO;YAAiB;QACnE;IACF;AACF"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport * as AWS from '@aws-sdk/client-s3'\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n\n acl?: 'private' | 'public-read'\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 * Collection options to apply the S3 adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\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\ntype S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin\n\nexport const s3Storage: S3StoragePlugin =\n (s3StorageOptions: S3StorageOptions) =>\n (incomingConfig: Config): Config => {\n if (s3StorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = s3StorageInternal(s3StorageOptions)\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,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction s3StorageInternal({ acl, bucket, config = {} }: S3StorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: AWS.S3 | null = null\n const getStorageClient: () => AWS.S3 = () => {\n if (storageClient) return storageClient\n storageClient = new AWS.S3(config)\n return storageClient\n }\n\n return {\n name: 's3',\n generateURL: getGenerateURL({ bucket, config }),\n handleDelete: getHandleDelete({ bucket, getStorageClient }),\n handleUpload: getHandleUpload({\n acl,\n bucket,\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection, getStorageClient }),\n }\n }\n}\n"],"names":["AWS","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","s3Storage","s3StorageOptions","incomingConfig","enabled","adapter","s3StorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","acl","bucket","prefix","storageClient","getStorageClient","S3","name","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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,IAAIC,gBAA+B;QACnC,MAAMC,mBAAiC;YACrC,IAAID,eAAe,OAAOA;YAC1BA,gBAAgB,IAAI5B,IAAI8B,EAAE,CAACV;YAC3B,OAAOQ;QACT;QAEA,OAAO;YACLG,MAAM;YACNC,aAAa9B,eAAe;gBAAEwB;gBAAQN;YAAO;YAC7Ca,cAAc9B,gBAAgB;gBAAEuB;gBAAQG;YAAiB;YACzDK,cAAc9B,gBAAgB;gBAC5BqB;gBACAC;gBACAJ;gBACAO;gBACAF;YACF;YACAQ,eAAe9B,WAAW;gBAAEqB;gBAAQJ;gBAAYO;YAAiB;QACnE;IACF;AACF"}
package/package.json CHANGED
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "name": "@payloadcms/storage-s3",
3
- "version": "3.0.0-beta.18",
3
+ "version": "3.0.0-beta.20",
4
4
  "description": "Payload storage adapter for Amazon S3",
5
+ "homepage": "https://payloadcms.com",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/payloadcms/payload.git",
8
9
  "directory": "packages/storage-s3"
9
10
  },
10
11
  "license": "MIT",
11
- "homepage": "https://payloadcms.com",
12
12
  "author": "Payload CMS, Inc.",
13
- "main": "./dist/index.js",
14
- "types": "./dist/index.d.ts",
15
13
  "type": "module",
16
14
  "exports": {
17
15
  ".": {
@@ -20,28 +18,30 @@
20
18
  "types": "./dist/index.d.ts"
21
19
  }
22
20
  },
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "files": [
24
+ "dist"
25
+ ],
23
26
  "dependencies": {
24
27
  "@aws-sdk/client-s3": "^3.525.0",
25
28
  "@aws-sdk/lib-storage": "^3.525.0",
26
- "@payloadcms/plugin-cloud-storage": "3.0.0-beta.18"
29
+ "@payloadcms/plugin-cloud-storage": "3.0.0-beta.20"
27
30
  },
28
31
  "devDependencies": {
29
- "payload": "3.0.0-beta.18"
32
+ "payload": "3.0.0-beta.20"
30
33
  },
31
34
  "peerDependencies": {
32
- "payload": "3.0.0-beta.18"
35
+ "payload": "3.0.0-beta.20"
33
36
  },
34
37
  "engines": {
35
38
  "node": ">=18.20.2"
36
39
  },
37
- "files": [
38
- "dist"
39
- ],
40
40
  "scripts": {
41
41
  "build": "pnpm build:swc && pnpm build:types",
42
+ "build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
42
43
  "build:swc": "swc ./src -d ./dist --config-file .swcrc",
43
44
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
44
- "build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
45
45
  "clean": "rimraf {dist,*.tsbuildinfo}"
46
46
  }
47
47
  }