@payloadcms/plugin-cloud-storage 1.0.13 → 1.0.15-0

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 (104) hide show
  1. package/.editorconfig +10 -0
  2. package/.gitignore +248 -0
  3. package/.prettierignore +1 -0
  4. package/.prettierrc.js +8 -0
  5. package/.vscode/launch.json +40 -0
  6. package/.vscode/settings.json +9 -0
  7. package/LICENSE.md +1 -1
  8. package/README.md +25 -3
  9. package/dev/.env +21 -0
  10. package/dev/.env.example +21 -0
  11. package/dev/nodemon.json +8 -0
  12. package/dev/package.json +34 -0
  13. package/dev/src/collections/Media.ts +56 -0
  14. package/dev/src/collections/Users.ts +23 -0
  15. package/dev/src/mocks/fsMock.js +1 -0
  16. package/dev/src/mocks/promisifyMock.js +1 -0
  17. package/dev/src/payload.config.ts +111 -0
  18. package/dev/src/server.ts +26 -0
  19. package/dev/tsconfig.json +20 -0
  20. package/dist/adapters/azure/fileStub.d.ts +2 -0
  21. package/dist/adapters/azure/fileStub.js +4 -0
  22. package/dist/adapters/azure/fileStub.js.map +1 -0
  23. package/dist/adapters/azure/handleUpload.js +16 -1
  24. package/dist/adapters/azure/handleUpload.js.map +1 -1
  25. package/dist/adapters/azure/index.js.map +1 -1
  26. package/dist/adapters/azure/mock.d.ts +6 -0
  27. package/dist/adapters/azure/mock.js +4 -0
  28. package/dist/adapters/azure/mock.js.map +1 -1
  29. package/dist/adapters/azure/staticHandler.js +19 -15
  30. package/dist/adapters/azure/staticHandler.js.map +1 -1
  31. package/dist/adapters/azure/webpack.js +2 -2
  32. package/dist/adapters/azure/webpack.js.map +1 -1
  33. package/dist/adapters/gcs/webpack.js +2 -2
  34. package/dist/adapters/gcs/webpack.js.map +1 -1
  35. package/dist/adapters/s3/fileStub.d.ts +2 -0
  36. package/dist/adapters/s3/fileStub.js +4 -0
  37. package/dist/adapters/s3/fileStub.js.map +1 -0
  38. package/dist/adapters/s3/staticHandler.js +1 -0
  39. package/dist/adapters/s3/staticHandler.js.map +1 -1
  40. package/dist/adapters/s3/webpack.js +2 -2
  41. package/dist/adapters/s3/webpack.js.map +1 -1
  42. package/dist/hooks/afterDelete.js +5 -2
  43. package/dist/hooks/afterDelete.js.map +1 -1
  44. package/dist/hooks/beforeChange.js +36 -8
  45. package/dist/hooks/beforeChange.js.map +1 -1
  46. package/dist/plugin.d.ts +1 -1
  47. package/dist/plugin.js +10 -4
  48. package/dist/plugin.js.map +1 -1
  49. package/dist/types.d.ts +6 -0
  50. package/dist/utilities/getRangeFromHeader.d.ts +6 -0
  51. package/dist/utilities/getRangeFromHeader.js +67 -0
  52. package/dist/utilities/getRangeFromHeader.js.map +1 -0
  53. package/docs/local-dev.md +47 -0
  54. package/eslint-config/index.js +15 -0
  55. package/eslint-config/rules/import.js +38 -0
  56. package/eslint-config/rules/prettier.js +7 -0
  57. package/eslint-config/rules/style.js +21 -0
  58. package/eslint-config/rules/typescript.js +628 -0
  59. package/package.json +7 -4
  60. package/src/adapters/azure/emulator/docker-compose.yml +16 -0
  61. package/src/adapters/azure/fileStub.js +1 -0
  62. package/src/adapters/azure/generateURL.ts +13 -0
  63. package/src/adapters/azure/handleDelete.ts +16 -0
  64. package/src/adapters/azure/handleUpload.ts +41 -0
  65. package/src/adapters/azure/index.ts +48 -0
  66. package/src/adapters/azure/mock.js +13 -0
  67. package/src/adapters/azure/staticHandler.ts +38 -0
  68. package/src/adapters/azure/webpack.ts +24 -0
  69. package/src/adapters/gcs/emulator/docker-compose.yml +15 -0
  70. package/src/adapters/gcs/generateURL.ts +16 -0
  71. package/src/adapters/gcs/handleDelete.ts +16 -0
  72. package/src/adapters/gcs/handleUpload.ts +34 -0
  73. package/src/adapters/gcs/index.ts +37 -0
  74. package/src/adapters/gcs/mock.js +3 -0
  75. package/src/adapters/gcs/staticHandler.ts +34 -0
  76. package/src/adapters/gcs/webpack.ts +21 -0
  77. package/src/adapters/s3/emulator/.localstack/cache/machine.json +1 -0
  78. package/src/adapters/s3/emulator/.localstack/cache/server.test.pem +127 -0
  79. package/src/adapters/s3/emulator/.localstack/cache/server.test.pem.crt +99 -0
  80. package/src/adapters/s3/emulator/.localstack/cache/server.test.pem.key +28 -0
  81. package/src/adapters/s3/emulator/.localstack/cache/service-catalog-2_1_1_dev-1_29_149.pickle +0 -0
  82. package/src/adapters/s3/emulator/docker-compose.yml +15 -0
  83. package/src/adapters/s3/fileStub.js +1 -0
  84. package/src/adapters/s3/generateURL.ts +14 -0
  85. package/src/adapters/s3/handleDelete.ts +17 -0
  86. package/src/adapters/s3/handleUpload.ts +62 -0
  87. package/src/adapters/s3/index.ts +38 -0
  88. package/src/adapters/s3/mock.js +9 -0
  89. package/src/adapters/s3/staticHandler.ts +41 -0
  90. package/src/adapters/s3/webpack.ts +23 -0
  91. package/src/fields/getFields.ts +155 -0
  92. package/src/hooks/afterDelete.ts +35 -0
  93. package/src/hooks/afterRead.ts +38 -0
  94. package/src/hooks/beforeChange.ts +59 -0
  95. package/src/index.ts +1 -0
  96. package/src/plugin.ts +101 -0
  97. package/src/types.ts +79 -0
  98. package/src/utilities/getFilePrefix.ts +26 -0
  99. package/src/utilities/getIncomingFiles.ts +44 -0
  100. package/src/utilities/getRangeFromHeader.ts +27 -0
  101. package/src/webpack.ts +46 -0
  102. package/tsconfig.json +23 -0
  103. package/yarn-error.log +8163 -0
  104. package/yarn.lock +8062 -0
