@budibase/server 2.0.39 → 2.0.40
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.b20dee52.js → index.72aa3989.js} +340 -332
- 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
|
@@ -30,18 +30,16 @@ 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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ctx.throw(400, err)
|
|
44
|
-
}
|
|
33
|
+
const { row, table } = await quotas.addQuery(
|
|
34
|
+
() => pickApi(tableId).patch(ctx),
|
|
35
|
+
{
|
|
36
|
+
datasourceId: tableId,
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
ctx.status = 200
|
|
40
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
|
|
41
|
+
ctx.message = `${table.name} updated successfully.`
|
|
42
|
+
ctx.body = row
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
export const save = async (ctx: any) => {
|
|
@@ -52,44 +50,35 @@ export const save = async (ctx: any) => {
|
|
|
52
50
|
if (body && body._id) {
|
|
53
51
|
return patch(ctx)
|
|
54
52
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ctx.throw(400, err)
|
|
65
|
-
}
|
|
53
|
+
const { row, table } = await quotas.addRow(() =>
|
|
54
|
+
quotas.addQuery(() => pickApi(tableId).save(ctx), {
|
|
55
|
+
datasourceId: tableId,
|
|
56
|
+
})
|
|
57
|
+
)
|
|
58
|
+
ctx.status = 200
|
|
59
|
+
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
|
|
60
|
+
ctx.message = `${table.name} saved successfully`
|
|
61
|
+
ctx.body = row
|
|
66
62
|
}
|
|
67
|
-
|
|
68
63
|
export async function fetchView(ctx: any) {
|
|
69
64
|
const tableId = getTableId(ctx)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
ctx.throw(400, err)
|
|
74
|
-
}
|
|
65
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx), {
|
|
66
|
+
datasourceId: tableId,
|
|
67
|
+
})
|
|
75
68
|
}
|
|
76
69
|
|
|
77
70
|
export async function fetch(ctx: any) {
|
|
78
71
|
const tableId = getTableId(ctx)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
ctx.throw(400, err)
|
|
83
|
-
}
|
|
72
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx), {
|
|
73
|
+
datasourceId: tableId,
|
|
74
|
+
})
|
|
84
75
|
}
|
|
85
76
|
|
|
86
77
|
export async function find(ctx: any) {
|
|
87
78
|
const tableId = getTableId(ctx)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
ctx.throw(400, err)
|
|
92
|
-
}
|
|
79
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx), {
|
|
80
|
+
datasourceId: tableId,
|
|
81
|
+
})
|
|
93
82
|
}
|
|
94
83
|
|
|
95
84
|
export async function destroy(ctx: any) {
|
|
@@ -98,8 +87,11 @@ export async function destroy(ctx: any) {
|
|
|
98
87
|
const tableId = getTableId(ctx)
|
|
99
88
|
let response, row
|
|
100
89
|
if (inputs.rows) {
|
|
101
|
-
let { rows } = await quotas.addQuery(
|
|
102
|
-
pickApi(tableId).bulkDestroy(ctx)
|
|
90
|
+
let { rows } = await quotas.addQuery(
|
|
91
|
+
() => pickApi(tableId).bulkDestroy(ctx),
|
|
92
|
+
{
|
|
93
|
+
datasourceId: tableId,
|
|
94
|
+
}
|
|
103
95
|
)
|
|
104
96
|
await quotas.removeRows(rows.length)
|
|
105
97
|
response = rows
|
|
@@ -107,7 +99,9 @@ export async function destroy(ctx: any) {
|
|
|
107
99
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
|
|
108
100
|
}
|
|
109
101
|
} else {
|
|
110
|
-
let resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx)
|
|
102
|
+
let resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx), {
|
|
103
|
+
datasourceId: tableId,
|
|
104
|
+
})
|
|
111
105
|
await quotas.removeRow()
|
|
112
106
|
response = resp.response
|
|
113
107
|
row = resp.row
|
|
@@ -121,39 +115,30 @@ export async function destroy(ctx: any) {
|
|
|
121
115
|
|
|
122
116
|
export async function search(ctx: any) {
|
|
123
117
|
const tableId = getTableId(ctx)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
ctx.throw(400, err)
|
|
129
|
-
}
|
|
118
|
+
ctx.status = 200
|
|
119
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx), {
|
|
120
|
+
datasourceId: tableId,
|
|
121
|
+
})
|
|
130
122
|
}
|
|
131
123
|
|
|
132
124
|
export async function validate(ctx: any) {
|
|
133
125
|
const tableId = getTableId(ctx)
|
|
134
|
-
|
|
135
|
-
ctx.body = await pickApi(tableId).validate(ctx)
|
|
136
|
-
} catch (err) {
|
|
137
|
-
ctx.throw(400, err)
|
|
138
|
-
}
|
|
126
|
+
ctx.body = await pickApi(tableId).validate(ctx)
|
|
139
127
|
}
|
|
140
128
|
|
|
141
129
|
export async function fetchEnrichedRow(ctx: any) {
|
|
142
130
|
const tableId = getTableId(ctx)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
131
|
+
ctx.body = await quotas.addQuery(
|
|
132
|
+
() => pickApi(tableId).fetchEnrichedRow(ctx),
|
|
133
|
+
{
|
|
134
|
+
datasourceId: tableId,
|
|
135
|
+
}
|
|
136
|
+
)
|
|
150
137
|
}
|
|
151
138
|
|
|
152
139
|
export const exportRows = async (ctx: any) => {
|
|
153
140
|
const tableId = getTableId(ctx)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
ctx.throw(400, err)
|
|
158
|
-
}
|
|
141
|
+
ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx), {
|
|
142
|
+
datasourceId: tableId,
|
|
143
|
+
})
|
|
159
144
|
}
|
|
@@ -118,7 +118,7 @@ exports.patch = async ctx => {
|
|
|
118
118
|
})
|
|
119
119
|
|
|
120
120
|
if (!validateResult.valid) {
|
|
121
|
-
throw { validation: validateResult.errors }
|
|
121
|
+
ctx.throw(400, { validation: validateResult.errors })
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// returned row is cleaned and prepared for writing to DB
|
|
@@ -5,7 +5,7 @@ require("svelte/register")
|
|
|
5
5
|
const send = require("koa-send")
|
|
6
6
|
const { resolve, join } = require("../../../utilities/centralPath")
|
|
7
7
|
const uuid = require("uuid")
|
|
8
|
-
const { ObjectStoreBuckets } = require("../../../constants")
|
|
8
|
+
const { ObjectStoreBuckets, ATTACHMENT_DIR } = require("../../../constants")
|
|
9
9
|
const { processString } = require("@budibase/string-templates")
|
|
10
10
|
const {
|
|
11
11
|
loadHandlebarsFile,
|
|
@@ -90,7 +90,7 @@ export const uploadFile = async function (ctx: any) {
|
|
|
90
90
|
|
|
91
91
|
return prepareUpload({
|
|
92
92
|
file,
|
|
93
|
-
s3Key: `${ctx.appId}
|
|
93
|
+
s3Key: `${ctx.appId}/${ATTACHMENT_DIR}/${processedFileName}`,
|
|
94
94
|
bucket: ObjectStoreBuckets.APPS,
|
|
95
95
|
})
|
|
96
96
|
})
|
|
@@ -111,6 +111,8 @@ export const serveApp = async function (ctx: any) {
|
|
|
111
111
|
const App = require("./templates/BudibaseApp.svelte").default
|
|
112
112
|
const plugins = enrichPluginURLs(appInfo.usedPlugins)
|
|
113
113
|
const { head, html, css } = App.render({
|
|
114
|
+
metaImage:
|
|
115
|
+
"https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png",
|
|
114
116
|
title: appInfo.name,
|
|
115
117
|
production: env.isProd(),
|
|
116
118
|
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} />
|
|
@@ -56,6 +56,16 @@
|
|
|
56
56
|
return
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// If this is a custom event, try and handle it
|
|
60
|
+
if (parsed.runtimeEvent) {
|
|
61
|
+
const { name, payload } = parsed
|
|
62
|
+
if (window.handleBuilderRuntimeEvent) {
|
|
63
|
+
window.handleBuilderRuntimeEvent(name, payload)
|
|
64
|
+
}
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Otherwise this is a full reload message
|
|
59
69
|
// Extract data from message
|
|
60
70
|
const {
|
|
61
71
|
selectedComponentId,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const { FieldTypes, FormulaTypes } = require("../../../constants")
|
|
2
|
-
const {
|
|
2
|
+
const { clearColumns } = require("./utils")
|
|
3
3
|
const { doesContainStrings } = require("@budibase/string-templates")
|
|
4
4
|
const { cloneDeep } = require("lodash/fp")
|
|
5
5
|
const { isEqual, uniq } = require("lodash")
|
|
6
6
|
const { updateAllFormulasInTable } = require("../row/staticFormula")
|
|
7
7
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
8
|
+
const sdk = require("../../../sdk")
|
|
8
9
|
|
|
9
10
|
function isStaticFormula(column) {
|
|
10
11
|
return (
|
|
@@ -39,7 +40,7 @@ function getFormulaThatUseColumn(table, columnNames) {
|
|
|
39
40
|
*/
|
|
40
41
|
async function checkIfFormulaNeedsCleared(table, { oldTable, deletion }) {
|
|
41
42
|
// start by retrieving all tables, remove the current table from the list
|
|
42
|
-
const tables = (await getAllInternalTables()).filter(
|
|
43
|
+
const tables = (await sdk.tables.getAllInternalTables()).filter(
|
|
43
44
|
tbl => tbl._id !== table._id
|
|
44
45
|
)
|
|
45
46
|
const schemaToUse = oldTable ? oldTable.schema : table.schema
|
|
@@ -99,7 +100,7 @@ async function updateRelatedFormulaLinksOnTables(
|
|
|
99
100
|
) {
|
|
100
101
|
const db = getAppDB()
|
|
101
102
|
// start by retrieving all tables, remove the current table from the list
|
|
102
|
-
const tables = (await getAllInternalTables()).filter(
|
|
103
|
+
const tables = (await sdk.tables.getAllInternalTables()).filter(
|
|
103
104
|
tbl => tbl._id !== table._id
|
|
104
105
|
)
|
|
105
106
|
// clone the tables, so we can compare at end
|
|
@@ -3,7 +3,6 @@ const {
|
|
|
3
3
|
breakExternalTableId,
|
|
4
4
|
} = require("../../../integrations/utils")
|
|
5
5
|
const {
|
|
6
|
-
getTable,
|
|
7
6
|
generateForeignKey,
|
|
8
7
|
generateJunctionTableName,
|
|
9
8
|
foreignKeyStructure,
|
|
@@ -20,6 +19,7 @@ const csvParser = require("../../../utilities/csvParser")
|
|
|
20
19
|
const { handleRequest } = require("../row/external")
|
|
21
20
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
22
21
|
const { events } = require("@budibase/backend-core")
|
|
22
|
+
const sdk = require("../../../sdk")
|
|
23
23
|
|
|
24
24
|
async function makeTableRequest(
|
|
25
25
|
datasource,
|
|
@@ -181,7 +181,7 @@ exports.save = async function (ctx) {
|
|
|
181
181
|
|
|
182
182
|
let oldTable
|
|
183
183
|
if (ctx.request.body && ctx.request.body._id) {
|
|
184
|
-
oldTable = await getTable(ctx.request.body._id)
|
|
184
|
+
oldTable = await sdk.tables.getTable(ctx.request.body._id)
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
if (hasTypeChanged(tableToSave, oldTable)) {
|
|
@@ -281,7 +281,7 @@ exports.save = async function (ctx) {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
exports.destroy = async function (ctx) {
|
|
284
|
-
const tableToDelete = await getTable(ctx.params.tableId)
|
|
284
|
+
const tableToDelete = await sdk.tables.getTable(ctx.params.tableId)
|
|
285
285
|
if (!tableToDelete || !tableToDelete.created) {
|
|
286
286
|
ctx.throw(400, "Cannot delete tables which weren't created in Budibase.")
|
|
287
287
|
}
|
|
@@ -303,7 +303,7 @@ exports.destroy = async function (ctx) {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
exports.bulkImport = async function (ctx) {
|
|
306
|
-
const table = await getTable(ctx.params.tableId)
|
|
306
|
+
const table = await sdk.tables.getTable(ctx.params.tableId)
|
|
307
307
|
const { dataImport } = ctx.request.body
|
|
308
308
|
if (!dataImport || !dataImport.schema || !dataImport.csvString) {
|
|
309
309
|
ctx.throw(400, "Provided data import information is invalid.")
|
|
@@ -4,8 +4,8 @@ const csvParser = require("../../../utilities/csvParser")
|
|
|
4
4
|
const { isExternalTable, isSQL } = require("../../../integrations/utils")
|
|
5
5
|
const { getDatasourceParams } = require("../../../db/utils")
|
|
6
6
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
7
|
-
const { getTable, getAllInternalTables } = require("./utils")
|
|
8
7
|
const { events } = require("@budibase/backend-core")
|
|
8
|
+
const sdk = require("../../../sdk")
|
|
9
9
|
|
|
10
10
|
function pickApi({ tableId, table }) {
|
|
11
11
|
if (table && !tableId) {
|
|
@@ -23,7 +23,7 @@ function pickApi({ tableId, table }) {
|
|
|
23
23
|
exports.fetch = async function (ctx) {
|
|
24
24
|
const db = getAppDB()
|
|
25
25
|
|
|
26
|
-
const internal = await getAllInternalTables()
|
|
26
|
+
const internal = await sdk.tables.getAllInternalTables()
|
|
27
27
|
|
|
28
28
|
const externalTables = await db.allDocs(
|
|
29
29
|
getDatasourceParams("plus", {
|
|
@@ -50,7 +50,7 @@ exports.fetch = async function (ctx) {
|
|
|
50
50
|
|
|
51
51
|
exports.find = async function (ctx) {
|
|
52
52
|
const tableId = ctx.params.tableId
|
|
53
|
-
ctx.body = await getTable(tableId)
|
|
53
|
+
ctx.body = await sdk.tables.getTable(tableId)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
exports.save = async function (ctx) {
|
|
@@ -101,7 +101,7 @@ exports.validateCSVSchema = async function (ctx) {
|
|
|
101
101
|
const { csvString, schema = {}, tableId } = ctx.request.body
|
|
102
102
|
let existingTable
|
|
103
103
|
if (tableId) {
|
|
104
|
-
existingTable = await getTable(tableId)
|
|
104
|
+
existingTable = await sdk.tables.getTable(tableId)
|
|
105
105
|
}
|
|
106
106
|
let result = await csvParser.parse(csvString, schema)
|
|
107
107
|
if (existingTable) {
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { updateLinks, EventType } from "../../../db/linkedRows"
|
|
2
2
|
import { getRowParams, generateTableID } from "../../../db/utils"
|
|
3
3
|
import { FieldTypes } from "../../../constants"
|
|
4
|
-
import {
|
|
5
|
-
TableSaveFunctions,
|
|
6
|
-
hasTypeChanged,
|
|
7
|
-
getTable,
|
|
8
|
-
handleDataImport,
|
|
9
|
-
} from "./utils"
|
|
4
|
+
import { TableSaveFunctions, hasTypeChanged, handleDataImport } from "./utils"
|
|
10
5
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
11
6
|
import { isTest } from "../../../environment"
|
|
12
7
|
import {
|
|
@@ -18,6 +13,8 @@ import { Table } from "@budibase/types"
|
|
|
18
13
|
import { quotas } from "@budibase/pro"
|
|
19
14
|
import { isEqual } from "lodash"
|
|
20
15
|
import { cloneDeep } from "lodash/fp"
|
|
16
|
+
import env from "../../../environment"
|
|
17
|
+
import sdk from "../../../sdk"
|
|
21
18
|
|
|
22
19
|
function checkAutoColumns(table: Table, oldTable: Table) {
|
|
23
20
|
if (!table.schema) {
|
|
@@ -153,7 +150,9 @@ export async function destroy(ctx: any) {
|
|
|
153
150
|
await db.bulkDocs(
|
|
154
151
|
rows.rows.map((row: any) => ({ ...row.doc, _deleted: true }))
|
|
155
152
|
)
|
|
156
|
-
await quotas.removeRows(rows.rows.length
|
|
153
|
+
await quotas.removeRows(rows.rows.length, {
|
|
154
|
+
tableId: ctx.params.tableId,
|
|
155
|
+
})
|
|
157
156
|
|
|
158
157
|
// update linked rows
|
|
159
158
|
await updateLinks({
|
|
@@ -165,7 +164,7 @@ export async function destroy(ctx: any) {
|
|
|
165
164
|
await db.remove(tableToDelete)
|
|
166
165
|
|
|
167
166
|
// remove table search index
|
|
168
|
-
if (!isTest()) {
|
|
167
|
+
if (!isTest() || env.COUCH_DB_URL) {
|
|
169
168
|
const currentIndexes = await db.getIndexes()
|
|
170
169
|
const existingIndex = currentIndexes.indexes.find(
|
|
171
170
|
(existing: any) => existing.name === `search:${ctx.params.tableId}`
|
|
@@ -185,7 +184,7 @@ export async function destroy(ctx: any) {
|
|
|
185
184
|
}
|
|
186
185
|
|
|
187
186
|
export async function bulkImport(ctx: any) {
|
|
188
|
-
const table = await getTable(ctx.params.tableId)
|
|
187
|
+
const table = await sdk.tables.getTable(ctx.params.tableId)
|
|
189
188
|
const { dataImport } = ctx.request.body
|
|
190
189
|
await handleDataImport(ctx.user, table, dataImport)
|
|
191
190
|
return table
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { transform } from "../../../utilities/csvParser"
|
|
2
|
-
import {
|
|
3
|
-
getRowParams,
|
|
4
|
-
generateRowID,
|
|
5
|
-
InternalTables,
|
|
6
|
-
getTableParams,
|
|
7
|
-
BudibaseInternalDB,
|
|
8
|
-
} from "../../../db/utils"
|
|
2
|
+
import { getRowParams, generateRowID, InternalTables } from "../../../db/utils"
|
|
9
3
|
import { isEqual } from "lodash"
|
|
10
4
|
import { AutoFieldSubTypes, FieldTypes } from "../../../constants"
|
|
11
5
|
import {
|
|
@@ -17,11 +11,6 @@ import {
|
|
|
17
11
|
SwitchableTypes,
|
|
18
12
|
CanSwitchTypes,
|
|
19
13
|
} from "../../../constants"
|
|
20
|
-
import {
|
|
21
|
-
isExternalTable,
|
|
22
|
-
breakExternalTableId,
|
|
23
|
-
isSQL,
|
|
24
|
-
} from "../../../integrations/utils"
|
|
25
14
|
import { getViews, saveView } from "../view/utils"
|
|
26
15
|
import viewTemplate from "../view/viewBuilder"
|
|
27
16
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
@@ -148,7 +137,9 @@ export async function handleDataImport(user: any, table: any, dataImport: any) {
|
|
|
148
137
|
finalData.push(row)
|
|
149
138
|
}
|
|
150
139
|
|
|
151
|
-
await quotas.addRows(finalData.length, () => db.bulkDocs(finalData)
|
|
140
|
+
await quotas.addRows(finalData.length, () => db.bulkDocs(finalData), {
|
|
141
|
+
tableId: table._id,
|
|
142
|
+
})
|
|
152
143
|
await events.rows.imported(table, "csv", finalData.length)
|
|
153
144
|
return table
|
|
154
145
|
}
|
|
@@ -254,46 +245,6 @@ class TableSaveFunctions {
|
|
|
254
245
|
}
|
|
255
246
|
}
|
|
256
247
|
|
|
257
|
-
export async function getAllInternalTables() {
|
|
258
|
-
const db = getAppDB()
|
|
259
|
-
const internalTables = await db.allDocs(
|
|
260
|
-
getTableParams(null, {
|
|
261
|
-
include_docs: true,
|
|
262
|
-
})
|
|
263
|
-
)
|
|
264
|
-
return internalTables.rows.map((tableDoc: any) => ({
|
|
265
|
-
...tableDoc.doc,
|
|
266
|
-
type: "internal",
|
|
267
|
-
sourceId: BudibaseInternalDB._id,
|
|
268
|
-
}))
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export async function getAllExternalTables(datasourceId: any) {
|
|
272
|
-
const db = getAppDB()
|
|
273
|
-
const datasource = await db.get(datasourceId)
|
|
274
|
-
if (!datasource || !datasource.entities) {
|
|
275
|
-
throw "Datasource is not configured fully."
|
|
276
|
-
}
|
|
277
|
-
return datasource.entities
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export async function getExternalTable(datasourceId: any, tableName: any) {
|
|
281
|
-
const entities = await getAllExternalTables(datasourceId)
|
|
282
|
-
return entities[tableName]
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export async function getTable(tableId: any) {
|
|
286
|
-
const db = getAppDB()
|
|
287
|
-
if (isExternalTable(tableId)) {
|
|
288
|
-
let { datasourceId, tableName } = breakExternalTableId(tableId)
|
|
289
|
-
const datasource = await db.get(datasourceId)
|
|
290
|
-
const table = await getExternalTable(datasourceId, tableName)
|
|
291
|
-
return { ...table, sql: isSQL(datasource) }
|
|
292
|
-
} else {
|
|
293
|
-
return db.get(tableId)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
248
|
export async function checkForViewUpdates(
|
|
298
249
|
table: any,
|
|
299
250
|
rename: any,
|
|
@@ -3,12 +3,12 @@ const { apiFileReturn } = require("../../../utilities/fileSystem")
|
|
|
3
3
|
const exporters = require("./exporters")
|
|
4
4
|
const { saveView, getView, getViews, deleteView } = require("./utils")
|
|
5
5
|
const { fetchView } = require("../row")
|
|
6
|
-
const { getTable } = require("../table/utils")
|
|
7
6
|
const { FieldTypes } = require("../../../constants")
|
|
8
7
|
const { getAppDB } = require("@budibase/backend-core/context")
|
|
9
8
|
const { events } = require("@budibase/backend-core")
|
|
10
9
|
const { DocumentType } = require("../../../db/utils")
|
|
11
10
|
const { cloneDeep, isEqual } = require("lodash")
|
|
11
|
+
const sdk = require("../../../sdk")
|
|
12
12
|
|
|
13
13
|
exports.fetch = async ctx => {
|
|
14
14
|
ctx.body = await getViews()
|
|
@@ -144,7 +144,7 @@ exports.exportView = async ctx => {
|
|
|
144
144
|
|
|
145
145
|
let schema = view && view.meta && view.meta.schema
|
|
146
146
|
const tableId = ctx.params.tableId || view.meta.tableId
|
|
147
|
-
const table = await getTable(tableId)
|
|
147
|
+
const table = await sdk.tables.getTable(tableId)
|
|
148
148
|
if (!schema) {
|
|
149
149
|
schema = table.schema
|
|
150
150
|
}
|
|
@@ -1,66 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
import { getWebhookParams } from "../../db/utils"
|
|
2
|
+
import triggers from "../../automations/triggers"
|
|
3
|
+
import { db as dbCore, context } from "@budibase/backend-core"
|
|
4
|
+
import {
|
|
5
|
+
Webhook,
|
|
6
|
+
WebhookActionType,
|
|
7
|
+
BBContext,
|
|
8
|
+
Automation,
|
|
9
|
+
} from "@budibase/types"
|
|
10
|
+
import sdk from "../../sdk"
|
|
2
11
|
const toJsonSchema = require("to-json-schema")
|
|
3
12
|
const validate = require("jsonschema").validate
|
|
4
|
-
const { WebhookType } = require("../../constants")
|
|
5
|
-
const triggers = require("../../automations/triggers")
|
|
6
|
-
const { getProdAppID } = require("@budibase/backend-core/db")
|
|
7
|
-
const { getAppDB, updateAppId } = require("@budibase/backend-core/context")
|
|
8
13
|
|
|
9
14
|
const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema"
|
|
10
15
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
this.name = name
|
|
14
|
-
this.action = {
|
|
15
|
-
type,
|
|
16
|
-
target,
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.Webhook = Webhook
|
|
21
|
-
|
|
22
|
-
exports.fetch = async ctx => {
|
|
23
|
-
const db = getAppDB()
|
|
16
|
+
export async function fetch(ctx: BBContext) {
|
|
17
|
+
const db = context.getAppDB()
|
|
24
18
|
const response = await db.allDocs(
|
|
25
19
|
getWebhookParams(null, {
|
|
26
20
|
include_docs: true,
|
|
27
21
|
})
|
|
28
22
|
)
|
|
29
|
-
ctx.body = response.rows.map(row => row.doc)
|
|
23
|
+
ctx.body = response.rows.map((row: any) => row.doc)
|
|
30
24
|
}
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const webhook = ctx.request.body
|
|
35
|
-
webhook.appId = ctx.appId
|
|
36
|
-
|
|
37
|
-
// check that the webhook exists
|
|
38
|
-
if (webhook._id) {
|
|
39
|
-
await db.get(webhook._id)
|
|
40
|
-
} else {
|
|
41
|
-
webhook._id = generateWebhookID()
|
|
42
|
-
}
|
|
43
|
-
const response = await db.put(webhook)
|
|
44
|
-
webhook._rev = response.rev
|
|
26
|
+
export async function save(ctx: BBContext) {
|
|
27
|
+
const webhook = await sdk.automations.webhook.save(ctx.request.body)
|
|
45
28
|
ctx.body = {
|
|
46
29
|
message: "Webhook created successfully",
|
|
47
30
|
webhook,
|
|
48
31
|
}
|
|
49
32
|
}
|
|
50
33
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
export async function destroy(ctx: BBContext) {
|
|
35
|
+
ctx.body = await sdk.automations.webhook.destroy(
|
|
36
|
+
ctx.params.id,
|
|
37
|
+
ctx.params.rev
|
|
38
|
+
)
|
|
54
39
|
}
|
|
55
40
|
|
|
56
|
-
|
|
57
|
-
await updateAppId(ctx.params.instance)
|
|
58
|
-
const db = getAppDB()
|
|
59
|
-
const webhook = await db.get(ctx.params.id)
|
|
41
|
+
export async function buildSchema(ctx: BBContext) {
|
|
42
|
+
await context.updateAppId(ctx.params.instance)
|
|
43
|
+
const db = context.getAppDB()
|
|
44
|
+
const webhook = (await db.get(ctx.params.id)) as Webhook
|
|
60
45
|
webhook.bodySchema = toJsonSchema(ctx.request.body)
|
|
61
46
|
// update the automation outputs
|
|
62
|
-
if (webhook.action.type ===
|
|
63
|
-
let automation = await db.get(webhook.action.target)
|
|
47
|
+
if (webhook.action.type === WebhookActionType.AUTOMATION) {
|
|
48
|
+
let automation = (await db.get(webhook.action.target)) as Automation
|
|
64
49
|
const autoOutputs = automation.definition.trigger.schema.outputs
|
|
65
50
|
let properties = webhook.bodySchema.properties
|
|
66
51
|
// reset webhook outputs
|
|
@@ -78,18 +63,18 @@ exports.buildSchema = async ctx => {
|
|
|
78
63
|
ctx.body = await db.put(webhook)
|
|
79
64
|
}
|
|
80
65
|
|
|
81
|
-
|
|
82
|
-
const prodAppId = getProdAppID(ctx.params.instance)
|
|
83
|
-
await updateAppId(prodAppId)
|
|
66
|
+
export async function trigger(ctx: BBContext) {
|
|
67
|
+
const prodAppId = dbCore.getProdAppID(ctx.params.instance)
|
|
68
|
+
await context.updateAppId(prodAppId)
|
|
84
69
|
try {
|
|
85
|
-
const db = getAppDB()
|
|
86
|
-
const webhook = await db.get(ctx.params.id)
|
|
70
|
+
const db = context.getAppDB()
|
|
71
|
+
const webhook = (await db.get(ctx.params.id)) as Webhook
|
|
87
72
|
// validate against the schema
|
|
88
73
|
if (webhook.bodySchema) {
|
|
89
74
|
validate(ctx.request.body, webhook.bodySchema)
|
|
90
75
|
}
|
|
91
76
|
const target = await db.get(webhook.action.target)
|
|
92
|
-
if (webhook.action.type ===
|
|
77
|
+
if (webhook.action.type === WebhookActionType.AUTOMATION) {
|
|
93
78
|
// trigger with both the pure request and then expand it
|
|
94
79
|
// incase the user has produced a schema to bind to
|
|
95
80
|
await triggers.externalTrigger(target, {
|
|
@@ -102,7 +87,7 @@ exports.trigger = async ctx => {
|
|
|
102
87
|
ctx.body = {
|
|
103
88
|
message: "Webhook trigger fired successfully",
|
|
104
89
|
}
|
|
105
|
-
} catch (err) {
|
|
90
|
+
} catch (err: any) {
|
|
106
91
|
if (err.status === 404) {
|
|
107
92
|
ctx.status = 200
|
|
108
93
|
ctx.body = {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Router from "@koa/router"
|
|
2
|
+
import * as controller from "../controllers/backup"
|
|
3
|
+
import authorized from "../../middleware/authorized"
|
|
4
|
+
import { BUILDER } from "@budibase/backend-core/permissions"
|
|
5
|
+
|
|
6
|
+
const router = new Router()
|
|
7
|
+
|
|
8
|
+
router.get("/api/backups/export", authorized(BUILDER), controller.exportAppDump)
|
|
9
|
+
|
|
10
|
+
export default router
|