@budibase/server 2.0.34-alpha.5 → 2.0.34-alpha.7

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 (182) hide show
  1. package/__mocks__/node-fetch.ts +12 -2
  2. package/builder/assets/{index.33bdfd8f.js → index.ffeaa56c.js} +1 -1
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +426 -496
  5. package/coverage/coverage-final.json +47 -49
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  7. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/cloud.js.html +13 -13
  9. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/dev.js.html +20 -20
  11. package/coverage/lcov-report/api/controllers/index.html +9 -24
  12. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  13. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  15. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  16. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  18. package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
  19. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  21. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  23. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  33. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  36. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  39. package/coverage/lcov-report/api/index.html +1 -1
  40. package/coverage/lcov-report/api/index.js.html +26 -26
  41. package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
  42. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  43. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  44. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  45. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  46. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  47. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  48. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  49. package/coverage/lcov-report/api/routes/index.html +5 -20
  50. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  53. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  54. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  55. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  56. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  57. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  58. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  59. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  61. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  62. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  63. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  64. package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
  65. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  66. package/coverage/lcov-report/automations/actions.js.html +1 -1
  67. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  68. package/coverage/lcov-report/automations/bullboard.js.html +25 -10
  69. package/coverage/lcov-report/automations/index.html +16 -16
  70. package/coverage/lcov-report/automations/index.js.html +4 -4
  71. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  72. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  73. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  74. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  75. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/index.html +1 -1
  78. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  88. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  89. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  90. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  91. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggers.js.html +23 -23
  97. package/coverage/lcov-report/constants/index.html +5 -5
  98. package/coverage/lcov-report/constants/index.js.html +4 -16
  99. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  100. package/coverage/lcov-report/constants/screens.js.html +1 -1
  101. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  102. package/coverage/lcov-report/db/index.html +1 -1
  103. package/coverage/lcov-report/db/index.js.html +1 -1
  104. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  105. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  106. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  107. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  108. package/coverage/lcov-report/db/newid.js.html +1 -1
  109. package/coverage/lcov-report/db/utils.js.html +2 -2
  110. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  111. package/coverage/lcov-report/events/index.html +1 -1
  112. package/coverage/lcov-report/events/index.js.html +2 -2
  113. package/coverage/lcov-report/events/utils.js.html +1 -1
  114. package/coverage/lcov-report/index.html +45 -45
  115. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  116. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  117. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  118. package/coverage/lcov-report/middleware/builder.js.html +9 -9
  119. package/coverage/lcov-report/middleware/currentapp.js.html +14 -14
  120. package/coverage/lcov-report/middleware/index.html +1 -1
  121. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  122. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  123. package/coverage/lcov-report/middleware/resourceId.js.html +22 -22
  124. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  125. package/coverage/lcov-report/middleware/utils.js.html +3 -3
  126. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  127. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  128. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  129. package/coverage/lcov-report/utilities/global.js.html +1 -1
  130. package/coverage/lcov-report/utilities/index.html +20 -20
  131. package/coverage/lcov-report/utilities/index.js.html +2 -2
  132. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  133. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  134. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  135. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  136. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  137. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  138. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  139. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  140. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  141. package/coverage/lcov-report/utilities/security.js.html +1 -1
  142. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  143. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  144. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  145. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  146. package/coverage/lcov-report/utilities/users.js.html +1 -1
  147. package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
  148. package/coverage/lcov.info +492 -596
  149. package/dist/api/controllers/webhook.js +88 -89
  150. package/dist/api/routes/utils/validators.js +2 -2
  151. package/dist/api/routes/webhook.js +39 -11
  152. package/dist/app.js +2 -84
  153. package/dist/automations/bullboard.js +7 -2
  154. package/dist/automations/utils.js +5 -37
  155. package/dist/constants/index.js +0 -3
  156. package/dist/package.json +6 -6
  157. package/dist/sdk/app/automations/index.js +29 -0
  158. package/dist/sdk/app/automations/webhook.js +54 -0
  159. package/dist/sdk/app/backups/imports.js +24 -0
  160. package/dist/sdk/index.js +2 -0
  161. package/dist/startup.js +152 -0
  162. package/dist/tests/utilities/TestConfiguration.js +8 -0
  163. package/dist/tsconfig.build.tsbuildinfo +1 -1
  164. package/package.json +7 -7
  165. package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
  166. package/src/api/routes/utils/validators.js +2 -2
  167. package/src/api/routes/{webhook.js → webhook.ts} +7 -6
  168. package/src/app.ts +3 -108
  169. package/src/automations/bullboard.js +6 -1
  170. package/src/automations/utils.ts +12 -20
  171. package/src/constants/index.js +0 -4
  172. package/src/definitions/automations.ts +1 -6
  173. package/src/migrations/functions/tests/syncQuotas.spec.js +1 -3
  174. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
  175. package/src/sdk/app/automations/index.ts +5 -0
  176. package/src/sdk/app/automations/webhook.ts +43 -0
  177. package/src/sdk/app/backups/imports.ts +39 -5
  178. package/src/sdk/index.ts +2 -0
  179. package/src/startup.ts +138 -0
  180. package/src/tests/utilities/TestConfiguration.js +7 -0
  181. package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
  182. package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
