@budibase/server 2.5.9 → 2.5.10-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/builder/assets/index.24635afb.js +1794 -0
  2. package/builder/assets/index.4eae16b2.css +6 -0
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/application.js +3 -4
  5. package/dist/api/controllers/automation.js +13 -7
  6. package/dist/api/controllers/datasource.js +1 -1
  7. package/dist/api/controllers/dev.js +1 -1
  8. package/dist/api/controllers/ops.js +40 -0
  9. package/dist/api/controllers/plugin/index.js +6 -37
  10. package/dist/api/controllers/query/index.js +2 -2
  11. package/dist/api/controllers/row/ExternalRequest.js +21 -14
  12. package/dist/api/controllers/table/utils.js +9 -3
  13. package/dist/api/controllers/user.js +1 -83
  14. package/dist/api/index.js +1 -2
  15. package/dist/api/routes/index.js +2 -2
  16. package/dist/api/routes/{cloud.js → ops.js} +19 -6
  17. package/dist/api/routes/user.js +0 -1
  18. package/dist/app.js +4 -13
  19. package/dist/automations/actions.js +32 -6
  20. package/dist/automations/index.js +3 -2
  21. package/dist/automations/steps/bash.js +6 -6
  22. package/dist/automations/steps/createRow.js +11 -11
  23. package/dist/automations/steps/delay.js +3 -3
  24. package/dist/automations/steps/deleteRow.js +8 -8
  25. package/dist/automations/steps/discord.js +8 -8
  26. package/dist/automations/steps/executeQuery.js +9 -9
  27. package/dist/automations/steps/executeScript.js +6 -6
  28. package/dist/automations/steps/filter.js +6 -6
  29. package/dist/automations/steps/integromat.js +10 -10
  30. package/dist/automations/steps/loop.js +9 -9
  31. package/dist/automations/steps/outgoingWebhook.js +10 -10
  32. package/dist/automations/steps/queryRows.js +14 -14
  33. package/dist/automations/steps/sendSmtpEmail.js +9 -9
  34. package/dist/automations/steps/serverLog.js +4 -4
  35. package/dist/automations/steps/slack.js +6 -6
  36. package/dist/automations/steps/updateRow.js +11 -11
  37. package/dist/automations/steps/zapier.js +9 -9
  38. package/dist/automations/triggerInfo/app.js +5 -5
  39. package/dist/automations/triggerInfo/cron.js +4 -4
  40. package/dist/automations/triggerInfo/rowDeleted.js +5 -5
  41. package/dist/automations/triggerInfo/rowSaved.js +7 -7
  42. package/dist/automations/triggerInfo/rowUpdated.js +7 -7
  43. package/dist/automations/triggerInfo/webhook.js +6 -6
  44. package/dist/db/utils.js +3 -2
  45. package/dist/environment.js +0 -1
  46. package/dist/events/docUpdates/index.js +17 -0
  47. package/dist/events/docUpdates/processors.js +18 -0
  48. package/dist/events/docUpdates/syncUsers.js +49 -0
  49. package/dist/events/index.js +3 -0
  50. package/dist/integrations/base/sqlTable.js +9 -2
  51. package/dist/integrations/index.js +3 -3
  52. package/dist/integrations/microsoftSqlServer.js +5 -2
  53. package/dist/integrations/mysql.js +5 -3
  54. package/dist/integrations/postgres.js +7 -5
  55. package/dist/integrations/redis.js +7 -0
  56. package/dist/integrations/rest.js +4 -0
  57. package/dist/migrations/functions/syncQuotas.js +2 -0
  58. package/dist/migrations/functions/usageQuotas/syncApps.js +1 -2
  59. package/dist/migrations/functions/usageQuotas/syncRows.js +1 -2
  60. package/dist/migrations/functions/usageQuotas/syncUsers.js +21 -0
  61. package/dist/sdk/app/applications/sync.js +117 -23
  62. package/dist/sdk/app/backups/exports.js +14 -38
  63. package/dist/sdk/index.js +2 -0
  64. package/dist/sdk/plugins/index.js +27 -0
  65. package/dist/sdk/plugins/plugins.js +53 -0
  66. package/dist/sdk/users/utils.js +21 -4
  67. package/dist/startup.js +31 -28
  68. package/dist/threads/automation.js +16 -5
  69. package/dist/tsconfig.build.tsbuildinfo +1 -1
  70. package/dist/utilities/fileSystem/plugin.js +33 -23
  71. package/dist/utilities/global.js +17 -12
  72. package/dist/utilities/rowProcessor/utils.js +4 -5
  73. package/dist/watch.js +2 -2
  74. package/dist/websockets/client.js +14 -0
  75. package/dist/websockets/grid.js +60 -0
  76. package/dist/websockets/index.js +17 -0
  77. package/dist/websockets/websocket.js +78 -0
  78. package/package.json +16 -16
  79. package/scripts/dev/manage.js +2 -0
  80. package/scripts/integrations/mssql/data/entrypoint.sh +1 -0
  81. package/scripts/integrations/mssql/data/setup.sql +17 -17
  82. package/scripts/integrations/mysql/init.sql +1 -1
  83. package/scripts/integrations/postgres/init.sql +1 -0
  84. package/src/api/controllers/application.ts +4 -4
  85. package/src/api/controllers/automation.ts +12 -6
  86. package/src/api/controllers/datasource.ts +15 -5
  87. package/src/api/controllers/dev.ts +2 -2
  88. package/src/api/controllers/ops.ts +32 -0
  89. package/src/api/controllers/plugin/index.ts +8 -45
  90. package/src/api/controllers/query/index.ts +2 -2
  91. package/src/api/controllers/row/ExternalRequest.ts +21 -12
  92. package/src/api/controllers/row/internal.ts +9 -10
  93. package/src/api/controllers/row/utils.ts +2 -2
  94. package/src/api/controllers/table/utils.ts +10 -3
  95. package/src/api/controllers/user.ts +10 -96
  96. package/src/api/index.ts +2 -4
  97. package/src/api/routes/index.ts +2 -2
  98. package/src/api/routes/ops.ts +30 -0
  99. package/src/api/routes/tests/automation.spec.js +7 -4
  100. package/src/api/routes/tests/user.spec.js +48 -37
  101. package/src/api/routes/user.ts +0 -5
  102. package/src/app.ts +4 -15
  103. package/src/automations/actions.ts +56 -24
  104. package/src/automations/index.ts +1 -1
  105. package/src/automations/steps/bash.ts +10 -7
  106. package/src/automations/steps/createRow.ts +15 -12
  107. package/src/automations/steps/delay.ts +6 -4
  108. package/src/automations/steps/deleteRow.ts +12 -9
  109. package/src/automations/steps/discord.ts +10 -8
  110. package/src/automations/steps/executeQuery.ts +13 -10
  111. package/src/automations/steps/executeScript.ts +10 -7
  112. package/src/automations/steps/filter.ts +8 -6
  113. package/src/automations/steps/integromat.ts +12 -10
  114. package/src/automations/steps/loop.ts +16 -10
  115. package/src/automations/steps/outgoingWebhook.ts +14 -11
  116. package/src/automations/steps/queryRows.ts +18 -15
  117. package/src/automations/steps/sendSmtpEmail.ts +11 -9
  118. package/src/automations/steps/serverLog.ts +6 -4
  119. package/src/automations/steps/slack.ts +8 -6
  120. package/src/automations/steps/updateRow.ts +15 -12
  121. package/src/automations/steps/zapier.ts +11 -9
  122. package/src/automations/tests/utilities/index.ts +2 -2
  123. package/src/automations/triggerInfo/app.ts +8 -5
  124. package/src/automations/triggerInfo/cron.ts +7 -4
  125. package/src/automations/triggerInfo/rowDeleted.ts +8 -5
  126. package/src/automations/triggerInfo/rowSaved.ts +10 -7
  127. package/src/automations/triggerInfo/rowUpdated.ts +10 -7
  128. package/src/automations/triggerInfo/webhook.ts +9 -6
  129. package/src/db/utils.ts +1 -0
  130. package/src/environment.ts +0 -1
  131. package/src/events/docUpdates/index.ts +1 -0
  132. package/src/events/docUpdates/processors.ts +14 -0
  133. package/src/events/docUpdates/syncUsers.ts +35 -0
  134. package/src/events/index.ts +1 -0
  135. package/src/integration-test/postgres.spec.ts +3 -1
  136. package/src/integrations/base/sqlTable.ts +9 -2
  137. package/src/integrations/index.ts +3 -3
  138. package/src/integrations/microsoftSqlServer.ts +5 -2
  139. package/src/integrations/mysql.ts +5 -3
  140. package/src/integrations/postgres.ts +7 -5
  141. package/src/integrations/redis.ts +8 -0
  142. package/src/integrations/rest.ts +3 -0
  143. package/src/migrations/functions/syncQuotas.ts +2 -0
  144. package/src/migrations/functions/usageQuotas/syncApps.ts +2 -3
  145. package/src/migrations/functions/usageQuotas/syncRows.ts +2 -3
  146. package/src/migrations/functions/usageQuotas/syncUsers.ts +9 -0
  147. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +2 -2
  148. package/src/migrations/functions/usageQuotas/tests/syncUsers.spec.ts +26 -0
  149. package/src/migrations/index.ts +1 -0
  150. package/src/sdk/app/applications/sync.ts +129 -22
  151. package/src/sdk/app/applications/tests/sync.spec.ts +137 -0
  152. package/src/sdk/app/backups/exports.ts +17 -41
  153. package/src/sdk/index.ts +2 -0
  154. package/src/sdk/plugins/index.ts +5 -0
  155. package/src/sdk/plugins/plugins.ts +41 -0
  156. package/src/sdk/users/tests/utils.spec.ts +1 -32
  157. package/src/sdk/users/utils.ts +23 -5
  158. package/src/startup.ts +36 -34
  159. package/src/tests/jestEnv.ts +0 -1
  160. package/src/tests/jestSetup.ts +0 -1
  161. package/src/tests/utilities/TestConfiguration.ts +28 -0
  162. package/src/tests/utilities/structures.ts +25 -17
  163. package/src/threads/automation.ts +18 -6
  164. package/src/utilities/fileSystem/plugin.ts +13 -4
  165. package/src/utilities/global.ts +21 -16
  166. package/src/utilities/rowProcessor/utils.ts +9 -10
  167. package/src/watch.ts +2 -2
  168. package/src/websockets/client.ts +11 -0
  169. package/src/websockets/grid.ts +55 -0
  170. package/src/websockets/index.ts +14 -0
  171. package/src/websockets/websocket.ts +83 -0
  172. package/tsconfig.build.json +3 -5
  173. package/tsconfig.json +2 -1
  174. package/builder/assets/index.0b358332.js +0 -1817
  175. package/builder/assets/index.7f9a008b.css +0 -6
  176. package/dist/api/controllers/cloud.js +0 -130
  177. package/dist/elasticApm.js +0 -14
  178. package/dist/package.json +0 -180
  179. package/dist/websocket.js +0 -22
  180. package/scripts/likeCypress.ts +0 -35
  181. package/src/api/controllers/cloud.ts +0 -119
  182. package/src/api/routes/cloud.ts +0 -18
  183. package/src/api/routes/tests/cloud.spec.ts +0 -54
  184. package/src/elasticApm.ts +0 -10
  185. package/src/migrations/functions/tests/syncQuotas.spec.js +0 -26
  186. package/src/tests/logging.ts +0 -34
  187. 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;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const elastic_apm_node_1 = __importDefault(require("elastic-apm-node"));
