@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
@@ -8,8 +8,8 @@
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap"
10
10
  rel="stylesheet" />
11
- <script type="module" crossorigin src="/builder/assets/index.0b358332.js"></script>
12
- <link rel="stylesheet" href="/builder/assets/index.7f9a008b.css">
11
+ <script type="module" crossorigin src="/builder/assets/index.24635afb.js"></script>
12
+ <link rel="stylesheet" href="/builder/assets/index.4eae16b2.css">
13
13
  </head>
14
14
 
15
15
  <body id="app">
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.updateAppPackage = exports.sync = exports.unpublish = exports.destroy = exports.revertClient = exports.updateClient = exports.update = exports.create = exports.fetchAppPackage = exports.fetchAppDefinition = exports.fetch = void 0;
16
16
  const environment_1 = __importDefault(require("../../environment"));
17
- const package_json_1 = __importDefault(require("../../../package.json"));
18
17
  const staticViews_1 = require("../../db/views/staticViews");
19
18
  const fileSystem_1 = require("../../utilities/fileSystem");
20
19
  const utils_1 = require("../../db/utils");
@@ -174,7 +173,7 @@ function fetchAppPackage(ctx) {
174
173
  }
175
174
  const clientLibPath = backend_core_1.objectStore.clientLibraryUrl(ctx.params.appId, application.version);
