@budibase/server 0.9.169-alpha.9 → 0.9.172

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 (227) hide show
  1. package/builder/assets/{index.aafb155b.js → index.9ab01cd4.js} +34 -34
  2. package/builder/assets/{index.0ea76a5c.css → index.dbc6728e.css} +2 -2
  3. package/builder/assets/{vendor.2053eff2.js → vendor.54435e8f.js} +2 -2
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +517 -609
  6. package/coverage/coverage-final.json +31 -32
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/application.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/backup.js.html +9 -6
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/dev.js.html +17 -41
  17. package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/index.html +45 -45
  19. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +4 -7
  23. package/coverage/lcov-report/api/controllers/query.js.html +24 -129
  24. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/index.html +5 -5
  28. package/coverage/lcov-report/api/controllers/row/index.js.html +15 -15
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/script.js.html +57 -12
  34. package/coverage/lcov-report/api/controllers/table/index.html +28 -28
  35. package/coverage/lcov-report/api/controllers/table/index.js.html +37 -16
  36. package/coverage/lcov-report/api/controllers/table/utils.js.html +33 -279
  37. package/coverage/lcov-report/api/controllers/templates.js.html +13 -49
  38. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +8 -8
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +6 -6
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  45. package/coverage/lcov-report/api/index.html +1 -1
  46. package/coverage/lcov-report/api/index.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/dev.js.html +11 -26
  58. package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/index.html +9 -9
  60. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/query.js.html +3 -9
  66. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  77. package/coverage/lcov-report/automations/actions.js.html +10 -31
  78. package/coverage/lcov-report/automations/automationUtils.js.html +86 -14
  79. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  80. package/coverage/lcov-report/automations/index.html +25 -25
  81. package/coverage/lcov-report/automations/index.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/bash.js.html +7 -10
  83. package/coverage/lcov-report/automations/steps/createRow.js.html +2 -2
  84. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/deleteRow.js.html +5 -8
  86. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/executeQuery.js.html +7 -10
  88. package/coverage/lcov-report/automations/steps/executeScript.js.html +7 -10
  89. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/index.html +57 -57
  91. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +7 -10
  93. package/coverage/lcov-report/automations/steps/queryRows.js.html +7 -10
  94. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +7 -10
  95. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/updateRow.js.html +14 -14
  98. package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
  99. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  100. package/coverage/lcov-report/automations/thread.js.html +12 -54
  101. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  109. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  110. package/coverage/lcov-report/automations/utils.js.html +1 -1
  111. package/coverage/lcov-report/constants/index.html +1 -1
  112. package/coverage/lcov-report/constants/index.js.html +2 -5
  113. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  114. package/coverage/lcov-report/constants/screens.js.html +1 -1
  115. package/coverage/lcov-report/db/client.js.html +1 -1
  116. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  117. package/coverage/lcov-report/db/index.html +1 -1
  118. package/coverage/lcov-report/db/index.js.html +1 -1
  119. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +12 -12
  120. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  121. package/coverage/lcov-report/db/linkedRows/index.js.html +9 -9
  122. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  123. package/coverage/lcov-report/db/newid.js.html +1 -1
  124. package/coverage/lcov-report/db/utils.js.html +1 -1
  125. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  126. package/coverage/lcov-report/events/index.html +1 -1
  127. package/coverage/lcov-report/events/index.js.html +1 -1
  128. package/coverage/lcov-report/events/utils.js.html +1 -1
  129. package/coverage/lcov-report/index.html +69 -69
  130. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  131. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  132. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  133. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  134. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  135. package/coverage/lcov-report/middleware/currentapp.js.html +2 -2
  136. package/coverage/lcov-report/middleware/index.html +1 -1
  137. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  138. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  139. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  140. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  141. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  142. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  143. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  144. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  145. package/coverage/lcov-report/utilities/global.js.html +2 -2
  146. package/coverage/lcov-report/utilities/index.html +7 -22
  147. package/coverage/lcov-report/utilities/index.js.html +1 -1
  148. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  149. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  150. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  151. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  152. package/coverage/lcov-report/utilities/rowProcessor/index.html +14 -14
  153. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +8 -38
  154. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  155. package/coverage/lcov-report/utilities/security.js.html +1 -1
  156. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  157. package/coverage/lcov-report/utilities/users.js.html +1 -1
  158. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  159. package/coverage/lcov.info +848 -1026
  160. package/dist/api/controllers/backup.js +4 -4
  161. package/dist/api/controllers/dev.js +11 -17
  162. package/dist/api/controllers/permission.js +0 -1
  163. package/dist/api/controllers/query.js +8 -26
  164. package/dist/api/controllers/row/ExternalRequest.js +5 -46
  165. package/dist/api/controllers/script.js +16 -4
  166. package/dist/api/controllers/table/index.js +10 -5
  167. package/dist/api/controllers/table/utils.js +10 -83
  168. package/dist/api/controllers/templates.js +3 -18
  169. package/dist/api/routes/dev.js +4 -8
  170. package/dist/api/routes/query.js +1 -3
  171. package/dist/automations/actions.js +3 -9
  172. package/dist/automations/automationUtils.js +29 -8
  173. package/dist/automations/steps/bash.js +1 -2
  174. package/dist/automations/steps/createRow.js +1 -1
  175. package/dist/automations/steps/deleteRow.js +1 -2
  176. package/dist/automations/steps/executeQuery.js +1 -2
  177. package/dist/automations/steps/executeScript.js +1 -2
  178. package/dist/automations/steps/outgoingWebhook.js +1 -2
  179. package/dist/automations/steps/queryRows.js +1 -2
  180. package/dist/automations/steps/sendSmtpEmail.js +1 -2
  181. package/dist/automations/steps/updateRow.js +2 -6
  182. package/dist/automations/thread.js +3 -14
  183. package/dist/constants/index.js +0 -1
  184. package/dist/integrations/base/sql.js +4 -4
  185. package/dist/integrations/utils.js +1 -16
  186. package/dist/middleware/currentapp.js +1 -1
  187. package/dist/package.json +5 -6
  188. package/dist/tsconfig.tsbuildinfo +1 -1
  189. package/dist/utilities/fileSystem/index.js +33 -49
  190. package/dist/utilities/global.js +1 -1
  191. package/dist/utilities/rowProcessor/index.js +0 -8
  192. package/package.json +6 -7
  193. package/src/api/controllers/backup.js +5 -4
  194. package/src/api/controllers/dev.js +8 -16
  195. package/src/api/controllers/permission.js +0 -1
  196. package/src/api/controllers/query.js +11 -46
  197. package/src/api/controllers/row/ExternalRequest.ts +4 -49
  198. package/src/api/controllers/script.js +19 -4
  199. package/src/api/controllers/table/index.js +12 -5
  200. package/src/api/controllers/table/utils.js +12 -94
  201. package/src/api/controllers/templates.js +5 -17
  202. package/src/api/routes/dev.js +4 -9
  203. package/src/api/routes/query.js +1 -3
  204. package/src/automations/actions.js +3 -10
  205. package/src/automations/automationUtils.js +31 -7
  206. package/src/automations/steps/bash.js +1 -2
  207. package/src/automations/steps/createRow.js +1 -1
  208. package/src/automations/steps/deleteRow.js +1 -2
  209. package/src/automations/steps/executeQuery.js +1 -2
  210. package/src/automations/steps/executeScript.js +1 -2
  211. package/src/automations/steps/outgoingWebhook.js +1 -2
  212. package/src/automations/steps/queryRows.js +1 -2
  213. package/src/automations/steps/sendSmtpEmail.js +1 -2
  214. package/src/automations/steps/updateRow.js +6 -6
  215. package/src/automations/thread.js +3 -17
  216. package/src/constants/index.js +0 -1
  217. package/src/integrations/base/sql.ts +3 -5
  218. package/src/integrations/tests/mongo.spec.js +6 -10
  219. package/src/integrations/utils.ts +0 -15
  220. package/src/middleware/currentapp.js +1 -1
  221. package/src/middleware/tests/currentapp.spec.js +3 -3
  222. package/src/utilities/fileSystem/index.js +43 -65
  223. package/src/utilities/global.js +1 -1
  224. package/src/utilities/rowProcessor/index.js +0 -10
  225. package/coverage/lcov-report/utilities/scriptRunner.js.html +0 -143
  226. package/dist/utilities/scriptRunner.js +0 -19
  227. package/src/utilities/scriptRunner.js +0 -21
