@lowdefy/plugin-aws 4.0.0-rc.9 → 4.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/dist/blocks/S3UploadButton/S3UploadButton.js +30 -32
- package/dist/blocks/S3UploadButton/examples.yaml +1 -1
- package/dist/blocks/S3UploadButton/style.less +1 -1
- package/dist/blocks/S3UploadPhoto/S3UploadPhoto.js +28 -27
- package/dist/blocks/S3UploadPhoto/style.less +1 -1
- package/dist/blocks.js +1 -1
- package/dist/connections/AwsS3Bucket/AwsS3Bucket.js +1 -1
- package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/AwsS3PresignedGetObject.js +4 -4
- package/dist/connections/AwsS3Bucket/AwsS3PresignedGetObject/schema.js +1 -1
- package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/AwsS3PresignedPostPolicy.js +4 -4
- package/dist/connections/AwsS3Bucket/AwsS3PresignedPostPolicy/schema.js +1 -1
- package/dist/connections/AwsS3Bucket/schema.js +1 -1
- package/dist/connections.js +1 -1
- package/dist/types.js +3 -3
- package/package.json +20 -21
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -18,8 +18,8 @@ import { get } from '@lowdefy/helpers';
|
|
|
18
18
|
import { Button } from '@lowdefy/blocks-antd/blocks';
|
|
19
19
|
import { Upload } from 'antd';
|
|
20
20
|
const makeFileValue = (file, s3Parameters)=>{
|
|
21
|
-
const { lastModified
|
|
22
|
-
const { bucket
|
|
21
|
+
const { lastModified, name, percent, size, status, type, uid } = file;
|
|
22
|
+
const { bucket, key } = get(s3Parameters, uid, {
|
|
23
23
|
default: {}
|
|
24
24
|
});
|
|
25
25
|
return {
|
|
@@ -35,22 +35,20 @@ const makeFileValue = (file, s3Parameters)=>{
|
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
const makeOnChangeValue = (s3Parameters, changeEvent)=>{
|
|
38
|
-
const { file
|
|
38
|
+
const { file, fileList } = changeEvent;
|
|
39
39
|
return {
|
|
40
40
|
file: makeFileValue(file, s3Parameters),
|
|
41
41
|
fileList: fileList.map((fl)=>makeFileValue(fl, s3Parameters))
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
-
const getDisabled = ({ properties
|
|
44
|
+
const getDisabled = ({ properties, value })=>{
|
|
45
45
|
if (properties.disabled) return true;
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
46
|
+
return properties.singleFile && value && (value.fileList || []).length >= 1;
|
|
50
47
|
};
|
|
51
|
-
const getCustomRequest = ({ methods
|
|
48
|
+
const getCustomRequest = ({ methods, setS3Parameters })=>async ({ file, onError, onProgress, onSuccess })=>{
|
|
49
|
+
let meta;
|
|
52
50
|
try {
|
|
53
|
-
const { name
|
|
51
|
+
const { name, size, type, uid } = file;
|
|
54
52
|
const s3PostPolicyResponse = await methods.triggerEvent({
|
|
55
53
|
name: '__getS3PostPolicy',
|
|
56
54
|
event: {
|
|
@@ -63,9 +61,9 @@ const getCustomRequest = ({ methods , setS3Parameters })=>async ({ file , onErr
|
|
|
63
61
|
if (s3PostPolicyResponse.success !== true) {
|
|
64
62
|
throw new Error('S3 post policy request error.');
|
|
65
63
|
}
|
|
66
|
-
const { url
|
|
67
|
-
const { bucket
|
|
68
|
-
|
|
64
|
+
const { url, fields } = s3PostPolicyResponse.responses.__getS3PostPolicy.response[0];
|
|
65
|
+
const { bucket, key } = fields;
|
|
66
|
+
meta = {
|
|
69
67
|
bucket,
|
|
70
68
|
key,
|
|
71
69
|
filename: name,
|
|
@@ -95,39 +93,39 @@ const getCustomRequest = ({ methods , setS3Parameters })=>async ({ file , onErr
|
|
|
95
93
|
// file needs to be the last field in the form
|
|
96
94
|
formData.append('file', file);
|
|
97
95
|
const xhr = new XMLHttpRequest();
|
|
98
|
-
xhr.upload.onprogress = (
|
|
99
|
-
if (
|
|
96
|
+
xhr.upload.onprogress = (event)=>{
|
|
97
|
+
if (event.lengthComputable) {
|
|
100
98
|
onProgress({
|
|
101
|
-
percent:
|
|
99
|
+
percent: event.loaded / event.total * 80 + 20
|
|
102
100
|
});
|
|
103
101
|
}
|
|
104
102
|
};
|
|
105
|
-
xhr.addEventListener('error', async (
|
|
103
|
+
xhr.addEventListener('error', async (event)=>{
|
|
106
104
|
await methods.triggerEvent({
|
|
107
105
|
name: 'onError',
|
|
108
106
|
event: {
|
|
109
|
-
meta
|
|
110
|
-
event
|
|
107
|
+
meta,
|
|
108
|
+
event
|
|
111
109
|
}
|
|
112
110
|
});
|
|
113
|
-
onError(
|
|
111
|
+
onError(event);
|
|
114
112
|
});
|
|
115
|
-
xhr.addEventListener('load', async (
|
|
113
|
+
xhr.addEventListener('load', async (event)=>{
|
|
116
114
|
await methods.triggerEvent({
|
|
117
115
|
name: 'onSuccess',
|
|
118
116
|
event: {
|
|
119
|
-
meta
|
|
120
|
-
event
|
|
117
|
+
meta,
|
|
118
|
+
event
|
|
121
119
|
}
|
|
122
120
|
});
|
|
123
|
-
onSuccess(
|
|
121
|
+
onSuccess(event);
|
|
124
122
|
});
|
|
125
|
-
xhr.addEventListener('loadend', async (
|
|
123
|
+
xhr.addEventListener('loadend', async (event)=>{
|
|
126
124
|
await methods.triggerEvent({
|
|
127
125
|
name: 'onDone',
|
|
128
126
|
event: {
|
|
129
|
-
meta
|
|
130
|
-
event
|
|
127
|
+
meta,
|
|
128
|
+
event
|
|
131
129
|
}
|
|
132
130
|
});
|
|
133
131
|
});
|
|
@@ -139,13 +137,13 @@ const getCustomRequest = ({ methods , setS3Parameters })=>async ({ file , onErr
|
|
|
139
137
|
name: 'onError',
|
|
140
138
|
event: {
|
|
141
139
|
meta,
|
|
142
|
-
|
|
140
|
+
error
|
|
143
141
|
}
|
|
144
142
|
});
|
|
145
143
|
onError(error);
|
|
146
144
|
}
|
|
147
145
|
};
|
|
148
|
-
const S3UploadButtonBlock = ({ blockId
|
|
146
|
+
const S3UploadButtonBlock = ({ blockId, components, events, methods, properties, value })=>{
|
|
149
147
|
// Use state here because we need to set s3 bucket and key as block value
|
|
150
148
|
// The customRequest function does not have access to the updated block value,
|
|
151
149
|
// so it cannot set the value directly. customRequest sets the parameters to s3Parameters state,
|
|
@@ -184,8 +182,8 @@ const S3UploadButtonBlock = ({ blockId , components , events , methods , propert
|
|
|
184
182
|
id: blockId,
|
|
185
183
|
multiple: !properties.singleFile,
|
|
186
184
|
showUploadList: properties.showUploadList,
|
|
187
|
-
onChange: (
|
|
188
|
-
methods.setValue(makeOnChangeValue(s3Parameters,
|
|
185
|
+
onChange: (event)=>{
|
|
186
|
+
methods.setValue(makeOnChangeValue(s3Parameters, event));
|
|
189
187
|
methods.triggerEvent({
|
|
190
188
|
name: 'onChange'
|
|
191
189
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -17,8 +17,8 @@ import { blockDefaultProps } from '@lowdefy/block-utils';
|
|
|
17
17
|
import { get } from '@lowdefy/helpers';
|
|
18
18
|
import { Upload } from 'antd';
|
|
19
19
|
const makeFileValue = (file, s3Parameters)=>{
|
|
20
|
-
const { lastModified
|
|
21
|
-
const { bucket
|
|
20
|
+
const { lastModified, name, percent, size, status, type, uid } = file;
|
|
21
|
+
const { bucket, key } = get(s3Parameters, uid, {
|
|
22
22
|
default: {}
|
|
23
23
|
});
|
|
24
24
|
return {
|
|
@@ -34,16 +34,17 @@ const makeFileValue = (file, s3Parameters)=>{
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
const makeOnChangeValue = (s3Parameters, changeEvent)=>{
|
|
37
|
-
const { file
|
|
37
|
+
const { file, fileList } = changeEvent;
|
|
38
38
|
return {
|
|
39
39
|
file: makeFileValue(file, s3Parameters),
|
|
40
40
|
fileList: fileList.map((fl)=>makeFileValue(fl, s3Parameters))
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
-
const getCustomRequest = ({ methods
|
|
43
|
+
const getCustomRequest = ({ methods, setS3Parameters, setLoading })=>async ({ file, onError, onProgress, onSuccess })=>{
|
|
44
|
+
let meta;
|
|
44
45
|
try {
|
|
45
46
|
setLoading(true);
|
|
46
|
-
const { name
|
|
47
|
+
const { name, size, type, uid } = file;
|
|
47
48
|
if (size > 1024 * 1024 * 10) throw new Error('File cannot exceed 10mb.');
|
|
48
49
|
const s3PostPolicyResponse = await methods.triggerEvent({
|
|
49
50
|
name: '__getS3PostPolicy',
|
|
@@ -57,9 +58,9 @@ const getCustomRequest = ({ methods , setS3Parameters , setLoading })=>async ({
|
|
|
57
58
|
if (s3PostPolicyResponse.success !== true) {
|
|
58
59
|
throw new Error('S3 post policy request error.');
|
|
59
60
|
}
|
|
60
|
-
const { url
|
|
61
|
-
const { bucket
|
|
62
|
-
|
|
61
|
+
const { url, fields } = s3PostPolicyResponse.responses.__getS3PostPolicy.response[0];
|
|
62
|
+
const { bucket, key } = fields;
|
|
63
|
+
meta = {
|
|
63
64
|
bucket,
|
|
64
65
|
key,
|
|
65
66
|
filename: name,
|
|
@@ -89,39 +90,39 @@ const getCustomRequest = ({ methods , setS3Parameters , setLoading })=>async ({
|
|
|
89
90
|
// file needs to be the last field in the form
|
|
90
91
|
formData.append('file', file);
|
|
91
92
|
const xhr = new XMLHttpRequest();
|
|
92
|
-
xhr.upload.onprogress = (
|
|
93
|
-
if (
|
|
93
|
+
xhr.upload.onprogress = (event)=>{
|
|
94
|
+
if (event.lengthComputable) {
|
|
94
95
|
onProgress({
|
|
95
|
-
percent:
|
|
96
|
+
percent: event.loaded / event.total * 80 + 20
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
};
|
|
99
|
-
xhr.addEventListener('error', async (
|
|
100
|
+
xhr.addEventListener('error', async (event)=>{
|
|
100
101
|
await methods.triggerEvent({
|
|
101
102
|
name: 'onError',
|
|
102
103
|
event: {
|
|
103
|
-
meta
|
|
104
|
-
event
|
|
104
|
+
meta,
|
|
105
|
+
event
|
|
105
106
|
}
|
|
106
107
|
});
|
|
107
|
-
onError(
|
|
108
|
+
onError(event);
|
|
108
109
|
});
|
|
109
|
-
xhr.addEventListener('load', async (
|
|
110
|
+
xhr.addEventListener('load', async (event)=>{
|
|
110
111
|
await methods.triggerEvent({
|
|
111
112
|
name: 'onSuccess',
|
|
112
113
|
event: {
|
|
113
|
-
meta
|
|
114
|
-
event
|
|
114
|
+
meta,
|
|
115
|
+
event
|
|
115
116
|
}
|
|
116
117
|
});
|
|
117
|
-
onSuccess(
|
|
118
|
+
onSuccess(event);
|
|
118
119
|
});
|
|
119
|
-
xhr.addEventListener('loadend', async (
|
|
120
|
+
xhr.addEventListener('loadend', async (event)=>{
|
|
120
121
|
await methods.triggerEvent({
|
|
121
122
|
name: 'onDone',
|
|
122
123
|
event: {
|
|
123
|
-
meta
|
|
124
|
-
event
|
|
124
|
+
meta,
|
|
125
|
+
event
|
|
125
126
|
}
|
|
126
127
|
});
|
|
127
128
|
setLoading(false);
|
|
@@ -134,13 +135,13 @@ const getCustomRequest = ({ methods , setS3Parameters , setLoading })=>async ({
|
|
|
134
135
|
name: 'onError',
|
|
135
136
|
event: {
|
|
136
137
|
meta,
|
|
137
|
-
|
|
138
|
+
error
|
|
138
139
|
}
|
|
139
140
|
});
|
|
140
141
|
onError(error);
|
|
141
142
|
}
|
|
142
143
|
};
|
|
143
|
-
const S3UploadPhoto = ({ blockId
|
|
144
|
+
const S3UploadPhoto = ({ blockId, components: { Icon }, events, methods, properties, value })=>{
|
|
144
145
|
// Use state here because we need to set s3 bucket and key as block value
|
|
145
146
|
// The customRequest function does not have access to the updated block value,
|
|
146
147
|
// so it cannot set the value directly. customRequest sets the parameters to s3Parameters state,
|
|
@@ -179,8 +180,8 @@ const S3UploadPhoto = ({ blockId , components: { Icon } , events , methods , pr
|
|
|
179
180
|
id: blockId,
|
|
180
181
|
multiple: !properties.singleFile,
|
|
181
182
|
showUploadList: properties.showUploadList,
|
|
182
|
-
onChange: (
|
|
183
|
-
methods.setValue(makeOnChangeValue(s3Parameters,
|
|
183
|
+
onChange: (event)=>{
|
|
184
|
+
methods.setValue(makeOnChangeValue(s3Parameters, event));
|
|
184
185
|
methods.triggerEvent({
|
|
185
186
|
name: 'onChange'
|
|
186
187
|
});
|
package/dist/blocks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import AWS from 'aws-sdk';
|
|
16
16
|
import schema from './schema.js';
|
|
17
|
-
function AwsS3PresignedGetObject({ request
|
|
18
|
-
const { accessKeyId
|
|
19
|
-
const { expires
|
|
17
|
+
function AwsS3PresignedGetObject({ request, connection }) {
|
|
18
|
+
const { accessKeyId, secretAccessKey, region, bucket } = connection;
|
|
19
|
+
const { expires, key, versionId, responseContentDisposition, responseContentType } = request;
|
|
20
20
|
const params = {
|
|
21
21
|
Bucket: bucket,
|
|
22
22
|
Key: key,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import AWS from 'aws-sdk';
|
|
16
16
|
import schema from './schema.js';
|
|
17
|
-
function AwsS3PresignedPostPolicy({ request
|
|
18
|
-
const { accessKeyId
|
|
19
|
-
const { acl
|
|
17
|
+
function AwsS3PresignedPostPolicy({ request, connection }) {
|
|
18
|
+
const { accessKeyId, secretAccessKey, region, bucket } = connection;
|
|
19
|
+
const { acl, conditions, expires, key } = request;
|
|
20
20
|
const params = {
|
|
21
21
|
Bucket: bucket,
|
|
22
22
|
Fields: {
|
package/dist/connections.js
CHANGED
package/dist/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable import/namespace */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2024 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -17,8 +17,8 @@ import * as blocks from './blocks.js';
|
|
|
17
17
|
const icons = {};
|
|
18
18
|
const styles = {};
|
|
19
19
|
Object.keys(blocks).forEach((block)=>{
|
|
20
|
-
icons[block] = blocks[block].meta.icons
|
|
21
|
-
styles[block] = blocks[block].meta.styles
|
|
20
|
+
icons[block] = blocks[block].meta.icons ?? [];
|
|
21
|
+
styles[block] = blocks[block].meta.styles ?? [];
|
|
22
22
|
});
|
|
23
23
|
export default {
|
|
24
24
|
blocks: Object.keys(blocks),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/plugin-aws",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -39,38 +39,37 @@
|
|
|
39
39
|
"files": [
|
|
40
40
|
"dist/*"
|
|
41
41
|
],
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "swc src --out-dir dist --config-file ../../../../.swcrc --delete-dir-on-start --copy-files",
|
|
44
|
-
"clean": "rm -rf dist",
|
|
45
|
-
"copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\""
|
|
46
|
-
},
|
|
47
42
|
"dependencies": {
|
|
48
|
-
"@lowdefy/block-utils": "4.0.
|
|
49
|
-
"@lowdefy/blocks-antd": "4.0.
|
|
50
|
-
"@lowdefy/helpers": "4.0.
|
|
51
|
-
"antd": "4.
|
|
52
|
-
"aws-sdk": "2.
|
|
43
|
+
"@lowdefy/block-utils": "4.0.1",
|
|
44
|
+
"@lowdefy/blocks-antd": "4.0.1",
|
|
45
|
+
"@lowdefy/helpers": "4.0.1",
|
|
46
|
+
"antd": "4.24.14",
|
|
47
|
+
"aws-sdk": "2.1459.0",
|
|
53
48
|
"react": "18.2.0",
|
|
54
49
|
"react-dom": "18.2.0"
|
|
55
50
|
},
|
|
56
51
|
"devDependencies": {
|
|
57
52
|
"@emotion/jest": "11.10.5",
|
|
58
|
-
"@lowdefy/ajv": "4.0.
|
|
59
|
-
"@lowdefy/block-dev": "4.0.
|
|
60
|
-
"@lowdefy/jest-yaml-transform": "4.0.
|
|
61
|
-
"@swc/cli": "0.1.
|
|
62
|
-
"@swc/core": "1.3.
|
|
63
|
-
"@swc/jest": "0.2.
|
|
53
|
+
"@lowdefy/ajv": "4.0.1",
|
|
54
|
+
"@lowdefy/block-dev": "4.0.1",
|
|
55
|
+
"@lowdefy/jest-yaml-transform": "4.0.1",
|
|
56
|
+
"@swc/cli": "0.1.63",
|
|
57
|
+
"@swc/core": "1.3.99",
|
|
58
|
+
"@swc/jest": "0.2.29",
|
|
64
59
|
"@testing-library/dom": "8.19.1",
|
|
65
60
|
"@testing-library/react": "13.4.0",
|
|
66
61
|
"@testing-library/user-event": "14.4.3",
|
|
67
62
|
"copyfiles": "2.4.1",
|
|
68
|
-
"jest": "28.1.
|
|
69
|
-
"jest-environment-jsdom": "28.1.
|
|
63
|
+
"jest": "28.1.3",
|
|
64
|
+
"jest-environment-jsdom": "28.1.3",
|
|
70
65
|
"jest-serializer-html": "7.1.0"
|
|
71
66
|
},
|
|
72
67
|
"publishConfig": {
|
|
73
68
|
"access": "public"
|
|
74
69
|
},
|
|
75
|
-
"
|
|
76
|
-
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "swc src --out-dir dist --config-file ../../../../.swcrc --delete-dir-on-start --copy-files",
|
|
72
|
+
"clean": "rm -rf dist",
|
|
73
|
+
"copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\""
|
|
74
|
+
}
|
|
75
|
+
}
|