package/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ charset = utf-8
7
+ trim_trailing_whitespace = true
8
+ insert_final_newline = true
9
+ end_of_line = lf
10
+ max_line_length = null
package/.gitignore ADDED
@@ -0,0 +1,248 @@
1
+ dev/tmp
2
+ dev/yarn.lock
3
+
4
+ # Created by https://www.gitignore.io/api/node,macos,windows,webstorm,sublimetext,visualstudiocode
5
+
6
+ ### macOS ###
7
+ *.DS_Store
8
+ .AppleDouble
9
+ .LSOverride
10
+
11
+ # Thumbnails
12
+ ._*
13
+
14
+ # Files that might appear in the root of a volume
15
+ .DocumentRevisions-V100
16
+ .fseventsd
17
+ .Spotlight-V100
18
+ .TemporaryItems
19
+ .Trashes
20
+ .VolumeIcon.icns
21
+ .com.apple.timemachine.donotpresent
22
+
23
+ # Directories potentially created on remote AFP share
24
+ .AppleDB
25
+ .AppleDesktop
26
+ Network Trash Folder
27
+ Temporary Items
28
+ .apdisk
29
+
30
+ ### Node ###
31
+ # Logs
32
+ logs
33
+ *.log
34
+ npm-debug.log*
35
+ yarn-debug.log*
36
+ yarn-error.log*
37
+
38
+ # Runtime data
39
+ pids
40
+ *.pid
41
+ *.seed
42
+ *.pid.lock
43
+
44
+ # Directory for instrumented libs generated by jscoverage/JSCover
45
+ lib-cov
46
+
47
+ # Coverage directory used by tools like istanbul
48
+ coverage
49
+
50
+ # nyc test coverage
51
+ .nyc_output
52
+
53
+ # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
54
+ .grunt
55
+
56
+ # Bower dependency directory (https://bower.io/)
57
+ bower_components
58
+
59
+ # node-waf configuration
60
+ .lock-wscript
61
+
62
+ # Compiled binary addons (http://nodejs.org/api/addons.html)
63
+ build/Release
64
+
65
+ # Dependency directories
66
+ node_modules/
67
+ jspm_packages/
68
+
69
+ # Typescript v1 declaration files
70
+ typings/
71
+
72
+ # Optional npm cache directory
73
+ .npm
74
+
75
+ # Optional eslint cache
76
+ .eslintcache
77
+
78
+ # Optional REPL history
79
+ .node_repl_history
80
+
81
+ # Output of 'npm pack'
82
+ *.tgz
83
+
84
+ # Yarn Integrity file
85
+ .yarn-integrity
86
+
87
+ # Yarn Berry
88
+ .yarn/*
89
+ !.yarn/patches
90
+ !.yarn/plugins
91
+ !.yarn/releases
92
+ !.yarn/sdks
93
+ !.yarn/versions
94
+ .pnp.*
95
+
96
+ # dotenv environment variables file
97
+ .env
98
+
99
+
100
+ ### SublimeText ###
101
+ # cache files for sublime text
102
+ *.tmlanguage.cache
103
+ *.tmPreferences.cache
104
+ *.stTheme.cache
105
+
106
+ # workspace files are user-specific
107
+ *.sublime-workspace
108
+
109
+ # project files should be checked into the repository, unless a significant
110
+ # proportion of contributors will probably not be using SublimeText
111
+ # *.sublime-project
112
+
113
+ # sftp configuration file
114
+ sftp-config.json
115
+
116
+ # Package control specific files
117
+ Package Control.last-run
118
+ Package Control.ca-list
119
+ Package Control.ca-bundle
120
+ Package Control.system-ca-bundle
121
+ Package Control.cache/
122
+ Package Control.ca-certs/
123
+ Package Control.merged-ca-bundle
124
+ Package Control.user-ca-bundle
125
+ oscrypto-ca-bundle.crt
126
+ bh_unicode_properties.cache
127
+
128
+ # Sublime-github package stores a github token in this file
129
+ # https://packagecontrol.io/packages/sublime-github
130
+ GitHub.sublime-settings
131
+
132
+ ### VisualStudioCode ###
133
+ .vscode/*
134
+ !.vscode/tasks.json
135
+ !.vscode/launch.json
136
+ !.vscode/extensions.json
137
+ .history
138
+
139
+ ### WebStorm ###
140
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
141
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
142
+
143
+ .idea/*
144
+ # User-specific stuff:
145
+ .idea/**/workspace.xml
146
+ .idea/**/tasks.xml
147
+ .idea/dictionaries
148
+
149
+ # Sensitive or high-churn files:
150
+ .idea/**/dataSources/
151
+ .idea/**/dataSources.ids
152
+ .idea/**/dataSources.xml
153
+ .idea/**/dataSources.local.xml
154
+ .idea/**/sqlDataSources.xml
155
+ .idea/**/dynamic.xml
156
+ .idea/**/uiDesigner.xml
157
+
158
+ # Gradle:
159
+ .idea/**/gradle.xml
160
+ .idea/**/libraries
161
+
162
+ # CMake
163
+ cmake-build-debug/
164
+
165
+ # Mongo Explorer plugin:
166
+ .idea/**/mongoSettings.xml
167
+
168
+ ## File-based project format:
169
+ *.iws
170
+
171
+ ## Plugin-specific files:
172
+
173
+ # IntelliJ
174
+ /out/
175
+
176
+ # mpeltonen/sbt-idea plugin
177
+ .idea_modules/
178
+
179
+ # JIRA plugin
180
+ atlassian-ide-plugin.xml
181
+
182
+ # Cursive Clojure plugin
183
+ .idea/replstate.xml
184
+
185
+ # Ruby plugin and RubyMine
186
+ /.rakeTasks
187
+
188
+ # Crashlytics plugin (for Android Studio and IntelliJ)
189
+ com_crashlytics_export_strings.xml
190
+ crashlytics.properties
191
+ crashlytics-build.properties
192
+ fabric.properties
193
+
194
+ ### WebStorm Patch ###
195
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
196
+
197
+ # *.iml
198
+ # modules.xml
199
+ # .idea/misc.xml
200
+ # *.ipr
201
+
202
+ # Sonarlint plugin
203
+ .idea/sonarlint
204
+
205
+ ### Windows ###
206
+ # Windows thumbnail cache files
207
+ Thumbs.db
208
+ ehthumbs.db
209
+ ehthumbs_vista.db
210
+
211
+ # Folder config file
212
+ Desktop.ini
213
+
214
+ # Recycle Bin used on file shares
215
+ $RECYCLE.BIN/
216
+
217
+ # Windows Installer files
218
+ *.cab
219
+ *.msi
220
+ *.msm
221
+ *.msp
222
+
223
+ # Windows shortcuts
224
+ *.lnk
225
+
226
+ # End of https://www.gitignore.io/api/node,macos,windows,webstorm,sublimetext,visualstudiocode
227
+
228
+ # Ignore all uploads
229
+ demo/upload
230
+ demo/media
231
+ demo/files
232
+
233
+ # Ignore build folder
234
+ build
235
+
236
+ # Ignore built components
237
+ components/index.js
238
+ components/styles.css
239
+
240
+ # Ignore generated
241
+ demo/generated-types.ts
242
+ demo/generated-schema.graphql
243
+
244
+ # Ignore dist, no need for git
245
+ dist
246
+
247
+ # Ignore emulator volumes
248
+ src/adapters/s3/emulator/.localstack/
@@ -0,0 +1 @@
1
+ eslint-config
package/.prettierrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ printWidth: 100,
3
+ parser: "typescript",
4
+ semi: false,
5
+ singleQuote: true,
6
+ trailingComma: "all",
7
+ arrowParens: "avoid",
8
+ };
@@ -0,0 +1,40 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "cwd": "${workspaceFolder}/dev",
11
+ "runtimeArgs": [
12
+ "-r",
13
+ "./node_modules/ts-node/register"
14
+ ],
15
+ "name": "Debug Cloud Storage - S3",
16
+ "program": "${workspaceFolder}/dev/src/server.ts",
17
+ "outputCapture": "std",
18
+ "env": {
19
+ "PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER": "s3",
20
+ "PAYLOAD_CONFIG_PATH": "${workspaceFolder}/dev/src/payload.config.ts"
21
+ }
22
+ },
23
+ {
24
+ "type": "node",
25
+ "request": "launch",
26
+ "cwd": "${workspaceFolder}/dev",
27
+ "runtimeArgs": [
28
+ "-r",
29
+ "./node_modules/ts-node/register"
30
+ ],
31
+ "name": "Debug Cloud Storage - Azure",
32
+ "program": "${workspaceFolder}/dev/src/server.ts",
33
+ "outputCapture": "std",
34
+ "env": {
35
+ "PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER": "azure",
36
+ "PAYLOAD_CONFIG_PATH": "${workspaceFolder}/dev/src/payload.config.ts"
37
+ }
38
+ },
39
+ ]
40
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "[typescript]": {
3
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
4
+ "editor.codeActionsOnSave": {
5
+ "source.fixAll": true,
6
+ },
7
+ "editor.formatOnSave": true,
8
+ },
9
+ }
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2018-2022 Payload CMS, LLC <info@payloadcms.com>
3
+ Copyright (c) 2018-20223 Payload CMS, INC <info@payloadcms.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -12,7 +12,11 @@ This repository contains the officially supported Payload Cloud Storage plugin.
12
12
 
