@lowdefy/plugin-aws 4.2.0 → 4.2.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.
Files changed (28) hide show
  1. package/dist/blocks/S3Download/S3Download.js +70 -0
  2. package/dist/blocks/S3Download/schema.json +85 -0
  3. package/dist/blocks/S3Download/style.less +17 -0
  4. package/dist/blocks/S3UploadButton/S3UploadButton.js +97 -0
  5. package/dist/blocks/S3UploadButton/__snapshots__/S3UploadButton.mock.test.js.snap +1597 -0
  6. package/dist/blocks/S3UploadButton/__snapshots__/S3UploadButton.test.js.snap +281 -0
  7. package/dist/blocks/S3UploadButton/examples.yaml +44 -0
  8. package/dist/blocks/S3UploadButton/schema.json +87 -0
  9. package/dist/blocks/S3UploadButton/style.less +18 -0
  10. package/dist/blocks/S3UploadDragger/S3UploadDragger.js +101 -0
  11. package/dist/blocks/S3UploadDragger/schema.json +81 -0
  12. package/dist/blocks/S3UploadDragger/style.less +17 -0
  13. package/dist/blocks/S3UploadPhoto/S3UploadPhoto.js +114 -0
  14. package/dist/blocks/S3UploadPhoto/schema.json +79 -0
  15. package/dist/blocks/S3UploadPhoto/style.less +17 -0
  16. package/dist/blocks/utils/getOnPaste.js +48 -0
  17. package/dist/blocks/utils/getS3Upload.js +81 -0
  18. package/dist/blocks/utils/useFileList.js +115 -0
  19. package/dist/blocks.js +18 -0
  20. package/dist/connections/AwsS3Bucket/AwsS3Bucket.js +24 -0
  21. package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/AwsS3PresignedGetObject.js +41 -0
  22. package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/schema.js +64 -0
  23. package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/AwsS3PresignedPostPolicy.js +57 -0
  24. package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/schema.js +70 -0
  25. package/dist/connections/AwsS3Bucket/schema.js +80 -0
  26. package/dist/connections.js +15 -0
  27. package/dist/types.js +32 -0
  28. package/package.json +7 -7