7
- // enable APM if configured
8
- if (process.env.ELASTIC_APM_ENABLED) {
9
- console.log("Starting elastic-apm-node");
10
- elastic_apm_node_1.default.start({
11
- serviceName: process.env.SERVICE,
12
- environment: process.env.BUDIBASE_ENVIRONMENT,
13
- });
14
- }
package/dist/package.json DELETED
@@ -1,180 +0,0 @@
1
- {
2
- "name": "@budibase/server",
3
- "email": "hi@budibase.com",
4
- "version": "2.5.8",
5
- "description": "Budibase Web Server",
6
- "main": "src/index.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/Budibase/budibase.git"
10
- },
11
- "scripts": {
12
- "prebuild": "rimraf dist/",
13
- "build": "tsc -p tsconfig.build.json && mv dist/src/* dist/ && rimraf dist/src/",
14
- "build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
15
- "debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js",
16
- "postbuild": "copyfiles -u 1 src/**/*.svelte dist/ && copyfiles -u 1 src/**/*.hbs dist/ && copyfiles -u 1 src/**/*.json dist/",
17
- "test": "bash scripts/test.sh",
18
- "test:memory": "jest --maxWorkers=2 --logHeapUsage --forceExit",
19
- "test:watch": "jest --watch",
20
- "predocker": "copyfiles -f ../client/dist/budibase-client.js ../client/manifest.json client",
21
- "build:docker": "yarn run predocker && docker build . -t app-service --label version=$BUDIBASE_RELEASE_VERSION",
22
- "build:docs": "node ./scripts/docs/generate.js open",
23
- "run:docker": "node dist/index.js",
24
- "run:docker:cluster": "pm2-runtime start pm2.config.js",
25
- "dev:stack:up": "node scripts/dev/manage.js up",
26
- "dev:stack:down": "node scripts/dev/manage.js down",
27
- "dev:stack:nuke": "node scripts/dev/manage.js nuke",
28
- "dev:builder": "yarn run dev:stack:up && nodemon",
29
- "specs": "ts-node specs/generate.ts && openapi-typescript specs/openapi.yaml --output src/definitions/openapi.ts",
30
- "initialise": "node scripts/initialise.js",
31
- "env:multi:enable": "node scripts/multiTenancy.js enable",
32
- "env:multi:disable": "node scripts/multiTenancy.js disable",
33
- "env:selfhost:enable": "node scripts/selfhost.js enable",
34
- "env:selfhost:disable": "node scripts/selfhost.js disable",
35
- "env:localdomain:enable": "node scripts/localdomain.js enable",
36
- "env:localdomain:disable": "node scripts/localdomain.js disable",
37
- "env:account:enable": "node scripts/account.js enable",
38
- "env:account:disable": "node scripts/account.js disable"
39
- },
40
- "keywords": [
41
- "budibase"
42
- ],
43
- "author": "Budibase",
44
- "license": "GPL-3.0",
45
- "dependencies": {
46
- "@apidevtools/swagger-parser": "10.0.3",
47
- "@budibase/backend-core": "^2.5.8",
48
- "@budibase/client": "^2.5.8",
49
- "@budibase/pro": "2.5.8",
50
- "@budibase/shared-core": "^2.5.8",
51
- "@budibase/string-templates": "^2.5.8",
52
- "@budibase/types": "^2.5.8",
53
- "@bull-board/api": "3.7.0",
54
- "@bull-board/koa": "3.9.4",
55
- "@elastic/elasticsearch": "7.10.0",
56
- "@google-cloud/firestore": "5.0.2",
57
- "@koa/router": "8.0.8",
58
- "@sendgrid/mail": "7.1.1",
59
- "@sentry/node": "6.17.7",
60
- "airtable": "0.10.1",
61
- "arangojs": "7.2.0",
62
- "aws-sdk": "2.1030.0",
63
- "bcryptjs": "2.4.3",
64
- "bull": "4.10.1",
65
- "chmodr": "1.2.0",
66
- "chokidar": "3.5.3",
67
- "csvtojson": "2.0.10",
68
- "curlconverter": "3.21.0",
69
- "dd-trace": "3.13.2",
70
- "dotenv": "8.2.0",
71
- "download": "8.0.0",
72
- "elastic-apm-node": "3.38.0",
73
- "fix-path": "3.0.0",
74
- "form-data": "4.0.0",
75
- "fs-extra": "8.1.0",
76
- "global-agent": "3.0.0",
77
- "google-auth-library": "7.12.0",
78
- "google-spreadsheet": "3.2.0",
79
- "jimp": "0.16.1",
80
- "joi": "17.6.0",
81
- "js-yaml": "4.1.0",
82
- "jsonschema": "1.4.0",
83
- "knex": "2.4.0",
84
- "koa": "2.13.4",
85
- "koa-body": "4.2.0",
86
- "koa-compress": "4.0.1",
87
- "koa-connect": "2.1.0",
88
- "koa-pino-logger": "3.0.0",
89
- "koa-send": "5.0.0",
90
- "koa-session": "5.12.0",
91
- "koa-static": "5.0.0",
92
- "koa-useragent": "^4.1.0",
93
- "koa2-ratelimit": "1.1.1",
94
- "lodash": "4.17.21",
95
- "memorystream": "0.3.1",
96
- "mongodb": "4.9",
97
- "mssql": "6.2.3",
98
- "mysql2": "2.3.3",
99
- "node-fetch": "2.6.7",
100
- "open": "8.4.0",
101
- "pg": "8.5.1",
102
- "pino-pretty": "4.0.0",
103
- "posthog-node": "1.3.0",
104
- "pouchdb": "7.3.0",
105
- "pouchdb-adapter-memory": "7.2.2",
106
- "pouchdb-all-dbs": "1.0.2",
107
- "pouchdb-find": "7.2.2",
108
- "pouchdb-replication-stream": "1.2.9",
109
- "redis": "4",
110
- "server-destroy": "1.0.1",
111
- "snowflake-promise": "^4.5.0",
112
- "socket.io": "^4.5.1",
113
- "svelte": "3.49.0",
114
- "swagger-parser": "10.0.3",
115
- "tar": "6.1.11",
116
- "to-json-schema": "0.2.5",
117
- "uuid": "3.3.2",
118
- "validate.js": "0.13.1",
119
- "vm2": "^3.9.15",
120
- "worker-farm": "1.7.0",
121
- "xml2js": "0.4.23",
122
- "yargs": "13.2.4",
123
- "zlib": "1.0.5"
124
- },
125
- "devDependencies": {
126
- "@babel/core": "7.17.4",
127
- "@babel/preset-env": "7.16.11",
128
- "@budibase/standard-components": "^0.9.139",
129
- "@jest/test-sequencer": "29.5.0",
130
- "@swc/core": "^1.3.25",
131
- "@swc/jest": "^0.2.24",
132
- "@trendyol/jest-testcontainers": "^2.1.1",
133
- "@types/apidoc": "0.50.0",
134
- "@types/bson": "4.2.0",
135
- "@types/global-agent": "2.1.1",
136
- "@types/google-spreadsheet": "3.1.5",
137
- "@types/ioredis": "4.28.10",
138
- "@types/jest": "29.5.0",
139
- "@types/koa": "2.13.4",
140
- "@types/koa__router": "8.0.8",
141
- "@types/lodash": "4.14.180",
142
- "@types/node": "14.18.20",
143
- "@types/node-fetch": "2.6.1",
144
- "@types/oracledb": "5.2.2",
145
- "@types/pouchdb": "6.4.0",
146
- "@types/redis": "4.0.11",
147
- "@types/server-destroy": "1.0.1",
148
- "@types/supertest": "2.0.12",
149
- "@types/tar": "6.1.3",
150
- "@typescript-eslint/parser": "5.45.0",
151
- "apidoc": "0.50.4",
152
- "babel-jest": "27.5.1",
153
- "copyfiles": "2.4.1",
154
- "docker-compose": "0.23.17",
155
- "eslint": "6.8.0",
156
- "ioredis-mock": "7.2.0",
157
- "is-wsl": "2.2.0",
158
- "jest": "29.5.0",
159
- "jest-openapi": "0.14.2",
160
- "jest-serial-runner": "^1.2.1",
161
- "nodemon": "2.0.15",
162
- "openapi-types": "9.3.1",
163
- "openapi-typescript": "5.2.0",
164
- "path-to-regexp": "6.2.0",
165
- "prettier": "2.5.1",
166
- "rimraf": "3.0.2",
167
- "supertest": "6.2.2",
168
- "swagger-jsdoc": "6.1.0",
169
- "timekeeper": "2.2.0",
170
- "ts-jest": "29.0.5",
171
- "ts-node": "10.8.1",
172
- "tsconfig-paths": "4.0.0",
173
- "typescript": "4.7.3",
174
- "update-dotenv": "1.1.1"
175
- },
176
- "optionalDependencies": {
177
- "oracledb": "5.3.0"
178
- },
179
- "gitHead": "d1836a898cab3f8ab80ee6d8f42be1a9eed7dcdc"
180
- }
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,35 +0,0 @@
1
- /******************************************************
2
- * This script just makes it easy to re-create *
3
- * a cypress like environment for testing the backend *
4
- ******************************************************/
5
- import path from "path"
6
- const tmpdir = path.join(require("os").tmpdir(), ".budibase")
7
-
8
- const SERVER_PORT = "4100"
9
- const WORKER_PORT = "4200"
10
-
11
- // @ts-ignore
12
- process.env.NODE_ENV = "cypress"
13
- process.env.ENABLE_ANALYTICS = "0"
14
- process.env.JWT_SECRET = "budibase"
15
- process.env.COUCH_URL = `leveldb://${tmpdir}/.data/`
16
- process.env.SELF_HOSTED = "1"
17
- process.env.WORKER_URL = `http://localhost:${WORKER_PORT}/`
18
- process.env.MINIO_URL = `http://localhost:4004`
19
- process.env.MINIO_ACCESS_KEY = "budibase"
20
- process.env.MINIO_SECRET_KEY = "budibase"
21
- process.env.COUCH_DB_USER = "budibase"
22
- process.env.COUCH_DB_PASSWORD = "budibase"
23
- process.env.INTERNAL_API_KEY = "budibase"
24
- process.env.ALLOW_DEV_AUTOMATIONS = "1"
25
-
26
- // don't make this a variable or top level require
27
- // it will cause environment module to be loaded prematurely
28
-
29
- // override the port with the worker port temporarily
30
- process.env.PORT = WORKER_PORT
31
- const worker = require("../../worker/src/index")
32
-
33
- // override the port with the server port
34
- process.env.PORT = SERVER_PORT
35
- const server = require("../src/app")
@@ -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
- })
package/src/elasticApm.ts DELETED
@@ -1,10 +0,0 @@
1
- import apm from "elastic-apm-node"
2
-
3
- // enable APM if configured
4
- if (process.env.ELASTIC_APM_ENABLED) {
5
- console.log("Starting elastic-apm-node")
6
- apm.start({
7
- serviceName: process.env.SERVICE,
8
- environment: process.env.BUDIBASE_ENVIRONMENT,
9
- })
10
- }
@@ -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
- })
@@ -1,34 +0,0 @@
1
- export enum LogLevel {
2
- TRACE = "trace",
3
- DEBUG = "debug",
4
- INFO = "info",
5
- WARN = "warn",
6
- ERROR = "error",
7
- }
8
-
9
- const LOG_INDEX: { [key in LogLevel]: number } = {
10
- [LogLevel.TRACE]: 1,
11
- [LogLevel.DEBUG]: 2,
12
- [LogLevel.INFO]: 3,
13
- [LogLevel.WARN]: 4,
14
- [LogLevel.ERROR]: 5,
15
- }
16
-
17
- const setIndex = LOG_INDEX[process.env.LOG_LEVEL as LogLevel]
18
-
19
- if (setIndex > LOG_INDEX.trace) {
20
- global.console.trace = jest.fn()
21
- }
22
-
23
- if (setIndex > LOG_INDEX.debug) {
24
- global.console.debug = jest.fn()
25
- }
26
-
27
- if (setIndex > LOG_INDEX.info) {
28
- global.console.info = jest.fn()
29
- global.console.log = jest.fn()
30
- }
31
-
32
- if (setIndex > LOG_INDEX.warn) {
33
- global.console.warn = jest.fn()
34
- }
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 }