@@ -8,13 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { streamBackup } = require("../../utilities/fileSystem");
11
+ const { performBackup } = require("../../utilities/fileSystem");
12
12
  exports.exportAppDump = function (ctx) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  const { appId } = ctx.query;
15
- const appName = decodeURI(ctx.query.appname);
16
- const backupIdentifier = `${appName}-export-${new Date().getTime()}.txt`;
15
+ const appname = decodeURI(ctx.query.appname);
16
+ const backupIdentifier = `${appname}Backup${new Date().getTime()}.txt`;
17
17
  ctx.attachment(backupIdentifier);
18
- ctx.body = yield streamBackup(appId);
18
+ ctx.body = yield performBackup(appId, backupIdentifier);
19
19
  });
20
20
  };
@@ -16,11 +16,11 @@ const { request } = require("../../utilities/workerRequests");
16
16
  const { clearLock } = require("../../utilities/redis");
17
17
  const { Replication } = require("@budibase/auth").db;
18
18
  const { DocumentTypes } = require("../../db/utils");
19
- function redirect(ctx, method, path = "global") {
19
+ function redirect(ctx, method) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  const { devPath } = ctx.params;
22
22
  const queryString = ctx.originalUrl.split("?")[1] || "";
23
- const response = yield fetch(checkSlashesInUrl(`${env.WORKER_URL}/api/${path}/${devPath}?${queryString}`), request(ctx, {
23
+ const response = yield fetch(checkSlashesInUrl(`${env.WORKER_URL}/api/global/${devPath}?${queryString}`), request(ctx, {
24
24
  method,
25
25
  body: ctx.request.body,
26
26
  }, true));
@@ -45,21 +45,15 @@ function redirect(ctx, method, path = "global") {
45
45
  ctx.cookies;
46
46
  });
47
47
  }
48
- exports.buildRedirectGet = path => {
49
- return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
50
- yield redirect(ctx, "GET", path);
51
- });
52
- };
53
- exports.buildRedirectPost = path => {
54
- return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
55
- yield redirect(ctx, "POST", path);
56
- });
57
- };
58
- exports.buildRedirectDelete = path => {
59
- return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
60
- yield redirect(ctx, "DELETE", path);
61
- });
62
- };
48
+ exports.redirectGet = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
49
+ yield redirect(ctx, "GET");
50
+ });
51
+ exports.redirectPost = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
52
+ yield redirect(ctx, "POST");
53
+ });
54
+ exports.redirectDelete = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
55
+ yield redirect(ctx, "DELETE");
56
+ });
63
57
  exports.clearLock = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