13
13
  ## Usage
14
14
 
15
- Install this plugin within your Payload as follows:
15
+ Add this package into your dependencies executing this code in your command line:
16
+
17
+ `yarn add @payloadcms/plugin-cloud-storage`
18
+
19
+ Now install this plugin within your Payload as follows:
16
20
 
17
21
  ```ts
18
22
  import { buildConfig } from 'payload/config';
@@ -33,6 +37,23 @@ export default buildConfig({
33
37
  });
34
38
  ```
35
39
 
40
+ ### Conditionally Enabling/Disabling
41
+
42
+ The proper way to conditionally enable/disable this plugin is to use the `enabled` property.
43
+
44
+ ```ts
45
+ cloudStorage({
46
+ enabled: process.env.MY_CONDITION === 'true',
47
+ collections: {
48
+ 'my-collection-slug': {
49
+ adapter: theAdapterToUse, // see docs for the adapter you want to use
50
+ },
51
+ },
52
+ }),
53
+ ```
54
+
55
+ If the code is included *in any way in your config* but conditionally disabled in another fashion, you may run into issues such as `Webpack Build Error: Can't Resolve 'fs' and 'stream'` or similar because the plugin must be run at all times in order to properly extend the webpack config.
56
+
36
57
  ## Features
37
58
 