176
175
  ctx.body = {
177
- application,
176
+ application: Object.assign(Object.assign({}, application), { upgradableVersion: backend_core_1.env.VERSION }),
178
177
  screens,
179
178
  layouts,
180
179
  clientLibPath,
@@ -209,7 +208,7 @@ function performAppCreate(ctx) {
209
208
  _rev: undefined,
210
209
  appId,
211
210
  type: "app",
212
- version: package_json_1.default.version,
211
+ version: backend_core_1.env.VERSION,
213
212
  componentLibraries: ["@budibase/standard-components"],
214
213
  name: name,
215
214
  url: url,
@@ -377,7 +376,7 @@ function updateClient(ctx) {
377
376
  yield (0, fileSystem_2.updateClientLibrary)(ctx.params.appId);
378
377
  }
379
378
  // Update versions in app package
380
- const updatedToVersion = package_json_1.default.version;
379
+ const updatedToVersion = backend_core_1.env.VERSION;
381
380
  const appPackageUpdates = {
382
381
  version: updatedToVersion,
383
382
  revertableVersion: currentVersion,
@@ -33,7 +33,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.test = exports.trigger = exports.getDefinitionList = exports.getTriggerList = exports.getActionList = exports.clearLogError = exports.logSearch = exports.destroy = exports.find = exports.fetch = exports.update = exports.handleStepEvents = exports.getDeletedSteps = exports.getNewSteps = exports.create = void 0;
36
- const actions = __importStar(require("../../automations/actions"));
37
36
  const triggers = __importStar(require("../../automations/triggers"));
38
37
  const utils_1 = require("../../db/utils");
39
38
  const utils_2 = require("../../automations/utils");
@@ -42,8 +41,15 @@ const constants_1 = require("../../constants");
42
41
  const redis_1 = require("../../utilities/redis");
43
42
  const backend_core_1 = require("@budibase/backend-core");
44
43
  const pro_1 = require("@budibase/pro");
45
- const ACTION_DEFS = (0, utils_2.removeDeprecated)(actions.ACTION_DEFINITIONS);
46
- const TRIGGER_DEFS = (0, utils_2.removeDeprecated)(triggers.TRIGGER_DEFINITIONS);
44
+ const actions_1 = require("../../automations/actions");
45
+ function getActionDefinitions() {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return (0, utils_2.removeDeprecated)(yield (0, actions_1.getActionDefinitions)());
48
+ });
49
+ }
50
+ function getTriggerDefinitions() {
51
+ return (0, utils_2.removeDeprecated)(triggers.TRIGGER_DEFINITIONS);
52
+ }
47
53
  /*************************
48
54
  * *
49
55
  * BUILDER FUNCTIONS *
@@ -234,21 +240,21 @@ function clearLogError(ctx) {
234
240
  exports.clearLogError = clearLogError;
235
241
  function getActionList(ctx) {
236
242
  return __awaiter(this, void 0, void 0, function* () {
237
- ctx.body = ACTION_DEFS;
243
+ ctx.body = yield getActionDefinitions();
238
244
  });
239
245
  }
240
246
  exports.getActionList = getActionList;
241
247
  function getTriggerList(ctx) {
242
248
  return __awaiter(this, void 0, void 0, function* () {
243
- ctx.body = TRIGGER_DEFS;
249
+ ctx.body = getTriggerDefinitions();
244
250
  });
245
251
  }
246
252
  exports.getTriggerList = getTriggerList;
247
253
  function getDefinitionList(ctx) {
248
254
  return __awaiter(this, void 0, void 0, function* () {
249
255
  ctx.body = {
250
- trigger: TRIGGER_DEFS,
251
- action: ACTION_DEFS,
256
+ trigger: getTriggerDefinitions(),
257
+ action: yield getActionDefinitions(),
252
258
  };
253
259
  });
254
260
  }
@@ -168,7 +168,7 @@ function save(ctx) {
168
168
  const db = backend_core_1.context.getAppDB();
169
169
  const plus = ctx.request.body.datasource.plus;
170
170
  const fetchSchema = ctx.request.body.fetchSchema;
171
- const datasource = Object.assign({ _id: (0, utils_1.generateDatasourceID)({ plus }), type: plus ? utils_1.DocumentType.DATASOURCE_PLUS : utils_1.DocumentType.DATASOURCE }, ctx.request.body.datasource);
171
+ const datasource = Object.assign(Object.assign({ _id: (0, utils_1.generateDatasourceID)({ plus }) }, ctx.request.body.datasource), { type: plus ? utils_1.DocumentType.DATASOURCE_PLUS : utils_1.DocumentType.DATASOURCE });
172
172
  let schemaError = null;
173
173
  if (fetchSchema) {
174
174
  const { tables, error } = yield buildSchemaHelper(datasource);
@@ -136,7 +136,7 @@ function revert(ctx) {
136
136
  exports.revert = revert;
137
137
  function getBudibaseVersion(ctx) {
138
138
  return __awaiter(this, void 0, void 0, function* () {
139
- const version = require("../../../package.json").version;
139
+ const version = backend_core_1.env.VERSION;
140
140
  ctx.body = {
141
141
  version,
142
142
  };
@@ -0,0 +1,40 @@
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.error = exports.alert = exports.log = void 0;
13
+ const backend_core_1 = require("@budibase/backend-core");
14
+ function log(ctx) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const body = ctx.request.body;
17
+ console.trace(body.message, body.data);
18
+ console.debug(body.message, body.data);
19
+ console.info(body.message, body.data);
20
+ console.warn(body.message, body.data);
21
+ console.error(body.message, body.data);
22
+ ctx.status = 204;
23
+ });
24
+ }
25
+ exports.log = log;
26
+ function alert(ctx) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const body = ctx.request.body;
29
+ backend_core_1.logging.logAlert(body.message, new Error(body.message));
30
+ ctx.status = 204;
31
+ });
32
+ }
33
+ exports.alert = alert;
34
+ function error(ctx) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const body = ctx.request.body;
37
+ throw new Error(body.message);
38
+ });
39
+ }
40
+ exports.error = error;
@@ -12,30 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.processUploadedPlugin = exports.destroy = exports.fetch = exports.create = exports.upload = exports.getPlugins = void 0;
15
+ exports.destroy = exports.fetch = exports.create = exports.upload = void 0;
16
16
  const uploaders_1 = require("./uploaders");
17
17
  const backend_core_1 = require("@budibase/backend-core");
18
18
  const types_1 = require("@budibase/types");
19
19
  const environment_1 = __importDefault(require("../../../environment"));
20
- const websocket_1 = require("../../../websocket");
20
+ const websockets_1 = require("../../../websockets");
21
+ const sdk_1 = __importDefault(require("../../../sdk"));
21
22
  const pro_1 = require("@budibase/pro");
22
- function getPlugins(type) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const db = backend_core_1.tenancy.getGlobalDB();
25
- const response = yield db.allDocs(backend_core_1.db.getPluginParams(null, {
26
- include_docs: true,
27
- }));
28
- let plugins = response.rows.map((row) => row.doc);
29
- plugins = backend_core_1.objectStore.enrichPluginURLs(plugins);
30
- if (type) {
31
- return plugins.filter((plugin) => { var _a; return ((_a = plugin.schema) === null || _a === void 0 ? void 0 : _a.type) === type; });
32
- }
33
- else {
34
- return plugins;
35
- }
36
- });
37
- }
38
- exports.getPlugins = getPlugins;
39
23
  function upload(ctx) {
40
24
  return __awaiter(this, void 0, void 0, function* () {
41
25
  const plugins = ctx.request.files.file.length > 1
@@ -45,7 +29,7 @@ function upload(ctx) {
45
29
  let docs = [];
46
30
  // can do single or multiple plugins
47
31
  for (let plugin of plugins) {
48
- const doc = yield processUploadedPlugin(plugin, types_1.PluginSource.FILE);
32
+ const doc = yield sdk_1.default.plugins.processUploaded(plugin, types_1.PluginSource.FILE);
49
33
  docs.push(doc);
50
34
  }
51
35
  ctx.body = {
@@ -93,7 +77,7 @@ function create(ctx) {
93
77
  throw new Error("Only component plugins are supported outside of self-host");
94
78
  }
95
79
  const doc = yield pro_1.sdk.plugins.storePlugin(metadata, directory, source);
96
- websocket_1.ClientAppSocket.emit("plugins-update", { name, hash: doc.hash });
80
+ websockets_1.clientAppSocket.emit("plugins-update", { name, hash: doc.hash });
97
81
  ctx.body = {
98
82
  message: "Plugin uploaded successfully",
99
83
  plugins: [doc],
@@ -109,7 +93,7 @@ function create(ctx) {
109
93
  exports.create = create;
110
94
  function fetch(ctx) {
111
95
  return __awaiter(this, void 0, void 0, function* () {
112
- ctx.body = yield getPlugins();
96
+ ctx.body = yield sdk_1.default.plugins.fetch();
113
97
  });
114
98
  }
115
99
  exports.fetch = fetch;
@@ -126,18 +110,3 @@ function destroy(ctx) {
126
110
  });
127
111
  }
128
112
  exports.destroy = destroy;
129
- function processUploadedPlugin(plugin, source) {
130
- var _a;
131
- return __awaiter(this, void 0, void 0, function* () {
132
- const { metadata, directory } = yield (0, uploaders_1.fileUpload)(plugin);
133
- backend_core_1.plugins.validate(metadata === null || metadata === void 0 ? void 0 : metadata.schema);
134
- // Only allow components in cloud
135
- if (!environment_1.default.SELF_HOSTED && ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.schema) === null || _a === void 0 ? void 0 : _a.type) !== types_1.PluginType.COMPONENT) {
136
- throw new Error("Only component plugins are supported outside of self-host");
137
- }
138
- const doc = yield pro_1.sdk.plugins.storePlugin(metadata, directory, source);
139
- websocket_1.ClientAppSocket.emit("plugin-update", { name: doc.name, hash: doc.hash });
140
- return doc;
141
- });
142
- }
143
- exports.processUploadedPlugin = processUploadedPlugin;
@@ -237,7 +237,7 @@ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
237
237
  },
238
238
  };
239
239
  const runFn = () => Runner.run(inputs);
240
- const { rows, pagination, extra } = yield pro_1.quotas.addQuery(runFn, {
240
+ const { rows, pagination, extra, info } = yield pro_1.quotas.addQuery(runFn, {
241
241
  datasourceId: datasource._id,
242
242
  });
243
243
  // remove the raw from execution incase transformer being used to hide data
@@ -248,7 +248,7 @@ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
248
248
  ctx.body = rows;
249
249
  }
250
250
  else {
251
- ctx.body = Object.assign({ data: rows, pagination }, extra);
251
+ ctx.body = Object.assign(Object.assign({ data: rows, pagination }, extra), info);
252
252
  }
253
253
  }
254
254
  catch (err) {
@@ -28,7 +28,6 @@ const types_1 = require("@budibase/types");
28
28
  const utils_1 = require("../../../integrations/utils");
29
29
  const utils_2 = require("./utils");
30
30
  const constants_1 = require("../../../constants");
31
- const utils_3 = require("../../../integrations/utils");
32
31
  const string_templates_1 = require("@budibase/string-templates");
33
32
  const fp_1 = require("lodash/fp");
34
33
  const rowProcessor_1 = require("../../../utilities/rowProcessor");
@@ -146,7 +145,7 @@ function getEndpoint(tableId, operation) {
146
145
  if (!tableId) {
147
146
  return {};
148
147
  }
149
- const { datasourceId, tableName } = (0, utils_3.breakExternalTableId)(tableId);
148
+ const { datasourceId, tableName } = (0, utils_1.breakExternalTableId)(tableId);
150
149
  return {
151
150
  datasourceId,
152
151
  entityId: tableName,
@@ -214,7 +213,7 @@ class ExternalRequest {
214
213
  if (!tableId) {
215
214
  throw "Table ID is unknown, cannot find table";
216
215
  }
217
- const { tableName } = (0, utils_3.breakExternalTableId)(tableId);
216
+ const { tableName } = (0, utils_1.breakExternalTableId)(tableId);
218
217
  if (tableName) {
219
218
  return this.tables[tableName];
220
219
  }
@@ -250,7 +249,7 @@ class ExternalRequest {
250
249
  newRow[key] = row[key];
251
250
  continue;
252
251
  }
253
- const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field === null || field === void 0 ? void 0 : field.tableId);
252
+ const { tableName: linkTableName } = (0, utils_1.breakExternalTableId)(field === null || field === void 0 ? void 0 : field.tableId);
254
253
  // table has to exist for many to many
255
254
  if (!linkTableName || !this.tables[linkTableName]) {
256
255
  continue;
@@ -312,10 +311,18 @@ class ExternalRequest {
312
311
  }
313
312
  const display = linkedTable.primaryDisplay;
314
313
  for (let key of Object.keys(row[relationship.column])) {
315
- const related = row[relationship.column][key];
314
+ let relatedRow = row[relationship.column][key];
315
+ // add this row as context for the relationship
316
+ for (let col of Object.values(linkedTable.schema)) {
317
+ if (col.type === types_1.FieldType.LINK && col.tableId === table._id) {
318
+ relatedRow[col.name] = [row];
319
+ }
320
+ }
321
+ relatedRow = (0, rowProcessor_1.processFormulas)(linkedTable, relatedRow);
322
+ const relatedDisplay = display ? relatedRow[display] : undefined;
316
323
  row[relationship.column][key] = {
317
- primaryDisplay: display ? related[display] : undefined,
318
- _id: related._id,
324
+ primaryDisplay: relatedDisplay || "Invalid display column",
325
+ _id: relatedRow._id,
319
326
  };
320
327
  }
321
328
  }
@@ -404,7 +411,7 @@ class ExternalRequest {
404
411
  if (field.type !== constants_1.FieldTypes.LINK) {
405
412
  continue;
406
413
  }
407
- const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field.tableId);
414
+ const { tableName: linkTableName } = (0, utils_1.breakExternalTableId)(field.tableId);
408
415
  // no table to link to, this is not a valid relationships
409
416
  if (!linkTableName || !this.tables[linkTableName]) {
410
417
  continue;
@@ -422,7 +429,7 @@ class ExternalRequest {
422
429
  column: fieldName,
423
430
  };
424
431
  if (field.through) {
425
- const { tableName: throughTableName } = (0, utils_3.breakExternalTableId)(field.through);
432
+ const { tableName: throughTableName } = (0, utils_1.breakExternalTableId)(field.through);
426
433
  definition.through = throughTableName;
427
434
  // don't support composite keys for relationships
428
435
  definition.from = field.throughTo || table.primary[0];
@@ -441,7 +448,7 @@ class ExternalRequest {
441
448
  lookupRelations(tableId, row) {
442
449
  return __awaiter(this, void 0, void 0, function* () {
443
450
  const related = {};
444
- const { tableName } = (0, utils_3.breakExternalTableId)(tableId);
451
+ const { tableName } = (0, utils_1.breakExternalTableId)(tableId);
445
452
  if (!tableName) {
446
453
  return related;
447
454
  }
@@ -458,7 +465,7 @@ class ExternalRequest {
458
465
  }
459
466
  const isMany = field.relationshipType === types_1.RelationshipTypes.MANY_TO_MANY;
460
467
  const tableId = isMany ? field.through : field.tableId;
461
- const { tableName: relatedTableName } = (0, utils_3.breakExternalTableId)(tableId);
468
+ const { tableName: relatedTableName } = (0, utils_1.breakExternalTableId)(tableId);
462
469
  // @ts-ignore
463
470
  const linkPrimaryKey = this.tables[relatedTableName].primary[0];
464
471
  const manyKey = field.throughTo || primaryKey;
@@ -579,7 +586,7 @@ class ExternalRequest {
579
586
  if (field.type !== constants_1.FieldTypes.LINK || !includeRelations) {
580
587
  continue;
581
588
  }
582
- const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field.tableId);
589
+ const { tableName: linkTableName } = (0, utils_1.breakExternalTableId)(field.tableId);
583
590
  if (linkTableName) {
584
591
  const linkTable = this.tables[linkTableName];
585
592
  if (linkTable) {
@@ -594,7 +601,7 @@ class ExternalRequest {
594
601
  var _a;
595
602
  return __awaiter(this, void 0, void 0, function* () {
596
603
  const { operation, tableId } = this;
597
- let { datasourceId, tableName } = (0, utils_3.breakExternalTableId)(tableId);
604
+ let { datasourceId, tableName } = (0, utils_1.breakExternalTableId)(tableId);
598
605
  if (!tableName) {
599
606
  throw "Unable to run without a table name";
600
607
  }
@@ -606,7 +613,7 @@ class ExternalRequest {
606
613
  this.tables = this.datasource.entities;
607
614
  }
608
615
  const table = this.tables[tableName];
609
- let isSql = (0, utils_3.isSQL)(this.datasource);
616
+ let isSql = (0, utils_1.isSQL)(this.datasource);
610
617
  if (!table) {
611
618
  throw `Unable to process query, table "${tableName}" not defined.`;
612
619
  }
@@ -97,19 +97,25 @@ function makeSureTableUpToDate(table, tableToSave) {
97
97
  }
98
98
  exports.makeSureTableUpToDate = makeSureTableUpToDate;
99
99
  function importToRows(data, table, user = null) {
100
+ let originalTable = table;
100
101
  let finalData = [];
101
102
  for (let i = 0; i < data.length; i++) {
102
103
  let row = data[i];
103
104
  row._id = (0, utils_1.generateRowID)(table._id);
104
105
  row.tableId = table._id;
106
+ // We use a reference to table here and update it after input processing,
107
+ // so that we can auto increment auto IDs in imported data properly
105
108
  const processed = (0, rowProcessor_1.inputProcessing)(user, table, row, {
106
109
  noAutoRelationships: true,
107
110
  });
108
111
  row = processed.row;
109
112
  table = processed.table;
110
- for (const [fieldName, schema] of Object.entries(table.schema)) {
111
- // check whether the options need to be updated for inclusion as part of the data import
112
- if (schema.type === constants_1.FieldTypes.OPTIONS &&
113
+ // However here we must reference the original table, as we want to mutate
114
+ // the real schema of the table passed in, not the clone used for
115
+ // incrementing auto IDs
116
+ for (const [fieldName, schema] of Object.entries(originalTable.schema)) {
117
+ if ((schema.type === constants_1.FieldTypes.OPTIONS ||
118
+ schema.type === constants_1.FieldTypes.ARRAY) &&
113
119
  row[fieldName] &&
114
120
  (!schema.constraints.inclusion ||
115
121
  schema.constraints.inclusion.indexOf(row[fieldName]) === -1)) {
@@ -12,95 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getFlags = exports.setFlag = exports.findMetadata = exports.destroyMetadata = exports.updateMetadata = exports.updateSelfMetadata = exports.fetchMetadata = exports.syncUser = void 0;
15
+ exports.getFlags = exports.setFlag = exports.findMetadata = exports.destroyMetadata = exports.updateMetadata = exports.updateSelfMetadata = exports.fetchMetadata = void 0;
16
16
  const utils_1 = require("../../db/utils");
17
17
  const utils_2 = require("../../db/utils");
18
18
  const global_1 = require("../../utilities/global");
19
19
  const users_1 = require("../../utilities/users");
20
20
  const backend_core_1 = require("@budibase/backend-core");
21
21
  const sdk_1 = __importDefault(require("../../sdk"));
22
- function syncUser(ctx) {
23
- var _a;
24
- return __awaiter(this, void 0, void 0, function* () {
25
- let deleting = false, user;
26
- const userId = ctx.params.id;
27
- const previousUser = (_a = ctx.request.body) === null || _a === void 0 ? void 0 : _a.previousUser;
28
- try {
29
- user = (yield (0, global_1.getRawGlobalUser)(userId));
30
- }
31
- catch (err) {
32
- if (err && err.status === 404) {
33
- user = {};
34
- deleting = true;
35
- }
36
- else {
37
- throw err;
38
- }
39
- }
40
- let previousApps = previousUser
41
- ? Object.keys(previousUser.roles).map(appId => appId)
42
- : [];
43
- const roles = deleting ? {} : user.roles;
44
- // remove props which aren't useful to metadata
45
- delete user.password;
46
- delete user.forceResetPassword;
47
- delete user.roles;
48
- // run through all production appIDs in the users roles
49
- let prodAppIds;
50
- // if they are a builder then get all production app IDs
51
- if ((user.builder && user.builder.global) || deleting) {
52
- prodAppIds = yield backend_core_1.db.getProdAppIDs();
53
- }
54
- else {
55
- prodAppIds = Object.entries(roles)
56
- .filter(entry => entry[1] !== backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC)
57
- .map(([appId]) => appId);
58
- }
59
- for (let prodAppId of new Set([...prodAppIds, ...previousApps])) {
60
- const roleId = roles[prodAppId];
61
- const deleteFromApp = !roleId;
62
- const devAppId = backend_core_1.db.getDevelopmentAppID(prodAppId);
63
- for (let appId of [prodAppId, devAppId]) {
64
- if (!(yield backend_core_1.db.dbExists(appId))) {
65
- continue;
66
- }
67
- yield backend_core_1.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
68
- const db = backend_core_1.context.getAppDB();
69
- const metadataId = (0, utils_1.generateUserMetadataID)(userId);
70
- let metadata;
71
- try {
72
- metadata = yield db.get(metadataId);
73
- }
74
- catch (err) {
75
- if (deleteFromApp) {
76
- return;
77
- }
78
- metadata = {
79
- tableId: utils_2.InternalTables.USER_METADATA,
80
- };
81
- }
82
- if (deleteFromApp) {
83
- yield db.remove(metadata);
84
- return;
85
- }
86
- // assign the roleId for the metadata doc
87
- if (roleId) {
88
- metadata.roleId = roleId;
89
- }
90
- let combined = sdk_1.default.users.combineMetadataAndUser(user, metadata);
91
- // if its null then there was no updates required
92
- if (combined) {
93
- yield db.put(combined);
94
- }
95
- }));
96
- }
97
- }
98
- ctx.body = {
99
- message: "User synced.",
100
- };
101
- });
102
- }
103
- exports.syncUser = syncUser;
104
22
  function fetchMetadata(ctx) {
105
23
  return __awaiter(this, void 0, void 0, function* () {
106
24
  const global = yield (0, global_1.getGlobalUsers)();
package/dist/api/index.js CHANGED
@@ -9,14 +9,13 @@ const backend_core_1 = require("@budibase/backend-core");
9
9
  const currentapp_1 = __importDefault(require("../middleware/currentapp"));
10
10
  const zlib_1 = __importDefault(require("zlib"));
11
11
  const routes_1 = require("./routes");
12
- const package_json_1 = __importDefault(require("../../package.json"));
13
12
  const pro_1 = require("@budibase/pro");
14
13
  var public_1 = require("./routes/public");
15
14
  Object.defineProperty(exports, "shutdown", { enumerable: true, get: function () { return public_1.shutdown; } });
16
15
  const compress = require("koa-compress");
17
16
  exports.router = new router_1.default();
18
17
  exports.router.get("/health", ctx => (ctx.status = 200));
19
- exports.router.get("/version", ctx => (ctx.body = package_json_1.default.version));
18
+ exports.router.get("/version", ctx => (ctx.body = backend_core_1.env.VERSION));
20
19
  exports.router.use(backend_core_1.middleware.errorHandling);
21
20
  exports.router
22
21
  .use(compress({
@@ -28,9 +28,9 @@ const query_1 = __importDefault(require("./query"));
28
28
  const backup_1 = __importDefault(require("./backup"));
29
29
  const metadata_1 = __importDefault(require("./metadata"));
30
30
  const dev_1 = __importDefault(require("./dev"));
31
- const cloud_1 = __importDefault(require("./cloud"));
32
31
  const migrations_1 = __importDefault(require("./migrations"));
33
32
  const plugin_1 = __importDefault(require("./plugin"));
33
+ const ops_1 = __importDefault(require("./ops"));
34
34
  const pro_1 = require("@budibase/pro");
35
35
  var static_1 = require("./static");
36
36
  Object.defineProperty(exports, "staticRoutes", { enumerable: true, get: function () { return __importDefault(static_1).default; } });
@@ -63,10 +63,10 @@ exports.mainRoutes = [
63
63
  query_1.default,
64
64
  metadata_1.default,
65
65
  dev_1.default,
66
- cloud_1.default,
67
66
  row_1.default,
68
67
  migrations_1.default,
69
68
  plugin_1.default,
69
+ ops_1.default,
70
70
  scheduleRoutes,
71
71
  environmentVariableRoutes,
72
72
  // these need to be handled last as they still use /api/:tableId
@@ -26,14 +26,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.errorValidator = exports.logsValidator = void 0;
29
30
  const router_1 = __importDefault(require("@koa/router"));
30
- const controller = __importStar(require("../controllers/cloud"));
31
- const authorized_1 = __importDefault(require("../../middleware/authorized"));
31
+ const controller = __importStar(require("../controllers/ops"));
32
32
  const backend_core_1 = require("@budibase/backend-core");
33
+ const joi_1 = __importDefault(require("joi"));
34
+ function logsValidator() {
35
+ return backend_core_1.middleware.joiValidator.body(joi_1.default.object({
36
+ message: joi_1.default.string().required(),
37
+ data: joi_1.default.object(),
38
+ }));
39
+ }
40
+ exports.logsValidator = logsValidator;
41
+ function errorValidator() {
42
+ return backend_core_1.middleware.joiValidator.body(joi_1.default.object({
43
+ message: joi_1.default.string().required(),
44
+ }));
45
+ }
46
+ exports.errorValidator = errorValidator;
33
47
  const router = new router_1.default();
34
48
  router
35
- .get("/api/cloud/export", (0, authorized_1.default)(backend_core_1.permissions.BUILDER), controller.exportApps)
36
- // has to be public, only run if apps don't exist
37
- .post("/api/cloud/import", controller.importApps)
38
- .get("/api/cloud/import/complete", controller.hasBeenImported);
49
+ .post("/api/ops/log", logsValidator(), controller.log)
50
+ .post("/api/ops/error", errorValidator(), controller.error)
51
+ .post("/api/ops/alert", errorValidator(), controller.alert);
39
52
  exports.default = router;
@@ -38,7 +38,6 @@ router
38
38
  .put("/api/users/metadata", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.updateMetadata)
39
39
  .post("/api/users/metadata/self", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.updateSelfMetadata)
40
40
  .delete("/api/users/metadata/:id", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.destroyMetadata)
41
- .post("/api/users/metadata/sync/:id", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.syncUser)
42
41
  .post("/api/users/flags", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.setFlag)
43
42
  .get("/api/users/flags", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.READ), controller.getFlags);
44
43
  exports.default = router;
package/dist/app.js CHANGED
@@ -38,18 +38,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  if (process.env.DD_APM_ENABLED) {
39
39
  require("./ddApm");
40
40
  }
41
- if (process.env.ELASTIC_APM_ENABLED) {
42
- require("./elasticApm");
43
- }
44
41
  // need to load environment first
45
42
  const environment_1 = __importDefault(require("./environment"));
46
- // enable APM if configured
47
- if (process.env.ELASTIC_APM_ENABLED) {
48
- const apm = require("elastic-apm-node").start({
49
- serviceName: process.env.SERVICE,
50
- environment: process.env.BUDIBASE_ENVIRONMENT,
51
- });
52
- }
53
43
  const db = __importStar(require("./db"));
54
44
  db.init();
55
45
  const koa_1 = __importDefault(require("koa"));
@@ -59,8 +49,8 @@ const api = __importStar(require("./api"));
59
49
  const automations = __importStar(require("./automations"));
60
50
  const threads_1 = require("./threads");
61
51
  const redis = __importStar(require("./utilities/redis"));
52
+ const websockets_1 = require("./websockets");
62
53
  const backend_core_1 = require("@budibase/backend-core");
63
- const websocket_1 = require("./websocket");
64
54
  const startup_1 = require("./startup");
65
55
  const Sentry = require("@sentry/node");
66
56
  const destroyable = require("server-destroy");
@@ -80,7 +70,8 @@ app.use((0, koa_body_1.default)({
80
70
  enableTypes: ["json", "form", "text"],
81
71
  parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
82
72
  }));
83
- app.use(backend_core_1.middleware.logging);
73
+ app.use(backend_core_1.middleware.correlation);
74
+ app.use(backend_core_1.middleware.pino);
84
75
  app.use(userAgent);
85
76
  if (environment_1.default.isProd()) {
86
77
  environment_1.default._set("NODE_ENV", "production");
@@ -96,7 +87,7 @@ if (environment_1.default.isProd()) {
96
87
  }
97
88
  const server = http_1.default.createServer(app.callback());
98
89
  destroyable(server);
99
- (0, websocket_1.initialise)(server);
90
+ (0, websockets_1.initialise)(app, server);
100
91
  let shuttingDown = false, errCode = 0;
101
92
  server.on("close", () => __awaiter(void 0, void 0, void 0, function* () {
102
93
  // already in process