64
58
  const { appId } = ctx.params;
65
59
  try {
@@ -132,7 +132,6 @@ exports.getResourcePerms = function (ctx) {
132
132
  for (let role of roles) {
133
133
  const rolePerms = role.permissions;
134
134
  if (rolePerms &&
135
- rolePerms[resourceId] &&
136
135
  (rolePerms[resourceId] === level ||
137
136
  rolePerms[resourceId].indexOf(level) !== -1)) {
138
137
  permissions[level] = getExternalRoleID(role._id);
@@ -14,7 +14,6 @@ const { generateQueryID, getQueryParams } = require("../../db/utils");
14
14
  const { integrations } = require("../../integrations");
15
15
  const { BaseQueryVerbs } = require("../../constants");
16
16
  const env = require("../../environment");
17
- const ScriptRunner = require("../../utilities/scriptRunner");
18
17
  // simple function to append "readable" to all read queries
19
18
  function enrichQueries(input) {
20
19
  const wasArray = Array.isArray(input);
@@ -36,29 +35,11 @@ function formatResponse(resp) {
36
35
  resp = { response: resp };
37
36
  }
38
37
  }
38
+ if (!Array.isArray(resp)) {
39
+ resp = [resp];
40
+ }
39
41
  return resp;
40
42
  }
41
- function runAndTransform(integration, queryVerb, enrichedQuery, transformer) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- let rows = formatResponse(yield integration[queryVerb](enrichedQuery));
44
- // transform as required
45
- if (transformer) {
46
- const runner = new ScriptRunner(transformer, { data: rows });
47
- rows = runner.execute();
48
- }
49
- // needs to an array for next step
50
- if (!Array.isArray(rows)) {
51
- rows = [rows];
52
- }
53
- // map into JSON if just raw primitive here
54
- if (rows.find(row => typeof row !== "object")) {
55
- rows = rows.map(value => ({ value }));
56
- }
57
- // get all the potential fields in the schema
58
- let keys = rows.flatMap(Object.keys);
59
- return { rows, keys };
60
- });
61
- }
62
43
  exports.fetch = function (ctx) {
63
44
  return __awaiter(this, void 0, void 0, function* () {
64
45
  const db = new CouchDB(ctx.appId);
@@ -138,10 +119,12 @@ exports.preview = function (ctx) {
138
119
  if (!Integration) {
139
120
  ctx.throw(400, "Integration type does not exist.");
140
121
  }
141
- const { fields, parameters, queryVerb, transformer } = ctx.request.body;
122
+ const { fields, parameters, queryVerb } = ctx.request.body;
142
123
  const enrichedQuery = yield enrichQueryFields(fields, parameters);
143
124
  const integration = new Integration(datasource.config);
144
- const { rows, keys } = yield runAndTransform(integration, queryVerb, enrichedQuery, transformer);
125
+ const rows = formatResponse(yield integration[queryVerb](enrichedQuery));
126
+ // get all the potential fields in the schema
127
+ const keys = rows.flatMap(Object.keys);
145
128
  ctx.body = {
146
129
  rows,
147
130
  schemaFields: [...new Set(keys)],
@@ -164,8 +147,7 @@ exports.execute = function (ctx) {
164
147
  const enrichedQuery = yield enrichQueryFields(query.fields, ctx.request.body.parameters);
165
148
  const integration = new Integration(datasource.config);
166
149
  // call the relevant CRUD method on the integration class
167
- const { rows } = yield runAndTransform(integration, query.queryVerb, enrichedQuery, query.transformer);
168
- ctx.body = rows;
150
+ ctx.body = formatResponse(yield integration[query.queryVerb](enrichedQuery));
169
151
  // cleanup
170
152
  if (integration.end) {
171
153
  integration.end();
@@ -22,10 +22,11 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  const datasource_1 = require("../../../definitions/datasource");
24
24
  const utils_1 = require("../../../integrations/utils");
25
+ const constants_1 = require("../../../constants");
25
26
  var External;
26
27
  (function (External) {
27
28
  const { makeExternalQuery } = require("./utils");
28
- const { DataSourceOperation, FieldTypes, RelationshipTypes } = require("../../../constants");
29
+ const { DataSourceOperation, FieldTypes } = require("../../../constants");
29
30
  const { breakExternalTableId, isSQL } = require("../../../integrations/utils");
30
31
  const { processObjectSync } = require("@budibase/string-templates");
31
32
  const { cloneDeep } = require("lodash/fp");
@@ -66,46 +67,6 @@ var External;
66
67
  equal,
67
68
  };
68
69
  }
69
- /**
70
- * This function checks the incoming parameters to make sure all the inputs are
71
- * valid based on on the table schema. The main thing this is looking for is when a
72
- * user has made use of the _id field of a row for a foreign key or a search parameter.
73
- * In these cases the key will be sent up as [1], rather than 1. In these cases we will
74
- * simplify it down to the requirements. This function is quite complex as we try to be
75
- * relatively restrictive over what types of columns we will perform this action for.
76
- */
77
- function cleanupConfig(config, table) {
78
- const primaryOptions = [
79
- FieldTypes.STRING,
80
- FieldTypes.LONGFORM,
81
- FieldTypes.OPTIONS,
82
- FieldTypes.NUMBER,
83
- ];
84
- // filter out fields which cannot be keys
85
- const fieldNames = Object.entries(table.schema)
86
- .filter(schema => primaryOptions.find(val => val === schema[1].type))
87
- .map(([fieldName]) => fieldName);
88
- const iterateObject = (obj) => {
89
- for (let [field, value] of Object.entries(obj)) {
90
- if (fieldNames.find(name => name === field) && utils_1.isRowId(value)) {
91
- obj[field] = utils_1.convertRowId(value);
92
- }
93
- }
94
- };
95
- // check the row and filters to make sure they aren't a key of some sort
96
- if (config.filters) {
97
- for (let filter of Object.values(config.filters)) {
98
- if (typeof filter !== "object" || Object.keys(filter).length === 0) {
99
- continue;
100
- }
101
- iterateObject(filter);
102
- }
103
- }
104
- if (config.row) {
105
- iterateObject(config.row);
106
- }
107
- return config;
108
- }
109
70
  function generateIdForRow(row, table) {
110
71
  const primary = table.primary;
111
72
  if (!row || !primary) {
@@ -355,7 +316,7 @@ var External;
355
316
  if (field.type !== FieldTypes.LINK || !field.fieldName) {
356
317
  continue;
357
318
  }
358
- const isMany = field.relationshipType === RelationshipTypes.MANY_TO_MANY;
319
+ const isMany = field.relationshipType === constants_1.RelationshipTypes.MANY_TO_MANY;
359
320
  const tableId = isMany ? field.through : field.tableId;
360
321
  const manyKey = field.throughFrom || primaryKey;
361
322
  const fieldName = isMany ? manyKey : field.fieldName;
@@ -469,7 +430,7 @@ var External;
469
430
  }
470
431
  return fields;
471
432
  }
472
- run(config) {
433
+ run({ id, row, filters, sort, paginate }) {
473
434
  return __awaiter(this, void 0, void 0, function* () {
474
435
  const { appId, operation, tableId } = this;
475
436
  let { datasourceId, tableName } = breakExternalTableId(tableId);
@@ -486,11 +447,9 @@ var External;
486
447
  if (!table) {
487
448
  throw `Unable to process query, table "${tableName}" not defined.`;
488
449
  }
489
- // look for specific components of config which may not be considered acceptable
490
- let { id, row, filters, sort, paginate } = cleanupConfig(config, table);
450
+ // clean up row on ingress using schema
491
451
  filters = buildFilters(id, filters || {}, table);
492
452
  const relationships = this.buildRelationships(table);
493
- // clean up row on ingress using schema
494
453
  const processed = this.inputProcessing(row, table);
495
454
  row = processed.row;
496
455
  if (operation === DataSourceOperation.DELETE &&
@@ -8,12 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const ScriptRunner = require("../../utilities/scriptRunner");
11
+ const fetch = require("node-fetch");
12
+ const vm = require("vm");
13
+ class ScriptExecutor {
14
+ constructor(body) {
15
+ const code = `let fn = () => {\n${body.script}\n}; out = fn();`;
16
+ this.script = new vm.Script(code);
17
+ this.context = vm.createContext(body.context);
18
+ this.context.fetch = fetch;
19
+ }
20
+ execute() {
21
+ this.script.runInContext(this.context);
22
+ return this.context.out;
23
+ }
24
+ }
12
25
  exports.execute = function (ctx) {
13
26
  return __awaiter(this, void 0, void 0, function* () {
14
- const { script, context } = ctx.request.body;
15
- const runner = new ScriptRunner(script, context);
16
- ctx.body = runner.execute();
27
+ const executor = new ScriptExecutor(ctx.request.body);
28
+ ctx.body = executor.execute();
17
29
  });
18
30
  };
19
31
  exports.save = function (ctx) {
@@ -24,7 +24,8 @@ const linkRows = require("../../../db/linkedRows");
24
24
  const csvParser = require("../../../utilities/csvParser");
25
25
  const { getRowParams, getTableParams, generateTableID, getDatasourceParams, BudibaseInternalDB, } = require("../../../db/utils");
26
26
  const { FieldTypes } = require("../../../constants");
27
- const { TableSaveFunctions, getTable } = require("./utils");
27
+ const { TableSaveFunctions, getExternalTable } = require("./utils");
28
+ const { isExternalTable, breakExternalTableId, } = require("../../../integrations/utils");
28
29
  exports.fetch = function (ctx) {
29
30
  return __awaiter(this, void 0, void 0, function* () {
30
31
  const db = new CouchDB(ctx.appId);
@@ -43,8 +44,15 @@ exports.fetch = function (ctx) {
43
44
  };
44
45
  exports.find = function (ctx) {
45
46
  return __awaiter(this, void 0, void 0, function* () {
47
+ const db = new CouchDB(ctx.appId);
46
48
  const tableId = ctx.params.id;
47
- ctx.body = yield getTable(ctx.appId, tableId);
49
+ if (isExternalTable(tableId)) {
50
+ let { datasourceId, tableName } = breakExternalTableId(tableId);
51
+ ctx.body = yield getExternalTable(ctx.appId, datasourceId, tableName);
52
+ }
53
+ else {
54
+ ctx.body = yield db.get(ctx.params.id);
55
+ }
48
56
  });
49
57
  };
50
58
  exports.save = function (ctx) {
@@ -73,9 +81,6 @@ exports.save = function (ctx) {
73
81
  for (let propKey of Object.keys(tableToSave.schema)) {
74
82
  let column = tableToSave.schema[propKey];
75
83
  let oldColumn = oldTable.schema[propKey];
76
- if (oldColumn && oldColumn.type === "internal") {
77
- oldColumn.type = "auto";
78
- }
79
84
  if (oldColumn && oldColumn.type !== column.type) {
80
85
  ctx.throw(400, "Cannot change the type of a column");
81
86
  }
@@ -9,15 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const CouchDB = require("../../../db");
12
+ const linkRows = require("../../../db/linkedRows");
12
13
  const csvParser = require("../../../utilities/csvParser");
13
14
  const { getRowParams, generateRowID, InternalTables, } = require("../../../db/utils");
14
15
  const { isEqual } = require("lodash/fp");
15
16
  const { AutoFieldSubTypes, FieldTypes } = require("../../../constants");
16
17
  const { inputProcessing } = require("../../../utilities/rowProcessor");
17
18
  const { USERS_TABLE_SCHEMA } = require("../../../constants");
18
- const { isExternalTable, breakExternalTableId, } = require("../../../integrations/utils");
19
- const { getViews, saveView } = require("../view/utils");
20
- const viewTemplate = require("../view/viewBuilder");
21
19
  exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0, void 0, void 0, function* () {
22
20
  let updatedRows = [];
23
21
  const rename = updatedTable._rename;
@@ -27,7 +25,6 @@ exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0
27
25
  }
28
26
  // check for renaming of columns or deleted columns
29
27
  if (rename || deletedColumns.length !== 0) {
30
- // Update all rows
31
28
  const rows = yield db.allDocs(getRowParams(updatedTable._id, null, {
32
29
  include_docs: true,
33
30
  }));
@@ -41,8 +38,6 @@ exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0
41
38
  }
42
39
  return doc;
43
40
  });
44
- // Update views
45
- yield exports.checkForViewUpdates(db, updatedTable, rename, deletedColumns);
46
41
  delete updatedTable._rename;
47
42
  }
48
43
  return { rows: updatedRows, table: updatedTable };
@@ -91,9 +86,16 @@ exports.handleDataImport = (appId, user, table, dataImport) => __awaiter(void 0,
91
86
  ];
92
87
  }
93
88
  }
94
- finalData.push(row);
89
+ // make sure link rows are up to date
90
+ finalData.push(linkRows.updateLinks({
91
+ appId,
92
+ eventType: linkRows.EventType.ROW_SAVE,
93
+ row,
94
+ tableId: row.tableId,
95
+ table,
96
+ }));
95
97
  }
96
- yield db.bulkDocs(finalData);
98
+ yield db.bulkDocs(yield Promise.all(finalData));
97
99
  let response = yield db.put(table);
98
100
  table._rev = response._rev;
99
101
  }
@@ -202,79 +204,4 @@ exports.getExternalTable = (appId, datasourceId, tableName) => __awaiter(void 0,
202
204
  const entities = yield exports.getAllExternalTables(appId, datasourceId);
203
205
  return entities[tableName];
204
206
  });
205
- exports.getTable = (appId, tableId) => __awaiter(void 0, void 0, void 0, function* () {
206
- const db = new CouchDB(appId);
207
- if (isExternalTable(tableId)) {
208
- let { datasourceId, tableName } = breakExternalTableId(tableId);
209
- return exports.getExternalTable(appId, datasourceId, tableName);
210
- }
211
- else {
212
- return db.get(tableId);
213
- }
214
- });
215
- exports.checkForViewUpdates = (db, table, rename, deletedColumns) => __awaiter(void 0, void 0, void 0, function* () {
216
- const views = yield getViews(db);
217
- const tableViews = views.filter(view => view.meta.tableId === table._id);
218
- // Check each table view to see if impacted by this table action
219
- for (let view of tableViews) {
220
- let needsUpdated = false;
221
- // First check for renames, otherwise check for deletions
222
- if (rename) {
223
- // Update calculation field if required
224
- if (view.meta.field === rename.old) {
225
- view.meta.field = rename.updated;
226
- needsUpdated = true;
227
- }
228
- // Update group by field if required
229
- if (view.meta.groupBy === rename.old) {
230
- view.meta.groupBy = rename.updated;
231
- needsUpdated = true;
232
- }
233
- // Update filters if required
234
- if (view.meta.filters) {
235
- view.meta.filters.forEach(filter => {
236
- if (filter.key === rename.old) {
237
- filter.key = rename.updated;
238
- needsUpdated = true;
239
- }
240
- });
241
- }
242
- }
243
- else if (deletedColumns) {
244
- deletedColumns.forEach(column => {
245
- // Remove calculation statement if required
246
- if (view.meta.field === column) {
247
- delete view.meta.field;
248
- delete view.meta.calculation;
249
- delete view.meta.groupBy;
250
- needsUpdated = true;
251
- }
252
- // Remove group by field if required
253
- if (view.meta.groupBy === column) {
254
- delete view.meta.groupBy;
255
- needsUpdated = true;
256
- }
257
- // Remove filters referencing deleted field if required
258
- if (view.meta.filters && view.meta.filters.length) {
259
- const initialLength = view.meta.filters.length;
260
- view.meta.filters = view.meta.filters.filter(filter => {
261
- return filter.key !== column;
262
- });
263
- if (initialLength !== view.meta.filters.length) {
264
- needsUpdated = true;
265
- }
266
- }
267
- });
268
- }
269
- // Update view if required
270
- if (needsUpdated) {
271
- const newViewTemplate = viewTemplate(view.meta);
272
- yield saveView(db, null, view.name, newViewTemplate);
273
- if (!newViewTemplate.meta.schema) {
274
- newViewTemplate.meta.schema = table.schema;
275
- }
276
- table.views[view.name] = newViewTemplate.meta;
277
- }
278
- }
279
- });
280
207
  exports.TableSaveFunctions = TableSaveFunctions;
@@ -15,24 +15,9 @@ const DEFAULT_TEMPLATES_BUCKET = "prod-budi-templates.s3-eu-west-1.amazonaws.com
15
15
  exports.fetch = function (ctx) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  const { type = "app" } = ctx.query;
18
- let response, error = false;
19
- try {
20
- response = yield fetch(`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`);
21
- if (response.status !== 200) {
22
- error = true;
23
- }
24
- }
25
- catch (err) {
26
- error = true;
27
- }
28
- // if there is an error, simply return no templates
29
- if (!error && response) {
30
- const json = yield response.json();
31
- ctx.body = Object.values(json.templates[type]);
32
- }
33
- else {
34
- ctx.body = [];
35
- }
18
+ const response = yield fetch(`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`);
19
+ const json = yield response.json();
20
+ ctx.body = Object.values(json.templates[type]);
36
21
  });
37
22
  };
38
23
  // can't currently test this, have to ignore from coverage
@@ -5,15 +5,11 @@ const env = require("../../environment");
5
5
  const authorized = require("../../middleware/authorized");
6
6
  const { BUILDER } = require("@budibase/auth/permissions");
7
7
  const router = Router();
8
- function redirectPath(path) {
9
- router
10
- .get(`/api/${path}/:devPath(.*)`, controller.buildRedirectGet(path))
11
- .post(`/api/${path}/:devPath(.*)`, controller.buildRedirectPost(path))
12
- .delete(`/api/${path}/:devPath(.*)`, controller.buildRedirectDelete(path));
13
- }
14
8
  if (env.isDev() || env.isTest()) {
15
- redirectPath("global");
16
- redirectPath("system");
9
+ router
10
+ .get("/api/global/:devPath(.*)", controller.redirectGet)
11
+ .post("/api/global/:devPath(.*)", controller.redirectPost)
12
+ .delete("/api/global/:devPath(.*)", controller.redirectDelete);
17
13
  }
18
14
  router
19
15
  .get("/api/dev/version", authorized(BUILDER), controller.getBudibaseVersion)
@@ -22,8 +22,7 @@ function generateQueryValidation() {
22
22
  })),
23
23
  queryVerb: Joi.string().allow().required(),
24
24
  extra: Joi.object().optional(),
25
- schema: Joi.object({}).required().unknown(true),
26
- transformer: Joi.string().optional(),
25
+ schema: Joi.object({}).required().unknown(true)
27
26
  }));
28
27
  }
29
28
  function generateQueryPreviewValidation() {
@@ -33,7 +32,6 @@ function generateQueryPreviewValidation() {
33
32
  queryVerb: Joi.string().allow().required(),
34
33
  extra: Joi.object().optional(),
35
34
  datasourceId: Joi.string().required(),
36
- transformer: Joi.string().optional(),
37
35
  parameters: Joi.object({}).required().unknown(true)
38
36
  }));
39
37
  }
