@budibase/server 2.1.13 → 2.1.14-alpha.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/__mocks__/aws-sdk.ts +14 -0
- package/builder/assets/{index.0d3147a2.js → index.2b55d764.js} +184 -184
- package/builder/index.html +1 -1
- package/coverage/clover.xml +6 -6
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +1 -1
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +15 -15
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +1 -1
- package/coverage/lcov-report/db/utils.js.html +1 -1
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +14 -14
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +1 -1
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +4 -4
- package/dist/api/controllers/row/ExternalRequest.js +6 -1
- package/dist/api/controllers/row/index.js +16 -7
- package/dist/integrations/elasticsearch.js +26 -2
- package/dist/integrations/s3.js +157 -1
- package/dist/package.json +6 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/api/controllers/row/ExternalRequest.ts +5 -3
- package/src/api/controllers/row/index.ts +17 -9
- package/src/integrations/elasticsearch.ts +32 -2
- package/src/integrations/s3.ts +179 -3
- package/src/integrations/tests/s3.spec.ts +85 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.14-alpha.1",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
"license": "GPL-3.0",
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
80
|
-
"@budibase/backend-core": "
|
|
81
|
-
"@budibase/client": "
|
|
82
|
-
"@budibase/pro": "2.1.
|
|
83
|
-
"@budibase/string-templates": "
|
|
84
|
-
"@budibase/types": "
|
|
80
|
+
"@budibase/backend-core": "2.1.14-alpha.1",
|
|
81
|
+
"@budibase/client": "2.1.14-alpha.1",
|
|
82
|
+
"@budibase/pro": "2.1.14-alpha.0",
|
|
83
|
+
"@budibase/string-templates": "2.1.14-alpha.1",
|
|
84
|
+
"@budibase/types": "2.1.14-alpha.1",
|
|
85
85
|
"@bull-board/api": "3.7.0",
|
|
86
86
|
"@bull-board/koa": "3.9.4",
|
|
87
87
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -199,5 +199,5 @@
|
|
|
199
199
|
"optionalDependencies": {
|
|
200
200
|
"oracledb": "5.3.0"
|
|
201
201
|
},
|
|
202
|
-
"gitHead": "
|
|
202
|
+
"gitHead": "320eb3b8c5e1386dd0ce39332b777445eb3e8692"
|
|
203
203
|
}
|
|
@@ -282,9 +282,11 @@ module External {
|
|
|
282
282
|
const linkTablePrimary = linkTable.primary[0]
|
|
283
283
|
// one to many
|
|
284
284
|
if (isOneSide(field)) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
let id = row[key][0]
|
|
286
|
+
if (typeof row[key] === "string") {
|
|
287
|
+
id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1]
|
|
288
|
+
}
|
|
289
|
+
newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(id)[0]
|
|
288
290
|
}
|
|
289
291
|
// many to many
|
|
290
292
|
else if (field.through) {
|
|
@@ -30,16 +30,24 @@ export async function patch(ctx: any): Promise<any> {
|
|
|
30
30
|
if (body && !body._id) {
|
|
31
31
|
return save(ctx)
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
try {
|
|
34
|
+
const { row, table } = await quotas.addQuery(
|
|
35
|
+
() => pickApi(tableId).patch(ctx),
|
|
36
|
+
{
|
|
37
|
+
datasourceId: tableId,
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
if (!row) {
|
|
41
|
+
ctx.throw(404, "Row not found")
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
ctx.status = 200
|
|
44
|
+
ctx.eventEmitter &&
|
|
45
|
+
ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
|
|
46
|
+
ctx.message = `${table.name} updated successfully.`
|
|
47
|
+
ctx.body = row
|
|
48
|
+
} catch (err) {
|
|
49
|
+
ctx.throw(400, err)
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
export const save = async (ctx: any) => {
|
|
@@ -5,10 +5,13 @@ import {
|
|
|
5
5
|
IntegrationBase,
|
|
6
6
|
} from "@budibase/types"
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import { Client, ClientOptions } from "@elastic/elasticsearch"
|
|
9
9
|
|
|
10
10
|
interface ElasticsearchConfig {
|
|
11
11
|
url: string
|
|
12
|
+
ssl?: boolean
|
|
13
|
+
ca?: string
|
|
14
|
+
rejectUnauthorized?: boolean
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
const SCHEMA: Integration = {
|
|
@@ -23,6 +26,21 @@ const SCHEMA: Integration = {
|
|
|
23
26
|
required: true,
|
|
24
27
|
default: "http://localhost:9200",
|
|
25
28
|
},
|
|
29
|
+
ssl: {
|
|
30
|
+
type: DatasourceFieldType.BOOLEAN,
|
|
31
|
+
default: false,
|
|
32
|
+
required: false,
|
|
33
|
+
},
|
|
34
|
+
rejectUnauthorized: {
|
|
35
|
+
type: DatasourceFieldType.BOOLEAN,
|
|
36
|
+
default: true,
|
|
37
|
+
required: false,
|
|
38
|
+
},
|
|
39
|
+
ca: {
|
|
40
|
+
type: DatasourceFieldType.LONGFORM,
|
|
41
|
+
default: false,
|
|
42
|
+
required: false,
|
|
43
|
+
},
|
|
26
44
|
},
|
|
27
45
|
query: {
|
|
28
46
|
create: {
|
|
@@ -81,7 +99,19 @@ class ElasticSearchIntegration implements IntegrationBase {
|
|
|
81
99
|
|
|
82
100
|
constructor(config: ElasticsearchConfig) {
|
|
83
101
|
this.config = config
|
|
84
|
-
|
|
102
|
+
|
|
103
|
+
const clientConfig: ClientOptions = {
|
|
104
|
+
node: this.config.url,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (this.config.ssl) {
|
|
108
|
+
clientConfig.ssl = {
|
|
109
|
+
rejectUnauthorized: this.config.rejectUnauthorized,
|
|
110
|
+
ca: this.config.ca || undefined,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.client = new Client(clientConfig)
|
|
85
115
|
}
|
|
86
116
|
|
|
87
117
|
async create(query: { index: string; json: object }) {
|
package/src/integrations/s3.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Integration,
|
|
3
|
+
QueryType,
|
|
4
|
+
IntegrationBase,
|
|
5
|
+
DatasourceFieldType,
|
|
6
|
+
} from "@budibase/types"
|
|
7
|
+
|
|
2
8
|
const AWS = require("aws-sdk")
|
|
9
|
+
const csv = require("csvtojson")
|
|
3
10
|
|
|
4
11
|
interface S3Config {
|
|
5
12
|
region: string
|
|
@@ -40,16 +47,106 @@ const SCHEMA: Integration = {
|
|
|
40
47
|
},
|
|
41
48
|
},
|
|
42
49
|
query: {
|
|
50
|
+
create: {
|
|
51
|
+
type: QueryType.FIELDS,
|
|
52
|
+
fields: {
|
|
53
|
+
bucket: {
|
|
54
|
+
display: "New Bucket",
|
|
55
|
+
type: DatasourceFieldType.STRING,
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
location: {
|
|
59
|
+
required: true,
|
|
60
|
+
default: "us-east-1",
|
|
61
|
+
type: DatasourceFieldType.STRING,
|
|
62
|
+
},
|
|
63
|
+
grantFullControl: {
|
|
64
|
+
display: "Grant full control",
|
|
65
|
+
type: DatasourceFieldType.STRING,
|
|
66
|
+
},
|
|
67
|
+
grantRead: {
|
|
68
|
+
display: "Grant read",
|
|
69
|
+
type: DatasourceFieldType.STRING,
|
|
70
|
+
},
|
|
71
|
+
grantReadAcp: {
|
|
72
|
+
display: "Grant read ACP",
|
|
73
|
+
type: DatasourceFieldType.STRING,
|
|
74
|
+
},
|
|
75
|
+
grantWrite: {
|
|
76
|
+
display: "Grant write",
|
|
77
|
+
type: DatasourceFieldType.STRING,
|
|
78
|
+
},
|
|
79
|
+
grantWriteAcp: {
|
|
80
|
+
display: "Grant write ACP",
|
|
81
|
+
type: DatasourceFieldType.STRING,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
43
85
|
read: {
|
|
44
86
|
type: QueryType.FIELDS,
|
|
45
87
|
fields: {
|
|
46
88
|
bucket: {
|
|
47
|
-
type:
|
|
89
|
+
type: DatasourceFieldType.STRING,
|
|
90
|
+
required: true,
|
|
91
|
+
},
|
|
92
|
+
delimiter: {
|
|
93
|
+
type: DatasourceFieldType.STRING,
|
|
94
|
+
},
|
|
95
|
+
marker: {
|
|
96
|
+
type: DatasourceFieldType.STRING,
|
|
97
|
+
},
|
|
98
|
+
maxKeys: {
|
|
99
|
+
type: DatasourceFieldType.NUMBER,
|
|
100
|
+
display: "Max Keys",
|
|
101
|
+
},
|
|
102
|
+
prefix: {
|
|
103
|
+
type: DatasourceFieldType.STRING,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
readCsv: {
|
|
108
|
+
displayName: "Read CSV",
|
|
109
|
+
type: QueryType.FIELDS,
|
|
110
|
+
fields: {
|
|
111
|
+
bucket: {
|
|
112
|
+
type: DatasourceFieldType.STRING,
|
|
113
|
+
required: true,
|
|
114
|
+
},
|
|
115
|
+
key: {
|
|
116
|
+
type: DatasourceFieldType.STRING,
|
|
117
|
+
required: true,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
delete: {
|
|
122
|
+
type: QueryType.FIELDS,
|
|
123
|
+
fields: {
|
|
124
|
+
bucket: {
|
|
125
|
+
type: DatasourceFieldType.STRING,
|
|
126
|
+
required: true,
|
|
127
|
+
},
|
|
128
|
+
delete: {
|
|
129
|
+
type: DatasourceFieldType.JSON,
|
|
48
130
|
required: true,
|
|
49
131
|
},
|
|
50
132
|
},
|
|
51
133
|
},
|
|
52
134
|
},
|
|
135
|
+
extra: {
|
|
136
|
+
acl: {
|
|
137
|
+
required: false,
|
|
138
|
+
displayName: "ACL",
|
|
139
|
+
type: DatasourceFieldType.LIST,
|
|
140
|
+
data: {
|
|
141
|
+
create: [
|
|
142
|
+
"private",
|
|
143
|
+
"public-read",
|
|
144
|
+
"public-read-write",
|
|
145
|
+
"authenticated-read",
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
53
150
|
}
|
|
54
151
|
|
|
55
152
|
class S3Integration implements IntegrationBase {
|
|
@@ -67,14 +164,93 @@ class S3Integration implements IntegrationBase {
|
|
|
67
164
|
this.client = new AWS.S3(this.config)
|
|
68
165
|
}
|
|
69
166
|
|
|
70
|
-
async
|
|
167
|
+
async create(query: {
|
|
168
|
+
bucket: string
|
|
169
|
+
location: string
|
|
170
|
+
grantFullControl: string
|
|
171
|
+
grantRead: string
|
|
172
|
+
grantReadAcp: string
|
|
173
|
+
grantWrite: string
|
|
174
|
+
grantWriteAcp: string
|
|
175
|
+
extra: {
|
|
176
|
+
acl: string
|
|
177
|
+
}
|
|
178
|
+
}) {
|
|
179
|
+
let params: any = {
|
|
180
|
+
Bucket: query.bucket,
|
|
181
|
+
ACL: query.extra?.acl,
|
|
182
|
+
GrantFullControl: query.grantFullControl,
|
|
183
|
+
GrantRead: query.grantRead,
|
|
184
|
+
GrantReadACP: query.grantReadAcp,
|
|
185
|
+
GrantWrite: query.grantWrite,
|
|
186
|
+
GrantWriteACP: query.grantWriteAcp,
|
|
187
|
+
}
|
|
188
|
+
if (query.location) {
|
|
189
|
+
params["CreateBucketConfiguration"] = {
|
|
190
|
+
LocationConstraint: query.location,
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return await this.client.createBucket(params).promise()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async read(query: {
|
|
197
|
+
bucket: string
|
|
198
|
+
delimiter: string
|
|
199
|
+
expectedBucketOwner: string
|
|
200
|
+
marker: string
|
|
201
|
+
maxKeys: number
|
|
202
|
+
prefix: string
|
|
203
|
+
}) {
|
|
71
204
|
const response = await this.client
|
|
72
205
|
.listObjects({
|
|
73
206
|
Bucket: query.bucket,
|
|
207
|
+
Delimiter: query.delimiter,
|
|
208
|
+
Marker: query.marker,
|
|
209
|
+
MaxKeys: query.maxKeys,
|
|
210
|
+
Prefix: query.prefix,
|
|
74
211
|
})
|
|
75
212
|
.promise()
|
|
76
213
|
return response.Contents
|
|
77
214
|
}
|
|
215
|
+
|
|
216
|
+
async readCsv(query: { bucket: string; key: string }) {
|
|
217
|
+
const stream = this.client
|
|
218
|
+
.getObject({
|
|
219
|
+
Bucket: query.bucket,
|
|
220
|
+
Key: query.key,
|
|
221
|
+
})
|
|
222
|
+
.createReadStream()
|
|
223
|
+
|
|
224
|
+
let csvError = false
|
|
225
|
+
return new Promise((resolve, reject) => {
|
|
226
|
+
stream.on("error", (err: Error) => {
|
|
227
|
+
reject(err)
|
|
228
|
+
})
|
|
229
|
+
const response = csv()
|
|
230
|
+
.fromStream(stream)
|
|
231
|
+
.on("error", () => {
|
|
232
|
+
csvError = true
|
|
233
|
+
})
|
|
234
|
+
stream.on("finish", () => {
|
|
235
|
+
resolve(response)
|
|
236
|
+
})
|
|
237
|
+
}).catch(err => {
|
|
238
|
+
if (csvError) {
|
|
239
|
+
throw new Error("Could not read CSV")
|
|
240
|
+
} else {
|
|
241
|
+
throw err
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async delete(query: { bucket: string; delete: string }) {
|
|
247
|
+
return await this.client
|
|
248
|
+
.deleteObjects({
|
|
249
|
+
Bucket: query.bucket,
|
|
250
|
+
Delete: JSON.parse(query.delete),
|
|
251
|
+
})
|
|
252
|
+
.promise()
|
|
253
|
+
}
|
|
78
254
|
}
|
|
79
255
|
|
|
80
256
|
export default {
|
|
@@ -18,11 +18,95 @@ describe("S3 Integration", () => {
|
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
it("calls the read method with the correct params", async () => {
|
|
21
|
-
|
|
21
|
+
await config.integration.read({
|
|
22
22
|
bucket: "test",
|
|
23
|
+
delimiter: "/",
|
|
24
|
+
marker: "file.txt",
|
|
25
|
+
maxKeys: 999,
|
|
26
|
+
prefix: "directory/",
|
|
23
27
|
})
|
|
24
28
|
expect(config.integration.client.listObjects).toHaveBeenCalledWith({
|
|
25
29
|
Bucket: "test",
|
|
30
|
+
Delimiter: "/",
|
|
31
|
+
Marker: "file.txt",
|
|
32
|
+
MaxKeys: 999,
|
|
33
|
+
Prefix: "directory/",
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it("calls the create method with the correct params", async () => {
|
|
38
|
+
await config.integration.create({
|
|
39
|
+
bucket: "test",
|
|
40
|
+
location: "af-south-1",
|
|
41
|
+
grantFullControl: "me",
|
|
42
|
+
grantRead: "him",
|
|
43
|
+
grantReadAcp: "her",
|
|
44
|
+
grantWrite: "she",
|
|
45
|
+
grantWriteAcp: "he",
|
|
46
|
+
objectLockEnabledForBucket: true,
|
|
47
|
+
extra: {
|
|
48
|
+
acl: "private",
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
expect(config.integration.client.createBucket).toHaveBeenCalledWith({
|
|
52
|
+
Bucket: "test",
|
|
53
|
+
CreateBucketConfiguration: {
|
|
54
|
+
LocationConstraint: "af-south-1",
|
|
55
|
+
},
|
|
56
|
+
GrantFullControl: "me",
|
|
57
|
+
GrantRead: "him",
|
|
58
|
+
GrantReadACP: "her",
|
|
59
|
+
GrantWrite: "she",
|
|
60
|
+
GrantWriteACP: "he",
|
|
61
|
+
ACL: "private",
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it("does not add undefined location constraint when calling the create method", async () => {
|
|
66
|
+
await config.integration.create({
|
|
67
|
+
bucket: "test",
|
|
68
|
+
})
|
|
69
|
+
expect(config.integration.client.createBucket).toHaveBeenCalledWith({
|
|
70
|
+
Bucket: "test",
|
|
71
|
+
GrantFullControl: undefined,
|
|
72
|
+
GrantRead: undefined,
|
|
73
|
+
GrantReadACP: undefined,
|
|
74
|
+
GrantWrite: undefined,
|
|
75
|
+
GrantWriteACP: undefined,
|
|
76
|
+
ACL: undefined,
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it("calls the delete method with the correct params ", async () => {
|
|
81
|
+
await config.integration.delete({
|
|
82
|
+
bucket: "test",
|
|
83
|
+
delete: `{
|
|
84
|
+
"Objects": [
|
|
85
|
+
{
|
|
86
|
+
"Key": "HappyFace.jpg",
|
|
87
|
+
"VersionId": "2LWg7lQLnY41.maGB5Z6SWW.dcq0vx7b"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"Key": "HappyFace.jpg",
|
|
91
|
+
"VersionId": "yoz3HB.ZhCS_tKVEmIOr7qYyyAaZSKVd"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}`,
|
|
95
|
+
})
|
|
96
|
+
expect(config.integration.client.deleteObjects).toHaveBeenCalledWith({
|
|
97
|
+
Bucket: "test",
|
|
98
|
+
Delete: {
|
|
99
|
+
Objects: [
|
|
100
|
+
{
|
|
101
|
+
Key: "HappyFace.jpg",
|
|
102
|
+
VersionId: "2LWg7lQLnY41.maGB5Z6SWW.dcq0vx7b",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
Key: "HappyFace.jpg",
|
|
106
|
+
VersionId: "yoz3HB.ZhCS_tKVEmIOr7qYyyAaZSKVd",
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
26
110
|
})
|
|
27
111
|
})
|
|
28
112
|
})
|