@payloadcms/plugin-cloud-storage 1.0.0 → 1.0.1

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
@@ -31,9 +31,11 @@ export default buildConfig({
31
31
  ## Features
32
32
 
33
33
  **Adapter-based Implementation**
34
+
34
35
  This plugin supports the following adapters:
35
36
 
36
37
  - [Azure Blob Storage](#azure-blob-storage-adapter)
38
+ - [AWS S3-style Storage](#s3-adapter)
37
39
 
38
40
  However, you can create your own adapter for any third-party service you would like to use.
39
41
 
@@ -41,19 +43,19 @@ However, you can create your own adapter for any third-party service you would l
41
43
 
42
44
  This plugin is configurable to work across many different Payload collections. A `*` denotes that the property is required.
43
45
 
44
- | Option | Description |
45
- | ----------------------------- | ----------- |
46
- | **[`collections`]** * | Array of collection-specific options to enable the plugin for. |
46
+ | Option | Description |
47
+ | ----------------------- | ----------- |
48
+ | `collections` * | Array of collection-specific options to enable the plugin for. |
47
49
 
48
- #### Collection-specific options
50
+ **Collection-specific options:**
49
51
 
50
52
  | Option | Description |
51
53
  |------------------------------|---------------------------------|
52
- | **[`slug`]** * | The collection slug to extend. |
53
- | **[`disableLocalStorage`]** | Choose to disable local storage on this collection. Defaults to `true`. |
54
- | **[`adapter`]** | Pass in the adapter that you'd like to use for this collection. |
54
+ | `slug` * | The collection slug to extend. |
55
+ | `adapter` * | Pass in the adapter that you'd like to use for this collection. |
56
+ | `disableLocalStorage` | Choose to disable local storage on this collection. Defaults to `true`. |
55
57
 
56
- #### Azure Blob Storage Adapter
58
+ ### Azure Blob Storage Adapter
57
59
 
58
60
  To use the Azure Blob Storage adapter, you need to have `@azure/storage-blob` installed in your project dependencies. To do so, run `yarn add @azure/storage-blob`.
59
61
 
@@ -72,20 +74,37 @@ const adapter = azureBlobStorageAdapter({
72
74
  // Now you can pass this adapter to the plugin
73
75
  ```
74
76
 
75
- **Important:** make sure you have all of the above environment variables filled out and that they reflect your Azure blob storage configuration.
77
+ ### S3 Adapter
76
78
 
77
- #### Local sandbox & plugin development
79
+ To use the S3 adapter, you need to have `@aws-sdk/client-s3` isntalled in your project dependencies. To do so, run `yarn add @aws-sdk/client-s3`.
78
80
 
79
- This repository includes a local development environment for local testing and development of this plugin. To run the local sandbox, follow the instructions below.
81
+ From there, create the adapter, passing in all of its required properties:
80
82
 
81
- 1. Make sure you have Node and a MongoDB to work with
82
- 1. Clone the repo
83
- 1. `yarn` in both the root folder of the repo, and the `./dev` folder
84
- 1. `cd` into `./dev` and run `cp .env.example .env` to create an `.env` file
85
- 1. Open your newly created `./dev/.env` file and _completely_ fill out each property
86
- 1. Run `yarn dev` within the `/dev` folder
87
- 1. Open `http://localhost:3000/admin` in your browser
83
+ ```js
84
+ import { s3Adapter } from '@payloadcms/plugin-cloud-storage';
85
+
86
+ const adapter = s3Adapter({
87
+ config: {
88
+ endpoint: process.env.S3_ENDPOINT,
89
+ credentials: {
90
+ accessKeyId: process.env.S3_ACCESS_KEY_ID,
91
+ secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
92
+ }
93
+ },
94
+ bucket: process.env.S3_BUCKET,
95
+ })
96
+
97
+ // Now you can pass this adapter to the plugin
98
+ ```
99
+
100
+ ## Local development
101
+
102
+ For instructions regarding how to develop with this plugin locally, [click here](/docs/local-dev.md).
88
103
 
89
104
  ## Questions
90
105
 
91
106
  Please contact [Payload](dev@payloadcms.com) with any questions about using this plugin.
107
+
108
+ ## Credit
109
+
110
+ This plugin was created with significant help, and code, from [Alex Bechmann](https://github.com/alexbechmann) and [Richard VanBergen](https://github.com/richardvanbergen). Thank you!!
@@ -1,10 +1,9 @@
1
1
  import type { CollectionConfig } from 'payload/types';
2
+ import type { ContainerClient } from '@azure/storage-blob';
2
3
  import type { HandleDelete } from '../../types';
3
4
  interface Args {
4
5
  collection: CollectionConfig;
5
- connectionString: string;
6
- containerName: string;
7
- baseURL: string;
6
+ containerClient: ContainerClient;
8
7
  }
9
- export declare const getHandleDelete: ({ connectionString, containerName }: Args) => HandleDelete;
8
+ export declare const getHandleDelete: ({ containerClient }: Args) => HandleDelete;
10
9
  export {};
@@ -37,11 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getHandleDelete = void 0;
40
- var storage_blob_1 = require("@azure/storage-blob");
41
40
  var getHandleDelete = function (_a) {
42
- var connectionString = _a.connectionString, containerName = _a.containerName;
43
- var blobServiceClient = storage_blob_1.BlobServiceClient.fromConnectionString(connectionString);
44
- var containerClient = blobServiceClient.getContainerClient(containerName);
41
+ var containerClient = _a.containerClient;
45
42
  return function (_a) {
46
43
  var filename = _a.filename;
47
44
  return __awaiter(void 0, void 0, void 0, function () {
@@ -1 +1 @@
1
- {"version":3,"file":"handleDelete.js","sourceRoot":"","sources":["../../../src/adapters/azure/handleDelete.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAuD;AAUhD,IAAM,eAAe,GAAG,UAAC,EAAyC;QAAvC,gBAAgB,sBAAA,EAAE,aAAa,mBAAA;IAC/D,IAAM,iBAAiB,GAAG,gCAAiB,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAClF,IAAM,eAAe,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;IAE3E,OAAO,UAAO,EAAY;YAAV,QAAQ,cAAA;;;;;;wBAChB,eAAe,GAAG,eAAe,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;wBACpE,qBAAM,eAAe,CAAC,cAAc,EAAE,EAAA;;wBAAtC,SAAsC,CAAA;;;;;KACvC,CAAA;AACH,CAAC,CAAA;AARY,QAAA,eAAe,mBAQ3B"}
1
+ {"version":3,"file":"handleDelete.js","sourceRoot":"","sources":["../../../src/adapters/azure/handleDelete.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,IAAM,eAAe,GAAG,UAAC,EAAyB;QAAvB,eAAe,qBAAA;IAC/C,OAAO,UAAO,EAAY;YAAV,QAAQ,cAAA;;;;;;wBAChB,eAAe,GAAG,eAAe,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;wBACpE,qBAAM,eAAe,CAAC,cAAc,EAAE,EAAA;;wBAAtC,SAAsC,CAAA;;;;;KACvC,CAAA;AACH,CAAC,CAAA;AALY,QAAA,eAAe,mBAK3B"}
@@ -1,11 +1,10 @@
1
+ import type { ContainerClient } from '@azure/storage-blob';
1
2
  import type { CollectionConfig } from 'payload/types';
2
3
  import type { HandleUpload } from '../../types';
3
4
  interface Args {
4
5
  collection: CollectionConfig;
5
- connectionString: string;
6
- containerName: string;
7
- baseURL: string;
6
+ containerClient: ContainerClient;
8
7
  allowContainerCreate: boolean;
9
8
  }
10
- export declare const getHandleUpload: ({ allowContainerCreate, connectionString, containerName, }: Args) => HandleUpload;
9
+ export declare const getHandleUpload: ({ allowContainerCreate, containerClient }: Args) => HandleUpload;
11
10
  export {};
@@ -37,11 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getHandleUpload = void 0;
40
- var storage_blob_1 = require("@azure/storage-blob");
41
40
  var getHandleUpload = function (_a) {
42
- var allowContainerCreate = _a.allowContainerCreate, connectionString = _a.connectionString, containerName = _a.containerName;
43
- var blobServiceClient = storage_blob_1.BlobServiceClient.fromConnectionString(connectionString);
44
- var containerClient = blobServiceClient.getContainerClient(containerName);
41
+ var allowContainerCreate = _a.allowContainerCreate, containerClient = _a.containerClient;
45
42
  if (allowContainerCreate) {
46
43
  containerClient.createIfNotExists({ access: 'blob' });
47
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handleUpload.js","sourceRoot":"","sources":["../../../src/adapters/azure/handleUpload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oDAAuD;AAWhD,IAAM,eAAe,GAAG,UAAC,EAIzB;QAHL,oBAAoB,0BAAA,EACpB,gBAAgB,sBAAA,EAChB,aAAa,mBAAA;IAEb,IAAM,iBAAiB,GAAG,gCAAiB,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAClF,IAAM,eAAe,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;IAE3E,IAAI,oBAAoB,EAAE;QACxB,eAAe,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;KACtD;IAED,OAAO,UAAO,EAAc;YAAZ,IAAI,UAAA,EAAE,IAAI,UAAA;;;;;;wBAClB,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;wBACxB,eAAe,GAAG,eAAe,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;wBAEpE,qBAAM,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;gCAChE,eAAe,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,QAAQ,EAAE;6BACpD,CAAC,EAAA;;wBAFF,SAEE,CAAA;wBAEF,sBAAO,IAAI,EAAA;;;;KACZ,CAAA;AACH,CAAC,CAAA;AAtBY,QAAA,eAAe,mBAsB3B"}
1
+ {"version":3,"file":"handleUpload.js","sourceRoot":"","sources":["../../../src/adapters/azure/handleUpload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAAM,eAAe,GAAG,UAAC,EAA+C;QAA7C,oBAAoB,0BAAA,EAAE,eAAe,qBAAA;IACrE,IAAI,oBAAoB,EAAE;QACxB,eAAe,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;KACtD;IAED,OAAO,UAAO,EAAc;YAAZ,IAAI,UAAA,EAAE,IAAI,UAAA;;;;;;wBAClB,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;wBACxB,eAAe,GAAG,eAAe,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;wBAEpE,qBAAM,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;gCAChE,eAAe,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,QAAQ,EAAE;6BACpD,CAAC,EAAA;;wBAFF,SAEE,CAAA;wBAEF,sBAAO,IAAI,EAAA;;;;KACZ,CAAA;AACH,CAAC,CAAA;AAfY,QAAA,eAAe,mBAe3B"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.azureBlobStorageAdapter = void 0;
4
+ var storage_blob_1 = require("@azure/storage-blob");
4
5
  var generateURL_1 = require("./generateURL");
5
6
  var handleDelete_1 = require("./handleDelete");
6
7
  var handleUpload_1 = require("./handleUpload");
@@ -9,15 +10,15 @@ var azureBlobStorageAdapter = function (_a) {
9
10
  var connectionString = _a.connectionString, containerName = _a.containerName, baseURL = _a.baseURL, allowContainerCreate = _a.allowContainerCreate;
10
11
  return function (_a) {
11
12
  var collection = _a.collection;
13
+ var blobServiceClient = storage_blob_1.BlobServiceClient.fromConnectionString(connectionString);
14
+ var containerClient = blobServiceClient.getContainerClient(containerName);
12
15
  return {
13
16
  handleUpload: (0, handleUpload_1.getHandleUpload)({
14
17
  collection: collection,
15
- connectionString: connectionString,
16
- containerName: containerName,
17
- baseURL: baseURL,
18
+ containerClient: containerClient,
18
19
  allowContainerCreate: allowContainerCreate,
19
20
  }),
20
- handleDelete: (0, handleDelete_1.getHandleDelete)({ collection: collection, connectionString: connectionString, containerName: containerName, baseURL: baseURL }),
21
+ handleDelete: (0, handleDelete_1.getHandleDelete)({ collection: collection, containerClient: containerClient }),
21
22
  generateURL: (0, generateURL_1.getGenerateURL)({ containerName: containerName, baseURL: baseURL }),
22
23
  webpack: webpack_1.extendWebpackConfig,
23
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/azure/index.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,+CAAgD;AAChD,+CAAgD;AAChD,qCAA+C;AASxC,IAAM,uBAAuB,GAClC,UAAC,EAAwE;QAAtE,gBAAgB,sBAAA,EAAE,aAAa,mBAAA,EAAE,OAAO,aAAA,EAAE,oBAAoB,0BAAA;IACjE,OAAA,UAAC,EAAc;YAAZ,UAAU,gBAAA;QACX,OAAO;YACL,YAAY,EAAE,IAAA,8BAAe,EAAC;gBAC5B,UAAU,YAAA;gBACV,gBAAgB,kBAAA;gBAChB,aAAa,eAAA;gBACb,OAAO,SAAA;gBACP,oBAAoB,sBAAA;aACrB,CAAC;YACF,YAAY,EAAE,IAAA,8BAAe,EAAC,EAAE,UAAU,YAAA,EAAE,gBAAgB,kBAAA,EAAE,aAAa,eAAA,EAAE,OAAO,SAAA,EAAE,CAAC;YACvF,WAAW,EAAE,IAAA,4BAAc,EAAC,EAAE,aAAa,eAAA,EAAE,OAAO,SAAA,EAAE,CAAC;YACvD,OAAO,EAAE,6BAAmB;SAC7B,CAAA;IACH,CAAC;AAbD,CAaC,CAAA;AAfU,QAAA,uBAAuB,2BAejC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/azure/index.ts"],"names":[],"mappings":";;;AAAA,oDAAuD;AAEvD,6CAA8C;AAC9C,+CAAgD;AAChD,+CAAgD;AAChD,qCAA+C;AASxC,IAAM,uBAAuB,GAClC,UAAC,EAAwE;QAAtE,gBAAgB,sBAAA,EAAE,aAAa,mBAAA,EAAE,OAAO,aAAA,EAAE,oBAAoB,0BAAA;IACjE,OAAA,UAAC,EAAc;YAAZ,UAAU,gBAAA;QACX,IAAM,iBAAiB,GAAG,gCAAiB,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;QAClF,IAAM,eAAe,GAAG,iBAAiB,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;QAE3E,OAAO;YACL,YAAY,EAAE,IAAA,8BAAe,EAAC;gBAC5B,UAAU,YAAA;gBACV,eAAe,iBAAA;gBACf,oBAAoB,sBAAA;aACrB,CAAC;YACF,YAAY,EAAE,IAAA,8BAAe,EAAC,EAAE,UAAU,YAAA,EAAE,eAAe,iBAAA,EAAE,CAAC;YAC9D,WAAW,EAAE,IAAA,4BAAc,EAAC,EAAE,aAAa,eAAA,EAAE,OAAO,SAAA,EAAE,CAAC;YACvD,OAAO,EAAE,6BAAmB;SAC7B,CAAA;IACH,CAAC;AAdD,CAcC,CAAA;AAhBU,QAAA,uBAAuB,2BAgBjC"}
@@ -0,0 +1,8 @@
1
+ import type * as AWS from '@aws-sdk/client-s3';
2
+ import type { GenerateURL } from '../../types';
3
+ interface Args {
4
+ config: AWS.S3ClientConfig;
5
+ bucket: string;
6
+ }
7
+ export declare const getGenerateURL: ({ config: { endpoint }, bucket }: Args) => GenerateURL;
8
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGenerateURL = void 0;
4
+ var getGenerateURL = function (_a) {
5
+ var endpoint = _a.config.endpoint, bucket = _a.bucket;
6
+ return function (_a) {
7
+ var filename = _a.filename;
8
+ return "".concat(endpoint, "/").concat(bucket, "/").concat(filename);
9
+ };
10
+ };
11
+ exports.getGenerateURL = getGenerateURL;
12
+ //# sourceMappingURL=generateURL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateURL.js","sourceRoot":"","sources":["../../../src/adapters/s3/generateURL.ts"],"names":[],"mappings":";;;AAQO,IAAM,cAAc,GACzB,UAAC,EAAsC;QAA1B,QAAQ,qBAAA,EAAI,MAAM,YAAA;IAC/B,OAAA,UAAC,EAAY;YAAV,QAAQ,cAAA;QACT,OAAO,UAAG,QAAQ,cAAI,MAAM,cAAI,QAAQ,CAAE,CAAA;IAC5C,CAAC;AAFD,CAEC,CAAA;AAJU,QAAA,cAAc,kBAIxB"}
@@ -0,0 +1,10 @@
1
+ import type { CollectionConfig } from 'payload/types';
2
+ import type * as AWS from '@aws-sdk/client-s3';
3
+ import type { HandleDelete } from '../../types';
4
+ interface Args {
5
+ collection: CollectionConfig;
6
+ s3: AWS.S3;
7
+ bucket: string;
8
+ }
9
+ export declare const getHandleDelete: ({ s3, bucket }: Args) => HandleDelete;
10
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getHandleDelete = void 0;
40
+ var getHandleDelete = function (_a) {
41
+ var s3 = _a.s3, bucket = _a.bucket;
42
+ return function (_a) {
43
+ var filename = _a.filename;
44
+ return __awaiter(void 0, void 0, void 0, function () {
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0: return [4 /*yield*/, s3.deleteObject({
48
+ Bucket: bucket,
49
+ Key: filename,
50
+ })];
51
+ case 1:
52
+ _b.sent();
53
+ return [2 /*return*/];
54
+ }
55
+ });
56
+ });
57
+ };
58
+ };
59
+ exports.getHandleDelete = getHandleDelete;
60
+ //# sourceMappingURL=handleDelete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleDelete.js","sourceRoot":"","sources":["../../../src/adapters/s3/handleDelete.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAAM,eAAe,GAAG,UAAC,EAAoB;QAAlB,EAAE,QAAA,EAAE,MAAM,YAAA;IAC1C,OAAO,UAAO,EAAY;YAAV,QAAQ,cAAA;;;;4BACtB,qBAAM,EAAE,CAAC,YAAY,CAAC;4BACpB,MAAM,EAAE,MAAM;4BACd,GAAG,EAAE,QAAQ;yBACd,CAAC,EAAA;;wBAHF,SAGE,CAAA;;;;;KACH,CAAA;AACH,CAAC,CAAA;AAPY,QAAA,eAAe,mBAO3B"}
@@ -0,0 +1,11 @@
1
+ import type * as AWS from '@aws-sdk/client-s3';
2
+ import type { CollectionConfig } from 'payload/types';
3
+ import type { HandleUpload } from '../../types';
4
+ interface Args {
5
+ collection: CollectionConfig;
6
+ bucket: string;
7
+ acl?: 'private' | 'public-read';
8
+ s3: AWS.S3;
9
+ }
10
+ export declare const getHandleUpload: ({ s3, bucket, acl }: Args) => HandleUpload;
11
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getHandleUpload = void 0;
40
+ var getHandleUpload = function (_a) {
41
+ var s3 = _a.s3, bucket = _a.bucket, acl = _a.acl;
42
+ return function (_a) {
43
+ var data = _a.data, file = _a.file;
44
+ return __awaiter(void 0, void 0, void 0, function () {
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0: return [4 /*yield*/, s3.putObject({
48
+ Bucket: bucket,
49
+ Key: file.filename,
50
+ Body: file.buffer,
51
+ ACL: acl,
52
+ ContentType: file.mimeType,
53
+ })];
54
+ case 1:
55
+ _b.sent();
56
+ return [2 /*return*/, data];
57
+ }
58
+ });
59
+ });
60
+ };
61
+ };
62
+ exports.getHandleUpload = getHandleUpload;
63
+ //# sourceMappingURL=handleUpload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleUpload.js","sourceRoot":"","sources":["../../../src/adapters/s3/handleUpload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,IAAM,eAAe,GAAG,UAAC,EAAyB;QAAvB,EAAE,QAAA,EAAE,MAAM,YAAA,EAAE,GAAG,SAAA;IAC/C,OAAO,UAAO,EAAc;YAAZ,IAAI,UAAA,EAAE,IAAI,UAAA;;;;4BACxB,qBAAM,EAAE,CAAC,SAAS,CAAC;4BACjB,MAAM,EAAE,MAAM;4BACd,GAAG,EAAE,IAAI,CAAC,QAAQ;4BAClB,IAAI,EAAE,IAAI,CAAC,MAAM;4BACjB,GAAG,EAAE,GAAG;4BACR,WAAW,EAAE,IAAI,CAAC,QAAQ;yBAC3B,CAAC,EAAA;;wBANF,SAME,CAAA;wBAEF,sBAAO,IAAI,EAAA;;;;KACZ,CAAA;AACH,CAAC,CAAA;AAZY,QAAA,eAAe,mBAY3B"}
@@ -0,0 +1,8 @@
1
+ import * as AWS from '@aws-sdk/client-s3';
2
+ import type { Adapter } from '../../types';
3
+ export interface Args {
4
+ config: AWS.S3ClientConfig;
5
+ bucket: string;
6
+ acl?: 'private' | 'public-read';
7
+ }
8
+ export declare const s3Adapter: ({ config, bucket, acl }: Args) => Adapter;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.s3Adapter = void 0;
27
+ var AWS = __importStar(require("@aws-sdk/client-s3"));
28
+ var generateURL_1 = require("./generateURL");
29
+ var handleDelete_1 = require("./handleDelete");
30
+ var handleUpload_1 = require("./handleUpload");
31
+ var webpack_1 = require("./webpack");
32
+ var s3Adapter = function (_a) {
33
+ var config = _a.config, bucket = _a.bucket, acl = _a.acl;
34
+ return function (_a) {
35
+ var collection = _a.collection;
36
+ var s3 = new AWS.S3(config);
37
+ return {
38
+ handleUpload: (0, handleUpload_1.getHandleUpload)({
39
+ collection: collection,
40
+ s3: s3,
41
+ bucket: bucket,
42
+ acl: acl,
43
+ }),
44
+ handleDelete: (0, handleDelete_1.getHandleDelete)({ collection: collection, s3: s3, bucket: bucket }),
45
+ generateURL: (0, generateURL_1.getGenerateURL)({ bucket: bucket, config: config }),
46
+ webpack: webpack_1.extendWebpackConfig,
47
+ };
48
+ };
49
+ };
50
+ exports.s3Adapter = s3Adapter;
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapters/s3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAyC;AAEzC,6CAA8C;AAC9C,+CAAgD;AAChD,+CAAgD;AAChD,qCAA+C;AAQxC,IAAM,SAAS,GACpB,UAAC,EAA6B;QAA3B,MAAM,YAAA,EAAE,MAAM,YAAA,EAAE,GAAG,SAAA;IACtB,OAAA,UAAC,EAAc;YAAZ,UAAU,gBAAA;QACX,IAAM,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;QAE7B,OAAO;YACL,YAAY,EAAE,IAAA,8BAAe,EAAC;gBAC5B,UAAU,YAAA;gBACV,EAAE,IAAA;gBACF,MAAM,QAAA;gBACN,GAAG,KAAA;aACJ,CAAC;YACF,YAAY,EAAE,IAAA,8BAAe,EAAC,EAAE,UAAU,YAAA,EAAE,EAAE,IAAA,EAAE,MAAM,QAAA,EAAE,CAAC;YACzD,WAAW,EAAE,IAAA,4BAAc,EAAC,EAAE,MAAM,QAAA,EAAE,MAAM,QAAA,EAAE,CAAC;YAC/C,OAAO,EAAE,6BAAmB;SAC7B,CAAA;IACH,CAAC;AAdD,CAcC,CAAA;AAhBU,QAAA,SAAS,aAgBnB"}
@@ -0,0 +1 @@
1
+ export function S3(): null;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ exports.S3 = function () {
3
+ return null;
4
+ };
5
+ //# sourceMappingURL=mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.js","sourceRoot":"","sources":["../../../src/adapters/s3/mock.js"],"names":[],"mappings":";AAAA,OAAO,CAAC,EAAE,GAAG;IACX,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ import type { Configuration as WebpackConfig } from 'webpack';
2
+ export declare const extendWebpackConfig: (existingWebpackConfig: WebpackConfig) => WebpackConfig;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.extendWebpackConfig = void 0;
18
+ var path_1 = __importDefault(require("path"));
19
+ var extendWebpackConfig = function (existingWebpackConfig) {
20
+ var _a;
21
+ var newConfig = __assign(__assign({}, existingWebpackConfig), { resolve: __assign(__assign({}, (existingWebpackConfig.resolve || {})), { alias: __assign(__assign({}, (((_a = existingWebpackConfig.resolve) === null || _a === void 0 ? void 0 : _a.alias) ? existingWebpackConfig.resolve.alias : {})), { '@aws-sdk/client-s3': path_1.default.resolve(__dirname, './mock.js') }) }) });
22
+ return newConfig;
23
+ };
24
+ exports.extendWebpackConfig = extendWebpackConfig;
25
+ //# sourceMappingURL=webpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../../src/adapters/s3/webpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,8CAAuB;AAEhB,IAAM,mBAAmB,GAAG,UAAC,qBAAoC;;IACtE,IAAM,SAAS,yBACV,qBAAqB,KACxB,OAAO,wBACF,CAAC,qBAAqB,CAAC,OAAO,IAAI,EAAE,CAAC,KACxC,KAAK,wBACA,CAAC,CAAA,MAAA,qBAAqB,CAAC,OAAO,0CAAE,KAAK,EAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KACpF,oBAAoB,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,SAG/D,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAbY,QAAA,mBAAmB,uBAa/B"}
@@ -44,11 +44,10 @@ var getBeforeChangeHook = function (_a) {
44
44
  var req = _a.req, data = _a.data;
45
45
  return __awaiter(void 0, void 0, void 0, function () {
46
46
  var files, promises, err_1;
47
- var _b;
48
- return __generator(this, function (_c) {
49
- switch (_c.label) {
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
50
49
  case 0:
51
- _c.trys.push([0, 2, , 3]);
50
+ _b.trys.push([0, 2, , 3]);
52
51
  files = (0, getIncomingFiles_1.getIncomingFiles)({ req: req, data: data });
53
52
  promises = files.map(function (file) { return __awaiter(void 0, void 0, void 0, function () {
54
53
  return __generator(this, function (_a) {
@@ -62,11 +61,11 @@ var getBeforeChangeHook = function (_a) {
62
61
  }); });
63
62
  return [4 /*yield*/, Promise.all(promises)];
64
63
  case 1:
65
- _c.sent();
64
+ _b.sent();
66
65
  return [3 /*break*/, 3];
67
66
  case 2:
68
- err_1 = _c.sent();
69
- req.payload.logger.error("There was an error while uploading files corresponding to the ".concat((_b = collection.labels) === null || _b === void 0 ? void 0 : _b.singular, " with filename ").concat(data.filename, ":"));
67
+ err_1 = _b.sent();
68
+ req.payload.logger.error("There was an error while uploading files corresponding to the collection ".concat(collection.slug, " with filename ").concat(data.filename, ":"));
70
69
  req.payload.logger.error(err_1);
71
70
  return [3 /*break*/, 3];
72
71
  case 3: return [2 /*return*/, data];
@@ -1 +1 @@
1
- {"version":3,"file":"beforeChange.js","sourceRoot":"","sources":["../../src/hooks/beforeChange.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kEAAgE;AAOzD,IAAM,mBAAmB,GAC9B,UAAC,EAA6B;QAA3B,UAAU,gBAAA,EAAE,OAAO,aAAA;IACtB,OAAA,UAAO,EAAa;YAAX,GAAG,SAAA,EAAE,IAAI,UAAA;;;;;;;;wBAER,KAAK,GAAG,IAAA,mCAAgB,EAAC,EAAE,GAAG,KAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAA;wBAEvC,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,UAAM,IAAI;;;4CACnC,qBAAM,OAAO,CAAC,YAAY,CAAC,EAAE,UAAU,YAAA,EAAE,IAAI,MAAA,EAAE,GAAG,KAAA,EAAE,IAAI,MAAA,EAAE,CAAC,EAAA;;wCAA3D,SAA2D,CAAA;;;;6BAC5D,CAAC,CAAA;wBAEF,qBAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAA;;wBAA3B,SAA2B,CAAA;;;;wBAE3B,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CACtB,wEAAiE,MAAA,UAAU,CAAC,MAAM,0CAAE,QAAQ,4BAAkB,IAAI,CAAC,QAAQ,MAAG,CAC/H,CAAA;wBACD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAG,CAAC,CAAA;;4BAE/B,sBAAO,IAAI,EAAA;;;;KACZ;AAhBD,CAgBC,CAAA;AAlBU,QAAA,mBAAmB,uBAkB7B"}
1
+ {"version":3,"file":"beforeChange.js","sourceRoot":"","sources":["../../src/hooks/beforeChange.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,kEAAgE;AAOzD,IAAM,mBAAmB,GAC9B,UAAC,EAA6B;QAA3B,UAAU,gBAAA,EAAE,OAAO,aAAA;IACtB,OAAA,UAAO,EAAa;YAAX,GAAG,SAAA,EAAE,IAAI,UAAA;;;;;;;wBAER,KAAK,GAAG,IAAA,mCAAgB,EAAC,EAAE,GAAG,KAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAA;wBAEvC,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,UAAM,IAAI;;;4CACnC,qBAAM,OAAO,CAAC,YAAY,CAAC,EAAE,UAAU,YAAA,EAAE,IAAI,MAAA,EAAE,GAAG,KAAA,EAAE,IAAI,MAAA,EAAE,CAAC,EAAA;;wCAA3D,SAA2D,CAAA;;;;6BAC5D,CAAC,CAAA;wBAEF,qBAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAA;;wBAA3B,SAA2B,CAAA;;;;wBAE3B,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CACtB,mFAA4E,UAAU,CAAC,IAAI,4BAAkB,IAAI,CAAC,QAAQ,MAAG,CAC9H,CAAA;wBACD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAG,CAAC,CAAA;;4BAE/B,sBAAO,IAAI,EAAA;;;;KACZ;AAhBD,CAgBC,CAAA;AAlBU,QAAA,mBAAmB,uBAkB7B"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { cloudStorage } from './plugin';
2
2
  export { azureBlobStorageAdapter } from './adapters/azure';
3
+ export { s3Adapter } from './adapters/s3';
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.azureBlobStorageAdapter = exports.cloudStorage = void 0;
3
+ exports.s3Adapter = exports.azureBlobStorageAdapter = exports.cloudStorage = void 0;
4
4
  var plugin_1 = require("./plugin");
5
5
  Object.defineProperty(exports, "cloudStorage", { enumerable: true, get: function () { return plugin_1.cloudStorage; } });
6
6
  var azure_1 = require("./adapters/azure");
7
7
  Object.defineProperty(exports, "azureBlobStorageAdapter", { enumerable: true, get: function () { return azure_1.azureBlobStorageAdapter; } });
8
+ var s3_1 = require("./adapters/s3");
9
+ Object.defineProperty(exports, "s3Adapter", { enumerable: true, get: function () { return s3_1.s3Adapter; } });
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AAA9B,sGAAA,YAAY,OAAA;AACrB,0CAA0D;AAAjD,gHAAA,uBAAuB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AAA9B,sGAAA,YAAY,OAAA;AACrB,0CAA0D;AAAjD,gHAAA,uBAAuB,OAAA;AAChC,oCAAyC;AAAhC,+FAAA,SAAS,OAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-cloud-storage",
3
3
  "description": "The official cloud storage plugin for Payload CMS",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -14,14 +14,19 @@
14
14
  "lint:fix": "eslint --fix --ext .ts,.tsx src"
15
15
  },
16
16
  "peerDependencies": {
17
+ "@aws-sdk/client-s3": "^3.142.0",
17
18
  "@azure/storage-blob": "^12.11.0"
18
19
  },
19
20
  "peerDependenciesMeta": {
21
+ "@aws-sdk/client-s3": {
22
+ "optional": true
23
+ },
20
24
  "@azure/storage-blob": {
21
25
  "optional": true
22
26
  }
23
27
  },
24
28
  "devDependencies": {
29
+ "@aws-sdk/client-s3": "^3.142.0",
25
30
  "@azure/storage-blob": "^12.11.0",
26
31
  "@types/express": "^4.17.9",
27
32
  "@typescript-eslint/eslint-plugin": "5.12.1",