@budibase/server 2.0.34-alpha.1 → 2.0.34-alpha.10
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__/node-fetch.ts +12 -2
- package/builder/assets/{index.cf543543.js → index.02132811.js} +201 -201
- package/builder/index.html +1 -1
- package/coverage/clover.xml +429 -499
- package/coverage/coverage-final.json +49 -51
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +13 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +20 -20
- package/coverage/lcov-report/api/controllers/index.html +9 -24
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- 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 +4 -4
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- 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 +2 -2
- 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 +6 -6
- 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 +26 -26
- package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/automation.js.html +11 -11
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +5 -20
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +9 -9
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +9 -9
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/screen.js.html +9 -9
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +10 -10
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- 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 +25 -10
- package/coverage/lcov-report/automations/index.html +16 -16
- package/coverage/lcov-report/automations/index.js.html +4 -4
- 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 +23 -23
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +4 -16
- 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 +2 -2
- 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 +2 -2
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +52 -52
- 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 +5 -5
- package/coverage/lcov-report/middleware/builder.js.html +9 -9
- package/coverage/lcov-report/middleware/currentapp.js.html +14 -14
- 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 +5 -5
- package/coverage/lcov-report/middleware/resourceId.js.html +22 -22
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +3 -3
- 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 +20 -20
- package/coverage/lcov-report/utilities/index.js.html +2 -2
- 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 +6 -6
- 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 +46 -46
- package/coverage/lcov.info +496 -600
- package/dist/api/controllers/row/index.js +34 -80
- package/dist/api/controllers/row/internal.js +1 -1
- package/dist/api/controllers/static/index.js +1 -0
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/dist/api/controllers/webhook.js +88 -89
- package/dist/api/routes/utils/validators.js +2 -2
- package/dist/api/routes/webhook.js +39 -11
- package/dist/app.js +2 -84
- package/dist/automations/bullboard.js +7 -2
- package/dist/automations/utils.js +5 -37
- package/dist/constants/index.js +0 -3
- package/dist/package.json +6 -6
- package/dist/sdk/app/automations/index.js +29 -0
- package/dist/sdk/app/automations/webhook.js +54 -0
- package/dist/sdk/app/backups/imports.js +29 -1
- package/dist/sdk/index.js +2 -0
- package/dist/startup.js +152 -0
- package/dist/tests/utilities/TestConfiguration.js +8 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/api/controllers/row/index.ts +42 -80
- package/src/api/controllers/row/internal.js +1 -1
- package/src/api/controllers/static/index.ts +2 -0
- package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
- package/src/api/routes/utils/validators.js +2 -2
- package/src/api/routes/{webhook.js → webhook.ts} +7 -6
- package/src/app.ts +3 -108
- package/src/automations/bullboard.js +6 -1
- package/src/automations/utils.ts +12 -20
- package/src/constants/index.js +0 -4
- package/src/definitions/automations.ts +1 -6
- package/src/migrations/functions/tests/syncQuotas.spec.js +1 -3
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
- package/src/sdk/app/automations/index.ts +5 -0
- package/src/sdk/app/automations/webhook.ts +43 -0
- package/src/sdk/app/backups/imports.ts +43 -6
- package/src/sdk/index.ts +2 -0
- package/src/startup.ts +138 -0
- package/src/tests/utilities/TestConfiguration.js +7 -0
- package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
- package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
|
@@ -43,19 +43,13 @@ function patch(ctx) {
|
|
|
43
43
|
if (body && !body._id) {
|
|
44
44
|
return (0, exports.save)(ctx);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
ctx.message = `${table.name} updated successfully.`;
|
|
54
|
-
ctx.body = row;
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
ctx.throw(400, err);
|
|
58
|
-
}
|
|
46
|
+
const { row, table } = yield pro_1.quotas.addQuery(() => pickApi(tableId).patch(ctx), {
|
|
47
|
+
datasourceId: tableId,
|
|
48
|
+
});
|
|
49
|
+
ctx.status = 200;
|
|
50
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
|
|
51
|
+
ctx.message = `${table.name} updated successfully.`;
|
|
52
|
+
ctx.body = row;
|
|
59
53
|
});
|
|
60
54
|
}
|
|
61
55
|
exports.patch = patch;
|
|
@@ -67,59 +61,39 @@ const save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
67
61
|
if (body && body._id) {
|
|
68
62
|
return patch(ctx);
|
|
69
63
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
ctx.body = row;
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
ctx.throw(400, err);
|
|
81
|
-
}
|
|
64
|
+
const { row, table } = yield pro_1.quotas.addRow(() => pro_1.quotas.addQuery(() => pickApi(tableId).save(ctx), {
|
|
65
|
+
datasourceId: tableId,
|
|
66
|
+
}));
|
|
67
|
+
ctx.status = 200;
|
|
68
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
|
|
69
|
+
ctx.message = `${table.name} saved successfully`;
|
|
70
|
+
ctx.body = row;
|
|
82
71
|
});
|
|
83
72
|
exports.save = save;
|
|
84
73
|
function fetchView(ctx) {
|
|
85
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
75
|
const tableId = getTableId(ctx);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
ctx.throw(400, err);
|
|
94
|
-
}
|
|
76
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchView(ctx), {
|
|
77
|
+
datasourceId: tableId,
|
|
78
|
+
});
|
|
95
79
|
});
|
|
96
80
|
}
|
|
97
81
|
exports.fetchView = fetchView;
|
|
98
82
|
function fetch(ctx) {
|
|
99
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
84
|
const tableId = getTableId(ctx);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
ctx.throw(400, err);
|
|
108
|
-
}
|
|
85
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetch(ctx), {
|
|
86
|
+
datasourceId: tableId,
|
|
87
|
+
});
|
|
109
88
|
});
|
|
110
89
|
}
|
|
111
90
|
exports.fetch = fetch;
|
|
112
91
|
function find(ctx) {
|
|
113
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
93
|
const tableId = getTableId(ctx);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
catch (err) {
|
|
121
|
-
ctx.throw(400, err);
|
|
122
|
-
}
|
|
94
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).find(ctx), {
|
|
95
|
+
datasourceId: tableId,
|
|
96
|
+
});
|
|
123
97
|
});
|
|
124
98
|
}
|
|
125
99
|
exports.find = find;
|
|
@@ -158,53 +132,33 @@ exports.destroy = destroy;
|
|
|
158
132
|
function search(ctx) {
|
|
159
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
134
|
const tableId = getTableId(ctx);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
catch (err) {
|
|
168
|
-
ctx.throw(400, err);
|
|
169
|
-
}
|
|
135
|
+
ctx.status = 200;
|
|
136
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).search(ctx), {
|
|
137
|
+
datasourceId: tableId,
|
|
138
|
+
});
|
|
170
139
|
});
|
|
171
140
|
}
|
|
172
141
|
exports.search = search;
|
|
173
142
|
function validate(ctx) {
|
|
174
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
144
|
const tableId = getTableId(ctx);
|
|
176
|
-
|
|
177
|
-
ctx.body = yield pickApi(tableId).validate(ctx);
|
|
178
|
-
}
|
|
179
|
-
catch (err) {
|
|
180
|
-
ctx.throw(400, err);
|
|
181
|
-
}
|
|
145
|
+
ctx.body = yield pickApi(tableId).validate(ctx);
|
|
182
146
|
});
|
|
183
147
|
}
|
|
184
148
|
exports.validate = validate;
|
|
185
149
|
function fetchEnrichedRow(ctx) {
|
|
186
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
151
|
const tableId = getTableId(ctx);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
catch (err) {
|
|
194
|
-
ctx.throw(400, err);
|
|
195
|
-
}
|
|
152
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchEnrichedRow(ctx), {
|
|
153
|
+
datasourceId: tableId,
|
|
154
|
+
});
|
|
196
155
|
});
|
|
197
156
|
}
|
|
198
157
|
exports.fetchEnrichedRow = fetchEnrichedRow;
|
|
199
158
|
const exportRows = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
200
159
|
const tableId = getTableId(ctx);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
catch (err) {
|
|
207
|
-
ctx.throw(400, err);
|
|
208
|
-
}
|
|
160
|
+
ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).exportRows(ctx), {
|
|
161
|
+
datasourceId: tableId,
|
|
162
|
+
});
|
|
209
163
|
});
|
|
210
164
|
exports.exportRows = exportRows;
|
|
@@ -122,7 +122,7 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
122
122
|
table,
|
|
123
123
|
});
|
|
124
124
|
if (!validateResult.valid) {
|
|
125
|
-
throw { validation: validateResult.errors };
|
|
125
|
+
ctx.throw(400, { validation: validateResult.errors });
|
|
126
126
|
}
|
|
127
127
|
// returned row is cleaned and prepared for writing to DB
|
|
128
128
|
row = yield linkRows.updateLinks({
|
|
@@ -111,6 +111,7 @@ const serveApp = function (ctx) {
|
|
|
111
111
|
const App = require("./templates/BudibaseApp.svelte").default;
|
|
112
112
|
const plugins = (0, plugins_1.enrichPluginURLs)(appInfo.usedPlugins);
|
|
113
113
|
const { head, html, css } = App.render({
|
|
114
|
+
metaImage: "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png",
|
|
114
115
|
title: appInfo.name,
|
|
115
116
|
production: env.isProd(),
|
|
116
117
|
appId,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
export let title = ""
|
|
3
3
|
export let favicon = ""
|
|
4
|
+
export let metaImage = ""
|
|
5
|
+
export let url = ""
|
|
4
6
|
|
|
5
7
|
export let clientLibPath
|
|
6
8
|
export let usedPlugins
|
|
@@ -12,6 +14,15 @@
|
|
|
12
14
|
name="viewport"
|
|
13
15
|
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
|
14
16
|
/>
|
|
17
|
+
<!-- Opengraph Meta Tags -->
|
|
18
|
+
<meta name="twitter:card" content="summary_large_image" />
|
|
19
|
+
<meta name="twitter:site" content="@budibase" />
|
|
20
|
+
<meta name="twitter:image" content={metaImage} />
|
|
21
|
+
<meta name="twitter:title" content="{title} - built with Budibase" />
|
|
22
|
+
<meta property="og:site_name" content="Budibase" />
|
|
23
|
+
<meta property="og:title" content="{title} - built with Budibase" />
|
|
24
|
+
<meta property="og:type" content="website" />
|
|
25
|
+
<meta property="og:image" content={metaImage} />
|
|
15
26
|
|
|
16
27
|
<title>{title}</title>
|
|
17
28
|
<link rel="icon" type="image/png" href={favicon} />
|
|
@@ -8,103 +8,102 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.trigger = exports.buildSchema = exports.destroy = exports.save = exports.fetch = void 0;
|
|
16
|
+
const utils_1 = require("../../db/utils");
|
|
17
|
+
const triggers_1 = __importDefault(require("../../automations/triggers"));
|
|
18
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
19
|
+
const types_1 = require("@budibase/types");
|
|
20
|
+
const sdk_1 = __importDefault(require("../../sdk"));
|
|
12
21
|
const toJsonSchema = require("to-json-schema");
|
|
13
22
|
const validate = require("jsonschema").validate;
|
|
14
|
-
const { WebhookType } = require("../../constants");
|
|
15
|
-
const triggers = require("../../automations/triggers");
|
|
16
|
-
const { getProdAppID } = require("@budibase/backend-core/db");
|
|
17
|
-
const { getAppDB, updateAppId } = require("@budibase/backend-core/context");
|
|
18
23
|
const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema";
|
|
19
|
-
function
|
|
20
|
-
this
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
function fetch(ctx) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const db = backend_core_1.context.getAppDB();
|
|
27
|
+
const response = yield db.allDocs((0, utils_1.getWebhookParams)(null, {
|
|
28
|
+
include_docs: true,
|
|
29
|
+
}));
|
|
30
|
+
ctx.body = response.rows.map((row) => row.doc);
|
|
31
|
+
});
|
|
26
32
|
}
|
|
27
|
-
exports.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
const db = getAppDB();
|
|
37
|
-
const webhook = ctx.request.body;
|
|
38
|
-
webhook.appId = ctx.appId;
|
|
39
|
-
// check that the webhook exists
|
|
40
|
-
if (webhook._id) {
|
|
41
|
-
yield db.get(webhook._id);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
webhook._id = generateWebhookID();
|
|
45
|
-
}
|
|
46
|
-
const response = yield db.put(webhook);
|
|
47
|
-
webhook._rev = response.rev;
|
|
48
|
-
ctx.body = {
|
|
49
|
-
message: "Webhook created successfully",
|
|
50
|
-
webhook,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const db = getAppDB();
|
|
55
|
-
ctx.body = yield db.remove(ctx.params.id, ctx.params.rev);
|
|
56
|
-
});
|
|
57
|
-
exports.buildSchema = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
yield updateAppId(ctx.params.instance);
|
|
59
|
-
const db = getAppDB();
|
|
60
|
-
const webhook = yield db.get(ctx.params.id);
|
|
61
|
-
webhook.bodySchema = toJsonSchema(ctx.request.body);
|
|
62
|
-
// update the automation outputs
|
|
63
|
-
if (webhook.action.type === WebhookType.AUTOMATION) {
|
|
64
|
-
let automation = yield db.get(webhook.action.target);
|
|
65
|
-
const autoOutputs = automation.definition.trigger.schema.outputs;
|
|
66
|
-
let properties = webhook.bodySchema.properties;
|
|
67
|
-
// reset webhook outputs
|
|
68
|
-
autoOutputs.properties = {
|
|
69
|
-
body: autoOutputs.properties.body,
|
|
33
|
+
exports.fetch = fetch;
|
|
34
|
+
function save(ctx) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const webhook = yield sdk_1.default.automations.webhook.save(ctx.request.body);
|
|
37
|
+
ctx.body = {
|
|
38
|
+
message: "Webhook created successfully",
|
|
39
|
+
webhook,
|
|
70
40
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.save = save;
|
|
44
|
+
function destroy(ctx) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
ctx.body = yield sdk_1.default.automations.webhook.destroy(ctx.params.id, ctx.params.rev);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.destroy = destroy;
|
|
50
|
+
function buildSchema(ctx) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield backend_core_1.context.updateAppId(ctx.params.instance);
|
|
53
|
+
const db = backend_core_1.context.getAppDB();
|
|
54
|
+
const webhook = (yield db.get(ctx.params.id));
|
|
55
|
+
webhook.bodySchema = toJsonSchema(ctx.request.body);
|
|
56
|
+
// update the automation outputs
|
|
57
|
+
if (webhook.action.type === types_1.WebhookActionType.AUTOMATION) {
|
|
58
|
+
let automation = (yield db.get(webhook.action.target));
|
|
59
|
+
const autoOutputs = automation.definition.trigger.schema.outputs;
|
|
60
|
+
let properties = webhook.bodySchema.properties;
|
|
61
|
+
// reset webhook outputs
|
|
62
|
+
autoOutputs.properties = {
|
|
63
|
+
body: autoOutputs.properties.body,
|
|
75
64
|
};
|
|
65
|
+
for (let prop of Object.keys(properties)) {
|
|
66
|
+
autoOutputs.properties[prop] = {
|
|
67
|
+
type: properties[prop].type,
|
|
68
|
+
description: AUTOMATION_DESCRIPTION,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
yield db.put(automation);
|
|
76
72
|
}
|
|
77
|
-
yield db.put(
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
ctx.body = {
|
|
99
|
-
message: "Webhook trigger fired successfully",
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
if (err.status === 404) {
|
|
73
|
+
ctx.body = yield db.put(webhook);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.buildSchema = buildSchema;
|
|
77
|
+
function trigger(ctx) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const prodAppId = backend_core_1.db.getProdAppID(ctx.params.instance);
|
|
80
|
+
yield backend_core_1.context.updateAppId(prodAppId);
|
|
81
|
+
try {
|
|
82
|
+
const db = backend_core_1.context.getAppDB();
|
|
83
|
+
const webhook = (yield db.get(ctx.params.id));
|
|
84
|
+
// validate against the schema
|
|
85
|
+
if (webhook.bodySchema) {
|
|
86
|
+
validate(ctx.request.body, webhook.bodySchema);
|
|
87
|
+
}
|
|
88
|
+
const target = yield db.get(webhook.action.target);
|
|
89
|
+
if (webhook.action.type === types_1.WebhookActionType.AUTOMATION) {
|
|
90
|
+
// trigger with both the pure request and then expand it
|
|
91
|
+
// incase the user has produced a schema to bind to
|
|
92
|
+
yield triggers_1.default.externalTrigger(target, Object.assign(Object.assign({ body: ctx.request.body }, ctx.request.body), { appId: prodAppId }));
|
|
93
|
+
}
|
|
104
94
|
ctx.status = 200;
|
|
105
95
|
ctx.body = {
|
|
106
|
-
message: "
|
|
96
|
+
message: "Webhook trigger fired successfully",
|
|
107
97
|
};
|
|
108
98
|
}
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
catch (err) {
|
|
100
|
+
if (err.status === 404) {
|
|
101
|
+
ctx.status = 200;
|
|
102
|
+
ctx.body = {
|
|
103
|
+
message: "Application not deployed yet.",
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
exports.trigger = trigger;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { joiValidator } = require("@budibase/backend-core/auth");
|
|
3
3
|
const { DataSourceOperation } = require("../../../constants");
|
|
4
|
-
const { WebhookType } = require("../../../constants");
|
|
5
4
|
const { BUILTIN_PERMISSION_IDS, PermissionLevels, } = require("@budibase/backend-core/permissions");
|
|
5
|
+
const { WebhookActionType } = require("@budibase/types");
|
|
6
6
|
const Joi = require("joi");
|
|
7
7
|
const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("");
|
|
8
8
|
const OPTIONAL_NUMBER = Joi.number().optional().allow(null);
|
|
@@ -113,7 +113,7 @@ exports.webhookValidator = () => {
|
|
|
113
113
|
name: Joi.string().required(),
|
|
114
114
|
bodySchema: Joi.object().optional(),
|
|
115
115
|
action: Joi.object({
|
|
116
|
-
type: Joi.string().required().valid(
|
|
116
|
+
type: Joi.string().required().valid(WebhookActionType.AUTOMATION),
|
|
117
117
|
target: Joi.string().required(),
|
|
118
118
|
}).required(),
|
|
119
119
|
}).unknown(true));
|
|
@@ -1,15 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const router_1 = __importDefault(require("@koa/router"));
|
|
30
|
+
const controller = __importStar(require("../controllers/webhook"));
|
|
31
|
+
const authorized_1 = __importDefault(require("../../middleware/authorized"));
|
|
32
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
33
|
+
const validators_1 = require("./utils/validators");
|
|
34
|
+
const BUILDER = backend_core_1.permissions.BUILDER;
|
|
35
|
+
const router = new router_1.default();
|
|
8
36
|
router
|
|
9
|
-
.get("/api/webhooks",
|
|
10
|
-
.put("/api/webhooks",
|
|
11
|
-
.delete("/api/webhooks/:id/:rev",
|
|
12
|
-
.post("/api/webhooks/schema/:instance/:id",
|
|
37
|
+
.get("/api/webhooks", (0, authorized_1.default)(BUILDER), controller.fetch)
|
|
38
|
+
.put("/api/webhooks", (0, authorized_1.default)(BUILDER), (0, validators_1.webhookValidator)(), controller.save)
|
|
39
|
+
.delete("/api/webhooks/:id/:rev", (0, authorized_1.default)(BUILDER), controller.destroy)
|
|
40
|
+
.post("/api/webhooks/schema/:instance/:id", (0, authorized_1.default)(BUILDER), controller.buildSchema)
|
|
13
41
|
// this shouldn't have authorisation, right now its always public
|
|
14
42
|
.post("/api/webhooks/trigger/:instance/:id", controller.trigger);
|
|
15
|
-
|
|
43
|
+
exports.default = router;
|
package/dist/app.js
CHANGED
|
@@ -49,26 +49,16 @@ db_1.default.init();
|
|
|
49
49
|
const Koa = require("koa");
|
|
50
50
|
const destroyable = require("server-destroy");
|
|
51
51
|
const koaBody = require("koa-body");
|
|
52
|
-
const pino = require("koa-pino-logger");
|
|
53
52
|
const http = require("http");
|
|
54
53
|
const api = require("./api");
|
|
55
|
-
const eventEmitter = require("./events");
|
|
56
54
|
const automations = require("./automations/index");
|
|
57
55
|
const Sentry = require("@sentry/node");
|
|
58
|
-
const fileSystem = require("./utilities/fileSystem");
|
|
59
|
-
const bullboard = require("./automations/bullboard");
|
|
60
56
|
const { logAlert } = require("@budibase/backend-core/logging");
|
|
61
|
-
const { pinoSettings } = require("@budibase/backend-core");
|
|
62
57
|
const { Thread } = require("./threads");
|
|
63
|
-
const fs = require("fs");
|
|
64
58
|
const redis_1 = __importDefault(require("./utilities/redis"));
|
|
65
|
-
const migrations = __importStar(require("./migrations"));
|
|
66
59
|
const backend_core_1 = require("@budibase/backend-core");
|
|
67
|
-
const workerRequests_1 = require("./utilities/workerRequests");
|
|
68
|
-
const watch_1 = require("./watch");
|
|
69
60
|
const websocket_1 = require("./websocket");
|
|
70
|
-
const
|
|
71
|
-
const pro = __importStar(require("@budibase/pro"));
|
|
61
|
+
const startup_1 = require("./startup");
|
|
72
62
|
const app = new Koa();
|
|
73
63
|
// set up top level koa middleware
|
|
74
64
|
app.use(koaBody({
|
|
@@ -79,15 +69,6 @@ app.use(koaBody({
|
|
|
79
69
|
enableTypes: ["json", "form", "text"],
|
|
80
70
|
parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
|
|
81
71
|
}));
|
|
82
|
-
app.use(pino(pinoSettings()));
|
|
83
|
-
if (!env.isTest()) {
|
|
84
|
-
const plugin = bullboard.init();
|
|
85
|
-
app.use(plugin);
|
|
86
|
-
}
|
|
87
|
-
app.context.eventEmitter = eventEmitter;
|
|
88
|
-
app.context.auth = {};
|
|
89
|
-
// api routes
|
|
90
|
-
app.use(api.router.routes());
|
|
91
72
|
if (env.isProd()) {
|
|
92
73
|
env._set("NODE_ENV", "production");
|
|
93
74
|
Sentry.init();
|
|
@@ -120,71 +101,8 @@ server.on("close", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
120
101
|
process.exit(errCode);
|
|
121
102
|
}
|
|
122
103
|
}));
|
|
123
|
-
const initPro = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
yield pro.init({
|
|
125
|
-
backups: {
|
|
126
|
-
processing: {
|
|
127
|
-
exportAppFn: sdk_1.default.backups.exportApp,
|
|
128
|
-
importAppFn: sdk_1.default.backups.importApp,
|
|
129
|
-
statsFn: sdk_1.default.backups.calculateBackupStats,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
104
|
module.exports = server.listen(env.PORT || 0, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
-
|
|
136
|
-
console.log(`Budibase running on ${JSON.stringify(server.address())}`);
|
|
137
|
-
env._set("PORT", server.address().port);
|
|
138
|
-
eventEmitter.emitPort(env.PORT);
|
|
139
|
-
fileSystem.init();
|
|
140
|
-
yield redis_1.default.init();
|
|
141
|
-
// run migrations on startup if not done via http
|
|
142
|
-
// not recommended in a clustered environment
|
|
143
|
-
if (!env.HTTP_MIGRATIONS && !env.isTest()) {
|
|
144
|
-
try {
|
|
145
|
-
yield migrations.migrate();
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
logAlert("Error performing migrations. Exiting.", e);
|
|
149
|
-
shutdown();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// check and create admin user if required
|
|
153
|
-
if (env.SELF_HOSTED &&
|
|
154
|
-
!env.MULTI_TENANCY &&
|
|
155
|
-
env.BB_ADMIN_USER_EMAIL &&
|
|
156
|
-
env.BB_ADMIN_USER_PASSWORD) {
|
|
157
|
-
const checklist = yield (0, workerRequests_1.getChecklist)();
|
|
158
|
-
if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
|
|
159
|
-
try {
|
|
160
|
-
const tenantId = backend_core_1.tenancy.getTenantId();
|
|
161
|
-
const user = yield (0, workerRequests_1.createAdminUser)(env.BB_ADMIN_USER_EMAIL, env.BB_ADMIN_USER_PASSWORD, tenantId);
|
|
162
|
-
// Need to set up an API key for automated integration tests
|
|
163
|
-
if (env.isTest()) {
|
|
164
|
-
yield (0, workerRequests_1.generateApiKey)(user._id);
|
|
165
|
-
}
|
|
166
|
-
console.log("Admin account automatically created for", env.BB_ADMIN_USER_EMAIL);
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
logAlert("Error creating initial admin user. Exiting.", e);
|
|
170
|
-
shutdown();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
// monitor plugin directory if required
|
|
175
|
-
if (env.SELF_HOSTED &&
|
|
176
|
-
!env.MULTI_TENANCY &&
|
|
177
|
-
env.PLUGINS_DIR &&
|
|
178
|
-
fs.existsSync(env.PLUGINS_DIR)) {
|
|
179
|
-
(0, watch_1.watch)();
|
|
180
|
-
}
|
|
181
|
-
// check for version updates
|
|
182
|
-
yield backend_core_1.installation.checkInstallVersion();
|
|
183
|
-
// done last - these will never complete
|
|
184
|
-
let promises = [];
|
|
185
|
-
promises.push(automations.init());
|
|
186
|
-
promises.push(initPro());
|
|
187
|
-
yield Promise.all(promises);
|
|
105
|
+
yield (0, startup_1.startup)(app, server);
|
|
188
106
|
}));
|
|
189
107
|
const shutdown = () => {
|
|
190
108
|
server.close();
|
|
@@ -13,11 +13,16 @@ const { BullAdapter } = require("@bull-board/api/bullAdapter");
|
|
|
13
13
|
const { KoaAdapter } = require("@bull-board/koa");
|
|
14
14
|
const { queue } = require("@budibase/backend-core");
|
|
15
15
|
const automation = require("../threads/automation");
|
|
16
|
+
const { backups } = require("@budibase/pro");
|
|
16
17
|
let automationQueue = queue.createQueue(queue.JobQueue.AUTOMATION, automation.removeStalled);
|
|
17
18
|
const PATH_PREFIX = "/bulladmin";
|
|
18
|
-
exports.init = () => {
|
|
19
|
+
exports.init = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
20
|
// Set up queues for bull board admin
|
|
21
|
+
const backupQueue = yield backups.getBackupQueue();
|
|
20
22
|
const queues = [automationQueue];
|
|
23
|
+
if (backupQueue) {
|
|
24
|
+
queues.push(backupQueue);
|
|
25
|
+
}
|
|
21
26
|
const adapters = [];
|
|
22
27
|
const serverAdapter = new KoaAdapter();
|
|
23
28
|
for (let queue of queues) {
|
|
@@ -29,7 +34,7 @@ exports.init = () => {
|
|
|
29
34
|
});
|
|
30
35
|
serverAdapter.setBasePath(PATH_PREFIX);
|
|
31
36
|
return serverAdapter.registerPlugin();
|
|
32
|
-
};
|
|
37
|
+
});
|
|
33
38
|
exports.shutdown = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
39
|
yield queue.shutdown();
|
|
35
40
|
});
|