@budibase/server 2.6.19-alpha.3 → 2.6.19-alpha.31
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/.dockerignore +7 -6
- package/Dockerfile +16 -8
- package/builder/assets/{index.71388c79.js → index.3dd3d237.js} +435 -428
- package/builder/assets/{index.07382a47.css → index.8469b14c.css} +2 -2
- package/builder/index.html +2 -2
- package/client/manifest.json +5229 -0
- package/dist/automation.js +32436 -0
- package/dist/automation.js.map +7 -0
- package/dist/index.js +44735 -13
- package/dist/index.js.map +7 -0
- package/dist/query.js +24367 -0
- package/dist/query.js.map +7 -0
- package/jest.config.ts +3 -0
- package/nodemon.json +1 -1
- package/package.json +32 -13
- package/pm2.config.js +1 -1
- package/scripts/build.js +48 -0
- package/src/api/controllers/application.ts +21 -22
- package/src/api/controllers/automation.ts +37 -9
- package/src/api/controllers/datasource.ts +20 -0
- package/src/api/controllers/row/index.ts +15 -22
- package/src/api/controllers/row/internal.ts +1 -1
- package/src/api/controllers/row/utils.ts +12 -0
- package/src/api/controllers/static/index.ts +3 -3
- package/src/api/controllers/table/index.ts +3 -0
- package/src/api/controllers/table/internal.ts +2 -6
- package/src/api/controllers/table/utils.ts +32 -1
- package/src/api/controllers/view/index.ts +5 -5
- package/src/api/controllers/webhook.ts +33 -9
- package/src/api/routes/application.ts +5 -0
- package/src/api/routes/automation.ts +0 -1
- package/src/api/routes/datasource.ts +5 -0
- package/src/api/routes/static.ts +3 -1
- package/src/api/routes/tests/{automation.spec.js → automation.spec.ts} +106 -31
- package/src/api/routes/tests/datasource.spec.ts +1 -1
- package/src/api/routes/tests/{webhook.spec.js → webhook.spec.ts} +33 -11
- package/src/app.ts +0 -1
- package/src/automations/actions.ts +8 -0
- package/src/automations/logging/index.ts +21 -0
- package/src/automations/steps/bash.ts +4 -0
- package/src/automations/steps/collect.ts +58 -0
- package/src/automations/steps/createRow.ts +4 -0
- package/src/automations/steps/delay.ts +1 -0
- package/src/automations/steps/deleteRow.ts +4 -0
- package/src/automations/steps/discord.ts +4 -0
- package/src/automations/steps/executeQuery.ts +4 -0
- package/src/automations/steps/executeScript.ts +4 -0
- package/src/automations/steps/filter.ts +1 -0
- package/src/automations/steps/loop.ts +1 -0
- package/src/automations/steps/make.ts +4 -0
- package/src/automations/steps/openai.ts +106 -0
- package/src/automations/steps/outgoingWebhook.ts +4 -0
- package/src/automations/steps/queryRows.ts +4 -0
- package/src/automations/steps/sendSmtpEmail.ts +4 -0
- package/src/automations/steps/serverLog.ts +4 -0
- package/src/automations/steps/slack.ts +4 -0
- package/src/automations/steps/updateRow.ts +4 -0
- package/src/automations/steps/zapier.ts +4 -0
- package/src/automations/tests/openai.spec.ts +86 -0
- package/src/automations/triggers.ts +3 -2
- package/src/constants/index.ts +17 -16
- package/src/db/inMemoryView.ts +1 -0
- package/src/environment.ts +3 -0
- package/src/integration-test/postgres.spec.ts +47 -4
- package/src/integrations/airtable.ts +3 -1
- package/src/integrations/arangodb.ts +3 -1
- package/src/integrations/base/sqlTable.ts +0 -1
- package/src/integrations/couchdb.ts +3 -1
- package/src/integrations/dynamodb.ts +3 -1
- package/src/integrations/elasticsearch.ts +3 -1
- package/src/integrations/firebase.ts +3 -1
- package/src/integrations/googlesheets.ts +11 -3
- package/src/integrations/microsoftSqlServer.ts +18 -2
- package/src/integrations/mongodb.ts +3 -1
- package/src/integrations/mysql.ts +27 -11
- package/src/integrations/oracle.ts +11 -1
- package/src/integrations/postgres.ts +15 -1
- package/src/integrations/redis.ts +3 -1
- package/src/integrations/s3.ts +3 -1
- package/src/integrations/snowflake.ts +3 -1
- package/src/integrations/tests/googlesheets.spec.ts +41 -9
- package/src/middleware/builder.ts +4 -5
- package/src/sdk/app/automations/index.ts +2 -0
- package/src/sdk/app/automations/utils.ts +7 -0
- package/src/startup.ts +2 -0
- package/src/tests/utilities/TestConfiguration.ts +4 -2
- package/src/tests/utilities/structures.ts +42 -0
- package/src/threads/automation.ts +78 -22
- package/src/threads/index.ts +9 -3
- package/src/threads/utils.ts +2 -0
- package/src/utilities/fileSystem/app.ts +1 -1
- package/src/utilities/fileSystem/clientLibrary.ts +8 -3
- package/src/utilities/fileSystem/filesystem.ts +3 -1
- package/src/utilities/redis.ts +19 -2
- package/src/websockets/builder.ts +69 -0
- package/src/websockets/grid.ts +25 -7
- package/src/websockets/index.ts +5 -2
- package/src/websockets/websocket.ts +20 -4
- package/tsconfig.build.json +9 -1
- package/tsconfig.json +1 -14
- package/dist/api/controllers/analytics.js +0 -46
- package/dist/api/controllers/apikeys.js +0 -72
- package/dist/api/controllers/application.js +0 -574
- package/dist/api/controllers/auth.js +0 -80
- package/dist/api/controllers/automation.js +0 -303
- package/dist/api/controllers/backup.js +0 -37
- package/dist/api/controllers/component.js +0 -59
- package/dist/api/controllers/datasource.js +0 -337
- package/dist/api/controllers/deploy/Deployment.js +0 -53
- package/dist/api/controllers/deploy/index.js +0 -198
- package/dist/api/controllers/dev.js +0 -146
- package/dist/api/controllers/integration.js +0 -28
- package/dist/api/controllers/layout.js +0 -49
- package/dist/api/controllers/metadata.js +0 -63
- package/dist/api/controllers/migrations.js +0 -29
- package/dist/api/controllers/ops.js +0 -40
- package/dist/api/controllers/permission.js +0 -162
- package/dist/api/controllers/plugin/file.js +0 -24
- package/dist/api/controllers/plugin/github.js +0 -69
- package/dist/api/controllers/plugin/index.js +0 -112
- package/dist/api/controllers/plugin/npm.js +0 -58
- package/dist/api/controllers/plugin/uploaders.js +0 -11
- package/dist/api/controllers/plugin/url.js +0 -24
- package/dist/api/controllers/plugin/utils.js +0 -27
- package/dist/api/controllers/public/applications.js +0 -146
- package/dist/api/controllers/public/mapping/applications.js +0 -29
- package/dist/api/controllers/public/mapping/index.js +0 -11
- package/dist/api/controllers/public/mapping/queries.js +0 -36
- package/dist/api/controllers/public/mapping/rows.js +0 -24
- package/dist/api/controllers/public/mapping/tables.js +0 -23
- package/dist/api/controllers/public/mapping/types.js +0 -2
- package/dist/api/controllers/public/mapping/users.js +0 -29
- package/dist/api/controllers/public/metrics.js +0 -113
- package/dist/api/controllers/public/queries.js +0 -58
- package/dist/api/controllers/public/rows.js +0 -120
- package/dist/api/controllers/public/tables.js +0 -95
- package/dist/api/controllers/public/users.js +0 -93
- package/dist/api/controllers/public/utils.js +0 -56
- package/dist/api/controllers/query/import/index.js +0 -87
- package/dist/api/controllers/query/import/sources/base/index.js +0 -75
- package/dist/api/controllers/query/import/sources/base/openapi.js +0 -42
- package/dist/api/controllers/query/import/sources/curl.js +0 -99
- package/dist/api/controllers/query/import/sources/openapi2.js +0 -145
- package/dist/api/controllers/query/import/sources/openapi3.js +0 -177
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +0 -253
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +0 -1054
- package/dist/api/controllers/query/import/sources/tests/openapi3/data/crud/crud.json +0 -253
- package/dist/api/controllers/query/import/sources/tests/openapi3/data/petstore/petstore.json +0 -1225
- package/dist/api/controllers/query/index.js +0 -299
- package/dist/api/controllers/query/validation.js +0 -53
- package/dist/api/controllers/role.js +0 -109
- package/dist/api/controllers/routing.js +0 -105
- package/dist/api/controllers/row/ExternalRequest.js +0 -683
- package/dist/api/controllers/row/external.js +0 -339
- package/dist/api/controllers/row/index.js +0 -203
- package/dist/api/controllers/row/internal.js +0 -509
- package/dist/api/controllers/row/internalSearch.js +0 -28
- package/dist/api/controllers/row/staticFormula.js +0 -165
- package/dist/api/controllers/row/utils.js +0 -183
- package/dist/api/controllers/screen.js +0 -110
- package/dist/api/controllers/script.js +0 -30
- package/dist/api/controllers/static/index.js +0 -268
- package/dist/api/controllers/table/bulkFormula.js +0 -173
- package/dist/api/controllers/table/external.js +0 -279
- package/dist/api/controllers/table/index.js +0 -179
- package/dist/api/controllers/table/internal.js +0 -197
- package/dist/api/controllers/table/utils.js +0 -379
- package/dist/api/controllers/templates.js +0 -56
- package/dist/api/controllers/user.js +0 -124
- package/dist/api/controllers/view/exporters.js +0 -46
- package/dist/api/controllers/view/index.js +0 -193
- package/dist/api/controllers/view/utils.js +0 -177
- package/dist/api/controllers/view/viewBuilder.js +0 -158
- package/dist/api/controllers/webhook.js +0 -134
- package/dist/api/index.js +0 -55
- package/dist/api/routes/analytics.js +0 -34
- package/dist/api/routes/apikeys.js +0 -37
- package/dist/api/routes/application.js +0 -48
- package/dist/api/routes/auth.js +0 -33
- package/dist/api/routes/automation.js +0 -50
- package/dist/api/routes/backup.js +0 -35
- package/dist/api/routes/component.js +0 -35
- package/dist/api/routes/datasource.js +0 -44
- package/dist/api/routes/deploy.js +0 -37
- package/dist/api/routes/dev.js +0 -49
- package/dist/api/routes/index.js +0 -75
- package/dist/api/routes/integration.js +0 -37
- package/dist/api/routes/layout.js +0 -37
- package/dist/api/routes/metadata.js +0 -40
- package/dist/api/routes/migrations.js +0 -36
- package/dist/api/routes/ops.js +0 -52
- package/dist/api/routes/permission.js +0 -44
- package/dist/api/routes/plugin.js +0 -39
- package/dist/api/routes/public/applications.js +0 -174
- package/dist/api/routes/public/index.js +0 -140
- package/dist/api/routes/public/metrics.js +0 -30
- package/dist/api/routes/public/middleware/mapper.js +0 -97
- package/dist/api/routes/public/queries.js +0 -72
- package/dist/api/routes/public/rows.js +0 -158
- package/dist/api/routes/public/tables.js +0 -152
- package/dist/api/routes/public/users.js +0 -135
- package/dist/api/routes/public/utils/Endpoint.js +0 -36
- package/dist/api/routes/query.js +0 -47
- package/dist/api/routes/role.js +0 -40
- package/dist/api/routes/routing.js +0 -39
- package/dist/api/routes/row.js +0 -239
- package/dist/api/routes/screen.js +0 -39
- package/dist/api/routes/script.js +0 -35
- package/dist/api/routes/static.js +0 -80
- package/dist/api/routes/table.js +0 -163
- package/dist/api/routes/templates.js +0 -37
- package/dist/api/routes/user.js +0 -43
- package/dist/api/routes/utils/validators.js +0 -238
- package/dist/api/routes/view.js +0 -42
- package/dist/api/routes/webhook.js +0 -43
- package/dist/app.js +0 -132
- package/dist/automations/actions.js +0 -137
- package/dist/automations/automationUtils.js +0 -173
- package/dist/automations/bullboard.js +0 -71
- package/dist/automations/index.js +0 -43
- package/dist/automations/logging/index.js +0 -53
- package/dist/automations/steps/bash.js +0 -111
- package/dist/automations/steps/createRow.js +0 -108
- package/dist/automations/steps/delay.js +0 -53
- package/dist/automations/steps/deleteRow.js +0 -96
- package/dist/automations/steps/discord.js +0 -116
- package/dist/automations/steps/executeQuery.js +0 -134
- package/dist/automations/steps/executeScript.js +0 -106
- package/dist/automations/steps/filter.js +0 -112
- package/dist/automations/steps/loop.js +0 -54
- package/dist/automations/steps/make.js +0 -134
- package/dist/automations/steps/outgoingWebhook.js +0 -166
- package/dist/automations/steps/queryRows.js +0 -216
- package/dist/automations/steps/sendSmtpEmail.js +0 -115
- package/dist/automations/steps/serverLog.js +0 -65
- package/dist/automations/steps/slack.js +0 -98
- package/dist/automations/steps/updateRow.js +0 -144
- package/dist/automations/steps/utils.js +0 -56
- package/dist/automations/steps/zapier.js +0 -130
- package/dist/automations/triggerInfo/app.js +0 -36
- package/dist/automations/triggerInfo/cron.js +0 -35
- package/dist/automations/triggerInfo/index.js +0 -40
- package/dist/automations/triggerInfo/rowDeleted.js +0 -36
- package/dist/automations/triggerInfo/rowSaved.js +0 -44
- package/dist/automations/triggerInfo/rowUpdated.js +0 -44
- package/dist/automations/triggerInfo/webhook.js +0 -40
- package/dist/automations/triggers.js +0 -181
- package/dist/automations/utils.js +0 -275
- package/dist/constants/definitions.js +0 -2
- package/dist/constants/index.js +0 -181
- package/dist/constants/layouts.js +0 -148
- package/dist/constants/screens.js +0 -51
- package/dist/db/defaultData/datasource_bb_default.js +0 -574
- package/dist/db/defaultData/employeeImport.js +0 -155
- package/dist/db/defaultData/expensesImport.js +0 -117
- package/dist/db/defaultData/inventoryImport.js +0 -109
- package/dist/db/defaultData/jobsImport.js +0 -152
- package/dist/db/dynamoClient.js +0 -124
- package/dist/db/inMemoryView.js +0 -62
- package/dist/db/index.js +0 -43
- package/dist/db/linkedRows/LinkController.js +0 -392
- package/dist/db/linkedRows/LinkDocument.js +0 -33
- package/dist/db/linkedRows/index.js +0 -206
- package/dist/db/linkedRows/linkUtils.js +0 -131
- package/dist/db/newid.js +0 -7
- package/dist/db/utils.js +0 -248
- package/dist/db/views/staticViews.js +0 -144
- package/dist/ddApm.js +0 -11
- package/dist/definitions/automations.js +0 -8
- package/dist/definitions/common.js +0 -2
- package/dist/definitions/datasource.js +0 -7
- package/dist/definitions/openapi.js +0 -6
- package/dist/environment.js +0 -109
- package/dist/events/AutomationEmitter.js +0 -53
- package/dist/events/BudibaseEmitter.js +0 -25
- package/dist/events/docUpdates/index.js +0 -17
- package/dist/events/docUpdates/processors.js +0 -18
- package/dist/events/docUpdates/syncUsers.js +0 -49
- package/dist/events/index.js +0 -11
- package/dist/events/utils.js +0 -43
- package/dist/integrations/airtable.js +0 -173
- package/dist/integrations/arangodb.js +0 -119
- package/dist/integrations/base/query.js +0 -32
- package/dist/integrations/base/sql.js +0 -600
- package/dist/integrations/base/sqlTable.js +0 -167
- package/dist/integrations/base/types.js +0 -2
- package/dist/integrations/couchdb.js +0 -140
- package/dist/integrations/dynamodb.js +0 -210
- package/dist/integrations/elasticsearch.js +0 -201
- package/dist/integrations/firebase.js +0 -189
- package/dist/integrations/googlesheets.js +0 -484
- package/dist/integrations/index.js +0 -138
- package/dist/integrations/microsoftSqlServer.js +0 -289
- package/dist/integrations/mongodb.js +0 -630
- package/dist/integrations/mysql.js +0 -272
- package/dist/integrations/oracle.js +0 -404
- package/dist/integrations/postgres.js +0 -320
- package/dist/integrations/queries/sql.js +0 -84
- package/dist/integrations/redis.js +0 -187
- package/dist/integrations/rest.js +0 -400
- package/dist/integrations/s3.js +0 -256
- package/dist/integrations/snowflake.js +0 -114
- package/dist/integrations/utils.js +0 -295
- package/dist/middleware/appInfo.js +0 -22
- package/dist/middleware/authorized.js +0 -112
- package/dist/middleware/builder.js +0 -93
- package/dist/middleware/currentapp.js +0 -103
- package/dist/middleware/joi-validator.js +0 -43
- package/dist/middleware/publicApi.js +0 -25
- package/dist/middleware/resourceId.js +0 -59
- package/dist/middleware/selfhost.js +0 -24
- package/dist/middleware/utils.js +0 -8
- package/dist/migrations/functions/appUrls.js +0 -42
- package/dist/migrations/functions/backfill/app/automations.js +0 -31
- package/dist/migrations/functions/backfill/app/datasources.js +0 -28
- package/dist/migrations/functions/backfill/app/layouts.js +0 -33
- package/dist/migrations/functions/backfill/app/queries.js +0 -49
- package/dist/migrations/functions/backfill/app/roles.js +0 -28
- package/dist/migrations/functions/backfill/app/screens.js +0 -28
- package/dist/migrations/functions/backfill/app/tables.js +0 -37
- package/dist/migrations/functions/backfill/app.js +0 -176
- package/dist/migrations/functions/backfill/global/configs.js +0 -67
- package/dist/migrations/functions/backfill/global/quotas.js +0 -60
- package/dist/migrations/functions/backfill/global/users.js +0 -50
- package/dist/migrations/functions/backfill/global.js +0 -205
- package/dist/migrations/functions/backfill/index.js +0 -32
- package/dist/migrations/functions/backfill/installation.js +0 -80
- package/dist/migrations/functions/syncQuotas.js +0 -52
- package/dist/migrations/functions/tableSettings.js +0 -130
- package/dist/migrations/functions/usageQuotas/index.js +0 -16
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -24
- package/dist/migrations/functions/usageQuotas/syncPlugins.js +0 -23
- package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
- package/dist/migrations/functions/usageQuotas/syncUsers.js +0 -21
- package/dist/migrations/functions/userEmailViewCasing.js +0 -24
- package/dist/migrations/index.js +0 -111
- package/dist/migrations/tests/helpers.js +0 -72
- package/dist/migrations/tests/structures.js +0 -37
- package/dist/sdk/app/applications/index.js +0 -28
- package/dist/sdk/app/applications/sync.js +0 -164
- package/dist/sdk/app/applications/utils.js +0 -21
- package/dist/sdk/app/automations/index.js +0 -29
- package/dist/sdk/app/automations/webhook.js +0 -54
- package/dist/sdk/app/backups/constants.js +0 -6
- package/dist/sdk/app/backups/exports.js +0 -160
- package/dist/sdk/app/backups/imports.js +0 -170
- package/dist/sdk/app/backups/index.js +0 -29
- package/dist/sdk/app/backups/statistics.js +0 -73
- package/dist/sdk/app/datasources/datasources.js +0 -173
- package/dist/sdk/app/datasources/index.js +0 -27
- package/dist/sdk/app/queries/index.js +0 -27
- package/dist/sdk/app/queries/queries.js +0 -60
- package/dist/sdk/app/rows/attachments.js +0 -61
- package/dist/sdk/app/rows/index.js +0 -28
- package/dist/sdk/app/rows/rows.js +0 -30
- package/dist/sdk/app/tables/index.js +0 -65
- package/dist/sdk/index.js +0 -27
- package/dist/sdk/plugins/index.js +0 -27
- package/dist/sdk/plugins/plugins.js +0 -53
- package/dist/sdk/users/index.js +0 -27
- package/dist/sdk/users/utils.js +0 -87
- package/dist/sdk/utils/index.js +0 -29
- package/dist/startup.js +0 -158
- package/dist/threads/automation.js +0 -450
- package/dist/threads/definitions.js +0 -2
- package/dist/threads/index.js +0 -140
- package/dist/threads/query.js +0 -265
- package/dist/threads/utils.js +0 -120
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/utilities/appDirectoryTemplate/package.json +0 -10
- package/dist/utilities/budibaseDir.js +0 -5
- package/dist/utilities/centralPath.js +0 -27
- package/dist/utilities/csv.js +0 -33
- package/dist/utilities/fileSystem/app.js +0 -88
- package/dist/utilities/fileSystem/clientLibrary.js +0 -138
- package/dist/utilities/fileSystem/filesystem.js +0 -180
- package/dist/utilities/fileSystem/index.js +0 -21
- package/dist/utilities/fileSystem/plugin.js +0 -76
- package/dist/utilities/fileSystem/processor.js +0 -34
- package/dist/utilities/fileSystem/template.js +0 -47
- package/dist/utilities/global.js +0 -149
- package/dist/utilities/index.js +0 -143
- package/dist/utilities/redis.js +0 -117
- package/dist/utilities/retry.js +0 -30
- package/dist/utilities/routing/index.js +0 -39
- package/dist/utilities/rowProcessor/index.js +0 -282
- package/dist/utilities/rowProcessor/map.js +0 -116
- package/dist/utilities/rowProcessor/utils.js +0 -87
- package/dist/utilities/schema.js +0 -112
- package/dist/utilities/scriptRunner.js +0 -26
- package/dist/utilities/security.js +0 -57
- package/dist/utilities/statusCodes.js +0 -9
- package/dist/utilities/usageQuota/rows.js +0 -88
- package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
- package/dist/utilities/users.js +0 -57
- package/dist/utilities/workerRequests.js +0 -171
- package/dist/watch.js +0 -53
- package/dist/websockets/client.js +0 -14
- package/dist/websockets/grid.js +0 -60
- package/dist/websockets/index.js +0 -17
- package/dist/websockets/websocket.js +0 -78
- /package/dist/{api/controllers/static/templates/BudibaseApp.svelte → BudibaseApp-Y5NZEDTC.svelte} +0 -0
- /package/dist/{api/controllers/static/templates/app.hbs → app.hbs} +0 -0
- /package/dist/{api/controllers/static/templates/preview.hbs → preview.hbs} +0 -0
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
AutomationStatus,
|
|
20
20
|
AutomationMetadata,
|
|
21
21
|
AutomationJob,
|
|
22
|
+
AutomationData,
|
|
22
23
|
} from "@budibase/types"
|
|
23
24
|
import {
|
|
24
25
|
LoopStep,
|
|
@@ -37,8 +38,8 @@ const LOOP_STEP_ID = actions.BUILTIN_ACTION_DEFINITIONS.LOOP.stepId
|
|
|
37
38
|
const CRON_STEP_ID = triggerDefs.CRON.stepId
|
|
38
39
|
const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED }
|
|
39
40
|
|
|
40
|
-
function getLoopIterations(loopStep: LoopStep
|
|
41
|
-
|
|
41
|
+
function getLoopIterations(loopStep: LoopStep) {
|
|
42
|
+
let binding = loopStep.inputs.binding
|
|
42
43
|
if (!binding) {
|
|
43
44
|
return 0
|
|
44
45
|
}
|
|
@@ -240,7 +241,9 @@ class Orchestrator {
|
|
|
240
241
|
let loopStepNumber: any = undefined
|
|
241
242
|
let loopSteps: LoopStep[] | undefined = []
|
|
242
243
|
let metadata
|
|
244
|
+
let timeoutFlag = false
|
|
243
245
|
let wasLoopStep = false
|
|
246
|
+
let timeout = this._job.data.event.timeout
|
|
244
247
|
// check if this is a recurring automation,
|
|
245
248
|
if (isProdAppID(this._appId) && isRecurring(automation)) {
|
|
246
249
|
metadata = await this.getMetadata()
|
|
@@ -249,8 +252,18 @@ class Orchestrator {
|
|
|
249
252
|
return
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
|
-
|
|
255
|
+
const start = performance.now()
|
|
253
256
|
for (let step of automation.definition.steps) {
|
|
257
|
+
if (timeoutFlag) {
|
|
258
|
+
break
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (timeout) {
|
|
262
|
+
setTimeout(() => {
|
|
263
|
+
timeoutFlag = true
|
|
264
|
+
}, timeout || 12000)
|
|
265
|
+
}
|
|
266
|
+
|
|
254
267
|
stepCount++
|
|
255
268
|
let input: any,
|
|
256
269
|
iterations = 1,
|
|
@@ -264,22 +277,17 @@ class Orchestrator {
|
|
|
264
277
|
|
|
265
278
|
if (loopStep) {
|
|
266
279
|
input = await processObject(loopStep.inputs, this._context)
|
|
267
|
-
iterations = getLoopIterations(loopStep as LoopStep
|
|
280
|
+
iterations = getLoopIterations(loopStep as LoopStep)
|
|
268
281
|
}
|
|
269
282
|
for (let index = 0; index < iterations; index++) {
|
|
270
283
|
let originalStepInput = cloneDeep(step.inputs)
|
|
271
284
|
// Handle if the user has set a max iteration count or if it reaches the max limit set by us
|
|
272
285
|
if (loopStep && input.binding) {
|
|
273
|
-
let newInput: any = await processObject(
|
|
274
|
-
loopStep.inputs,
|
|
275
|
-
cloneDeep(this._context)
|
|
276
|
-
)
|
|
277
|
-
|
|
278
286
|
let tempOutput = { items: loopSteps, iterations: iterationCount }
|
|
279
287
|
try {
|
|
280
|
-
|
|
288
|
+
loopStep.inputs.binding = automationUtils.typecastForLooping(
|
|
281
289
|
loopStep as LoopStep,
|
|
282
|
-
|
|
290
|
+
loopStep.inputs as LoopInput
|
|
283
291
|
)
|
|
284
292
|
} catch (err) {
|
|
285
293
|
this.updateContextAndOutput(loopStepNumber, step, tempOutput, {
|
|
@@ -290,13 +298,12 @@ class Orchestrator {
|
|
|
290
298
|
loopStep = undefined
|
|
291
299
|
break
|
|
292
300
|
}
|
|
293
|
-
|
|
294
301
|
let item = []
|
|
295
302
|
if (
|
|
296
303
|
typeof loopStep.inputs.binding === "string" &&
|
|
297
304
|
loopStep.inputs.option === "String"
|
|
298
305
|
) {
|
|
299
|
-
item = automationUtils.stringSplit(
|
|
306
|
+
item = automationUtils.stringSplit(loopStep.inputs.binding)
|
|
300
307
|
} else if (Array.isArray(loopStep.inputs.binding)) {
|
|
301
308
|
item = loopStep.inputs.binding
|
|
302
309
|
}
|
|
@@ -338,6 +345,7 @@ class Orchestrator {
|
|
|
338
345
|
}
|
|
339
346
|
}
|
|
340
347
|
}
|
|
348
|
+
|
|
341
349
|
if (
|
|
342
350
|
index === env.AUTOMATION_MAX_ITERATIONS ||
|
|
343
351
|
index === parseInt(loopStep.inputs.iterations)
|
|
@@ -466,8 +474,22 @@ class Orchestrator {
|
|
|
466
474
|
}
|
|
467
475
|
}
|
|
468
476
|
|
|
477
|
+
const end = performance.now()
|
|
478
|
+
const executionTime = end - start
|
|
479
|
+
|
|
480
|
+
console.log(`Execution time: ${executionTime} milliseconds`)
|
|
481
|
+
|
|
469
482
|
// store the logs for the automation run
|
|
470
|
-
|
|
483
|
+
try {
|
|
484
|
+
await storeLog(this._automation, this.executionOutput)
|
|
485
|
+
} catch (e: any) {
|
|
486
|
+
if (e.status === 413 && e.request?.data) {
|
|
487
|
+
// if content is too large we shouldn't log it
|
|
488
|
+
delete e.request.data
|
|
489
|
+
e.request.data = { message: "removed due to large size" }
|
|
490
|
+
}
|
|
491
|
+
logging.logAlert("Error writing automation log", e)
|
|
492
|
+
}
|
|
471
493
|
if (isProdAppID(this._appId) && isRecurring(automation) && metadata) {
|
|
472
494
|
await this.updateMetadata(metadata)
|
|
473
495
|
}
|
|
@@ -475,22 +497,56 @@ class Orchestrator {
|
|
|
475
497
|
}
|
|
476
498
|
}
|
|
477
499
|
|
|
478
|
-
export function execute(job: Job
|
|
500
|
+
export function execute(job: Job<AutomationData>, callback: WorkerCallback) {
|
|
501
|
+
const appId = job.data.event.appId
|
|
502
|
+
const automationId = job.data.automation._id
|
|
503
|
+
if (!appId) {
|
|
504
|
+
throw new Error("Unable to execute, event doesn't contain app ID.")
|
|
505
|
+
}
|
|
506
|
+
if (!automationId) {
|
|
507
|
+
throw new Error("Unable to execute, event doesn't contain automation ID.")
|
|
508
|
+
}
|
|
509
|
+
return context.doInAutomationContext({
|
|
510
|
+
appId,
|
|
511
|
+
automationId,
|
|
512
|
+
task: async () => {
|
|
513
|
+
const envVars = await sdkUtils.getEnvironmentVariables()
|
|
514
|
+
// put into automation thread for whole context
|
|
515
|
+
await context.doInEnvironmentContext(envVars, async () => {
|
|
516
|
+
const automationOrchestrator = new Orchestrator(job)
|
|
517
|
+
try {
|
|
518
|
+
const response = await automationOrchestrator.execute()
|
|
519
|
+
callback(null, response)
|
|
520
|
+
} catch (err) {
|
|
521
|
+
callback(err)
|
|
522
|
+
}
|
|
523
|
+
})
|
|
524
|
+
},
|
|
525
|
+
})
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export function executeSynchronously(job: Job) {
|
|
479
529
|
const appId = job.data.event.appId
|
|
480
530
|
if (!appId) {
|
|
481
531
|
throw new Error("Unable to execute, event doesn't contain app ID.")
|
|
482
532
|
}
|
|
533
|
+
|
|
534
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
535
|
+
setTimeout(() => {
|
|
536
|
+
reject(new Error("Timeout exceeded"))
|
|
537
|
+
}, job.data.event.timeout || 12000)
|
|
538
|
+
})
|
|
539
|
+
|
|
483
540
|
return context.doInAppContext(appId, async () => {
|
|
484
541
|
const envVars = await sdkUtils.getEnvironmentVariables()
|
|
485
542
|
// put into automation thread for whole context
|
|
486
|
-
|
|
543
|
+
return context.doInEnvironmentContext(envVars, async () => {
|
|
487
544
|
const automationOrchestrator = new Orchestrator(job)
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
545
|
+
const response = await Promise.race([
|
|
546
|
+
automationOrchestrator.execute(),
|
|
547
|
+
timeoutPromise,
|
|
548
|
+
])
|
|
549
|
+
return response
|
|
494
550
|
})
|
|
495
551
|
})
|
|
496
552
|
}
|
package/src/threads/index.ts
CHANGED
|
@@ -38,6 +38,9 @@ export class Thread {
|
|
|
38
38
|
this.count = opts.count ? opts.count : 1
|
|
39
39
|
this.disableThreading = this.shouldDisableThreading()
|
|
40
40
|
if (!this.disableThreading) {
|
|
41
|
+
console.debug(
|
|
42
|
+
`[${env.FORKED_PROCESS_NAME}] initialising worker farm type=${type}`
|
|
43
|
+
)
|
|
41
44
|
const workerOpts: any = {
|
|
42
45
|
autoStart: true,
|
|
43
46
|
maxConcurrentWorkers: this.count,
|
|
@@ -45,6 +48,7 @@ export class Thread {
|
|
|
45
48
|
env: {
|
|
46
49
|
...process.env,
|
|
47
50
|
FORKED_PROCESS: "1",
|
|
51
|
+
FORKED_PROCESS_NAME: type,
|
|
48
52
|
},
|
|
49
53
|
},
|
|
50
54
|
}
|
|
@@ -54,6 +58,10 @@ export class Thread {
|
|
|
54
58
|
}
|
|
55
59
|
this.workers = workerFarm(workerOpts, typeToFile(type), ["execute"])
|
|
56
60
|
Thread.workerRefs.push(this.workers)
|
|
61
|
+
} else {
|
|
62
|
+
console.debug(
|
|
63
|
+
`[${env.FORKED_PROCESS_NAME}] skipping worker farm type=${type}`
|
|
64
|
+
)
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
67
|
|
|
@@ -72,9 +80,7 @@ export class Thread {
|
|
|
72
80
|
function fire(worker: any) {
|
|
73
81
|
worker.execute(job, (err: any, response: any) => {
|
|
74
82
|
if (err && err.type === "TimeoutError") {
|
|
75
|
-
reject(
|
|
76
|
-
new Error(`Query response time exceeded ${timeout}ms timeout.`)
|
|
77
|
-
)
|
|
83
|
+
reject(new Error(`Thread timeout exceeded ${timeout}ms timeout.`))
|
|
78
84
|
} else if (err) {
|
|
79
85
|
reject(err)
|
|
80
86
|
} else {
|
package/src/threads/utils.ts
CHANGED
|
@@ -26,8 +26,10 @@ function makeVariableKey(queryId: string, variable: string) {
|
|
|
26
26
|
export function threadSetup() {
|
|
27
27
|
// don't run this if not threading
|
|
28
28
|
if (env.isTest() || env.DISABLE_THREADING || !env.isInThread()) {
|
|
29
|
+
console.debug(`[${env.FORKED_PROCESS_NAME}] thread setup skipped`)
|
|
29
30
|
return
|
|
30
31
|
}
|
|
32
|
+
console.debug(`[${env.FORKED_PROCESS_NAME}] thread setup running`)
|
|
31
33
|
db.init()
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -35,7 +35,7 @@ export const getComponentLibraryManifest = async (library: string) => {
|
|
|
35
35
|
const filename = "manifest.json"
|
|
36
36
|
|
|
37
37
|
if (env.isDev() || env.isTest()) {
|
|
38
|
-
const path = join(TOP_LEVEL_PATH, "
|
|
38
|
+
const path = join(TOP_LEVEL_PATH, "packages/client", filename)
|
|
39
39
|
// always load from new so that updates are refreshed
|
|
40
40
|
delete require.cache[require.resolve(path)]
|
|
41
41
|
return require(path)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from "path"
|
|
1
|
+
import path, { join } from "path"
|
|
2
2
|
import { ObjectStoreBuckets } from "../../constants"
|
|
3
3
|
import fs from "fs"
|
|
4
4
|
import { objectStore } from "@budibase/backend-core"
|
|
@@ -6,6 +6,10 @@ import { resolve } from "../centralPath"
|
|
|
6
6
|
import env from "../../environment"
|
|
7
7
|
import { TOP_LEVEL_PATH } from "./filesystem"
|
|
8
8
|
|
|
9
|
+
export function devClientLibPath() {
|
|
10
|
+
return require.resolve("@budibase/client")
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* Client library paths in the object store:
|
|
11
15
|
* Previously, the entire client library package was downloaded from NPM
|
|
@@ -89,9 +93,10 @@ export async function updateClientLibrary(appId: string) {
|
|
|
89
93
|
let manifest, client
|
|
90
94
|
|
|
91
95
|
if (env.isDev()) {
|
|
96
|
+
const clientPath = devClientLibPath()
|
|
92
97
|
// Load the symlinked version in dev which is always the newest
|
|
93
|
-
manifest =
|
|
94
|
-
client =
|
|
98
|
+
manifest = join(path.dirname(path.dirname(clientPath)), "manifest.json")
|
|
99
|
+
client = clientPath
|
|
95
100
|
} else {
|
|
96
101
|
// Load the bundled version in prod
|
|
97
102
|
manifest = resolve(TOP_LEVEL_PATH, "client", "manifest.json")
|
|
@@ -4,9 +4,11 @@ import { budibaseTempDir } from "../budibaseDir"
|
|
|
4
4
|
import { join } from "path"
|
|
5
5
|
import env from "../../environment"
|
|
6
6
|
import tar from "tar"
|
|
7
|
+
import environment from "../../environment"
|
|
7
8
|
const uuid = require("uuid/v4")
|
|
8
9
|
|
|
9
|
-
export const TOP_LEVEL_PATH =
|
|
10
|
+
export const TOP_LEVEL_PATH =
|
|
11
|
+
environment.TOP_LEVEL_PATH || join(__dirname, "..", "..", "..")
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Upon first startup of instance there may not be everything we need in tmp directory, set it up.
|
package/src/utilities/redis.ts
CHANGED
|
@@ -4,23 +4,33 @@ import { ContextUser } from "@budibase/types"
|
|
|
4
4
|
|
|
5
5
|
const APP_DEV_LOCK_SECONDS = 600
|
|
6
6
|
const AUTOMATION_TEST_FLAG_SECONDS = 60
|
|
7
|
-
let devAppClient: any, debounceClient: any, flagClient: any
|
|
7
|
+
let devAppClient: any, debounceClient: any, flagClient: any, socketClient: any
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// We need to maintain a duplicate client for socket.io pub/sub
|
|
10
|
+
let socketSubClient: any
|
|
11
|
+
|
|
12
|
+
// We init this as we want to keep the connection open all the time
|
|
10
13
|
// reduces the performance hit
|
|
11
14
|
export async function init() {
|
|
12
15
|
devAppClient = new redis.Client(redis.utils.Databases.DEV_LOCKS)
|
|
13
16
|
debounceClient = new redis.Client(redis.utils.Databases.DEBOUNCE)
|
|
14
17
|
flagClient = new redis.Client(redis.utils.Databases.FLAGS)
|
|
18
|
+
socketClient = new redis.Client(redis.utils.Databases.SOCKET_IO)
|
|
15
19
|
await devAppClient.init()
|
|
16
20
|
await debounceClient.init()
|
|
17
21
|
await flagClient.init()
|
|
22
|
+
await socketClient.init()
|
|
23
|
+
|
|
24
|
+
// Duplicate the socket client for pub/sub
|
|
25
|
+
socketSubClient = socketClient.getClient().duplicate()
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
export async function shutdown() {
|
|
21
29
|
if (devAppClient) await devAppClient.finish()
|
|
22
30
|
if (debounceClient) await debounceClient.finish()
|
|
23
31
|
if (flagClient) await flagClient.finish()
|
|
32
|
+
if (socketClient) await socketClient.finish()
|
|
33
|
+
if (socketSubClient) socketSubClient.disconnect()
|
|
24
34
|
// shutdown core clients
|
|
25
35
|
await redis.clients.shutdown()
|
|
26
36
|
console.log("Redis shutdown")
|
|
@@ -86,3 +96,10 @@ export async function checkTestFlag(id: string) {
|
|
|
86
96
|
export async function clearTestFlag(id: string) {
|
|
87
97
|
await devAppClient.delete(id)
|
|
88
98
|
}
|
|
99
|
+
|
|
100
|
+
export function getSocketPubSubClients() {
|
|
101
|
+
return {
|
|
102
|
+
pub: socketClient.getClient(),
|
|
103
|
+
sub: socketSubClient,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import authorized from "../middleware/authorized"
|
|
2
|
+
import Socket from "./websocket"
|
|
3
|
+
import { permissions } from "@budibase/backend-core"
|
|
4
|
+
import http from "http"
|
|
5
|
+
import Koa from "koa"
|
|
6
|
+
import { Datasource, Table } from "@budibase/types"
|
|
7
|
+
import { gridSocket } from "./index"
|
|
8
|
+
import { clearLock } from "../utilities/redis"
|
|
9
|
+
|
|
10
|
+
export default class BuilderSocket extends Socket {
|
|
11
|
+
constructor(app: Koa, server: http.Server) {
|
|
12
|
+
super(app, server, "/socket/builder", [authorized(permissions.BUILDER)])
|
|
13
|
+
|
|
14
|
+
this.io.on("connection", socket => {
|
|
15
|
+
// Join a room for this app
|
|
16
|
+
const user = socket.data.user
|
|
17
|
+
const appId = socket.data.appId
|
|
18
|
+
socket.join(appId)
|
|
19
|
+
socket.to(appId).emit("user-update", user)
|
|
20
|
+
|
|
21
|
+
// Initial identification of connected spreadsheet
|
|
22
|
+
socket.on("get-users", async (payload, callback) => {
|
|
23
|
+
const sockets = await this.io.in(appId).fetchSockets()
|
|
24
|
+
callback({
|
|
25
|
+
users: sockets.map(socket => socket.data.user),
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// Disconnection cleanup
|
|
30
|
+
socket.on("disconnect", async () => {
|
|
31
|
+
socket.to(appId).emit("user-disconnect", user)
|
|
32
|
+
|
|
33
|
+
// Remove app lock from this user if they have no other connections
|
|
34
|
+
try {
|
|
35
|
+
const sockets = await this.io.in(appId).fetchSockets()
|
|
36
|
+
const hasOtherConnection = sockets.some(socket => {
|
|
37
|
+
const { _id, sessionId } = socket.data.user
|
|
38
|
+
return _id === user._id && sessionId !== user.sessionId
|
|
39
|
+
})
|
|
40
|
+
if (!hasOtherConnection) {
|
|
41
|
+
await clearLock(appId, user)
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// This is fine, just means this user didn't hold the lock
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
emitTableUpdate(ctx: any, table: Table) {
|
|
51
|
+
this.io.in(ctx.appId).emit("table-change", { id: table._id, table })
|
|
52
|
+
gridSocket.emitTableUpdate(table)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
emitTableDeletion(ctx: any, id: string) {
|
|
56
|
+
this.io.in(ctx.appId).emit("table-change", { id, table: null })
|
|
57
|
+
gridSocket.emitTableDeletion(id)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
emitDatasourceUpdate(ctx: any, datasource: Datasource) {
|
|
61
|
+
this.io
|
|
62
|
+
.in(ctx.appId)
|
|
63
|
+
.emit("datasource-change", { id: datasource._id, datasource })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
emitDatasourceDeletion(ctx: any, id: string) {
|
|
67
|
+
this.io.in(ctx.appId).emit("datasource-change", { id, datasource: null })
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/websockets/grid.ts
CHANGED
|
@@ -3,6 +3,8 @@ import Socket from "./websocket"
|
|
|
3
3
|
import { permissions } from "@budibase/backend-core"
|
|
4
4
|
import http from "http"
|
|
5
5
|
import Koa from "koa"
|
|
6
|
+
import { getTableId } from "../api/controllers/row/utils"
|
|
7
|
+
import { Row, Table } from "@budibase/types"
|
|
6
8
|
|
|
7
9
|
export default class GridSocket extends Socket {
|
|
8
10
|
constructor(app: Koa, server: http.Server) {
|
|
@@ -10,7 +12,6 @@ export default class GridSocket extends Socket {
|
|
|
10
12
|
|
|
11
13
|
this.io.on("connection", socket => {
|
|
12
14
|
const user = socket.data.user
|
|
13
|
-
console.log(`Spreadsheet user connected: ${user?.id}`)
|
|
14
15
|
|
|
15
16
|
// Socket state
|
|
16
17
|
let currentRoom: string
|
|
@@ -19,37 +20,54 @@ export default class GridSocket extends Socket {
|
|
|
19
20
|
socket.on("select-table", async (tableId, callback) => {
|
|
20
21
|
// Leave current room
|
|
21
22
|
if (currentRoom) {
|
|
22
|
-
socket.to(currentRoom).emit("user-disconnect",
|
|
23
|
+
socket.to(currentRoom).emit("user-disconnect", user)
|
|
23
24
|
socket.leave(currentRoom)
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
// Join new room
|
|
27
28
|
currentRoom = tableId
|
|
28
29
|
socket.join(currentRoom)
|
|
29
|
-
socket.to(currentRoom).emit("user-update",
|
|
30
|
+
socket.to(currentRoom).emit("user-update", user)
|
|
30
31
|
|
|
31
32
|
// Reply with all users in current room
|
|
32
33
|
const sockets = await this.io.in(currentRoom).fetchSockets()
|
|
33
34
|
callback({
|
|
34
35
|
users: sockets.map(socket => socket.data.user),
|
|
35
|
-
id: user.id,
|
|
36
36
|
})
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
// Handle users selecting a new cell
|
|
40
40
|
socket.on("select-cell", cellId => {
|
|
41
|
-
socket.data.user.
|
|
41
|
+
socket.data.user.focusedCellId = cellId
|
|
42
42
|
if (currentRoom) {
|
|
43
|
-
socket.to(currentRoom).emit("user-update",
|
|
43
|
+
socket.to(currentRoom).emit("user-update", user)
|
|
44
44
|
}
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
// Disconnection cleanup
|
|
48
48
|
socket.on("disconnect", () => {
|
|
49
49
|
if (currentRoom) {
|
|
50
|
-
socket.to(currentRoom).emit("user-disconnect",
|
|
50
|
+
socket.to(currentRoom).emit("user-disconnect", user)
|
|
51
51
|
}
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
54
|
}
|
|
55
|
+
|
|
56
|
+
emitRowUpdate(ctx: any, row: Row) {
|
|
57
|
+
const tableId = getTableId(ctx)
|
|
58
|
+
this.io.in(tableId).emit("row-change", { id: row._id, row })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
emitRowDeletion(ctx: any, id: string) {
|
|
62
|
+
const tableId = getTableId(ctx)
|
|
63
|
+
this.io.in(tableId).emit("row-change", { id, row: null })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
emitTableUpdate(table: Table) {
|
|
67
|
+
this.io.in(table._id!).emit("table-change", { id: table._id, table })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
emitTableDeletion(id: string) {
|
|
71
|
+
this.io.in(id).emit("table-change", { id, table: null })
|
|
72
|
+
}
|
|
55
73
|
}
|
package/src/websockets/index.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import http from "http"
|
|
2
2
|
import Koa from "koa"
|
|
3
|
-
import GridSocket from "./grid"
|
|
4
3
|
import ClientAppSocket from "./client"
|
|
4
|
+
import GridSocket from "./grid"
|
|
5
|
+
import BuilderSocket from "./builder"
|
|
5
6
|
|
|
6
7
|
let clientAppSocket: ClientAppSocket
|
|
7
8
|
let gridSocket: GridSocket
|
|
9
|
+
let builderSocket: BuilderSocket
|
|
8
10
|
|
|
9
11
|
export const initialise = (app: Koa, server: http.Server) => {
|
|
10
12
|
clientAppSocket = new ClientAppSocket(app, server)
|
|
11
13
|
gridSocket = new GridSocket(app, server)
|
|
14
|
+
builderSocket = new BuilderSocket(app, server)
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
export { clientAppSocket, gridSocket }
|
|
17
|
+
export { clientAppSocket, gridSocket, builderSocket }
|
|
@@ -5,6 +5,9 @@ import Cookies from "cookies"
|
|
|
5
5
|
import { userAgent } from "koa-useragent"
|
|
6
6
|
import { auth } from "@budibase/backend-core"
|
|
7
7
|
import currentApp from "../middleware/currentapp"
|
|
8
|
+
import { createAdapter } from "@socket.io/redis-adapter"
|
|
9
|
+
import { getSocketPubSubClients } from "../utilities/redis"
|
|
10
|
+
import uuid from "uuid"
|
|
8
11
|
|
|
9
12
|
export default class Socket {
|
|
10
13
|
io: Server
|
|
@@ -12,7 +15,7 @@ export default class Socket {
|
|
|
12
15
|
constructor(
|
|
13
16
|
app: Koa,
|
|
14
17
|
server: http.Server,
|
|
15
|
-
path: string,
|
|
18
|
+
path: string = "/",
|
|
16
19
|
additionalMiddlewares?: any[]
|
|
17
20
|
) {
|
|
18
21
|
this.io = new Server(server, {
|
|
@@ -59,13 +62,21 @@ export default class Socket {
|
|
|
59
62
|
for (let [idx, middleware] of middlewares.entries()) {
|
|
60
63
|
await middleware(ctx, () => {
|
|
61
64
|
if (idx === middlewares.length - 1) {
|
|
62
|
-
// Middlewares are finished
|
|
65
|
+
// Middlewares are finished
|
|
63
66
|
// Extract some data from our enriched koa context to persist
|
|
64
67
|
// as metadata for the socket
|
|
68
|
+
// Add user info, including a deterministic color and label
|
|
69
|
+
const { _id, email, firstName, lastName } = ctx.user
|
|
65
70
|
socket.data.user = {
|
|
66
|
-
|
|
67
|
-
email
|
|
71
|
+
_id,
|
|
72
|
+
email,
|
|
73
|
+
firstName,
|
|
74
|
+
lastName,
|
|
75
|
+
sessionId: uuid.v4(),
|
|
68
76
|
}
|
|
77
|
+
|
|
78
|
+
// Add app ID to help split sockets into rooms
|
|
79
|
+
socket.data.appId = ctx.appId
|
|
69
80
|
next()
|
|
70
81
|
}
|
|
71
82
|
})
|
|
@@ -74,6 +85,11 @@ export default class Socket {
|
|
|
74
85
|
next(error)
|
|
75
86
|
}
|
|
76
87
|
})
|
|
88
|
+
|
|
89
|
+
// Instantiate redis adapter
|
|
90
|
+
const { pub, sub } = getSocketPubSubClients()
|
|
91
|
+
const opts = { key: `socket.io-${path}` }
|
|
92
|
+
this.io.adapter(createAdapter(pub, sub, opts))
|
|
77
93
|
}
|
|
78
94
|
|
|
79
95
|
// Emit an event to all sockets
|
package/tsconfig.build.json
CHANGED
|
@@ -10,7 +10,15 @@
|
|
|
10
10
|
"incremental": true,
|
|
11
11
|
"types": ["node", "jest"],
|
|
12
12
|
"outDir": "dist/src",
|
|
13
|
-
"skipLibCheck": true
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"baseUrl": ".",
|
|
15
|
+
"paths": {
|
|
16
|
+
"@budibase/types": ["../types/src"],
|
|
17
|
+
"@budibase/backend-core": ["../backend-core/src"],
|
|
18
|
+
"@budibase/backend-core/*": ["../backend-core/*"],
|
|
19
|
+
"@budibase/shared-core": ["../shared-core/src"],
|
|
20
|
+
"@budibase/pro": ["../pro/packages/pro/src"]
|
|
21
|
+
}
|
|
14
22
|
},
|
|
15
23
|
"include": ["src/**/*"],
|
|
16
24
|
"exclude": [
|
package/tsconfig.json
CHANGED
|
@@ -5,25 +5,12 @@
|
|
|
5
5
|
"declaration": true,
|
|
6
6
|
"sourceMap": true,
|
|
7
7
|
"baseUrl": ".",
|
|
8
|
-
"outDir": "dist"
|
|
9
|
-
"paths": {
|
|
10
|
-
"@budibase/types": ["../types/src"],
|
|
11
|
-
"@budibase/backend-core": ["../backend-core/src"],
|
|
12
|
-
"@budibase/backend-core/*": ["../backend-core/*"],
|
|
13
|
-
"@budibase/shared-core": ["../shared-core/src"],
|
|
14
|
-
"@budibase/pro": ["../pro/packages/pro/src"]
|
|
15
|
-
}
|
|
8
|
+
"outDir": "dist"
|
|
16
9
|
},
|
|
17
10
|
"ts-node": {
|
|
18
11
|
"require": ["tsconfig-paths/register"],
|
|
19
12
|
"swc": true
|
|
20
13
|
},
|
|
21
|
-
"references": [
|
|
22
|
-
{ "path": "../types" },
|
|
23
|
-
{ "path": "../backend-core" },
|
|
24
|
-
{ "path": "../shared-core" },
|
|
25
|
-
{ "path": "../../../budibase-pro/packages/pro" }
|
|
26
|
-
],
|
|
27
14
|
"include": ["src/**/*", "specs"],
|
|
28
15
|
"exclude": ["node_modules", "dist"]
|
|
29
16
|
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ping = exports.isEnabled = void 0;
|
|
13
|
-
const backend_core_1 = require("@budibase/backend-core");
|
|
14
|
-
const types_1 = require("@budibase/types");
|
|
15
|
-
const utils_1 = require("../../db/utils");
|
|
16
|
-
const backend_core_2 = require("@budibase/backend-core");
|
|
17
|
-
const isEnabled = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const enabled = yield backend_core_1.events.analytics.enabled();
|
|
19
|
-
ctx.body = {
|
|
20
|
-
enabled,
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
exports.isEnabled = isEnabled;
|
|
24
|
-
const ping = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const body = ctx.request.body;
|
|
26
|
-
switch (body.source) {
|
|
27
|
-
case types_1.PingSource.APP: {
|
|
28
|
-
const db = backend_core_2.context.getAppDB({ skip_setup: true });
|
|
29
|
-
const appInfo = yield db.get(utils_1.DocumentType.APP_METADATA);
|
|
30
|
-
let appId = backend_core_2.context.getAppId();
|
|
31
|
-
if ((0, utils_1.isDevAppID)(appId)) {
|
|
32
|
-
yield backend_core_1.events.serve.servedAppPreview(appInfo, body.timezone);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
yield backend_core_1.events.serve.servedApp(appInfo, body.timezone);
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
case types_1.PingSource.BUILDER: {
|
|
40
|
-
yield backend_core_1.events.serve.servedBuilder(body.timezone);
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
ctx.status = 200;
|
|
45
|
-
});
|
|
46
|
-
exports.ping = ping;
|