@budibase/server 2.5.6-alpha.2 → 2.5.6-alpha.20

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.
Files changed (112) hide show
  1. package/builder/assets/{index.80d32454.js → index.3eea26b2.js} +378 -362
  2. package/builder/assets/index.7ec21ee2.css +6 -0
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/automation.js +13 -7
  5. package/dist/api/controllers/plugin/index.js +6 -37
  6. package/dist/api/controllers/query/index.js +2 -2
  7. package/dist/api/controllers/table/utils.js +9 -3
  8. package/dist/api/routes/index.js +0 -2
  9. package/dist/app.js +2 -2
  10. package/dist/automations/actions.js +32 -6
  11. package/dist/automations/index.js +3 -2
  12. package/dist/automations/steps/bash.js +6 -6
  13. package/dist/automations/steps/createRow.js +11 -11
  14. package/dist/automations/steps/delay.js +3 -3
  15. package/dist/automations/steps/deleteRow.js +8 -8
  16. package/dist/automations/steps/discord.js +8 -8
  17. package/dist/automations/steps/executeQuery.js +9 -9
  18. package/dist/automations/steps/executeScript.js +6 -6
  19. package/dist/automations/steps/filter.js +6 -6
  20. package/dist/automations/steps/integromat.js +10 -10
  21. package/dist/automations/steps/loop.js +9 -9
  22. package/dist/automations/steps/outgoingWebhook.js +10 -10
  23. package/dist/automations/steps/queryRows.js +14 -14
  24. package/dist/automations/steps/sendSmtpEmail.js +9 -9
  25. package/dist/automations/steps/serverLog.js +4 -4
  26. package/dist/automations/steps/slack.js +6 -6
  27. package/dist/automations/steps/updateRow.js +11 -11
  28. package/dist/automations/steps/zapier.js +9 -9
  29. package/dist/automations/triggerInfo/app.js +5 -5
  30. package/dist/automations/triggerInfo/cron.js +4 -4
  31. package/dist/automations/triggerInfo/rowDeleted.js +5 -5
  32. package/dist/automations/triggerInfo/rowSaved.js +7 -7
  33. package/dist/automations/triggerInfo/rowUpdated.js +7 -7
  34. package/dist/automations/triggerInfo/webhook.js +6 -6
  35. package/dist/integrations/index.js +3 -3
  36. package/dist/migrations/functions/syncQuotas.js +2 -0
  37. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
  38. package/dist/migrations/functions/usageQuotas/syncUsers.js +21 -0
  39. package/dist/package.json +10 -9
  40. package/dist/sdk/app/backups/exports.js +1 -35
  41. package/dist/sdk/index.js +2 -0
  42. package/dist/{api/routes/cloud.js → sdk/plugins/index.js} +2 -14
  43. package/dist/sdk/plugins/plugins.js +53 -0
  44. package/dist/threads/automation.js +2 -2
  45. package/dist/tsconfig.build.tsbuildinfo +1 -1
  46. package/dist/utilities/fileSystem/plugin.js +33 -23
  47. package/dist/watch.js +2 -2
  48. package/dist/websockets/client.js +14 -0
  49. package/dist/websockets/grid.js +60 -0
  50. package/dist/websockets/index.js +17 -0
  51. package/dist/websockets/websocket.js +78 -0
  52. package/package.json +11 -10
  53. package/src/api/controllers/automation.ts +12 -6
  54. package/src/api/controllers/plugin/index.ts +8 -45
  55. package/src/api/controllers/query/index.ts +2 -2
  56. package/src/api/controllers/table/utils.ts +10 -3
  57. package/src/api/index.ts +0 -1
  58. package/src/api/routes/index.ts +0 -2
  59. package/src/api/routes/tests/automation.spec.js +2 -2
  60. package/src/app.ts +2 -2
  61. package/src/automations/actions.ts +56 -24
  62. package/src/automations/index.ts +1 -1
  63. package/src/automations/steps/bash.ts +10 -7
  64. package/src/automations/steps/createRow.ts +15 -12
  65. package/src/automations/steps/delay.ts +6 -4
  66. package/src/automations/steps/deleteRow.ts +12 -9
  67. package/src/automations/steps/discord.ts +10 -8
  68. package/src/automations/steps/executeQuery.ts +13 -10
  69. package/src/automations/steps/executeScript.ts +10 -7
  70. package/src/automations/steps/filter.ts +8 -6
  71. package/src/automations/steps/integromat.ts +12 -10
  72. package/src/automations/steps/loop.ts +16 -10
  73. package/src/automations/steps/outgoingWebhook.ts +14 -11
  74. package/src/automations/steps/queryRows.ts +18 -15
  75. package/src/automations/steps/sendSmtpEmail.ts +11 -9
  76. package/src/automations/steps/serverLog.ts +6 -4
  77. package/src/automations/steps/slack.ts +8 -6
  78. package/src/automations/steps/updateRow.ts +15 -12
  79. package/src/automations/steps/zapier.ts +11 -9
  80. package/src/automations/tests/utilities/index.ts +2 -2
  81. package/src/automations/triggerInfo/app.ts +8 -5
  82. package/src/automations/triggerInfo/cron.ts +7 -4
  83. package/src/automations/triggerInfo/rowDeleted.ts +8 -5
  84. package/src/automations/triggerInfo/rowSaved.ts +10 -7
  85. package/src/automations/triggerInfo/rowUpdated.ts +10 -7
  86. package/src/automations/triggerInfo/webhook.ts +9 -6
  87. package/src/integrations/index.ts +3 -3
  88. package/src/migrations/functions/syncQuotas.ts +2 -0
  89. package/src/migrations/functions/usageQuotas/syncApps.ts +1 -2
  90. package/src/migrations/functions/usageQuotas/syncUsers.ts +9 -0
  91. package/src/migrations/functions/usageQuotas/tests/syncUsers.spec.ts +26 -0
  92. package/src/migrations/index.ts +1 -0
  93. package/src/sdk/app/backups/exports.ts +0 -35
  94. package/src/sdk/index.ts +2 -0
  95. package/src/sdk/plugins/index.ts +5 -0
  96. package/src/sdk/plugins/plugins.ts +41 -0
  97. package/src/tests/utilities/structures.ts +25 -17
  98. package/src/threads/automation.ts +2 -2
  99. package/src/utilities/fileSystem/plugin.ts +13 -4
  100. package/src/watch.ts +2 -2
  101. package/src/websockets/client.ts +11 -0
  102. package/src/websockets/grid.ts +55 -0
  103. package/src/websockets/index.ts +14 -0
  104. package/src/websockets/websocket.ts +83 -0
  105. package/builder/assets/index.841e62d8.css +0 -6
  106. package/dist/api/controllers/cloud.js +0 -130
  107. package/dist/websocket.js +0 -22
  108. package/src/api/controllers/cloud.ts +0 -119
  109. package/src/api/routes/cloud.ts +0 -18
  110. package/src/api/routes/tests/cloud.spec.ts +0 -54
  111. package/src/migrations/functions/tests/syncQuotas.spec.js +0 -26
  112. package/src/websocket.ts +0 -26
