@budibase/server 2.0.38 → 2.0.40-alpha.0
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__/mongodb.ts +1 -1
- package/__mocks__/node-fetch.ts +12 -2
- package/builder/assets/backups-default.8c011f1b.png +0 -0
- package/builder/assets/{index.e0ddd30b.css → index.442de33f.css} +2 -2
- package/builder/assets/{index.598a950c.js → index.d7b4247d.js} +342 -334
- package/builder/index.html +2 -2
- package/coverage/clover.xml +1125 -1250
- package/coverage/coverage-final.json +73 -77
- 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 +79 -67
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +21 -21
- package/coverage/lcov-report/api/controllers/index.html +17 -47
- 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 +13 -13
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/index.html +16 -16
- package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
- 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 +3 -3
- package/coverage/lcov-report/api/controllers/view/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -8
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +30 -30
- 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 -35
- 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 +6 -6
- package/coverage/lcov-report/automations/bullboard.js.html +24 -84
- package/coverage/lcov-report/automations/index.html +21 -21
- package/coverage/lcov-report/automations/index.js.html +9 -9
- 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 +3 -3
- 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 +49 -49
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +10 -28
- 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 +19 -19
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +28 -28
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +37 -316
- 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 +3 -3
- package/coverage/lcov-report/events/utils.js.html +9 -9
- package/coverage/lcov-report/index.html +88 -88
- 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 +19 -19
- package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
- 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 +28 -28
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +15 -12
- package/coverage/lcov-report/utilities/global.js.html +31 -31
- package/coverage/lcov-report/utilities/index.html +28 -28
- package/coverage/lcov-report/utilities/index.js.html +8 -8
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
- package/coverage/lcov-report/utilities/queue/index.html +21 -21
- 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 +72 -57
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
- 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 +1691 -1899
- package/dist/api/controllers/application.js +4 -7
- package/dist/api/controllers/backup.js +19 -13
- package/dist/api/controllers/cloud.js +38 -35
- package/dist/api/controllers/deploy/index.js +11 -2
- package/dist/api/controllers/dev.js +1 -1
- package/dist/api/controllers/query/index.js +7 -2
- package/dist/api/controllers/row/index.js +40 -66
- package/dist/api/controllers/row/internal.js +1 -1
- package/dist/api/controllers/static/index.js +3 -2
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/dist/api/controllers/static/templates/preview.hbs +10 -0
- package/dist/api/controllers/table/bulkFormula.js +4 -3
- package/dist/api/controllers/table/external.js +5 -4
- package/dist/api/controllers/table/index.js +4 -4
- package/dist/api/controllers/table/internal.js +10 -3
- package/dist/api/controllers/table/utils.js +7 -49
- package/dist/api/controllers/view/index.js +2 -2
- package/dist/api/controllers/webhook.js +88 -89
- package/dist/api/routes/backup.js +34 -7
- package/dist/api/routes/index.js +9 -4
- package/dist/api/routes/utils/validators.js +2 -2
- package/dist/api/routes/webhook.js +39 -11
- package/dist/app.js +2 -68
- package/dist/automations/automationUtils.js +2 -2
- package/dist/automations/bullboard.js +12 -35
- package/dist/automations/index.js +4 -4
- package/dist/automations/steps/updateRow.js +2 -2
- package/dist/automations/triggers.js +6 -6
- package/dist/automations/utils.js +23 -49
- package/dist/constants/index.js +4 -8
- package/dist/db/utils.js +10 -75
- package/dist/index.js +1 -0
- package/dist/integrations/arangodb.js +2 -0
- package/dist/integrations/base/sqlTable.js +1 -0
- package/dist/integrations/mongodb.js +300 -11
- package/dist/integrations/rest.js +38 -5
- package/dist/migrations/functions/backfill/app/tables.js +5 -8
- package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
- package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
- package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
- package/dist/migrations/index.js +10 -38
- package/dist/package.json +14 -14
- package/dist/sdk/app/automations/index.js +29 -0
- package/dist/sdk/app/automations/webhook.js +54 -0
- package/dist/sdk/app/backups/constants.js +5 -0
- package/dist/sdk/app/backups/exports.js +172 -0
- package/dist/sdk/app/backups/imports.js +190 -0
- package/dist/sdk/app/backups/index.js +29 -0
- package/dist/sdk/app/backups/statistics.js +73 -0
- package/dist/sdk/app/tables/index.js +61 -0
- package/dist/sdk/index.js +17 -0
- package/dist/startup.js +152 -0
- package/dist/tests/utilities/TestConfiguration.js +12 -2
- package/dist/threads/automation.js +12 -17
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +1 -0
- package/dist/utilities/fileSystem/index.js +3 -95
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/rowProcessor/index.js +5 -0
- package/dist/utilities/usageQuota/rows.js +6 -4
- package/package.json +15 -15
- package/specs/openapi.json +3 -0
- package/specs/openapi.yaml +3 -0
- package/src/api/controllers/application.ts +5 -12
- package/src/api/controllers/{backup.js → backup.ts} +7 -7
- package/src/api/controllers/cloud.js +44 -40
- package/src/api/controllers/deploy/index.ts +20 -8
- package/src/api/controllers/dev.js +1 -1
- package/src/api/controllers/query/index.ts +8 -2
- package/src/api/controllers/row/index.ts +50 -65
- package/src/api/controllers/row/internal.js +1 -1
- package/src/api/controllers/static/index.ts +4 -2
- package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/src/api/controllers/static/templates/preview.hbs +10 -0
- package/src/api/controllers/table/bulkFormula.js +4 -3
- package/src/api/controllers/table/external.js +4 -4
- package/src/api/controllers/table/index.js +4 -4
- package/src/api/controllers/table/internal.ts +8 -9
- package/src/api/controllers/table/utils.ts +4 -53
- package/src/api/controllers/view/index.js +2 -2
- package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
- package/src/api/routes/backup.ts +10 -0
- package/src/api/routes/index.ts +11 -5
- package/src/api/routes/tests/backup.spec.js +1 -1
- package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
- package/src/api/routes/tests/row.spec.js +22 -27
- package/src/api/routes/utils/validators.js +2 -2
- package/src/api/routes/{webhook.js → webhook.ts} +7 -6
- package/src/app.ts +3 -91
- package/src/automations/automationUtils.js +2 -2
- package/src/automations/bullboard.js +14 -34
- package/src/automations/index.js +4 -4
- package/src/automations/steps/updateRow.js +2 -2
- package/src/automations/tests/automation.spec.js +1 -6
- package/src/automations/triggers.js +6 -6
- package/src/automations/utils.ts +30 -32
- package/src/constants/index.js +4 -10
- package/src/db/utils.js +17 -110
- package/src/definitions/automations.ts +1 -18
- package/src/definitions/datasource.ts +1 -0
- package/src/index.ts +1 -0
- package/src/integrations/arangodb.ts +2 -0
- package/src/integrations/base/sqlTable.ts +1 -0
- package/src/integrations/mongodb.ts +290 -27
- package/src/integrations/rest.ts +17 -5
- package/src/integrations/tests/mongo.spec.ts +19 -19
- package/src/integrations/tests/rest.spec.ts +38 -22
- package/src/migrations/functions/backfill/app/tables.ts +7 -13
- package/src/migrations/functions/backfill/global.ts +1 -1
- package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
- package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +6 -5
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
- package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
- package/src/migrations/index.ts +21 -45
- package/src/migrations/tests/index.spec.ts +0 -1
- package/src/sdk/app/automations/index.ts +5 -0
- package/src/sdk/app/automations/webhook.ts +43 -0
- package/src/sdk/app/backups/constants.ts +2 -0
- package/src/sdk/app/backups/exports.ts +171 -0
- package/src/sdk/app/backups/imports.ts +206 -0
- package/src/sdk/app/backups/index.ts +9 -0
- package/src/sdk/app/backups/statistics.ts +78 -0
- package/src/sdk/app/tables/index.ts +61 -0
- package/src/sdk/index.ts +15 -0
- package/src/startup.ts +138 -0
- package/src/tests/utilities/TestConfiguration.js +12 -2
- package/src/threads/automation.ts +20 -27
- package/src/utilities/csvParser.js +1 -0
- package/src/utilities/fileSystem/index.js +2 -119
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/src/utilities/rowProcessor/index.js +5 -0
- package/src/utilities/usageQuota/rows.js +7 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
- package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
- package/coverage/lcov-report/api/routes/backup.js.html +0 -115
- package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
- package/dist/automations/listeners.js +0 -102
- package/src/api/routes/backup.js +0 -10
- package/src/automations/listeners.ts +0 -78
- package/src/migrations/functions/pluginCount.ts +0 -12
|
@@ -19,6 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
}
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
22
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
26
|
exports.bulkImport = exports.destroy = exports.save = void 0;
|
|
24
27
|
const linkedRows_1 = require("../../../db/linkedRows");
|
|
@@ -32,6 +35,8 @@ const bulkFormula_1 = require("./bulkFormula");
|
|
|
32
35
|
const pro_1 = require("@budibase/pro");
|
|
33
36
|
const lodash_1 = require("lodash");
|
|
34
37
|
const fp_1 = require("lodash/fp");
|
|
38
|
+
const environment_2 = __importDefault(require("../../../environment"));
|
|
39
|
+
const sdk_1 = __importDefault(require("../../../sdk"));
|
|
35
40
|
function checkAutoColumns(table, oldTable) {
|
|
36
41
|
if (!table.schema) {
|
|
37
42
|
return table;
|
|
@@ -150,7 +155,9 @@ function destroy(ctx) {
|
|
|
150
155
|
include_docs: true,
|
|
151
156
|
}));
|
|
152
157
|
yield db.bulkDocs(rows.rows.map((row) => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
|
|
153
|
-
yield pro_1.quotas.removeRows(rows.rows.length
|
|
158
|
+
yield pro_1.quotas.removeRows(rows.rows.length, {
|
|
159
|
+
tableId: ctx.params.tableId,
|
|
160
|
+
});
|
|
154
161
|
// update linked rows
|
|
155
162
|
yield (0, linkedRows_1.updateLinks)({
|
|
156
163
|
eventType: linkedRows_1.EventType.TABLE_DELETE,
|
|
@@ -159,7 +166,7 @@ function destroy(ctx) {
|
|
|
159
166
|
// don't remove the table itself until very end
|
|
160
167
|
yield db.remove(tableToDelete);
|
|
161
168
|
// remove table search index
|
|
162
|
-
if (!(0, environment_1.isTest)()) {
|
|
169
|
+
if (!(0, environment_1.isTest)() || environment_2.default.COUCH_DB_URL) {
|
|
163
170
|
const currentIndexes = yield db.getIndexes();
|
|
164
171
|
const existingIndex = currentIndexes.indexes.find((existing) => existing.name === `search:${ctx.params.tableId}`);
|
|
165
172
|
if (existingIndex) {
|
|
@@ -178,7 +185,7 @@ function destroy(ctx) {
|
|
|
178
185
|
exports.destroy = destroy;
|
|
179
186
|
function bulkImport(ctx) {
|
|
180
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
-
const table = yield
|
|
188
|
+
const table = yield sdk_1.default.tables.getTable(ctx.params.tableId);
|
|
182
189
|
const { dataImport } = ctx.request.body;
|
|
183
190
|
yield (0, utils_2.handleDataImport)(ctx.user, table, dataImport);
|
|
184
191
|
return table;
|
|
@@ -12,15 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.TableSaveFunctions = exports.hasTypeChanged = exports.areSwitchableTypes = exports.foreignKeyStructure = exports.generateJunctionTableName = exports.generateForeignKey = exports.checkForViewUpdates = exports.
|
|
15
|
+
exports.TableSaveFunctions = exports.hasTypeChanged = exports.areSwitchableTypes = exports.foreignKeyStructure = exports.generateJunctionTableName = exports.generateForeignKey = exports.checkForViewUpdates = exports.checkStaticTables = exports.handleSearchIndexes = exports.handleDataImport = exports.makeSureTableUpToDate = exports.checkForColumnUpdates = exports.clearColumns = void 0;
|
|
16
16
|
const csvParser_1 = require("../../../utilities/csvParser");
|
|
17
17
|
const utils_1 = require("../../../db/utils");
|
|
18
18
|
const lodash_1 = require("lodash");
|
|
19
19
|
const constants_1 = require("../../../constants");
|
|
20
20
|
const rowProcessor_1 = require("../../../utilities/rowProcessor");
|
|
21
21
|
const constants_2 = require("../../../constants");
|
|
22
|
-
const utils_2 = require("
|
|
23
|
-
const utils_3 = require("../view/utils");
|
|
22
|
+
const utils_2 = require("../view/utils");
|
|
24
23
|
const viewBuilder_1 = __importDefault(require("../view/viewBuilder"));
|
|
25
24
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
26
25
|
const fp_1 = require("lodash/fp");
|
|
@@ -130,7 +129,9 @@ function handleDataImport(user, table, dataImport) {
|
|
|
130
129
|
}
|
|
131
130
|
finalData.push(row);
|
|
132
131
|
}
|
|
133
|
-
yield pro_1.quotas.addRows(finalData.length, () => db.bulkDocs(finalData)
|
|
132
|
+
yield pro_1.quotas.addRows(finalData.length, () => db.bulkDocs(finalData), {
|
|
133
|
+
tableId: table._id,
|
|
134
|
+
});
|
|
134
135
|
yield backend_core_1.events.rows.imported(table, "csv", finalData.length);
|
|
135
136
|
return table;
|
|
136
137
|
});
|
|
@@ -228,52 +229,9 @@ class TableSaveFunctions {
|
|
|
228
229
|
return this.rows;
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
|
-
function getAllInternalTables() {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
const db = getAppDB();
|
|
234
|
-
const internalTables = yield db.allDocs((0, utils_1.getTableParams)(null, {
|
|
235
|
-
include_docs: true,
|
|
236
|
-
}));
|
|
237
|
-
return internalTables.rows.map((tableDoc) => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: utils_1.BudibaseInternalDB._id })));
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
exports.getAllInternalTables = getAllInternalTables;
|
|
241
|
-
function getAllExternalTables(datasourceId) {
|
|
242
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
-
const db = getAppDB();
|
|
244
|
-
const datasource = yield db.get(datasourceId);
|
|
245
|
-
if (!datasource || !datasource.entities) {
|
|
246
|
-
throw "Datasource is not configured fully.";
|
|
247
|
-
}
|
|
248
|
-
return datasource.entities;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
exports.getAllExternalTables = getAllExternalTables;
|
|
252
|
-
function getExternalTable(datasourceId, tableName) {
|
|
253
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
const entities = yield getAllExternalTables(datasourceId);
|
|
255
|
-
return entities[tableName];
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
exports.getExternalTable = getExternalTable;
|
|
259
|
-
function getTable(tableId) {
|
|
260
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
261
|
-
const db = getAppDB();
|
|
262
|
-
if ((0, utils_2.isExternalTable)(tableId)) {
|
|
263
|
-
let { datasourceId, tableName } = (0, utils_2.breakExternalTableId)(tableId);
|
|
264
|
-
const datasource = yield db.get(datasourceId);
|
|
265
|
-
const table = yield getExternalTable(datasourceId, tableName);
|
|
266
|
-
return Object.assign(Object.assign({}, table), { sql: (0, utils_2.isSQL)(datasource) });
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
return db.get(tableId);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
exports.getTable = getTable;
|
|
274
232
|
function checkForViewUpdates(table, rename, deletedColumns) {
|
|
275
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
-
const views = yield (0,
|
|
234
|
+
const views = yield (0, utils_2.getViews)();
|
|
277
235
|
const tableViews = views.filter(view => view.meta.tableId === table._id);
|
|
278
236
|
// Check each table view to see if impacted by this table action
|
|
279
237
|
for (let view of tableViews) {
|
|
@@ -329,7 +287,7 @@ function checkForViewUpdates(table, rename, deletedColumns) {
|
|
|
329
287
|
// Update view if required
|
|
330
288
|
if (needsUpdated) {
|
|
331
289
|
const newViewTemplate = (0, viewBuilder_1.default)(view.meta);
|
|
332
|
-
yield (0,
|
|
290
|
+
yield (0, utils_2.saveView)(null, view.name, newViewTemplate);
|
|
333
291
|
if (!newViewTemplate.meta.schema) {
|
|
334
292
|
newViewTemplate.meta.schema = table.schema;
|
|
335
293
|
}
|
|
@@ -24,12 +24,12 @@ const { apiFileReturn } = require("../../../utilities/fileSystem");
|
|
|
24
24
|
const exporters = require("./exporters");
|
|
25
25
|
const { saveView, getView, getViews, deleteView } = require("./utils");
|
|
26
26
|
const { fetchView } = require("../row");
|
|
27
|
-
const { getTable } = require("../table/utils");
|
|
28
27
|
const { FieldTypes } = require("../../../constants");
|
|
29
28
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
30
29
|
const { events } = require("@budibase/backend-core");
|
|
31
30
|
const { DocumentType } = require("../../../db/utils");
|
|
32
31
|
const { cloneDeep, isEqual } = require("lodash");
|
|
32
|
+
const sdk = require("../../../sdk");
|
|
33
33
|
exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
ctx.body = yield getViews();
|
|
35
35
|
});
|
|
@@ -137,7 +137,7 @@ exports.exportView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
137
137
|
let rows = ctx.body;
|
|
138
138
|
let schema = view && view.meta && view.meta.schema;
|
|
139
139
|
const tableId = ctx.params.tableId || view.meta.tableId;
|
|
140
|
-
const table = yield getTable(tableId);
|
|
140
|
+
const table = yield sdk.tables.getTable(tableId);
|
|
141
141
|
if (!schema) {
|
|
142
142
|
schema = table.schema;
|
|
143
143
|
}
|
|
@@ -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,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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/backup"));
|
|
31
|
+
const authorized_1 = __importDefault(require("../../middleware/authorized"));
|
|
32
|
+
const permissions_1 = require("@budibase/backend-core/permissions");
|
|
33
|
+
const router = new router_1.default();
|
|
34
|
+
router.get("/api/backups/export", (0, authorized_1.default)(permissions_1.BUILDER), controller.exportAppDump);
|
|
35
|
+
exports.default = router;
|
package/dist/api/routes/index.js
CHANGED
|
@@ -31,11 +31,16 @@ const dev_1 = __importDefault(require("./dev"));
|
|
|
31
31
|
const cloud_1 = __importDefault(require("./cloud"));
|
|
32
32
|
const migrations_1 = __importDefault(require("./migrations"));
|
|
33
33
|
const plugin_1 = __importDefault(require("./plugin"));
|
|
34
|
+
const pro_1 = require("@budibase/pro");
|
|
34
35
|
var static_1 = require("./static");
|
|
35
36
|
Object.defineProperty(exports, "staticRoutes", { enumerable: true, get: function () { return __importDefault(static_1).default; } });
|
|
36
37
|
var public_1 = require("./public");
|
|
37
38
|
Object.defineProperty(exports, "publicRoutes", { enumerable: true, get: function () { return __importDefault(public_1).default; } });
|
|
39
|
+
const appBackupRoutes = pro_1.api.appBackups;
|
|
40
|
+
const scheduleRoutes = pro_1.api.schedules;
|
|
38
41
|
exports.mainRoutes = [
|
|
42
|
+
appBackupRoutes,
|
|
43
|
+
backup_1.default,
|
|
39
44
|
auth_1.default,
|
|
40
45
|
deploy_1.default,
|
|
41
46
|
layout_1.default,
|
|
@@ -55,14 +60,14 @@ exports.mainRoutes = [
|
|
|
55
60
|
permission_1.default,
|
|
56
61
|
datasource_1.default,
|
|
57
62
|
query_1.default,
|
|
58
|
-
backup_1.default,
|
|
59
63
|
metadata_1.default,
|
|
60
64
|
dev_1.default,
|
|
61
65
|
cloud_1.default,
|
|
62
|
-
// these need to be handled last as they still use /api/:tableId
|
|
63
|
-
// this could be breaking as koa may recognise other routes as this
|
|
64
|
-
table_1.default,
|
|
65
66
|
row_1.default,
|
|
66
67
|
migrations_1.default,
|
|
67
68
|
plugin_1.default,
|
|
69
|
+
scheduleRoutes,
|
|
70
|
+
// these need to be handled last as they still use /api/:tableId
|
|
71
|
+
// this could be breaking as koa may recognise other routes as this
|
|
72
|
+
table_1.default,
|
|
68
73
|
];
|
|
@@ -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,24 +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");
|
|
61
|
+
const startup_1 = require("./startup");
|
|
70
62
|
const app = new Koa();
|
|
71
63
|
// set up top level koa middleware
|
|
72
64
|
app.use(koaBody({
|
|
@@ -77,15 +69,6 @@ app.use(koaBody({
|
|
|
77
69
|
enableTypes: ["json", "form", "text"],
|
|
78
70
|
parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
|
|
79
71
|
}));
|
|
80
|
-
app.use(pino(pinoSettings()));
|
|
81
|
-
if (!env.isTest()) {
|
|
82
|
-
const plugin = bullboard.init();
|
|
83
|
-
app.use(plugin);
|
|
84
|
-
}
|
|
85
|
-
app.context.eventEmitter = eventEmitter;
|
|
86
|
-
app.context.auth = {};
|
|
87
|
-
// api routes
|
|
88
|
-
app.use(api.router.routes());
|
|
89
72
|
if (env.isProd()) {
|
|
90
73
|
env._set("NODE_ENV", "production");
|
|
91
74
|
Sentry.init();
|
|
@@ -119,56 +102,7 @@ server.on("close", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
119
102
|
}
|
|
120
103
|
}));
|
|
121
104
|
module.exports = server.listen(env.PORT || 0, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
-
|
|
123
|
-
console.log(`Budibase running on ${JSON.stringify(server.address())}`);
|
|
124
|
-
env._set("PORT", server.address().port);
|
|
125
|
-
eventEmitter.emitPort(env.PORT);
|
|
126
|
-
fileSystem.init();
|
|
127
|
-
yield redis_1.default.init();
|
|
128
|
-
// run migrations on startup if not done via http
|
|
129
|
-
// not recommended in a clustered environment
|
|
130
|
-
if (!env.HTTP_MIGRATIONS && !env.isTest()) {
|
|
131
|
-
try {
|
|
132
|
-
yield migrations.migrate();
|
|
133
|
-
}
|
|
134
|
-
catch (e) {
|
|
135
|
-
logAlert("Error performing migrations. Exiting.", e);
|
|
136
|
-
shutdown();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
// check and create admin user if required
|
|
140
|
-
if (env.SELF_HOSTED &&
|
|
141
|
-
!env.MULTI_TENANCY &&
|
|
142
|
-
env.BB_ADMIN_USER_EMAIL &&
|
|
143
|
-
env.BB_ADMIN_USER_PASSWORD) {
|
|
144
|
-
const checklist = yield (0, workerRequests_1.getChecklist)();
|
|
145
|
-
if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
|
|
146
|
-
try {
|
|
147
|
-
const tenantId = backend_core_1.tenancy.getTenantId();
|
|
148
|
-
const user = yield (0, workerRequests_1.createAdminUser)(env.BB_ADMIN_USER_EMAIL, env.BB_ADMIN_USER_PASSWORD, tenantId);
|
|
149
|
-
// Need to set up an API key for automated integration tests
|
|
150
|
-
if (env.isTest()) {
|
|
151
|
-
yield (0, workerRequests_1.generateApiKey)(user._id);
|
|
152
|
-
}
|
|
153
|
-
console.log("Admin account automatically created for", env.BB_ADMIN_USER_EMAIL);
|
|
154
|
-
}
|
|
155
|
-
catch (e) {
|
|
156
|
-
logAlert("Error creating initial admin user. Exiting.", e);
|
|
157
|
-
shutdown();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// monitor plugin directory if required
|
|
162
|
-
if (env.SELF_HOSTED &&
|
|
163
|
-
!env.MULTI_TENANCY &&
|
|
164
|
-
env.PLUGINS_DIR &&
|
|
165
|
-
fs.existsSync(env.PLUGINS_DIR)) {
|
|
166
|
-
(0, watch_1.watch)();
|
|
167
|
-
}
|
|
168
|
-
// check for version updates
|
|
169
|
-
yield backend_core_1.installation.checkInstallVersion();
|
|
170
|
-
// done last - this will never complete
|
|
171
|
-
yield automations.init();
|
|
105
|
+
yield (0, startup_1.startup)(app, server);
|
|
172
106
|
}));
|
|
173
107
|
const shutdown = () => {
|
|
174
108
|
server.close();
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { getTable } = require("../api/controllers/table/utils");
|
|
12
11
|
const { decodeJSBinding, isJSBinding, encodeJSBinding, } = require("@budibase/string-templates");
|
|
12
|
+
const sdk = require("../sdk");
|
|
13
13
|
/**
|
|
14
14
|
* When values are input to the system generally they will be of type string as this is required for template strings.
|
|
15
15
|
* This can generate some odd scenarios as the Schema of the automation requires a number but the builder might supply
|
|
@@ -67,7 +67,7 @@ exports.cleanInputValues = (inputs, schema) => {
|
|
|
67
67
|
* @returns {Promise<Object>} The cleaned up rows object, will should now have all the required primitive types.
|
|
68
68
|
*/
|
|
69
69
|
exports.cleanUpRow = (tableId, row) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
let table = yield getTable(tableId);
|
|
70
|
+
let table = yield sdk.tables.getTable(tableId);
|
|
71
71
|
return exports.cleanInputValues(row, { properties: table.schema });
|
|
72
72
|
});
|
|
73
73
|
exports.getError = err => {
|