package/dist/sdk/index.js CHANGED
@@ -5,9 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const backups_1 = __importDefault(require("./app/backups"));
7
7
  const tables_1 = __importDefault(require("./app/tables"));
8
+ const automations_1 = __importDefault(require("./app/automations"));
8
9
  const sdk = {
9
10
  backups: backups_1.default,
10
11
  tables: tables_1.default,
12
+ automations: automations_1.default,
11
13
  };
12
14
  // default export for TS
13
15
  exports.default = sdk;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.startup = void 0;
39
+ const env = __importStar(require("./environment"));
40
+ const redis_1 = __importDefault(require("./utilities/redis"));
41
+ const workerRequests_1 = require("./utilities/workerRequests");
42
+ const backend_core_1 = require("@budibase/backend-core");
43
+ const fs_1 = __importDefault(require("fs"));
44
+ const watch_1 = require("./watch");
45
+ const automations_1 = __importDefault(require("./automations"));
46
+ const fileSystem_1 = __importDefault(require("./utilities/fileSystem"));
47
+ const events_1 = __importDefault(require("./events"));
48
+ const migrations = __importStar(require("./migrations"));
49
+ const bullboard_1 = __importDefault(require("./automations/bullboard"));
50
+ const pro = __importStar(require("../../../../budibase-pro/packages/pro"));
51
+ const api_1 = __importDefault(require("./api"));
52
+ const sdk_1 = __importDefault(require("./sdk"));
53
+ const pino = require("koa-pino-logger");
54
+ let STARTUP_RAN = false;
55
+ function initRoutes(app) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ app.use(pino((0, backend_core_1.pinoSettings)()));
58
+ if (!env.isTest()) {
59
+ const plugin = yield bullboard_1.default.init();
60
+ app.use(plugin);
61
+ }
62
+ app.context.eventEmitter = events_1.default;
63
+ app.context.auth = {};
64
+ // api routes
65
+ app.use(api_1.default.router.routes());
66
+ });
67
+ }
68
+ function initPro() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ yield pro.init({
71
+ backups: {
72
+ processing: {
73
+ exportAppFn: sdk_1.default.backups.exportApp,
74
+ importAppFn: sdk_1.default.backups.importApp,
75
+ statsFn: sdk_1.default.backups.calculateBackupStats,
76
+ },
77
+ },
78
+ });
79
+ });
80
+ }
81
+ function shutdown(server) {
82
+ server.close();
83
+ server.destroy();
84
+ }
85
+ function startup(app, server) {
86
+ var _a;
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (STARTUP_RAN) {
89
+ return;
90
+ }
91
+ STARTUP_RAN = true;
92
+ if (server) {
93
+ console.log(`Budibase running on ${JSON.stringify(server.address())}`);
94
+ env._set("PORT", server.address().port);
95
+ }
96
+ events_1.default.emitPort(env.PORT);
97
+ fileSystem_1.default.init();
98
+ yield redis_1.default.init();
99
+ // run migrations on startup if not done via http
100
+ // not recommended in a clustered environment
101
+ if (!env.HTTP_MIGRATIONS && !env.isTest()) {
102
+ try {
103
+ yield migrations.migrate();
104
+ }
105
+ catch (e) {
106
+ backend_core_1.logging.logAlert("Error performing migrations. Exiting.", e);
107
+ shutdown();
108
+ }
109
+ }
110
+ // check and create admin user if required
111
+ if (env.SELF_HOSTED &&
112
+ !env.MULTI_TENANCY &&
113
+ env.BB_ADMIN_USER_EMAIL &&
114
+ env.BB_ADMIN_USER_PASSWORD) {
115
+ const checklist = yield (0, workerRequests_1.getChecklist)();
116
+ if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
117
+ try {
118
+ const tenantId = backend_core_1.tenancy.getTenantId();
119
+ const user = yield (0, workerRequests_1.createAdminUser)(env.BB_ADMIN_USER_EMAIL, env.BB_ADMIN_USER_PASSWORD, tenantId);
120
+ // Need to set up an API key for automated integration tests
121
+ if (env.isTest()) {
122
+ yield (0, workerRequests_1.generateApiKey)(user._id);
123
+ }
124
+ console.log("Admin account automatically created for", env.BB_ADMIN_USER_EMAIL);
125
+ }
126
+ catch (e) {
127
+ backend_core_1.logging.logAlert("Error creating initial admin user. Exiting.", e);
128
+ shutdown();
129
+ }
130
+ }
131
+ }
132
+ // monitor plugin directory if required
133
+ if (env.SELF_HOSTED &&
134
+ !env.MULTI_TENANCY &&
135
+ env.PLUGINS_DIR &&
136
+ fs_1.default.existsSync(env.PLUGINS_DIR)) {
137
+ (0, watch_1.watch)();
138
+ }
139
+ // check for version updates
140
+ yield backend_core_1.installation.checkInstallVersion();
141
+ // get the references to the queue promises, don't await as
142
+ // they will never end, unless the processing stops
143
+ let queuePromises = [];
144
+ queuePromises.push(automations_1.default.init());
145
+ queuePromises.push(initPro());
146
+ if (app) {
147
+ // bring routes online as final step once everything ready
148
+ yield initRoutes(app);
149
+ }
150
+ });
151
+ }
152
+ exports.startup = startup;
@@ -25,6 +25,7 @@ const context = require("@budibase/backend-core/context");
25
25
  const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db");
26
26
  const { encrypt } = require("@budibase/backend-core/encryption");
27
27
  const { DocumentType, generateUserMetadataID } = require("../../db/utils");
28
+ const { startup } = require("../../startup");
28
29
  const GLOBAL_USER_ID = "us_uuid1";
29
30
  const EMAIL = "babs@babs.com";
30
31
  const FIRSTNAME = "Barbara";
@@ -38,6 +39,10 @@ class TestConfiguration {
38
39
  this.server = require("../../app");
39
40
  // we need the request for logging in, involves cookies, hard to fake
40
41
  this.request = supertest(this.server);
42
+ this.started = true;
43
+ }
44
+ else {
45
+ this.started = false;
41
46
  }
42
47
  this.appId = null;
43
48
  this.allApps = [];
@@ -87,6 +92,9 @@ class TestConfiguration {
87
92
  // use a new id as the name to avoid name collisions
88
93
  init(appName = newid()) {
89
94
  return __awaiter(this, void 0, void 0, function* () {
95
+ if (!this.started) {
96
+ yield startup();
97
+ }
90
98
  this.user = yield this.globalUser();
91
99
  this.globalUserId = this.user._id;
92
100
  this.userMetadataId = generateUserMetadataID(this.globalUserId);