38
59
  **Adapter-based Implementation**
@@ -54,6 +75,7 @@ This plugin is configurable to work across many different Payload collections. A
54
75
  | Option | Type | Description |
55
76
  |-------------------------|-----------------------------------------| ----------- |
56
77
  | `collections` * | Record<string, [CollectionOptions](https://github.com/payloadcms/plugin-cloud-storage/blob/c4a492a62abc2f21b4cd6a7c97778acd8e831212/src/types.ts#L48)> | Object with keys set to the slug of collections you want to enable the plugin for, and values set to collection-specific options. |
78
+ | `enabled` | | `boolean` to conditionally enable/disable plugin. Default: true. |
57
79
 
58
80
  **Collection-specific options:**
59
81
 
@@ -153,9 +175,9 @@ const adapter = gcsAdapter({
153
175
 
154
176
  ### Payload Access Control
155
177
 
156
- Payload ships with access control that runs _even on statically served files_. The same `read` access control property on your `upload`-enabled collections is used, and it allows you to restrict who can request your uploaded files.
178
+ Payload ships with access control that runs *even on statically served files*. The same `read` access control property on your `upload`-enabled collections is used, and it allows you to restrict who can request your uploaded files.
157
179
 
158
- To preserve this feature, by default, this plugin _keeps all file URLs exactly the same_. Your file URLs won't be updated to point directly to your cloud storage source, as in that case, Payload's access control will be completely bypassed and you would need public readability on your cloud-hosted files.
180
+ To preserve this feature, by default, this plugin *keeps all file URLs exactly the same*. Your file URLs won't be updated to point directly to your cloud storage source, as in that case, Payload's access control will be completely bypassed and you would need public readability on your cloud-hosted files.
159
181
 
160
182
  Instead, all uploads will still be reached from the default `/collectionSlug/staticURL/filename` path. This plugin will "pass through" all files that are hosted on your third-party cloud service—with the added benefit of keeping your existing access control in place.
161
183
 
package/dev/.env ADDED
@@ -0,0 +1,21 @@
1
+ MONGODB_URI=mongodb://localhost/payload-plugin-cloud-storage
2
+ PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
3
+ PAYLOAD_SECRET=45ligj345ligj4wl5igj4lw5igj45ligj45wlijl
4
+ PAYLOAD_CONFIG_PATH=src/payload.config.ts
5
+
6
+ AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;
7
+ AZURE_STORAGE_CONTAINER_NAME=az-media
8
+ AZURE_STORAGE_ALLOW_CONTAINER_CREATE=true
9
+ AZURE_STORAGE_ACCOUNT_BASEURL=http://localhost:10000/devstoreaccount1
10
+
11
+ S3_ENDPOINT=http://localhost:4566
12
+ S3_ACCESS_KEY_ID=payloadAccessKey
13
+ S3_SECRET_ACCESS_KEY=alwiejglaiwhewlihgawe
14
+ S3_BUCKET=payload-bucket
15
+ S3_FORCE_PATH_STYLE=true
16
+
17
+ GCS_ENDPOINT=http://localhost:4443
18
+ GCS_PROJECT_ID=test
19
+ GCS_BUCKET=payload-bucket
20
+
21
+ PAYLOAD_DROP_DATABASE=true
@@ -0,0 +1,21 @@
1
+ MONGODB_URI=mongodb://localhost/payload-plugin-cloud-storage
2
+ PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
3
+ PAYLOAD_SECRET=45ligj345ligj4wl5igj4lw5igj45ligj45wlijl
4
+ PAYLOAD_CONFIG_PATH=src/payload.config.ts
5
+
6
+ AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;
7
+ AZURE_STORAGE_CONTAINER_NAME=az-media
8
+ AZURE_STORAGE_ALLOW_CONTAINER_CREATE=true
9
+ AZURE_STORAGE_ACCOUNT_BASEURL=http://localhost:10000/devstoreaccount1
10
+
11
+ S3_ENDPOINT=http://localhost:4566
12
+ S3_ACCESS_KEY_ID=payloadAccessKey
13
+ S3_SECRET_ACCESS_KEY=alwiejglaiwhewlihgawe
14
+ S3_BUCKET=payload-bucket
15
+ S3_FORCE_PATH_STYLE=true
16
+
17
+ GCS_ENDPOINT=http://localhost:4443
18
+ GCS_PROJECT_ID=test
19
+ GCS_BUCKET=payload-bucket
20
+
21
+ PAYLOAD_DROP_DATABASE=true
@@ -0,0 +1,8 @@
1
+ {
2
+ "ext": "ts",
3
+ "exec": "node --trace-warnings -r ts-node/register -r ./src/server.ts",
4
+ "watch": [
5
+ "src/**/*.ts",
6
+ "../src/**/*.ts"
7
+ ]
8
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "payload-plugin-cloud-storage-demo",
3
+ "version": "1.0.0",
4
+ "main": "dist/server.js",
5
+ "license": "MIT",
6
+ "private": true,
7
+ "scripts": {
8
+ "dev:azure": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=azure nodemon",
9
+ "dev:s3": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=s3 nodemon",
10
+ "dev:gcs": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=gcs nodemon",
11
+ "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
12
+ "build:server": "tsc",
13
+ "build": "yarn build:payload && yarn build:server",
14
+ "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
15
+ "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
16
+ },
17
+ "dependencies": {
18
+ "@aws-sdk/client-s3": "^3.142.0",
19
+ "@azure/storage-blob": "^12.11.0",
20
+ "@google-cloud/storage": "^6.4.2",
21
+ "dotenv": "^8.2.0",
22
+ "express": "^4.17.1",
23
+ "image-size": "^1.0.2",
24
+ "payload": "^1.7.2",
25
+ "probe-image-size": "^7.2.3"
26
+ },
27
+ "devDependencies": {
28
+ "@types/express": "^4.17.9",
29
+ "cross-env": "^7.0.3",
30
+ "nodemon": "^2.0.6",
31
+ "ts-node": "^9.1.1",
32
+ "typescript": "^4.1.3"
33
+ }
34
+ }
@@ -0,0 +1,56 @@
1
+ /* eslint-disable no-console */
2
+ import type { CollectionConfig, Field } from 'payload/types'
3
+
4
+ const urlField: Field = {
5
+ name: 'url',
6
+ type: 'text',
7
+ hooks: {
8
+ afterRead: [
9
+ ({ value }) => {
10
+ console.log('hello from hook')
11
+ return value
12
+ },
13
+ ],
14
+ },
15
+ }
16
+
17
+ export const Media: CollectionConfig = {
18
+ slug: 'media',
19
+ upload: {
20
+ imageSizes: [
21
+ {
22
+ height: 400,
23
+ width: 400,
24
+ crop: 'center',
25
+ name: 'square',
26
+ },
27
+ {
28
+ width: 900,
29
+ height: 450,
30
+ crop: 'center',
31
+ name: 'sixteenByNineMedium',
32
+ },
33
+ ],
34
+ },
35
+ fields: [
36
+ {
37
+ name: 'alt',
38
+ label: 'Alt Text',
39
+ type: 'text',
40
+ },
41
+
42
+ // The following fields should be able to be merged in to default upload fields
43
+ urlField,
44
+ {
45
+ name: 'sizes',
46
+ type: 'group',
47
+ fields: [
48
+ {
49
+ name: 'square',
50
+ type: 'group',
51
+ fields: [urlField],
52
+ },
53
+ ],
54
+ },
55
+ ],
56
+ }
@@ -0,0 +1,23 @@
1
+ import type { CollectionConfig } from 'payload/types'
2
+
3
+ const Users: CollectionConfig = {
4
+ slug: 'users',
5
+ auth: true,
6
+ access: {
7
+ read: () => true,
8
+ },
9
+ fields: [
10
+ {
11
+ name: 'avatar',
12
+ type: 'upload',
13
+ relationTo: 'media',
14
+ },
15
+ {
16
+ name: 'background',
17
+ type: 'upload',
18
+ relationTo: 'media',
19
+ },
20
+ ],
21
+ }
22
+
23
+ export default Users
@@ -0,0 +1 @@
1
+ module.exports = { fs: { createReadStream: () => null } }
@@ -0,0 +1 @@
1
+ export const promisify = () => {}
@@ -0,0 +1,111 @@
1
+ import { buildConfig } from 'payload/config'
2
+ import path from 'path'
3
+ import Users from './collections/Users'
4
+ import { cloudStorage } from '../../src'
5
+ import { s3Adapter } from '../../src/adapters/s3'
6
+ import { gcsAdapter } from '../../src/adapters/gcs'
7
+ import { azureBlobStorageAdapter } from '../../src/adapters/azure'
8
+ import type { Adapter } from '../../src/types'
9
+ import { Media } from './collections/Media'
10
+
11
+ let adapter: Adapter
12
+ let uploadOptions
13
+
14
+ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'azure') {
15
+ adapter = azureBlobStorageAdapter({
16
+ connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
17
+ containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
18
+ allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
19
+ baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
20
+ })
21
+ // uploadOptions = {
22
+ // useTempFiles: true,
23
+ // }
24
+ }
25
+
26
+ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 's3') {
27
+ // The s3 adapter supports using temp files for uploads
28
+ uploadOptions = {
29
+ useTempFiles: true,
30
+ }
31
+
32
+ adapter = s3Adapter({
33
+ config: {
34
+ endpoint: process.env.S3_ENDPOINT,
35
+ forcePathStyle: process.env.S3_FORCE_PATH_STYLE === 'true',
36
+ region: process.env.S3_REGION,
37
+ credentials: {
38
+ accessKeyId: process.env.S3_ACCESS_KEY_ID,
39
+ secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
40
+ },
41
+ },
42
+ bucket: process.env.S3_BUCKET,
43
+ })
44
+ }
45
+
46
+ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'gcs') {
47
+ adapter = gcsAdapter({
48
+ options: {
49
+ apiEndpoint: process.env.GCS_ENDPOINT,
50
+ projectId: process.env.GCS_PROJECT_ID,
51
+ },
52
+ bucket: process.env.GCS_BUCKET,
53
+ })
54
+ }
55
+
56
+ export default buildConfig({
57
+ serverURL: 'http://localhost:3000',
58
+ collections: [Media, Users],
59
+ upload: uploadOptions,
60
+ admin: {
61
+ // NOTE - these webpack extensions are only required
62
+ // for development of this plugin.
63
+ // No need to use these aliases within your own projects.
64
+ webpack: config => {
65
+ const newConfig = {
66
+ ...config,
67
+ resolve: {
68
+ ...(config.resolve || {}),
69
+ alias: {
70
+ ...(config.resolve.alias || {}),
71
+ react: path.resolve(__dirname, '../node_modules/react'),
72
+ '@azure/storage-blob': path.resolve(__dirname, '../../src/adapters/azure/mock.js'),
73
+ '@aws-sdk/client-s3': path.resolve(__dirname, '../../src/adapters/s3/mock.js'),
74
+ '@google-cloud/storage': path.resolve(__dirname, '../../src/adapters/gcs/mock.js'),
75
+ fs: path.resolve(__dirname, './mocks/fsMock.js'),
76
+ },
77
+ },
78
+ }
79
+ return newConfig
80
+ },
81
+ },
82
+ typescript: {
83
+ outputFile: path.resolve(__dirname, 'payload-types.ts'),
84
+ },
85
+ plugins: [
86
+ // @ts-expect-error Conflicting types for relative package
87
+ cloudStorage({
88
+ collections: {
89
+ media: {
90
+ adapter,
91
+ },
92
+ },
93
+ }),
94
+ ],
95
+ onInit: async payload => {
96
+ const users = await payload.find({
97
+ collection: 'users',
98
+ limit: 1,
99
+ })
100
+
101
+ if (!users.docs.length) {
102
+ await payload.create({
103
+ collection: 'users',
104
+ data: {
105
+ email: 'dev@payloadcms.com',
106
+ password: 'test',
107
+ },
108
+ })
109
+ }
110
+ },
111
+ })