@@ -0,0 +1,114 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React, { useEffect, useState } from 'react';
16
+ import { blockDefaultProps, renderHtml } from '@lowdefy/block-utils';
17
+ import { Upload } from 'antd';
18
+ import useFileList from '../utils/useFileList.js';
19
+ import getS3Upload from '../utils/getS3Upload.js';
20
+ const S3UploadPhoto = ({ blockId, components: { Icon }, events, methods, properties, value })=>{
21
+ const [state, loadFileList, setFileList, removeFile, setValue] = useFileList({
22
+ properties,
23
+ methods,
24
+ value
25
+ });
26
+ const [loading, setLoading] = useState(false);
27
+ const s3UploadRequest = getS3Upload({
28
+ methods,
29
+ setFileList,
30
+ setLoading
31
+ });
32
+ useEffect(()=>{
33
+ methods.setValue({
34
+ file: null,
35
+ fileList: []
36
+ });
37
+ methods.registerEvent({
38
+ name: '__getS3PostPolicy',
39
+ actions: [
40
+ {
41
+ id: '__getS3PostPolicy',
42
+ type: 'Request',
43
+ params: [
44
+ properties.s3PostPolicyRequestId
45
+ ]
46
+ }
47
+ ]
48
+ });
49
+ }, []);
50
+ useEffect(()=>{
51
+ if (JSON.stringify(value) !== JSON.stringify(state)) {
52
+ setValue(value);
53
+ }
54
+ }, [
55
+ value
56
+ ]);
57
+ return /*#__PURE__*/ React.createElement(Upload, {
58
+ accept: "image/*",
59
+ beforeUpload: loadFileList,
60
+ className: "avatar-uploader",
61
+ customRequest: s3UploadRequest,
62
+ disabled: properties.disabled,
63
+ fileList: state.fileList,
64
+ id: blockId,
65
+ listType: "picture-card",
66
+ maxCount: properties.maxCount,
67
+ multiple: !properties.singleFile,
68
+ onRemove: removeFile,
69
+ showUploadList: properties.showUploadList,
70
+ onChange: ()=>{
71
+ methods.triggerEvent({
72
+ name: 'onChange'
73
+ });
74
+ }
75
+ }, /*#__PURE__*/ React.createElement("div", {
76
+ className: methods.makeCssClass([
77
+ properties.style
78
+ ])
79
+ }, loading ? /*#__PURE__*/ React.createElement(Icon, {
80
+ blockId: `${blockId}_icon`,
81
+ events: events,
82
+ properties: {
83
+ name: 'AiOutlineLoading',
84
+ size: 24
85
+ }
86
+ }) : /*#__PURE__*/ React.createElement(Icon, {
87
+ blockId: `${blockId}_icon`,
88
+ events: events,
89
+ properties: {
90
+ name: 'AiOutlineCamera',
91
+ size: 24
92
+ }
93
+ }), /*#__PURE__*/ React.createElement("div", {
94
+ style: {
95
+ marginTop: 8
96
+ }
97
+ }, renderHtml({
98
+ html: properties.title ?? 'Upload image',
99
+ methods
100
+ }))));
101
+ };
102
+ S3UploadPhoto.defaultProps = blockDefaultProps;
103
+ S3UploadPhoto.meta = {
104
+ valueType: 'object',
105
+ category: 'input',
106
+ icons: [
107
+ 'AiOutlineLoading',
108
+ 'AiOutlineCamera'
109
+ ],
110
+ styles: [
111
+ 'blocks/S3UploadPhoto/style.less'
112
+ ]
113
+ };
114
+ export default S3UploadPhoto;
@@ -0,0 +1,79 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "type": "object",
5
+ "required": ["s3PostPolicyRequestId"],
6
+ "properties": {
7
+ "title": {
8
+ "type": "string",
9
+ "description": "Title of the file input to be displayed instead of 'Upload image'.",
10
+ "default": "Upload image"
11
+ },
12
+ "disabled": {
13
+ "type": "boolean",
14
+ "description": "Disable the file input."
15
+ },
16
+ "maxCount": {
17
+ "type": "number",
18
+ "description": "Maximum number of files that can be uploaded."
19
+ },
20
+ "s3PostPolicyRequestId": {
21
+ "type": "string",
22
+ "description": "Id of a request of type AwsS3PresignedPostPolicy that defines to which S3 bucket and how the file should be uploaded.",
23
+ "docs": {
24
+ "displayType": "manual",
25
+ "block": {
26
+ "id": "block_properties_s3PostPolicyRequestId",
27
+ "layout": { "_global": "settings_input_layout" },
28
+ "type": "Label",
29
+ "required": true,
30
+ "properties": {
31
+ "title": "s3PostPolicyRequestId",
32
+ "span": 8,
33
+ "align": "right"
34
+ },
35
+ "blocks": [
36
+ {
37
+ "id": "block_properties_s3PostPolicyRequestId_text",
38
+ "type": "Markdown",
39
+ "style": {
40
+ "color": "#8c8c8c"
41
+ },
42
+ "properties": {
43
+ "content": "Id of a request of type AwsS3PresignedPostPolicy that defines to which S3 bucket and how the file should be uploaded."
44
+ }
45
+ }
46
+ ]
47
+ },
48
+ "getter": {}
49
+ }
50
+ },
51
+ "showUploadList": {
52
+ "type": "boolean",
53
+ "default": true,
54
+ "description": "Whether to show default upload list."
55
+ },
56
+ "singleFile": {
57
+ "type": "boolean",
58
+ "default": false,
59
+ "description": "Only allow a single file to be uploaded. Only one file can be selected in the prompt."
60
+ },
61
+ "style": {
62
+ "type": "object",
63
+ "description": "Css style object to applied to draggable area.",
64
+ "docs": {
65
+ "displayType": "yaml"
66
+ }
67
+ }
68
+ }
69
+ },
70
+ "events": {
71
+ "type": "object",
72
+ "properties": {
73
+ "onChange": {
74
+ "type": "array",
75
+ "description": "Triggered when the upload state is changing."
76
+ }
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ @import 'antd/lib/upload/style/index.less';
@@ -0,0 +1,48 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ const getFileFromEvent = async (event)=>{
16
+ const items = event.clipboardData.items;
17
+ for (const item of items){
18
+ if (item.kind === 'file') {
19
+ return item.getAsFile();
20
+ }
21
+ }
22
+ };
23
+ const getFileFromNavigator = async ()=>{
24
+ const items = await navigator.clipboard.read();
25
+ for (const item of items){
26
+ for (const type of item.types){
27
+ if (type === 'image/png' || type === 'image/jpeg') {
28
+ const blob = await item.getType(type);
29
+ return new File([
30
+ blob
31
+ ], 'clipboard.png', {
32
+ type: blob.type
33
+ });
34
+ }
35
+ }
36
+ }
37
+ };
38
+ const getOnPaste = ({ s3UploadRequest, properties })=>async (event)=>{
39
+ event?.preventDefault?.();
40
+ if (properties.disabled) return;
41
+ const file = event ? await getFileFromEvent(event) : await getFileFromNavigator();
42
+ if (!file) return;
43
+ file.uid = `${properties.fileName ?? file.name ?? 'clipboard'}-${Date.now()}`;
44
+ await s3UploadRequest({
45
+ file
46
+ });
47
+ };
48
+ export default getOnPaste;
@@ -0,0 +1,81 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ const getS3Upload = ({ methods, setFileList, setLoading = ()=>null })=>async ({ file })=>{
16
+ if (!file) {
17
+ console.warn('File is undefined in useS3Upload');
18
+ return;
19
+ }
20
+ try {
21
+ setLoading(true);
22
+ const { lastModified, name, size, type, uid } = file;
23
+ const s3PostPolicyResponse = await methods.triggerEvent({
24
+ name: '__getS3PostPolicy',
25
+ event: {
26
+ file: {
27
+ name,
28
+ lastModified,
29
+ size,
30
+ type,
31
+ uid
32
+ }
33
+ }
34
+ });
35
+ if (s3PostPolicyResponse.success !== true) {
36
+ throw new Error('S3 post policy request error.');
37
+ }
38
+ const { url, fields = {} } = s3PostPolicyResponse.responses.__getS3PostPolicy.response[0];
39
+ const { bucket, key } = fields;
40
+ file.bucket = bucket;
41
+ file.key = key;
42
+ file.percent = 20;
43
+ const formData = new FormData();
44
+ Object.keys(fields).forEach((field)=>{
45
+ formData.append(field, fields[field]);
46
+ });
47
+ formData.append('file', file);
48
+ const xhr = new XMLHttpRequest();
49
+ xhr.upload.onprogress = async (event)=>{
50
+ if (event.lengthComputable) {
51
+ await setFileList({
52
+ event: 'onProgress',
53
+ file,
54
+ percent: event.loaded / event.total * 80 + 20
55
+ });
56
+ }
57
+ };
58
+ xhr.addEventListener('error', async ()=>{
59
+ await setFileList({
60
+ event: 'onError',
61
+ file
62
+ });
63
+ });
64
+ xhr.addEventListener('loadend', async ()=>{
65
+ await setFileList({
66
+ event: 'onSuccess',
67
+ file
68
+ });
69
+ setLoading(false);
70
+ });
71
+ xhr.open('post', url);
72
+ xhr.send(formData);
73
+ } catch (error) {
74
+ console.error(error);
75
+ await setFileList({
76
+ event: 'onError',
77
+ file
78
+ });
79
+ }
80
+ };
81
+ export default getS3Upload;
@@ -0,0 +1,115 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { useState } from 'react';
16
+ import { type } from '@lowdefy/helpers';
17
+ const useFileList = ({ properties, methods, value = {} })=>{
18
+ const checkedValue = (value)=>{
19
+ let file = type.isObject(value?.file) ? value.file : null;
20
+ if (!file && type.isObject(value?.fileList?.[0])) {
21
+ file = value.fileList[0];
22
+ }
23
+ const fileList = type.isArray(value?.fileList) ? value.fileList : [];
24
+ if (properties.singleFile === true) {
25
+ fileList.splice(1);
26
+ }
27
+ if (type.isInt(properties.maxCount)) {
28
+ fileList.splice(properties.maxCount);
29
+ }
30
+ return {
31
+ file,
32
+ fileList
33
+ };
34
+ };
35
+ const [state, setState] = useState(checkedValue(value));
36
+ const setValue = (stateValue)=>{
37
+ setState(()=>{
38
+ return checkedValue(stateValue);
39
+ });
40
+ };
41
+ const setFileList = async ({ event, file, percent })=>{
42
+ if (!file) {
43
+ throw new Error('File is undefined in useFileList');
44
+ }
45
+ // destruct the file object to avoid the file object being mutated.
46
+ const { bucket, key, lastModified, name, size, status, type, uid } = file;
47
+ const fileObj = {
48
+ bucket,
49
+ key,
50
+ lastModified,
51
+ name,
52
+ percent: percent ?? file.percent ?? 0,
53
+ size,
54
+ status,
55
+ type,
56
+ uid,
57
+ url: file instanceof Blob || file instanceof File ? URL.createObjectURL(file) : null
58
+ };
59
+ switch(event){
60
+ case 'onProgress':
61
+ fileObj.status = 'uploading';
62
+ fileObj.percent = percent ?? fileObj.percent;
63
+ break;
64
+ case 'onSuccess':
65
+ fileObj.status = 'done';
66
+ fileObj.percent = 100;
67
+ break;
68
+ case 'onRemove':
69
+ fileObj.status = 'removed';
70
+ break;
71
+ default:
72
+ fileObj.status = 'error';
73
+ break;
74
+ }
75
+ state.fileList.splice(state.fileList.findIndex((f)=>f.uid === fileObj.uid), 1, fileObj);
76
+ const nextState = checkedValue({
77
+ file: fileObj,
78
+ fileList: state.fileList
79
+ });
80
+ await methods.triggerEvent({
81
+ name: event,
82
+ event: nextState
83
+ });
84
+ setValue(nextState);
85
+ methods.setValue(nextState);
86
+ };
87
+ const loadFileList = (file, nextFiles)=>{
88
+ if (properties.singleFile === true && nextFiles.filter((f)=>type.isString(f.uid)).length > 1) {
89
+ return false;
90
+ }
91
+ if (type.isInt(properties.maxCount) && nextFiles.filter((f)=>type.isString(f.uid)).length > properties.maxCount) {
92
+ return false;
93
+ }
94
+ setValue({
95
+ file,
96
+ fileList: [
97
+ ...nextFiles,
98
+ ...state.fileList
99
+ ]
100
+ });
101
+ };
102
+ const removeFile = (file)=>{
103
+ state.fileList.splice(state.fileList.findIndex((f)=>f.uid === file.uid), 1);
104
+ setValue(state);
105
+ methods.setValue(state);
106
+ };
107
+ return [
108
+ state,
109
+ loadFileList,
110
+ setFileList,
111
+ removeFile,
112
+ setValue
113
+ ];
114
+ };
115
+ export default useFileList;
package/dist/blocks.js ADDED
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export { default as S3Download } from './blocks/S3Download/S3Download.js';
16
+ export { default as S3UploadDragger } from './blocks/S3UploadDragger/S3UploadDragger.js';
17
+ export { default as S3UploadButton } from './blocks/S3UploadButton/S3UploadButton.js';
18
+ export { default as S3UploadPhoto } from './blocks/S3UploadPhoto/S3UploadPhoto.js';
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import AwsS3PresignedGetObject from './AwsS3PresignedGetObject/AwsS3PresignedGetObject.js';
16
+ import AwsS3PresignedPostPolicy from './AwsS3PresignedPostPolicy/AwsS3PresignedPostPolicy.js';
17
+ import schema from './schema.js';
18
+ export default {
19
+ schema,
20
+ requests: {
21
+ AwsS3PresignedGetObject,
22
+ AwsS3PresignedPostPolicy
23
+ }
24
+ };
@@ -0,0 +1,41 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import AWS from 'aws-sdk';
16
+ import schema from './schema.js';
17
+ function AwsS3PresignedGetObject({ request, connection }) {
18
+ const { accessKeyId, secretAccessKey, region, bucket } = connection;
19
+ const { expires, key, versionId, responseContentDisposition, responseContentType } = request;
20
+ const params = {
21
+ Bucket: bucket,
22
+ Key: key,
23
+ Expires: expires,
24
+ VersionId: versionId,
25
+ ResponseContentDisposition: responseContentDisposition,
26
+ ResponseContentType: responseContentType
27
+ };
28
+ const s3 = new AWS.S3({
29
+ accessKeyId,
30
+ secretAccessKey,
31
+ region,
32
+ bucket
33
+ });
34
+ return s3.getSignedUrl('getObject', params);
35
+ }
36
+ AwsS3PresignedGetObject.schema = schema;
37
+ AwsS3PresignedGetObject.meta = {
38
+ checkRead: true,
39
+ checkWrite: false
40
+ };
41
+ export default AwsS3PresignedGetObject;
@@ -0,0 +1,64 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ $schema: 'http://json-schema.org/draft-07/schema#',
17
+ title: 'Lowdefy Request Schema - AwsS3PresignedGetObject',
18
+ type: 'object',
19
+ required: [
20
+ 'key'
21
+ ],
22
+ properties: {
23
+ expires: {
24
+ type: 'number',
25
+ description: 'Number of seconds for which the policy should be valid.',
26
+ default: 3600,
27
+ errorMessage: {
28
+ type: 'AwsS3PresignedGetObject request property "expires" should be a number.'
29
+ }
30
+ },
31
+ key: {
32
+ type: 'string',
33
+ description: 'Key under which object is stored.',
34
+ errorMessage: {
35
+ type: 'AwsS3PresignedGetObject request property "key" should be a string.'
36
+ }
37
+ },
38
+ responseContentDisposition: {
39
+ type: 'string',
40
+ description: 'Sets the Content-Disposition header of the response.',
41
+ errorMessage: {
42
+ type: 'AwsS3PresignedGetObject request property "responseContentDisposition" should be a string.'
43
+ }
44
+ },
45
+ responseContentType: {
46
+ type: 'string',
47
+ description: 'Sets the Content-Type header of the response.',
48
+ errorMessage: {
49
+ type: 'AwsS3PresignedGetObject request property "responseContentType" should be a string.'
50
+ }
51
+ },
52
+ versionId: {
53
+ type: 'string',
54
+ description: 'VersionId used to reference a specific version of the object.',
55
+ errorMessage: {
56
+ type: 'AwsS3PresignedGetObject request property "versionId" should be a string.'
57
+ }
58
+ }
59
+ },
60
+ errorMessage: {
61
+ type: 'AwsS3PresignedGetObject request properties should be an object.',
62
+ required: 'AwsS3PresignedGetObject request should have required property "key".'
63
+ }
64
+ };
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright 2020-2024 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import AWS from 'aws-sdk';
16
+ import schema from './schema.js';
17
+ import { type } from '@lowdefy/helpers';
18
+ function AwsS3PresignedPostPolicy({ request, connection }) {
19
+ const { accessKeyId, secretAccessKey, region, bucket } = connection;
20
+ const { acl, conditions, expires, key, fields = {} } = request;
21
+ const params = {
22
+ Bucket: bucket,
23
+ Fields: {
24
+ key
25
+ }
26
+ };
27
+ if (conditions) {
28
+ params.Conditions = conditions;
29
+ }
30
+ if (expires) {
31
+ params.Expires = expires;
32
+ }
33
+ if (acl) {
34
+ params.Fields.acl = acl;
35
+ }
36
+ if (type.isObject(fields) === false) {
37
+ throw new Error('properties.fields must be an object.');
38
+ }
39
+ Object.keys(fields).forEach((field)=>{
40
+ if (fields[field]) {
41
+ params.Fields[field] = fields[field];
42
+ }
43
+ });
44
+ const s3 = new AWS.S3({
45
+ accessKeyId,
46
+ secretAccessKey,
47
+ region,
48
+ bucket
49
+ });
50
+ return s3.createPresignedPost(params);
51
+ }
52
+ AwsS3PresignedPostPolicy.schema = schema;
53
+ AwsS3PresignedPostPolicy.meta = {
54
+ checkRead: false,
55
+ checkWrite: true
56
+ };
57
+ export default AwsS3PresignedPostPolicy;