@@ -1,130 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.importApps = exports.hasBeenImported = exports.exportApps = void 0;
16
- const environment_1 = __importDefault(require("../../environment"));
17
- const backend_core_1 = require("@budibase/backend-core");
18
- const fileSystem_1 = require("../../utilities/fileSystem");
19
- const utilities_1 = require("../../utilities");
20
- const utils_1 = require("../../db/utils");
21
- const application_1 = require("./application");
22
- const path_1 = require("path");
23
- const sdk_1 = __importDefault(require("../../sdk"));
24
- function createApp(appName, appDirectory) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const ctx = {
27
- request: {
28
- body: {
29
- useTemplate: true,
30
- name: appName,
31
- },
32
- files: {
33
- templateFile: {
34
- path: appDirectory,
35
- },
36
- },
37
- },
38
- };
39
- // @ts-ignore
40
- return (0, application_1.create)(ctx);
41
- });
42
- }
43
- function getAllDocType(db, docType) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const response = yield db.allDocs((0, utils_1.getDocParams)(docType, null, {
46
- include_docs: true,
47
- }));
48
- return response.rows.map(row => row.doc);
49
- });
50
- }
51
- function exportApps(ctx) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- if (environment_1.default.SELF_HOSTED || !environment_1.default.MULTI_TENANCY) {
54
- ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.");
55
- }
56
- const apps = (yield backend_core_1.db.getAllApps({ all: true }));
57
- const globalDBString = yield sdk_1.default.backups.exportDB(backend_core_1.db.getGlobalDBName(), {
58
- filter: (doc) => !doc._id.startsWith(utils_1.DocumentType.USER),
59
- });
60
- // only export the dev apps as they will be the latest, the user can republish the apps
61
- // in their self-hosted environment
62
- let appMetadata = apps
63
- .filter((app) => (0, utils_1.isDevAppID)(app.appId || app._id))
64
- .map((app) => ({ appId: (app.appId || app._id), name: app.name }));
65
- const tmpPath = yield sdk_1.default.backups.exportMultipleApps(appMetadata, globalDBString);
66
- const filename = `cloud-export-${new Date().getTime()}.tar.gz`;
67
- ctx.attachment(filename);
68
- ctx.body = (0, fileSystem_1.streamFile)(tmpPath);
69
- });
70
- }
71
- exports.exportApps = exportApps;
72
- function checkHasBeenImported() {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- if (!environment_1.default.SELF_HOSTED) {
75
- return true;
76
- }
77
- const apps = yield backend_core_1.db.getAllApps({ all: true });
78
- return apps.length !== 0;
79
- });
80
- }
81
- function hasBeenImported(ctx) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- ctx.body = {
84
- imported: yield checkHasBeenImported(),
85
- };
86
- });
87
- }
88
- exports.hasBeenImported = hasBeenImported;
89
- function importApps(ctx) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- if (!environment_1.default.SELF_HOSTED) {
92
- ctx.throw(400, "Importing only allowed in self hosted environments.");
93
- }
94
- const beenImported = yield checkHasBeenImported();
95
- if (beenImported || !ctx.request.files || !ctx.request.files.importFile) {
96
- ctx.throw(400, "Import file is required and environment must be fresh to import apps.");
97
- }
98
- const file = ctx.request.files.importFile;
99
- if (Array.isArray(file)) {
100
- ctx.throw(400, "Single file is required");
101
- }
102
- if (file.type !== "application/gzip" && file.type !== "application/x-gzip") {
103
- ctx.throw(400, "Import file must be a gzipped tarball.");
104
- }
105
- // initially get all the app databases out of the tarball
106
- const tmpPath = sdk_1.default.backups.untarFile(file);
107
- const globalDbImport = sdk_1.default.backups.getGlobalDBFile(tmpPath);
108
- const appNames = sdk_1.default.backups.getListOfAppsInMulti(tmpPath);
109
- const globalDb = backend_core_1.tenancy.getGlobalDB();
110
- // load the global db first
111
- yield globalDb.load((0, utilities_1.stringToReadStream)(globalDbImport));
112
- for (let appName of appNames) {
113
- yield createApp(appName, (0, path_1.join)(tmpPath, appName));
114
- }
115
- // if there are any users make sure to remove them
116
- let users = yield getAllDocType(globalDb, utils_1.DocumentType.USER);
117
- let userDeletionPromises = [];
118
- for (let user of users) {
119
- userDeletionPromises.push(globalDb.remove(user._id, user._rev));
120
- }
121
- if (userDeletionPromises.length > 0) {
122
- yield Promise.all(userDeletionPromises);
123
- }
124
- yield globalDb.bulkDocs(users);
125
- ctx.body = {
126
- message: "Apps successfully imported.",
127
- };
128
- });
129
- }
130
- exports.importApps = importApps;
package/dist/websocket.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClientAppSocket = exports.initialise = void 0;
4
- const socket_io_1 = require("socket.io");
5
- class Websocket {
6
- constructor(server, path) {
7
- this.socketServer = new socket_io_1.Server(server, {
8
- path,
9
- });
10
- }
11
- // Emit an event to all sockets
12
- emit(event, payload) {
13
- this.socketServer.sockets.emit(event, payload);
14
- }
15
- }
16
- // Likely to be more socket instances in future
17
- let ClientAppSocket;
18
- exports.ClientAppSocket = ClientAppSocket;
19
- const initialise = (server) => {
20
- exports.ClientAppSocket = ClientAppSocket = new Websocket(server, "/socket/client");
21
- };
22
- exports.initialise = initialise;
@@ -1,119 +0,0 @@
1
- import env from "../../environment"
2
- import { db as dbCore, tenancy } from "@budibase/backend-core"
3
- import { streamFile } from "../../utilities/fileSystem"
4
- import { stringToReadStream } from "../../utilities"
5
- import { getDocParams, DocumentType, isDevAppID } from "../../db/utils"
6
- import { create } from "./application"
7
- import { join } from "path"
8
- import sdk from "../../sdk"
9
- import { App, Ctx, Database } from "@budibase/types"
10
-
11
- async function createApp(appName: string, appDirectory: string) {
12
- const ctx = {
13
- request: {
14
- body: {
15
- useTemplate: true,
16
- name: appName,
17
- },
18
- files: {
19
- templateFile: {
20
- path: appDirectory,
21
- },
22
- },
23
- },
24
- }
25
- // @ts-ignore
26
- return create(ctx)
27
- }
28
-
29
- async function getAllDocType(db: Database, docType: string) {
30
- const response = await db.allDocs(
31
- getDocParams(docType, null, {
32
- include_docs: true,
33
- })
34
- )
35
- return response.rows.map(row => row.doc)
36
- }
37
-
38
- export async function exportApps(ctx: Ctx) {
39
- if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
40
- ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.")
41
- }
42
- const apps = (await dbCore.getAllApps({ all: true })) as App[]
43
- const globalDBString = await sdk.backups.exportDB(dbCore.getGlobalDBName(), {
44
- filter: (doc: any) => !doc._id.startsWith(DocumentType.USER),
45
- })
46
- // only export the dev apps as they will be the latest, the user can republish the apps
47
- // in their self-hosted environment
48
- let appMetadata = apps
49
- .filter((app: App) => isDevAppID(app.appId || app._id))
50
- .map((app: App) => ({ appId: (app.appId || app._id)!, name: app.name }))
51
- const tmpPath = await sdk.backups.exportMultipleApps(
52
- appMetadata,
53
- globalDBString
54
- )
55
- const filename = `cloud-export-${new Date().getTime()}.tar.gz`
56
- ctx.attachment(filename)
57
- ctx.body = streamFile(tmpPath)
58
- }
59
-
60
- async function checkHasBeenImported() {
61
- if (!env.SELF_HOSTED) {
62
- return true
63
- }
64
- const apps = await dbCore.getAllApps({ all: true })
65
- return apps.length !== 0
66
- }
67
-
68
- export async function hasBeenImported(ctx: Ctx) {
69
- ctx.body = {
70
- imported: await checkHasBeenImported(),
71
- }
72
- }
73
-
74
- export async function importApps(ctx: Ctx) {
75
- if (!env.SELF_HOSTED) {
76
- ctx.throw(400, "Importing only allowed in self hosted environments.")
77
- }
78
- const beenImported = await checkHasBeenImported()
79
- if (beenImported || !ctx.request.files || !ctx.request.files.importFile) {
80
- ctx.throw(
81
- 400,
82
- "Import file is required and environment must be fresh to import apps."
83
- )
84
- }
85
- const file = ctx.request.files.importFile as any
86
- if (Array.isArray(file)) {
87
- ctx.throw(400, "Single file is required")
88
- }
89
- if (file.type !== "application/gzip" && file.type !== "application/x-gzip") {
90
- ctx.throw(400, "Import file must be a gzipped tarball.")
91
- }
92
-
93
- // initially get all the app databases out of the tarball
94
- const tmpPath = sdk.backups.untarFile(file)
95
- const globalDbImport = sdk.backups.getGlobalDBFile(tmpPath)
96
- const appNames = sdk.backups.getListOfAppsInMulti(tmpPath)
97
-
98
- const globalDb = tenancy.getGlobalDB()
99
- // load the global db first
100
- await globalDb.load(stringToReadStream(globalDbImport))
101
- for (let appName of appNames) {
102
- await createApp(appName, join(tmpPath, appName))
103
- }
104
-
105
- // if there are any users make sure to remove them
106
- let users = await getAllDocType(globalDb, DocumentType.USER)
107
- let userDeletionPromises = []
108
- for (let user of users) {
109
- userDeletionPromises.push(globalDb.remove(user._id, user._rev))
110
- }
111
- if (userDeletionPromises.length > 0) {
112
- await Promise.all(userDeletionPromises)
113
- }
114
-
115
- await globalDb.bulkDocs(users)
116
- ctx.body = {
117
- message: "Apps successfully imported.",
118
- }
119
- }
@@ -1,18 +0,0 @@
1
- import Router from "@koa/router"
2
- import * as controller from "../controllers/cloud"
3
- import authorized from "../../middleware/authorized"
4
- import { permissions } from "@budibase/backend-core"
5
-
6
- const router: Router = new Router()
7
-
8
- router
9
- .get(
10
- "/api/cloud/export",
11
- authorized(permissions.BUILDER),
12
- controller.exportApps
13
- )
14
- // has to be public, only run if apps don't exist
15
- .post("/api/cloud/import", controller.importApps)
16
- .get("/api/cloud/import/complete", controller.hasBeenImported)
17
-
18
- export default router
@@ -1,54 +0,0 @@
1
- import { App } from "@budibase/types"
2
-
3
- jest.setTimeout(30000)
4
-
5
- import { AppStatus } from "../../../db/utils"
6
-
7
- import * as setup from "./utilities"
8
-
9
- import { wipeDb } from "./utilities/TestFunctions"
10
- import { tenancy } from "@budibase/backend-core"
11
-
12
- describe("/cloud", () => {
13
- let request = setup.getRequest()!
14
- let config = setup.getConfig()
15
-
16
- afterAll(setup.afterAll)
17
-
18
- beforeAll(async () => {
19
- // Importing is only allowed in self hosted environments
20
- await config.init()
21
- config.modeSelf()
22
- })
23
-
24
- describe("import", () => {
25
- it("should be able to import apps", async () => {
26
- // first we need to delete any existing apps on the system so it looks clean otherwise the
27
- // import will not run
28
- await wipeDb()
29
-
30
- // Perform the import
31
- const res = await request
32
- .post(`/api/cloud/import`)
33
- .set(config.publicHeaders())
34
- .attach("importFile", "src/api/routes/tests/data/export-test.tar.gz")
35
- .expect(200)
36
- expect(res.body.message).toEqual("Apps successfully imported.")
37
-
38
- // get a count of apps after the import
39
- const postImportApps = await request
40
- .get(`/api/applications?status=${AppStatus.ALL}`)
41
- .set(config.publicHeaders())
42
- .expect("Content-Type", /json/)
43
- .expect(200)
44
-
45
- const apps = postImportApps.body as App[]
46
- // There are two apps in the file that was imported so check for this
47
- expect(apps.length).toEqual(2)
48
- // The new tenant id was assigned to the imported apps
49
- expect(tenancy.getTenantIDFromAppID(apps[0].appId)).toBe(
50
- config.getTenantId()
51
- )
52
- })
53
- })
54
- })
@@ -1,26 +0,0 @@
1
- const syncApps = jest.fn()
2
- const syncRows = jest.fn()
3
- const syncPlugins = jest.fn()
4
- jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
5
- jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
6
- jest.mock("../usageQuotas/syncPlugins", () => ({ run: syncPlugins }) )
7
-
8
- const TestConfig = require("../../../tests/utilities/TestConfiguration")
9
- const migration = require("../syncQuotas")
10
-
11
- describe("run", () => {
12
- let config = new TestConfig(false)
13
-
14
- beforeAll(async () => {
15
- await config.init()
16
- })
17
-
18
- afterAll(config.end)
19
-
20
- it("run", async () => {
21
- await migration.run()
22
- expect(syncApps).toHaveBeenCalledTimes(1)
23
- expect(syncRows).toHaveBeenCalledTimes(1)
24
- expect(syncPlugins).toHaveBeenCalledTimes(1)
25
- })
26
- })
package/src/websocket.ts DELETED
@@ -1,26 +0,0 @@
1
- import { Server } from "socket.io"
2
- import http from "http"
3
-
4
- class Websocket {
5
- socketServer: Server
6
-
7
- constructor(server: http.Server, path: string) {
8
- this.socketServer = new Server(server, {
9
- path,
10
- })
11
- }
12
-
13
- // Emit an event to all sockets
14
- emit(event: string, payload: any) {
15
- this.socketServer.sockets.emit(event, payload)
16
- }
17
- }
18
-
19
- // Likely to be more socket instances in future
20
- let ClientAppSocket: Websocket
21
-
22
- export const initialise = (server: http.Server) => {
23
- ClientAppSocket = new Websocket(server, "/socket/client")
24
- }
25
-
26
- export { ClientAppSocket }