@@ -13,6 +13,7 @@ const createRow = require("./steps/createRow");
13
13
  const updateRow = require("./steps/updateRow");
14
14
  const deleteRow = require("./steps/deleteRow");
15
15
  const executeScript = require("./steps/executeScript");
16
+ const bash = require("./steps/bash");
16
17
  const executeQuery = require("./steps/executeQuery");
17
18
  const outgoingWebhook = require("./steps/outgoingWebhook");
18
19
  const serverLog = require("./steps/serverLog");
@@ -23,7 +24,6 @@ const integromat = require("./steps/integromat");
23
24
  let filter = require("./steps/filter");
24
25
  let delay = require("./steps/delay");
25
26
  let queryRow = require("./steps/queryRows");
26
- const env = require("../environment");
27
27
  const ACTION_IMPLS = {
28
28
  SEND_EMAIL_SMTP: sendSmtpEmail.run,
29
29
  CREATE_ROW: createRow.run,
@@ -31,6 +31,7 @@ const ACTION_IMPLS = {
31
31
  DELETE_ROW: deleteRow.run,
32
32
  OUTGOING_WEBHOOK: outgoingWebhook.run,
33
33
  EXECUTE_SCRIPT: executeScript.run,
34
+ EXECUTE_BASH: bash.run,
34
35
  EXECUTE_QUERY: executeQuery.run,
35
36
  SERVER_LOG: serverLog.run,
36
37
  DELAY: delay.run,
@@ -50,6 +51,7 @@ const ACTION_DEFINITIONS = {
50
51
  OUTGOING_WEBHOOK: outgoingWebhook.definition,
51
52
  EXECUTE_SCRIPT: executeScript.definition,
52
53
  EXECUTE_QUERY: executeQuery.definition,
54
+ EXECUTE_BASH: bash.definition,
53
55
  SERVER_LOG: serverLog.definition,
54
56
  DELAY: delay.definition,
55
57
  FILTER: filter.definition,
@@ -60,14 +62,6 @@ const ACTION_DEFINITIONS = {
60
62
  zapier: zapier.definition,
61
63
  integromat: integromat.definition,
62
64
  };
63
- // don't add the bash script/definitions unless in self host
64
- // the fact this isn't included in any definitions means it cannot be
65
- // ran at all
66
- if (env.SELF_HOSTED) {
67
- const bash = require("./steps/bash");
68
- ACTION_IMPLS["EXECUTE_BASH"] = bash.run;
69
- ACTION_DEFINITIONS["EXECUTE_BASH"] = bash.definition;
70
- }
71
65
  /* istanbul ignore next */
72
66
  exports.getAction = function (actionName) {
73
67
  return __awaiter(this, void 0, void 0, function* () {
@@ -8,7 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { getTable } = require("../api/controllers/table/utils");
11
+ const CouchDB = require("../db");
12
+ const { isExternalTable, breakExternalTableId, } = require("../integrations/utils");
13
+ const { getExternalTable } = require("../api/controllers/table/utils");
12
14
  /**
13
15
  * When values are input to the system generally they will be of type string as this is required for template strings.
14
16
  * This can generate some odd scenarios as the Schema of the automation requires a number but the builder might supply
@@ -25,7 +27,7 @@ const { getTable } = require("../api/controllers/table/utils");
25
27
  * @returns {object} The inputs object which has had all the various types supported by this function converted to their
26
28
  * primitive types.
27
29
  */
28
- exports.cleanInputValues = (inputs, schema) => {
30
+ module.exports.cleanInputValues = (inputs, schema) => {
29
31
  if (schema == null) {
30
32
  return inputs;
31
33
  }
@@ -66,10 +68,29 @@ exports.cleanInputValues = (inputs, schema) => {
66
68
  * @param {object} row The input row structure which requires clean-up after having been through template statements.
67
69
  * @returns {Promise<Object>} The cleaned up rows object, will should now have all the required primitive types.
68
70
  */
69
- exports.cleanUpRow = (appId, tableId, row) => __awaiter(void 0, void 0, void 0, function* () {
70
- let table = yield getTable(appId, tableId);
71
- return exports.cleanInputValues(row, { properties: table.schema });
71
+ module.exports.cleanUpRow = (appId, tableId, row) => __awaiter(void 0, void 0, void 0, function* () {
72
+ const db = new CouchDB(appId);
73
+ let table;
74
+ if (isExternalTable(tableId)) {
75
+ const { datasourceId, tableName } = breakExternalTableId(tableId);
76
+ table = yield getExternalTable(appId, datasourceId, tableName);
77
+ }
78
+ else {
79
+ table = yield db.get(tableId);
80
+ }
81
+ return module.exports.cleanInputValues(row, { properties: table.schema });
82
+ });
83
+ /**
84
+ * A utility function for the cleanUpRow, which can be used if only the row ID is known (not the table ID) to clean
85
+ * up a row after template statements have been replaced. This is specifically useful for the update row action.
86
+ *
87
+ * @param {string} appId The instance which the Table/Table is contained under.
88
+ * @param {string} rowId The ID of the row from which the tableId will be extracted, to get the Table/Table schema.
89
+ * @param {object} row The input row structure which requires clean-up after having been through template statements.
90
+ * @returns {Promise<Object>} The cleaned up rows object, which will now have all the required primitive types.
91
+ */
92
+ module.exports.cleanUpRowById = (appId, rowId, row) => __awaiter(void 0, void 0, void 0, function* () {
93
+ const db = new CouchDB(appId);
94
+ const foundRow = yield db.get(rowId);
95
+ return module.exports.cleanUpRow(appId, foundRow.tableId, row);
72
96
  });
73
- exports.getError = err => {
74
- return typeof err !== "string" ? err.toString() : err;
75
- };
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const { execSync } = require("child_process");
12
12
  const { processStringSync } = require("@budibase/string-templates");
13
- const automationUtils = require("../automationUtils");
14
13
  exports.definition = {
15
14
  name: "Bash Scripting",
16
15
  tagline: "Execute a bash command",
@@ -71,7 +70,7 @@ exports.run = function ({ inputs, context }) {
71
70
  catch (err) {
72
71
  return {
73
72
  success: false,
74
- response: automationUtils.getError(err),
73
+ response: err,
75
74
  };
76
75
  }
77
76
  });
@@ -102,7 +102,7 @@ exports.run = function ({ inputs, appId, emitter }) {
102
102
  catch (err) {
103
103
  return {
104
104
  success: false,
105
- response: automationUtils.getError(err),
105
+ response: err,
106
106
  };
107
107
  }
108
108
  });
@@ -12,7 +12,6 @@ const rowController = require("../../api/controllers/row");
12
12
  const env = require("../../environment");
13
13
  const usage = require("../../utilities/usageQuota");
14
14
  const { buildCtx } = require("./utils");
15
- const automationUtils = require("../automationUtils");
16
15
  exports.definition = {
17
16
  description: "Delete a row from your database",
18
17
  icon: "TableRowRemoveCenter",
@@ -94,7 +93,7 @@ exports.run = function ({ inputs, appId, emitter }) {
94
93
  catch (err) {
95
94
  return {
96
95
  success: false,
97
- response: automationUtils.getError(err),
96
+ response: err,
98
97
  };
99
98
  }
100
99
  });
@@ -21,7 +21,6 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  const queryController = require("../../api/controllers/query");
23
23
  const { buildCtx } = require("./utils");
24
- const automationUtils = require("../automationUtils");
25
24
  exports.definition = {
26
25
  name: "External Data Connector",
27
26
  tagline: "Execute Data Connector",
@@ -93,7 +92,7 @@ exports.run = function ({ inputs, appId, emitter }) {
93
92
  catch (err) {
94
93
  return {
95
94
  success: false,
96
- response: automationUtils.getError(err),
95
+ response: err,
97
96
  };
98
97
  }
99
98
  });