@budibase/server 1.0.49-alpha.9 → 1.0.49
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__/arangojs.ts +1 -1
- package/__mocks__/aws-sdk.ts +4 -4
- package/__mocks__/mongodb.ts +5 -4
- package/__mocks__/mssql.ts +3 -3
- package/__mocks__/node-fetch.ts +1 -2
- package/__mocks__/pg.ts +5 -3
- package/builder/assets/{index.ad5370ae.js → index.2c37968e.js} +246 -249
- package/builder/assets/index.39e01193.css +1 -0
- package/builder/assets/{vendor.d526bfe8.js → vendor.f9faf6ab.js} +12 -12
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2827 -3117
- package/coverage/coverage-final.json +101 -106
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +152 -257
- package/coverage/lcov-report/api/controllers/auth.js.html +13 -22
- package/coverage/lcov-report/api/controllers/automation.js.html +69 -39
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -8
- package/coverage/lcov-report/api/controllers/component.js.html +16 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +51 -81
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- package/coverage/lcov-report/{utilities/usageQuota/usageQuoteReset.js.html → api/controllers/hosting.js.html} +48 -36
- package/coverage/lcov-report/api/controllers/index.html +76 -76
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
- package/coverage/lcov-report/api/controllers/metadata.js.html +21 -6
- package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
- package/coverage/lcov-report/api/controllers/query/index.html +10 -10
- package/coverage/lcov-report/api/controllers/query/index.js.html +35 -38
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
- package/coverage/lcov-report/api/controllers/role.js.html +16 -16
- package/coverage/lcov-report/api/controllers/routing.js.html +10 -7
- package/coverage/lcov-report/api/controllers/row/external.js.html +141 -48
- package/coverage/lcov-report/api/controllers/row/index.html +40 -55
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +226 -118
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +34 -52
- package/coverage/lcov-report/api/controllers/row/utils.js.html +62 -47
- package/coverage/lcov-report/api/controllers/screen.js.html +21 -15
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/external.js.html +34 -25
- package/coverage/lcov-report/api/controllers/table/index.html +43 -58
- package/coverage/lcov-report/api/controllers/table/index.js.html +82 -58
- package/coverage/lcov-report/api/controllers/table/internal.js.html +66 -81
- package/coverage/lcov-report/api/controllers/table/utils.js.html +110 -218
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +50 -47
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +16 -16
- package/coverage/lcov-report/api/controllers/view/index.js.html +33 -27
- package/coverage/lcov-report/api/controllers/view/utils.js.html +20 -35
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +28 -34
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +8 -8
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/{migrations.js.html → hosting.js.html} +14 -17
- package/coverage/lcov-report/api/routes/index.html +18 -18
- package/coverage/lcov-report/api/routes/index.js.html +3 -3
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +2 -17
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +10 -7
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +22 -13
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +13 -13
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +55 -61
- package/coverage/lcov-report/automations/utils.js.html +42 -54
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +26 -53
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +37 -25
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +96 -51
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +87 -87
- 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 +5 -5
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +120 -135
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +65 -173
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +83 -95
- package/coverage/lcov-report/middleware/index.html +38 -38
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +53 -281
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +24 -30
- package/coverage/lcov-report/threads/index.html +26 -26
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +24 -39
- package/coverage/lcov-report/threads/utils.js.html +14 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +49 -58
- package/coverage/lcov-report/utilities/index.html +37 -37
- package/coverage/lcov-report/utilities/index.js.html +73 -43
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
- 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 +7 -7
- package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +103 -97
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +27 -75
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +112 -43
- package/coverage/lcov.info +4431 -5013
- package/dist/api/controllers/application.js +60 -90
- package/dist/api/controllers/auth.js +5 -8
- package/dist/api/controllers/automation.js +19 -14
- package/dist/api/controllers/cloud.js +3 -2
- package/dist/api/controllers/component.js +4 -3
- package/dist/api/controllers/datasource.js +10 -20
- package/dist/api/controllers/deploy/Deployment.js +6 -3
- package/dist/api/controllers/deploy/index.js +13 -12
- package/dist/api/controllers/dev.js +5 -5
- package/dist/api/controllers/hosting.js +30 -0
- package/dist/api/controllers/layout.js +3 -3
- package/dist/api/controllers/metadata.js +4 -4
- package/dist/api/controllers/permission.js +4 -4
- package/dist/api/controllers/query/import/index.js +6 -4
- package/dist/api/controllers/query/index.js +10 -11
- package/dist/api/controllers/role.js +5 -5
- package/dist/api/controllers/routing.js +6 -5
- package/dist/api/controllers/row/ExternalRequest.js +67 -90
- package/dist/api/controllers/row/external.js +22 -14
- package/dist/api/controllers/row/internal.js +93 -55
- package/dist/api/controllers/row/internalSearch.js +17 -23
- package/dist/api/controllers/row/utils.js +14 -13
- package/dist/api/controllers/screen.js +7 -5
- package/dist/api/controllers/static/index.js +12 -61
- package/dist/api/controllers/table/external.js +10 -7
- package/dist/api/controllers/table/index.js +13 -16
- package/dist/api/controllers/table/internal.js +16 -22
- package/dist/api/controllers/table/utils.js +35 -62
- package/dist/api/controllers/user.js +20 -18
- package/dist/api/controllers/view/index.js +10 -8
- package/dist/api/controllers/view/utils.js +4 -9
- package/dist/api/controllers/webhook.js +8 -10
- package/dist/api/routes/hosting.js +11 -0
- package/dist/api/routes/index.js +2 -2
- package/dist/api/routes/static.js +1 -2
- package/dist/api/routes/tests/utilities/TestFunctions.js +17 -37
- package/dist/app.js +5 -35
- package/dist/automations/automationUtils.js +3 -2
- package/dist/automations/steps/createRow.js +5 -3
- package/dist/automations/steps/deleteRow.js +4 -1
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +25 -27
- package/dist/automations/utils.js +5 -10
- package/dist/constants/index.js +0 -7
- package/dist/db/linkedRows/LinkController.js +7 -3
- package/dist/db/linkedRows/index.js +27 -16
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +10 -9
- package/dist/definitions/datasource.js +0 -1
- package/dist/environment.js +1 -4
- package/dist/integrations/base/sql.js +14 -56
- package/dist/integrations/index.js +0 -3
- package/dist/integrations/utils.js +9 -60
- package/dist/middleware/authorized.js +30 -57
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +37 -41
- package/dist/middleware/usageQuota.js +15 -82
- package/dist/package.json +5 -8
- package/dist/tests/utilities/TestConfiguration.js +50 -80
- package/dist/threads/automation.js +11 -13
- package/dist/threads/query.js +11 -15
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +3 -4
- package/dist/utilities/global.js +12 -15
- package/dist/utilities/index.js +17 -7
- package/dist/utilities/routing/index.js +5 -5
- package/dist/utilities/rowProcessor/index.js +17 -23
- package/dist/utilities/rowProcessor/utils.js +4 -14
- package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -45
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +24 -4
- package/nodemon.json +1 -1
- package/package.json +6 -9
- package/scripts/integrations/postgres/init.sql +6 -11
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/application.js +50 -85
- package/src/api/controllers/auth.js +5 -8
- package/src/api/controllers/automation.js +23 -13
- package/src/api/controllers/cloud.js +3 -2
- package/src/api/controllers/component.js +4 -3
- package/src/api/controllers/datasource.js +11 -21
- package/src/api/controllers/deploy/Deployment.js +7 -3
- package/src/api/controllers/deploy/index.js +13 -20
- package/src/api/controllers/dev.js +5 -5
- package/src/api/controllers/hosting.js +22 -0
- package/src/api/controllers/layout.js +3 -3
- package/src/api/controllers/metadata.js +9 -4
- package/src/api/controllers/permission.js +4 -4
- package/src/api/controllers/query/import/index.ts +6 -4
- package/src/api/controllers/query/import/tests/index.spec.js +1 -2
- package/src/api/controllers/query/index.js +10 -11
- package/src/api/controllers/role.js +5 -5
- package/src/api/controllers/routing.js +6 -5
- package/src/api/controllers/row/ExternalRequest.ts +43 -67
- package/src/api/controllers/row/external.js +58 -27
- package/src/api/controllers/row/internal.js +90 -54
- package/src/api/controllers/row/internalSearch.js +17 -23
- package/src/api/controllers/row/utils.js +18 -13
- package/src/api/controllers/screen.js +7 -5
- package/src/api/controllers/static/index.js +12 -65
- package/src/api/controllers/table/external.js +10 -7
- package/src/api/controllers/table/index.js +28 -20
- package/src/api/controllers/table/internal.js +19 -24
- package/src/api/controllers/table/utils.js +42 -78
- package/src/api/controllers/user.js +20 -19
- package/src/api/controllers/view/index.js +10 -8
- package/src/api/controllers/view/utils.js +4 -9
- package/src/api/controllers/webhook.js +8 -10
- package/src/api/routes/hosting.js +13 -0
- package/src/api/routes/index.js +2 -2
- package/src/api/routes/static.js +0 -5
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +2 -1
- package/src/api/routes/tests/automation.spec.js +0 -1
- package/src/api/routes/tests/hosting.spec.js +36 -0
- package/src/api/routes/tests/misc.spec.js +1 -0
- package/src/api/routes/tests/routing.spec.js +12 -21
- package/src/api/routes/tests/row.spec.js +4 -7
- package/src/api/routes/tests/utilities/TestFunctions.js +17 -39
- package/src/app.ts +5 -18
- package/src/automations/automationUtils.js +3 -2
- package/src/automations/steps/createRow.js +5 -2
- package/src/automations/steps/deleteRow.js +4 -1
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +31 -33
- package/src/automations/utils.js +5 -9
- package/src/constants/index.js +0 -9
- package/src/db/linkedRows/LinkController.js +7 -3
- package/src/db/linkedRows/index.js +31 -16
- package/src/db/linkedRows/linkUtils.js +6 -6
- package/src/db/tests/linkController.spec.js +1 -0
- package/src/db/tests/linkTests.spec.js +6 -5
- package/src/db/views/staticViews.js +10 -8
- package/src/definitions/common.ts +0 -3
- package/src/definitions/datasource.ts +0 -3
- package/src/environment.js +1 -4
- package/src/integrations/base/sql.ts +21 -69
- package/src/integrations/index.ts +0 -3
- package/src/integrations/tests/sql.spec.js +0 -16
- package/src/integrations/utils.ts +12 -75
- package/src/middleware/authorized.js +30 -66
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +46 -50
- package/src/middleware/tests/authorized.spec.js +6 -13
- package/src/middleware/tests/currentapp.spec.js +0 -6
- package/src/middleware/tests/usageQuota.spec.js +24 -18
- package/src/middleware/usageQuota.js +17 -93
- package/src/tests/utilities/TestConfiguration.js +55 -82
- package/src/threads/automation.js +15 -17
- package/src/threads/query.js +12 -17
- package/src/utilities/fileSystem/index.js +3 -4
- package/src/utilities/global.js +12 -15
- package/src/utilities/index.js +17 -7
- package/src/utilities/routing/index.js +5 -5
- package/src/utilities/rowProcessor/index.js +27 -25
- package/src/utilities/rowProcessor/utils.js +7 -23
- package/src/utilities/usageQuota.js +73 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +27 -4
- package/tsconfig.json +1 -2
- package/builder/assets/index.83c0944f.css +0 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +0 -119
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +0 -548
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +0 -599
- package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -305
- package/dist/api/controllers/migrations.js +0 -21
- package/dist/api/controllers/row/staticFormula.js +0 -147
- package/dist/api/controllers/table/bulkFormula.js +0 -159
- package/dist/api/routes/migrations.js +0 -9
- package/dist/integrations/googlesheets.js +0 -340
- package/dist/migrations/functions/appUrls.js +0 -46
- package/dist/migrations/functions/quotas1.js +0 -50
- package/dist/migrations/functions/usageQuotas/index.js +0 -20
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -29
- package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
- package/dist/migrations/functions/userEmailViewCasing.js +0 -24
- package/dist/migrations/index.js +0 -62
- package/dist/utilities/usageQuota/rows.js +0 -78
- package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
- package/src/api/controllers/migrations.js +0 -13
- package/src/api/controllers/row/staticFormula.js +0 -156
- package/src/api/controllers/table/bulkFormula.js +0 -173
- package/src/api/routes/migrations.js +0 -14
- package/src/api/routes/tests/static.spec.js +0 -98
- package/src/integrations/googlesheets.ts +0 -353
- package/src/migrations/functions/appUrls.ts +0 -34
- package/src/migrations/functions/quotas1.ts +0 -20
- package/src/migrations/functions/tests/appUrls.spec.js +0 -29
- package/src/migrations/functions/tests/quotas1.spec.js +0 -27
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +0 -25
- package/src/migrations/functions/usageQuotas/index.ts +0 -8
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -18
- package/src/migrations/functions/usageQuotas/syncRows.ts +0 -22
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
- package/src/migrations/functions/userEmailViewCasing.ts +0 -13
- package/src/migrations/index.ts +0 -56
- package/src/module.d.ts +0 -3
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
- package/src/utilities/usageQuota/index.js +0 -93
- package/src/utilities/usageQuota/rows.js +0 -75
- package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DatasourceFieldTypes,
|
|
3
|
-
Integration,
|
|
4
|
-
QueryJson,
|
|
5
|
-
QueryTypes,
|
|
6
|
-
} from "../definitions/datasource"
|
|
7
|
-
import { OAuth2Client } from "google-auth-library"
|
|
8
|
-
import { DatasourcePlus } from "./base/datasourcePlus"
|
|
9
|
-
import { Row, Table, TableSchema } from "../definitions/common"
|
|
10
|
-
import { buildExternalTableId } from "./utils"
|
|
11
|
-
import { DataSourceOperation, FieldTypes } from "../constants"
|
|
12
|
-
import { GoogleSpreadsheet } from "google-spreadsheet"
|
|
13
|
-
import { table } from "console"
|
|
14
|
-
|
|
15
|
-
module GoogleSheetsModule {
|
|
16
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
17
|
-
const { getScopedConfig } = require("@budibase/backend-core/db")
|
|
18
|
-
const { Configs } = require("@budibase/backend-core/constants")
|
|
19
|
-
|
|
20
|
-
interface GoogleSheetsConfig {
|
|
21
|
-
spreadsheetId: string
|
|
22
|
-
auth: OAuthClientConfig
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface OAuthClientConfig {
|
|
26
|
-
appId: string
|
|
27
|
-
accessToken: string
|
|
28
|
-
refreshToken: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const SCHEMA: Integration = {
|
|
32
|
-
plus: true,
|
|
33
|
-
auth: {
|
|
34
|
-
type: "google",
|
|
35
|
-
},
|
|
36
|
-
relationships: false,
|
|
37
|
-
docs: "https://developers.google.com/sheets/api/quickstart/nodejs",
|
|
38
|
-
description:
|
|
39
|
-
"Create and collaborate on online spreadsheets in real-time and from any device. ",
|
|
40
|
-
friendlyName: "Google Sheets",
|
|
41
|
-
datasource: {
|
|
42
|
-
spreadsheetId: {
|
|
43
|
-
type: DatasourceFieldTypes.STRING,
|
|
44
|
-
required: true,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
query: {
|
|
48
|
-
create: {
|
|
49
|
-
type: QueryTypes.FIELDS,
|
|
50
|
-
fields: {
|
|
51
|
-
sheet: {
|
|
52
|
-
type: DatasourceFieldTypes.STRING,
|
|
53
|
-
required: true,
|
|
54
|
-
},
|
|
55
|
-
row: {
|
|
56
|
-
type: QueryTypes.JSON,
|
|
57
|
-
required: true,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
read: {
|
|
62
|
-
type: QueryTypes.FIELDS,
|
|
63
|
-
fields: {
|
|
64
|
-
sheet: {
|
|
65
|
-
type: DatasourceFieldTypes.STRING,
|
|
66
|
-
required: true,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
update: {
|
|
71
|
-
type: QueryTypes.FIELDS,
|
|
72
|
-
fields: {
|
|
73
|
-
sheet: {
|
|
74
|
-
type: DatasourceFieldTypes.STRING,
|
|
75
|
-
required: true,
|
|
76
|
-
},
|
|
77
|
-
rowIndex: {
|
|
78
|
-
type: DatasourceFieldTypes.STRING,
|
|
79
|
-
required: true,
|
|
80
|
-
},
|
|
81
|
-
row: {
|
|
82
|
-
type: QueryTypes.JSON,
|
|
83
|
-
required: true,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
delete: {
|
|
88
|
-
type: QueryTypes.FIELDS,
|
|
89
|
-
fields: {
|
|
90
|
-
sheet: {
|
|
91
|
-
type: DatasourceFieldTypes.STRING,
|
|
92
|
-
required: true,
|
|
93
|
-
},
|
|
94
|
-
rowIndex: {
|
|
95
|
-
type: DatasourceFieldTypes.NUMBER,
|
|
96
|
-
required: true,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
class GoogleSheetsIntegration implements DatasourcePlus {
|
|
104
|
-
private readonly config: GoogleSheetsConfig
|
|
105
|
-
private client: any
|
|
106
|
-
public tables: Record<string, Table> = {}
|
|
107
|
-
public schemaErrors: Record<string, string> = {}
|
|
108
|
-
|
|
109
|
-
constructor(config: GoogleSheetsConfig) {
|
|
110
|
-
this.config = config
|
|
111
|
-
const spreadsheetId = this.cleanSpreadsheetUrl(this.config.spreadsheetId)
|
|
112
|
-
this.client = new GoogleSpreadsheet(spreadsheetId)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Pull the spreadsheet ID out from a valid google sheets URL
|
|
117
|
-
* @param spreadsheetId - the URL or standard spreadsheetId of the google sheet
|
|
118
|
-
* @returns spreadsheet Id of the google sheet
|
|
119
|
-
*/
|
|
120
|
-
cleanSpreadsheetUrl(spreadsheetId: string) {
|
|
121
|
-
if (!spreadsheetId) {
|
|
122
|
-
throw new Error(
|
|
123
|
-
"You must set a spreadsheet ID in your configuration to fetch tables."
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
const parts = spreadsheetId.split("/")
|
|
127
|
-
return parts.length > 5 ? parts[5] : spreadsheetId
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async connect() {
|
|
131
|
-
try {
|
|
132
|
-
// Initialise oAuth client
|
|
133
|
-
const db = getGlobalDB()
|
|
134
|
-
const googleConfig = await getScopedConfig(db, {
|
|
135
|
-
type: Configs.GOOGLE,
|
|
136
|
-
})
|
|
137
|
-
const oauthClient = new OAuth2Client({
|
|
138
|
-
clientId: googleConfig.clientID,
|
|
139
|
-
clientSecret: googleConfig.clientSecret,
|
|
140
|
-
})
|
|
141
|
-
oauthClient.credentials.access_token = this.config.auth.accessToken
|
|
142
|
-
oauthClient.credentials.refresh_token = this.config.auth.refreshToken
|
|
143
|
-
this.client.useOAuth2Client(oauthClient)
|
|
144
|
-
await this.client.loadInfo()
|
|
145
|
-
} catch (err) {
|
|
146
|
-
console.error("Error connecting to google sheets", err)
|
|
147
|
-
throw err
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async buildSchema(datasourceId: string) {
|
|
152
|
-
await this.connect()
|
|
153
|
-
const sheets = await this.client.sheetsByIndex
|
|
154
|
-
const tables: Record<string, Table> = {}
|
|
155
|
-
for (let sheet of sheets) {
|
|
156
|
-
// must fetch rows to determine schema
|
|
157
|
-
await sheet.getRows()
|
|
158
|
-
// build schema
|
|
159
|
-
const schema: TableSchema = {}
|
|
160
|
-
|
|
161
|
-
// build schema from headers
|
|
162
|
-
for (let header of sheet.headerValues) {
|
|
163
|
-
schema[header] = {
|
|
164
|
-
name: header,
|
|
165
|
-
type: FieldTypes.STRING,
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// create tables
|
|
170
|
-
tables[sheet.title] = {
|
|
171
|
-
_id: buildExternalTableId(datasourceId, sheet.title),
|
|
172
|
-
name: sheet.title,
|
|
173
|
-
primary: ["rowNumber"],
|
|
174
|
-
schema,
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
this.tables = tables
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async query(json: QueryJson) {
|
|
182
|
-
const sheet = json.endpoint.entityId
|
|
183
|
-
|
|
184
|
-
const handlers = {
|
|
185
|
-
[DataSourceOperation.CREATE]: () =>
|
|
186
|
-
this.create({ sheet, row: json.body }),
|
|
187
|
-
[DataSourceOperation.READ]: () => this.read({ sheet }),
|
|
188
|
-
[DataSourceOperation.UPDATE]: () =>
|
|
189
|
-
this.update({
|
|
190
|
-
// exclude the header row and zero index
|
|
191
|
-
rowIndex: json.extra?.idFilter?.equal?.rowNumber - 2,
|
|
192
|
-
sheet,
|
|
193
|
-
row: json.body,
|
|
194
|
-
}),
|
|
195
|
-
[DataSourceOperation.DELETE]: () =>
|
|
196
|
-
this.delete({
|
|
197
|
-
// exclude the header row and zero index
|
|
198
|
-
rowIndex: json.extra?.idFilter?.equal?.rowNumber - 2,
|
|
199
|
-
sheet,
|
|
200
|
-
}),
|
|
201
|
-
[DataSourceOperation.CREATE_TABLE]: () =>
|
|
202
|
-
this.createTable(json?.table?.name),
|
|
203
|
-
[DataSourceOperation.UPDATE_TABLE]: () => this.updateTable(json.table),
|
|
204
|
-
[DataSourceOperation.DELETE_TABLE]: () =>
|
|
205
|
-
this.deleteTable(json?.table?.name),
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const internalQueryMethod = handlers[json.endpoint.operation]
|
|
209
|
-
|
|
210
|
-
return await internalQueryMethod()
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
buildRowObject(headers: string[], values: string[], rowNumber: number) {
|
|
214
|
-
const rowObject: { rowNumber: number; [key: string]: any } = { rowNumber }
|
|
215
|
-
for (let i = 0; i < headers.length; i++) {
|
|
216
|
-
rowObject._id = rowNumber
|
|
217
|
-
rowObject[headers[i]] = values[i]
|
|
218
|
-
}
|
|
219
|
-
return rowObject
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
async createTable(name?: string) {
|
|
223
|
-
try {
|
|
224
|
-
await this.connect()
|
|
225
|
-
const sheet = await this.client.addSheet({ title: name })
|
|
226
|
-
return sheet
|
|
227
|
-
} catch (err) {
|
|
228
|
-
console.error("Error creating new table in google sheets", err)
|
|
229
|
-
throw err
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async updateTable(table?: any) {
|
|
234
|
-
try {
|
|
235
|
-
await this.connect()
|
|
236
|
-
const sheet = await this.client.sheetsByTitle[table.name]
|
|
237
|
-
await sheet.loadHeaderRow()
|
|
238
|
-
|
|
239
|
-
if (table._rename) {
|
|
240
|
-
const headers = []
|
|
241
|
-
for (let header of sheet.headerValues) {
|
|
242
|
-
if (header === table._rename.old) {
|
|
243
|
-
headers.push(table._rename.updated)
|
|
244
|
-
} else {
|
|
245
|
-
headers.push(header)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
await sheet.setHeaderRow(headers)
|
|
249
|
-
} else {
|
|
250
|
-
let newField = Object.keys(table.schema).find(
|
|
251
|
-
key => !sheet.headerValues.includes(key)
|
|
252
|
-
)
|
|
253
|
-
await sheet.setHeaderRow([...sheet.headerValues, newField])
|
|
254
|
-
}
|
|
255
|
-
} catch (err) {
|
|
256
|
-
console.error("Error updating table in google sheets", err)
|
|
257
|
-
throw err
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
async deleteTable(sheet: any) {
|
|
262
|
-
try {
|
|
263
|
-
await this.connect()
|
|
264
|
-
const sheetToDelete = await this.client.sheetsByTitle[sheet]
|
|
265
|
-
return await sheetToDelete.delete()
|
|
266
|
-
} catch (err) {
|
|
267
|
-
console.error("Error deleting table in google sheets", err)
|
|
268
|
-
throw err
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
async create(query: { sheet: string; row: any }) {
|
|
273
|
-
try {
|
|
274
|
-
await this.connect()
|
|
275
|
-
const sheet = await this.client.sheetsByTitle[query.sheet]
|
|
276
|
-
const rowToInsert =
|
|
277
|
-
typeof query.row === "string" ? JSON.parse(query.row) : query.row
|
|
278
|
-
const row = await sheet.addRow(rowToInsert)
|
|
279
|
-
return [
|
|
280
|
-
this.buildRowObject(sheet.headerValues, row._rawData, row._rowNumber),
|
|
281
|
-
]
|
|
282
|
-
} catch (err) {
|
|
283
|
-
console.error("Error writing to google sheets", err)
|
|
284
|
-
throw err
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
async read(query: { sheet: string }) {
|
|
289
|
-
try {
|
|
290
|
-
await this.connect()
|
|
291
|
-
const sheet = await this.client.sheetsByTitle[query.sheet]
|
|
292
|
-
const rows = await sheet.getRows()
|
|
293
|
-
const headerValues = sheet.headerValues
|
|
294
|
-
const response = []
|
|
295
|
-
for (let row of rows) {
|
|
296
|
-
response.push(
|
|
297
|
-
this.buildRowObject(headerValues, row._rawData, row._rowNumber)
|
|
298
|
-
)
|
|
299
|
-
}
|
|
300
|
-
return response
|
|
301
|
-
} catch (err) {
|
|
302
|
-
console.error("Error reading from google sheets", err)
|
|
303
|
-
throw err
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
async update(query: { sheet: string; rowIndex: number; row: any }) {
|
|
308
|
-
try {
|
|
309
|
-
await this.connect()
|
|
310
|
-
const sheet = await this.client.sheetsByTitle[query.sheet]
|
|
311
|
-
const rows = await sheet.getRows()
|
|
312
|
-
const row = rows[query.rowIndex]
|
|
313
|
-
if (row) {
|
|
314
|
-
const updateValues = query.row
|
|
315
|
-
for (let key in updateValues) {
|
|
316
|
-
row[key] = updateValues[key]
|
|
317
|
-
}
|
|
318
|
-
await row.save()
|
|
319
|
-
return [
|
|
320
|
-
this.buildRowObject(
|
|
321
|
-
sheet.headerValues,
|
|
322
|
-
row._rawData,
|
|
323
|
-
row._rowNumber
|
|
324
|
-
),
|
|
325
|
-
]
|
|
326
|
-
} else {
|
|
327
|
-
throw new Error("Row does not exist.")
|
|
328
|
-
}
|
|
329
|
-
} catch (err) {
|
|
330
|
-
console.error("Error reading from google sheets", err)
|
|
331
|
-
throw err
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
async delete(query: { sheet: string; rowIndex: number }) {
|
|
336
|
-
await this.connect()
|
|
337
|
-
const sheet = await this.client.sheetsByTitle[query.sheet]
|
|
338
|
-
const rows = await sheet.getRows()
|
|
339
|
-
const row = rows[query.rowIndex]
|
|
340
|
-
if (row) {
|
|
341
|
-
await row.delete()
|
|
342
|
-
return [{ deleted: query.rowIndex }]
|
|
343
|
-
} else {
|
|
344
|
-
throw new Error("Row does not exist.")
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
module.exports = {
|
|
350
|
-
schema: SCHEMA,
|
|
351
|
-
integration: GoogleSheetsIntegration,
|
|
352
|
-
}
|
|
353
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const { DocumentTypes } = require("@budibase/backend-core/db")
|
|
2
|
-
import { getAppUrl } from "../../api/controllers/application"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Date:
|
|
6
|
-
* January 2022
|
|
7
|
-
*
|
|
8
|
-
* Description:
|
|
9
|
-
* Add the url to the app metadata if it doesn't exist
|
|
10
|
-
*/
|
|
11
|
-
export const run = async (appDb: any) => {
|
|
12
|
-
let metadata
|
|
13
|
-
try {
|
|
14
|
-
metadata = await appDb.get(DocumentTypes.APP_METADATA)
|
|
15
|
-
} catch (e) {
|
|
16
|
-
// sometimes the metadata document doesn't exist
|
|
17
|
-
// exit early instead of failing the migration
|
|
18
|
-
console.error("Error retrieving app metadata. Skipping", e)
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!metadata.url) {
|
|
23
|
-
const context = {
|
|
24
|
-
request: {
|
|
25
|
-
body: {
|
|
26
|
-
name: metadata.name,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
metadata.url = getAppUrl(context)
|
|
31
|
-
console.log(`Adding url to app: ${metadata.url}`)
|
|
32
|
-
await appDb.put(metadata)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { runQuotaMigration } from "./usageQuotas"
|
|
2
|
-
import * as syncApps from "./usageQuotas/syncApps"
|
|
3
|
-
import * as syncRows from "./usageQuotas/syncRows"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Date:
|
|
7
|
-
* January 2022
|
|
8
|
-
*
|
|
9
|
-
* Description:
|
|
10
|
-
* Synchronise the app and row quotas to the state of the db after it was
|
|
11
|
-
* discovered that the quota resets were still in place and the row quotas
|
|
12
|
-
* weren't being decremented correctly.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const run = async () => {
|
|
16
|
-
await runQuotaMigration(async () => {
|
|
17
|
-
await syncApps.run()
|
|
18
|
-
await syncRows.run()
|
|
19
|
-
})
|
|
20
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { DocumentTypes } = require("@budibase/backend-core/db")
|
|
2
|
-
const env = require("../../../environment")
|
|
3
|
-
const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
4
|
-
|
|
5
|
-
const migration = require("../appUrls")
|
|
6
|
-
|
|
7
|
-
describe("run", () => {
|
|
8
|
-
let config = new TestConfig(false)
|
|
9
|
-
const CouchDB = config.getCouch()
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
await config.init()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterAll(config.end)
|
|
16
|
-
|
|
17
|
-
it("runs successfully", async () => {
|
|
18
|
-
const app = await config.createApp("testApp")
|
|
19
|
-
const appDb = new CouchDB(app.appId)
|
|
20
|
-
let metadata = await appDb.get(DocumentTypes.APP_METADATA)
|
|
21
|
-
delete metadata.url
|
|
22
|
-
await appDb.put(metadata)
|
|
23
|
-
|
|
24
|
-
await migration.run(appDb)
|
|
25
|
-
|
|
26
|
-
metadata = await appDb.get(DocumentTypes.APP_METADATA)
|
|
27
|
-
expect(metadata.url).toEqual("/testapp")
|
|
28
|
-
})
|
|
29
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const env = require("../../../environment")
|
|
2
|
-
const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
3
|
-
|
|
4
|
-
const syncApps = jest.fn()
|
|
5
|
-
const syncRows = jest.fn()
|
|
6
|
-
|
|
7
|
-
jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
|
|
8
|
-
jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
|
|
9
|
-
|
|
10
|
-
const migration = require("../quotas1")
|
|
11
|
-
|
|
12
|
-
describe("run", () => {
|
|
13
|
-
let config = new TestConfig(false)
|
|
14
|
-
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
await config.init()
|
|
17
|
-
env._set("USE_QUOTAS", 1)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
afterAll(config.end)
|
|
21
|
-
|
|
22
|
-
it("runs ", async () => {
|
|
23
|
-
await migration.run()
|
|
24
|
-
expect(syncApps).toHaveBeenCalledTimes(1)
|
|
25
|
-
expect(syncRows).toHaveBeenCalledTimes(1)
|
|
26
|
-
})
|
|
27
|
-
})
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
2
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
3
|
-
|
|
4
|
-
// mock email view creation
|
|
5
|
-
const coreDb = require("@budibase/backend-core/db")
|
|
6
|
-
const createUserEmailView = jest.fn()
|
|
7
|
-
coreDb.createUserEmailView = createUserEmailView
|
|
8
|
-
|
|
9
|
-
const migration = require("../userEmailViewCasing")
|
|
10
|
-
|
|
11
|
-
describe("run", () => {
|
|
12
|
-
let config = new TestConfig(false)
|
|
13
|
-
const globalDb = getGlobalDB()
|
|
14
|
-
|
|
15
|
-
beforeEach(async () => {
|
|
16
|
-
await config.init()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
afterAll(config.end)
|
|
20
|
-
|
|
21
|
-
it("runs successfully", async () => {
|
|
22
|
-
await migration.run(globalDb)
|
|
23
|
-
expect(createUserEmailView).toHaveBeenCalledTimes(1)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { getGlobalDB, getTenantId } from "@budibase/backend-core/tenancy"
|
|
2
|
-
import { getAllApps } from "@budibase/backend-core/db"
|
|
3
|
-
import { getUsageQuotaDoc } from "../../../utilities/usageQuota"
|
|
4
|
-
|
|
5
|
-
export const run = async () => {
|
|
6
|
-
const db = getGlobalDB()
|
|
7
|
-
// get app count
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
const devApps = await getAllApps({ dev: true })
|
|
10
|
-
const appCount = devApps ? devApps.length : 0
|
|
11
|
-
|
|
12
|
-
// sync app count
|
|
13
|
-
const tenantId = getTenantId()
|
|
14
|
-
console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`)
|
|
15
|
-
const usageDoc = await getUsageQuotaDoc(db)
|
|
16
|
-
usageDoc.usageQuota.apps = appCount
|
|
17
|
-
await db.put(usageDoc)
|
|
18
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getGlobalDB, getTenantId } from "@budibase/backend-core/tenancy"
|
|
2
|
-
import { getAllApps } from "@budibase/backend-core/db"
|
|
3
|
-
import { getUsageQuotaDoc } from "../../../utilities/usageQuota"
|
|
4
|
-
import { getUniqueRows } from "../../../utilities/usageQuota/rows"
|
|
5
|
-
|
|
6
|
-
export const run = async () => {
|
|
7
|
-
const db = getGlobalDB()
|
|
8
|
-
// get all rows in all apps
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const allApps = await getAllApps({ all: true })
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
|
|
13
|
-
const rows = await getUniqueRows(appIds)
|
|
14
|
-
const rowCount = rows ? rows.length : 0
|
|
15
|
-
|
|
16
|
-
// sync row count
|
|
17
|
-
const tenantId = getTenantId()
|
|
18
|
-
console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`)
|
|
19
|
-
const usageDoc = await getUsageQuotaDoc(db)
|
|
20
|
-
usageDoc.usageQuota.rows = rowCount
|
|
21
|
-
await db.put(usageDoc)
|
|
22
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
2
|
-
const TestConfig = require("../../../../tests/utilities/TestConfiguration")
|
|
3
|
-
const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
|
|
4
|
-
const syncApps = require("../syncApps")
|
|
5
|
-
const env = require("../../../../environment")
|
|
6
|
-
|
|
7
|
-
describe("syncApps", () => {
|
|
8
|
-
let config = new TestConfig(false)
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
await config.init()
|
|
12
|
-
env._set("USE_QUOTAS", 1)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterAll(config.end)
|
|
16
|
-
|
|
17
|
-
it("runs successfully", async () => {
|
|
18
|
-
// create the usage quota doc and mock usages
|
|
19
|
-
const db = getGlobalDB()
|
|
20
|
-
await getUsageQuotaDoc(db)
|
|
21
|
-
await update(Properties.APPS, 3)
|
|
22
|
-
|
|
23
|
-
let usageDoc = await getUsageQuotaDoc(db)
|
|
24
|
-
expect(usageDoc.usageQuota.apps).toEqual(3)
|
|
25
|
-
|
|
26
|
-
// create an extra app to test the migration
|
|
27
|
-
await config.createApp("quota-test")
|
|
28
|
-
|
|
29
|
-
// migrate
|
|
30
|
-
await syncApps.run()
|
|
31
|
-
|
|
32
|
-
// assert the migration worked
|
|
33
|
-
usageDoc = await getUsageQuotaDoc(db)
|
|
34
|
-
expect(usageDoc.usageQuota.apps).toEqual(2)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
2
|
-
const TestConfig = require("../../../../tests/utilities/TestConfiguration")
|
|
3
|
-
const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
|
|
4
|
-
const syncRows = require("../syncRows")
|
|
5
|
-
const env = require("../../../../environment")
|
|
6
|
-
|
|
7
|
-
describe("syncRows", () => {
|
|
8
|
-
let config = new TestConfig(false)
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
await config.init()
|
|
12
|
-
env._set("USE_QUOTAS", 1)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterAll(config.end)
|
|
16
|
-
|
|
17
|
-
it("runs successfully", async () => {
|
|
18
|
-
// create the usage quota doc and mock usages
|
|
19
|
-
const db = getGlobalDB()
|
|
20
|
-
await getUsageQuotaDoc(db)
|
|
21
|
-
await update(Properties.ROW, 300)
|
|
22
|
-
|
|
23
|
-
let usageDoc = await getUsageQuotaDoc(db)
|
|
24
|
-
expect(usageDoc.usageQuota.rows).toEqual(300)
|
|
25
|
-
|
|
26
|
-
// app 1
|
|
27
|
-
await config.createTable()
|
|
28
|
-
await config.createRow()
|
|
29
|
-
// app 2
|
|
30
|
-
await config.createApp("second-app")
|
|
31
|
-
await config.createTable()
|
|
32
|
-
await config.createRow()
|
|
33
|
-
await config.createRow()
|
|
34
|
-
|
|
35
|
-
// migrate
|
|
36
|
-
await syncRows.run()
|
|
37
|
-
|
|
38
|
-
// assert the migration worked
|
|
39
|
-
usageDoc = await getUsageQuotaDoc(db)
|
|
40
|
-
expect(usageDoc.usageQuota.rows).toEqual(3)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const { createUserEmailView } = require("@budibase/backend-core/db")
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Date:
|
|
5
|
-
* October 2021
|
|
6
|
-
*
|
|
7
|
-
* Description:
|
|
8
|
-
* Recreate the user email view to include latest changes i.e. lower casing the email address
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const run = async (db: any) => {
|
|
12
|
-
await createUserEmailView(db)
|
|
13
|
-
}
|
package/src/migrations/index.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import CouchDB from "../db"
|
|
2
|
-
const {
|
|
3
|
-
MIGRATION_TYPES,
|
|
4
|
-
runMigrations,
|
|
5
|
-
} = require("@budibase/backend-core/migrations")
|
|
6
|
-
|
|
7
|
-
// migration functions
|
|
8
|
-
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
|
|
9
|
-
import * as quota1 from "./functions/quotas1"
|
|
10
|
-
import * as appUrls from "./functions/appUrls"
|
|
11
|
-
|
|
12
|
-
export interface Migration {
|
|
13
|
-
type: string
|
|
14
|
-
name: string
|
|
15
|
-
opts?: object
|
|
16
|
-
fn: Function
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* e.g.
|
|
21
|
-
* {
|
|
22
|
-
* tenantIds: ['bb'],
|
|
23
|
-
* force: {
|
|
24
|
-
* global: ['quota_1']
|
|
25
|
-
* }
|
|
26
|
-
* }
|
|
27
|
-
*/
|
|
28
|
-
export interface MigrationOptions {
|
|
29
|
-
tenantIds?: string[]
|
|
30
|
-
forced?: {
|
|
31
|
-
[type: string]: string[]
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const MIGRATIONS: Migration[] = [
|
|
36
|
-
{
|
|
37
|
-
type: MIGRATION_TYPES.GLOBAL,
|
|
38
|
-
name: "user_email_view_casing",
|
|
39
|
-
fn: userEmailViewCasing.run,
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: MIGRATION_TYPES.GLOBAL,
|
|
43
|
-
name: "quotas_1",
|
|
44
|
-
fn: quota1.run,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
type: MIGRATION_TYPES.APP,
|
|
48
|
-
name: "app_urls",
|
|
49
|
-
opts: { all: true },
|
|
50
|
-
fn: appUrls.run,
|
|
51
|
-
},
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
export const migrate = async (options?: MigrationOptions) => {
|
|
55
|
-
await runMigrations(CouchDB, MIGRATIONS, options)
|
|
56
|
-
}
|