@budibase/server 1.0.212-alpha.12 → 1.0.212-alpha.15

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 (202) hide show
  1. package/__mocks__/node-fetch.ts +9 -0
  2. package/builder/assets/{index.969c2236.css → index.7786f497.css} +2 -2
  3. package/builder/assets/index.83448a6c.js +977 -0
  4. package/builder/assets/{vendor.9bf2fcb4.js → vendor.001dcf8c.js} +163 -163
  5. package/builder/index.html +3 -3
  6. package/coverage/clover.xml +636 -590
  7. package/coverage/coverage-final.json +20 -20
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/automation.js.html +111 -12
  11. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  15. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/index.html +19 -19
  17. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  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 +1 -1
  28. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/staticFormula.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 +1 -1
  34. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  46. package/coverage/lcov-report/api/index.html +15 -15
  47. package/coverage/lcov-report/api/index.js.html +22 -13
  48. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/apikeys.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 +32 -2
  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 +1 -1
  58. package/coverage/lcov-report/api/routes/index.html +1 -1
  59. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  73. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  76. package/coverage/lcov-report/automations/actions.js.html +1 -1
  77. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  78. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  79. package/coverage/lcov-report/automations/index.html +1 -1
  80. package/coverage/lcov-report/automations/index.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/filter.js.html +58 -34
  87. package/coverage/lcov-report/automations/steps/index.html +11 -11
  88. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  107. package/coverage/lcov-report/constants/index.html +1 -1
  108. package/coverage/lcov-report/constants/index.js.html +1 -1
  109. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  110. package/coverage/lcov-report/constants/screens.js.html +1 -1
  111. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  112. package/coverage/lcov-report/db/index.html +14 -14
  113. package/coverage/lcov-report/db/index.js.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/index.html +13 -13
  116. package/coverage/lcov-report/db/linkedRows/index.js.html +10 -7
  117. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  118. package/coverage/lcov-report/db/newid.js.html +2 -2
  119. package/coverage/lcov-report/db/utils.js.html +25 -52
  120. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  121. package/coverage/lcov-report/events/index.html +1 -1
  122. package/coverage/lcov-report/events/index.js.html +1 -1
  123. package/coverage/lcov-report/events/utils.js.html +1 -1
  124. package/coverage/lcov-report/index.html +57 -57
  125. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  126. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  127. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  128. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  129. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  130. package/coverage/lcov-report/middleware/index.html +1 -1
  131. package/coverage/lcov-report/middleware/joi-validator.js.html +10 -10
  132. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  133. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  134. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  135. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  136. package/coverage/lcov-report/threads/automation.js.html +17 -8
  137. package/coverage/lcov-report/threads/index.html +25 -25
  138. package/coverage/lcov-report/threads/query.js.html +280 -76
  139. package/coverage/lcov-report/threads/utils.js.html +4 -4
  140. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  141. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  142. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  143. package/coverage/lcov-report/utilities/global.js.html +14 -14
  144. package/coverage/lcov-report/utilities/index.html +1 -1
  145. package/coverage/lcov-report/utilities/index.js.html +9 -9
  146. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  147. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  148. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  149. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  150. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  151. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  152. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  153. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  154. package/coverage/lcov-report/utilities/security.js.html +2 -2
  155. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  156. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  157. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  158. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  159. package/coverage/lcov-report/utilities/users.js.html +1 -1
  160. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  161. package/coverage/lcov.info +1131 -1049
  162. package/dist/api/controllers/application.js +2 -1
  163. package/dist/api/controllers/automation.js +28 -2
  164. package/dist/api/controllers/query/index.js +25 -0
  165. package/dist/api/index.js +4 -1
  166. package/dist/api/routes/automation.js +2 -0
  167. package/dist/automations/logging/index.js +70 -0
  168. package/dist/automations/steps/filter.js +38 -29
  169. package/dist/db/linkedRows/index.js +1 -0
  170. package/dist/db/utils.js +3 -31
  171. package/dist/environment.js +1 -0
  172. package/dist/integrations/queries/sql.js +3 -0
  173. package/dist/integrations/rest.js +1 -1
  174. package/dist/package.json +6 -6
  175. package/dist/tests/utilities/TestConfiguration.js +19 -6
  176. package/dist/threads/automation.js +5 -2
  177. package/dist/threads/index.js +15 -1
  178. package/dist/threads/query.js +53 -8
  179. package/dist/tsconfig.build.tsbuildinfo +1 -1
  180. package/package.json +7 -7
  181. package/src/api/controllers/application.ts +2 -1
  182. package/src/api/controllers/automation.js +35 -2
  183. package/src/api/controllers/query/index.ts +29 -1
  184. package/src/api/index.js +4 -1
  185. package/src/api/routes/automation.js +10 -0
  186. package/src/api/routes/tests/query.spec.js +166 -0
  187. package/src/automations/logging/index.ts +35 -0
  188. package/src/automations/steps/filter.js +36 -28
  189. package/src/automations/tests/filter.spec.js +2 -1
  190. package/src/db/linkedRows/index.js +1 -0
  191. package/src/db/utils.js +4 -13
  192. package/src/environment.js +1 -0
  193. package/src/integrations/queries/sql.ts +3 -1
  194. package/src/integrations/rest.ts +1 -1
  195. package/src/integrations/tests/rest.spec.js +16 -1
  196. package/src/migrations/tests/index.spec.ts +18 -2
  197. package/src/module.d.ts +2 -0
  198. package/src/tests/utilities/TestConfiguration.js +22 -3
  199. package/src/threads/automation.js +5 -2
  200. package/src/threads/index.ts +5 -1
  201. package/src/threads/query.js +78 -10
  202. package/builder/assets/index.a895b27f.js +0 -978
@@ -33,6 +33,7 @@ const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
33
33
  const user_1 = require("./user");
34
34
  const { app: appCache } = require("@budibase/backend-core/cache");
35
35
  const utils_2 = require("../../automations/utils");
36
+ const logging_1 = require("../../automations/logging");
36
37
  const { getAppDB, getProdAppDB, updateAppId, doInAppContext, } = require("@budibase/backend-core/context");
37
38
  const rows_1 = require("../../utilities/usageQuota/rows");
38
39
  const pro_1 = require("@budibase/pro");
@@ -159,7 +160,7 @@ const fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
159
160
  }
160
161
  }
161
162
  }
162
- ctx.body = apps;
163
+ ctx.body = yield (0, logging_1.checkAppMetadata)(apps);
163
164
  });
164
165
  exports.fetch = fetch;
165
166
  const fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
@@ -10,13 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const actions = require("../../automations/actions");
12
12
  const triggers = require("../../automations/triggers");
13
- const { getAutomationParams, generateAutomationID } = require("../../db/utils");
13
+ const { getAutomationParams, generateAutomationID, DocumentTypes, } = require("../../db/utils");
14
14
  const { checkForWebhooks, updateTestHistory, removeDeprecated, } = require("../../automations/utils");
15
15
  const { deleteEntityMetadata } = require("../../utilities");
16
16
  const { MetadataTypes } = require("../../constants");
17
17
  const { setTestFlag, clearTestFlag } = require("../../utilities/redis");
18
- const { getAppDB } = require("@budibase/backend-core/context");
18
+ const { getAppDB, getProdAppDB, doInAppContext, } = require("@budibase/backend-core/context");
19
19
  const { events } = require("@budibase/backend-core");
20
+ const { app } = require("@budibase/backend-core/cache");
21
+ const { automations } = require("@budibase/pro");
20
22
  const ACTION_DEFS = removeDeprecated(actions.ACTION_DEFINITIONS);
21
23
  const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS);
22
24
  /*************************
@@ -162,6 +164,30 @@ exports.destroy = function (ctx) {
162
164
  yield events.automation.deleted(oldAutomation);
163
165
  });
164
166
  };
167
+ exports.logSearch = function (ctx) {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ ctx.body = yield automations.logs.logSearch(ctx.request.body);
170
+ });
171
+ };
172
+ exports.clearLogError = function (ctx) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const { automationId, appId } = ctx.request.body;
175
+ yield doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
176
+ const db = getProdAppDB();
177
+ const metadata = yield db.get(DocumentTypes.APP_METADATA);
178
+ if (!automationId) {
179
+ delete metadata.automationErrors;
180
+ }
181
+ else if (metadata.automationErrors &&
182
+ metadata.automationErrors[automationId]) {
183
+ delete metadata.automationErrors[automationId];
184
+ }
185
+ yield db.put(metadata);
186
+ yield app.invalidateAppMetadata(metadata.appId, metadata);
187
+ ctx.body = { message: `Error logs cleared.` };
188
+ }));
189
+ });
190
+ };
165
191
  exports.getActionList = function (ctx) {
166
192
  return __awaiter(this, void 0, void 0, function* () {
167
193
  ctx.body = ACTION_DEFS;
@@ -20,6 +20,8 @@ const environment_1 = require("../../../environment");
20
20
  const context_1 = require("@budibase/backend-core/context");
21
21
  const pro_1 = require("@budibase/pro");
22
22
  const backend_core_1 = require("@budibase/backend-core");
23
+ const utils_3 = require("@budibase/backend-core/utils");
24
+ const constants_2 = require("@budibase/backend-core/constants");
23
25
  const Runner = new threads_1.Thread(threads_1.ThreadType.QUERY, {
24
26
  timeoutMs: environment_1.QUERY_THREAD_TIMEOUT || 10000,
25
27
  });
@@ -111,6 +113,19 @@ function find(ctx) {
111
113
  });
112
114
  }
113
115
  exports.find = find;
116
+ //Required to discern between OIDC OAuth config entries
117
+ function getOAuthConfigCookieId(ctx) {
118
+ if (ctx.user.providerType === constants_2.Configs.OIDC) {
119
+ return (0, utils_3.getCookie)(ctx, constants_2.Cookies.OIDC_CONFIG);
120
+ }
121
+ }
122
+ function getAuthConfig(ctx) {
123
+ const authCookie = (0, utils_3.getCookie)(ctx, constants_2.Cookies.Auth);
124
+ let authConfigCtx = {};
125
+ authConfigCtx["configId"] = getOAuthConfigCookieId(ctx);
126
+ authConfigCtx["sessionId"] = authCookie ? authCookie.sessionId : null;
127
+ return authConfigCtx;
128
+ }
114
129
  function preview(ctx) {
115
130
  return __awaiter(this, void 0, void 0, function* () {
116
131
  const db = (0, context_1.getAppDB)();
@@ -119,6 +134,7 @@ function preview(ctx) {
119
134
  // preview may not have a queryId as it hasn't been saved, but if it does
120
135
  // this stops dynamic variables from calling the same query
121
136
  const { fields, parameters, queryVerb, transformer, queryId } = query;
137
+ const authConfigCtx = getAuthConfig(ctx);
122
138
  try {
123
139
  const runFn = () => Runner.run({
124
140
  appId: ctx.appId,
@@ -128,6 +144,10 @@ function preview(ctx) {
128
144
  parameters,
129
145
  transformer,
130
146
  queryId,
147
+ ctx: {
148
+ user: ctx.user,
149
+ auth: Object.assign({}, authConfigCtx),
150
+ },
131
151
  });
132
152
  const { rows, keys, info, extra } = yield pro_1.quotas.addQuery(runFn);
133
153
  yield backend_core_1.events.query.previewed(datasource, query);
@@ -149,6 +169,7 @@ function execute(ctx, opts = { rowsOnly: false }) {
149
169
  const db = (0, context_1.getAppDB)();
150
170
  const query = yield db.get(ctx.params.queryId);
151
171
  const datasource = yield db.get(query.datasourceId);
172
+ const authConfigCtx = getAuthConfig(ctx);
152
173
  const enrichedParameters = ctx.request.body.parameters || {};
153
174
  // make sure parameters are fully enriched with defaults
154
175
  if (query && query.parameters) {
@@ -169,6 +190,10 @@ function execute(ctx, opts = { rowsOnly: false }) {
169
190
  parameters: enrichedParameters,
170
191
  transformer: query.transformer,
171
192
  queryId: ctx.params.queryId,
193
+ ctx: {
194
+ user: ctx.user,
195
+ auth: Object.assign({}, authConfigCtx),
196
+ },
172
197
  });
173
198
  const { rows, pagination, extra } = yield pro_1.quotas.addQuery(runFn);
174
199
  if (opts && opts.rowsOnly) {
package/dist/api/index.js CHANGED
@@ -69,7 +69,10 @@ router.use((ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
69
69
  error,
70
70
  };
71
71
  ctx.log.error(err);
72
- console.trace(err);
72
+ // unauthorised errors don't provide a useful trace
73
+ if (!env.isTest()) {
74
+ console.trace(err);
75
+ }
73
76
  }
74
77
  }));
75
78
  // authenticated routes
@@ -15,6 +15,8 @@ router
15
15
  .get("/api/automations/:id", paramResource("id"), authorized(BUILDER), controller.find)
16
16
  .put("/api/automations", bodyResource("_id"), authorized(BUILDER), automationValidator(true), controller.update)
17
17
  .post("/api/automations", authorized(BUILDER), automationValidator(false), controller.create)
18
+ .post("/api/automations/logs/search", authorized(BUILDER), controller.logSearch)
19
+ .delete("/api/automations/logs", authorized(BUILDER), controller.clearLogError)
18
20
  .delete("/api/automations/:id/:rev", paramResource("id"), authorized(BUILDER), controller.destroy)
19
21
  .post("/api/automations/:id/trigger", appInfoMiddleware({ appType: AppType.PROD }), paramResource("id"), authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE), controller.trigger)
20
22
  .post("/api/automations/:id/test", appInfoMiddleware({ appType: AppType.DEV }), paramResource("id"), authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE), controller.test);
@@ -0,0 +1,70 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.checkAppMetadata = exports.storeLog = void 0;
36
+ const env = __importStar(require("../../environment"));
37
+ const pro_1 = require("@budibase/pro");
38
+ const backend_core_1 = require("@budibase/backend-core");
39
+ function storeLog(automation, results) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ // can disable this if un-needed in self-host, also only do this for prod apps
42
+ if (env.DISABLE_AUTOMATION_LOGS) {
43
+ return;
44
+ }
45
+ yield pro_1.automations.logs.storeLog(automation, results);
46
+ });
47
+ }
48
+ exports.storeLog = storeLog;
49
+ function checkAppMetadata(apps) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const maxStartDate = yield pro_1.automations.logs.oldestLogDate();
52
+ for (let metadata of apps) {
53
+ if (!metadata.automationErrors) {
54
+ continue;
55
+ }
56
+ for (let [key, errors] of Object.entries(metadata.automationErrors)) {
57
+ const updated = [];
58
+ for (let error of errors) {
59
+ const startDate = error.split(backend_core_1.db.SEPARATOR)[2];
60
+ if (startDate > maxStartDate) {
61
+ updated.push(error);
62
+ }
63
+ }
64
+ metadata.automationErrors[key] = updated;
65
+ }
66
+ }
67
+ return apps;
68
+ });
69
+ }
70
+ exports.checkAppMetadata = checkAppMetadata;
@@ -56,46 +56,55 @@ exports.definition = {
56
56
  outputs: {
57
57
  properties: {
58
58
  success: {
59
+ type: "boolean",
60
+ description: "Whether the action was successful",
61
+ },
62
+ result: {
59
63
  type: "boolean",
60
64
  description: "Whether the logic block passed",
61
65
  },
62
66
  },
63
- required: ["success"],
67
+ required: ["success", "result"],
64
68
  },
65
69
  },
66
70
  };
67
71
  exports.run = function filter({ inputs }) {
68
72
  return __awaiter(this, void 0, void 0, function* () {
69
- let { field, condition, value } = inputs;
70
- // coerce types so that we can use them
71
- if (!isNaN(value) && !isNaN(field)) {
72
- value = parseFloat(value);
73
- field = parseFloat(field);
74
- }
75
- else if (!isNaN(Date.parse(value)) && !isNaN(Date.parse(field))) {
76
- value = Date.parse(value);
77
- field = Date.parse(field);
78
- }
79
- let success = false;
80
- if (typeof field !== "object" && typeof value !== "object") {
81
- switch (condition) {
82
- case FilterConditions.EQUAL:
83
- success = field === value;
84
- break;
85
- case FilterConditions.NOT_EQUAL:
86
- success = field !== value;
87
- break;
88
- case FilterConditions.GREATER_THAN:
89
- success = field > value;
90
- break;
91
- case FilterConditions.LESS_THAN:
92
- success = field < value;
93
- break;
73
+ try {
74
+ let { field, condition, value } = inputs;
75
+ // coerce types so that we can use them
76
+ if (!isNaN(value) && !isNaN(field)) {
77
+ value = parseFloat(value);
78
+ field = parseFloat(field);
79
+ }
80
+ else if (!isNaN(Date.parse(value)) && !isNaN(Date.parse(field))) {
81
+ value = Date.parse(value);
82
+ field = Date.parse(field);
83
+ }
84
+ let result = false;
85
+ if (typeof field !== "object" && typeof value !== "object") {
86
+ switch (condition) {
87
+ case FilterConditions.EQUAL:
88
+ result = field === value;
89
+ break;
90
+ case FilterConditions.NOT_EQUAL:
91
+ result = field !== value;
92
+ break;
93
+ case FilterConditions.GREATER_THAN:
94
+ result = field > value;
95
+ break;
96
+ case FilterConditions.LESS_THAN:
97
+ result = field < value;
98
+ break;
99
+ }
100
+ }
101
+ else {
102
+ result = false;
94
103
  }
104
+ return { success: true, result };
95
105
  }
96
- else {
97
- success = false;
106
+ catch (err) {
107
+ return { success: false, result: false };
98
108
  }
99
- return { success };
100
109
  });
101
110
  };
@@ -56,6 +56,7 @@ function getLinksForRows(rows) {
56
56
  // have to get unique as the previous table query can
57
57
  // return duplicates, could be querying for both tables in a relation
58
58
  return getUniqueByProp(responses
59
+ .filter(el => el != null)
59
60
  // create a unique ID which we can use for getting only unique ones
60
61
  .map(el => (Object.assign(Object.assign({}, el), { unique: el.id + el.thisId + el.fieldName }))), "unique");
61
62
  });
package/dist/db/utils.js CHANGED
@@ -1,39 +1,13 @@
1
1
  "use strict";
2
2
  const newid = require("./newid");
3
- const { DocumentTypes: CoreDocTypes, getRoleParams, generateRoleID, APP_DEV_PREFIX, APP_PREFIX, SEPARATOR, StaticDatabases, isDevAppID, isProdAppID, getDevelopmentAppID, generateAppID, } = require("@budibase/backend-core/db");
3
+ const { DocumentTypes: CoreDocTypes, getRoleParams, generateRoleID, APP_DEV_PREFIX, APP_PREFIX, SEPARATOR, StaticDatabases, isDevAppID, isProdAppID, getDevelopmentAppID, generateAppID, getQueryIndex, ViewNames, } = require("@budibase/backend-core/db");
4
4
  const UNICODE_MAX = "\ufff0";
5
5
  const AppStatus = {
6
6
  DEV: "development",
7
7
  ALL: "all",
8
8
  DEPLOYED: "published",
9
9
  };
10
- const DocumentTypes = {
11
- APP: CoreDocTypes.APP,
12
- DEV: CoreDocTypes.DEV,
13
- APP_DEV: CoreDocTypes.APP_DEV,
14
- APP_METADATA: CoreDocTypes.APP_METADATA,
15
- ROLE: CoreDocTypes.ROLE,
16
- TABLE: "ta",
17
- ROW: "ro",
18
- USER: "us",
19
- AUTOMATION: "au",
20
- LINK: "li",
21
- WEBHOOK: "wh",
22
- INSTANCE: "inst",
23
- LAYOUT: "layout",
24
- SCREEN: "screen",
25
- DATASOURCE: "datasource",
26
- DATASOURCE_PLUS: "datasource_plus",
27
- QUERY: "query",
28
- DEPLOYMENTS: "deployments",
29
- METADATA: "metadata",
30
- MEM_VIEW: "view",
31
- USER_FLAG: "flag",
32
- };
33
- const ViewNames = {
34
- LINK: "by_link",
35
- ROUTING: "screen_routes",
36
- };
10
+ const DocumentTypes = Object.assign(Object.assign({}, CoreDocTypes), { TABLE: "ta", ROW: "ro", USER: "us", AUTOMATION: "au", LINK: "li", WEBHOOK: "wh", INSTANCE: "inst", LAYOUT: "layout", SCREEN: "screen", DATASOURCE: "datasource", DATASOURCE_PLUS: "datasource_plus", QUERY: "query", DEPLOYMENTS: "deployments", METADATA: "metadata", MEM_VIEW: "view", USER_FLAG: "flag" });
37
11
  const InternalTables = {
38
12
  USER_METADATA: "ta_users",
39
13
  };
@@ -67,9 +41,7 @@ exports.generateAppID = generateAppID;
67
41
  exports.generateDevAppID = getDevelopmentAppID;
68
42
  exports.generateRoleID = generateRoleID;
69
43
  exports.getRoleParams = getRoleParams;
70
- exports.getQueryIndex = viewName => {
71
- return `database/${viewName}`;
72
- };
44
+ exports.getQueryIndex = getQueryIndex;
73
45
  /**
74
46
  * If creating DB allDocs/query params with only a single top level ID this can be used, this
75
47
  * is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
@@ -66,6 +66,7 @@ module.exports = {
66
66
  ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
67
67
  DISABLE_THREADING: process.env.DISABLE_THREADING,
68
68
  DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE,
69
+ DISABLE_AUTOMATION_LOGS: process.env.DISABLE_AUTOMATION_LOGS,
69
70
  MULTI_TENANCY: process.env.MULTI_TENANCY,
70
71
  ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
71
72
  SELF_HOSTED: process.env.SELF_HOSTED,
@@ -5,6 +5,9 @@ const string_templates_1 = require("@budibase/string-templates");
5
5
  const CONST_CHAR_REGEX = new RegExp("'[^']*'", "g");
6
6
  function enrichQueryFields(fields, parameters = {}) {
7
7
  const enrichedQuery = Array.isArray(fields) ? [] : {};
8
+ if (!fields || !parameters) {
9
+ return enrichedQuery;
10
+ }
8
11
  // enrich the fields with dynamic parameters
9
12
  for (let key of Object.keys(fields)) {
10
13
  if (fields[key] == null) {
@@ -252,7 +252,7 @@ var RestModule;
252
252
  input.body = form;
253
253
  break;
254
254
  case BodyTypes.XML:
255
- if (object != null) {
255
+ if (object != null && Object.keys(object).length) {
256
256
  string = new XmlBuilder().buildObject(object);
257
257
  }
258
258
  input.body = string;
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.0.212-alpha.11",
4
+ "version": "1.0.212-alpha.14",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -77,11 +77,11 @@
77
77
  "license": "GPL-3.0",
78
78
  "dependencies": {
79
79
  "@apidevtools/swagger-parser": "10.0.3",
80
- "@budibase/backend-core": "^1.0.212-alpha.11",
81
- "@budibase/client": "^1.0.212-alpha.11",
82
- "@budibase/pro": "1.0.212-alpha.11",
83
- "@budibase/string-templates": "^1.0.212-alpha.11",
84
- "@budibase/types": "^1.0.212-alpha.11",
80
+ "@budibase/backend-core": "^1.0.212-alpha.14",
81
+ "@budibase/client": "^1.0.212-alpha.14",
82
+ "@budibase/pro": "1.0.212-alpha.14",
83
+ "@budibase/string-templates": "^1.0.212-alpha.14",
84
+ "@budibase/types": "^1.0.212-alpha.14",
85
85
  "@bull-board/api": "3.7.0",
86
86
  "@bull-board/koa": "3.9.4",
87
87
  "@elastic/elasticsearch": "7.10.0",
@@ -26,6 +26,8 @@ const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db");
26
26
  const { encrypt } = require("@budibase/backend-core/encryption");
27
27
  const GLOBAL_USER_ID = "us_uuid1";
28
28
  const EMAIL = "babs@babs.com";
29
+ const FIRSTNAME = "Barbara";
30
+ const LASTNAME = "Barbington";
29
31
  const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306";
30
32
  class TestConfiguration {
31
33
  constructor(openServer = true) {
@@ -51,6 +53,14 @@ class TestConfiguration {
51
53
  getProdAppId() {
52
54
  return this.prodAppId;
53
55
  }
56
+ getUserDetails() {
57
+ return {
58
+ globalId: GLOBAL_USER_ID,
59
+ email: EMAIL,
60
+ firstName: FIRSTNAME,
61
+ lastName: LASTNAME,
62
+ };
63
+ }
54
64
  doInContext(appId, task) {
55
65
  return __awaiter(this, void 0, void 0, function* () {
56
66
  if (!appId) {
@@ -109,7 +119,7 @@ class TestConfiguration {
109
119
  });
110
120
  }
111
121
  // USER / AUTH
112
- globalUser({ id = GLOBAL_USER_ID, builder = true, admin = false, email = EMAIL, roles, } = {}) {
122
+ globalUser({ id = GLOBAL_USER_ID, firstName = FIRSTNAME, lastName = LASTNAME, builder = true, admin = false, email = EMAIL, roles, } = {}) {
113
123
  return __awaiter(this, void 0, void 0, function* () {
114
124
  return doWithGlobalDB(TENANT_ID, (db) => __awaiter(this, void 0, void 0, function* () {
115
125
  let existing;
@@ -119,7 +129,8 @@ class TestConfiguration {
119
129
  catch (err) {
120
130
  existing = { email };
121
131
  }
122
- const user = Object.assign(Object.assign({ _id: id }, existing), { roles: roles || {}, tenantId: TENANT_ID });
132
+ const user = Object.assign(Object.assign({ _id: id }, existing), { roles: roles || {}, tenantId: TENANT_ID, firstName,
133
+ lastName });
123
134
  yield createASession(id, {
124
135
  sessionId: "sessionid",
125
136
  tenantId: TENANT_ID,
@@ -142,11 +153,13 @@ class TestConfiguration {
142
153
  }));
143
154
  });
144
155
  }
145
- createUser(id = null, email = EMAIL, builder = true, admin = false, roles = {}) {
156
+ createUser(id = null, firstName = FIRSTNAME, lastName = LASTNAME, email = EMAIL, builder = true, admin = false, roles = {}) {
146
157
  return __awaiter(this, void 0, void 0, function* () {
147
158
  const globalId = !id ? `us_${Math.random()}` : `us_${id}`;
148
159
  const resp = yield this.globalUser({
149
160
  id: globalId,
161
+ firstName,
162
+ lastName,
150
163
  email,
151
164
  builder,
152
165
  admin,
@@ -466,15 +479,15 @@ class TestConfiguration {
466
479
  });
467
480
  }
468
481
  // QUERY
469
- previewQuery(request, config, datasource, fields) {
482
+ previewQuery(request, config, datasource, fields, params, verb) {
470
483
  return __awaiter(this, void 0, void 0, function* () {
471
484
  return request
472
485
  .post(`/api/queries/preview`)
473
486
  .send({
474
487
  datasourceId: datasource._id,
475
- parameters: {},
488
+ parameters: params || {},
476
489
  fields,
477
- queryVerb: "read",
490
+ queryVerb: verb || "read",
478
491
  name: datasource.name,
479
492
  })
480
493
  .set(config.defaultHeaders())
@@ -19,10 +19,11 @@ const { doInTenant } = require("@budibase/backend-core/tenancy");
19
19
  const { definitions: triggerDefs } = require("../automations/triggerInfo");
20
20
  const { doInAppContext, getAppDB } = require("@budibase/backend-core/context");
21
21
  const { AutomationErrors, LoopStepTypes } = require("../constants");
22
+ const { storeLog } = require("../automations/logging");
22
23
  const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId;
23
24
  const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId;
24
25
  const CRON_STEP_ID = triggerDefs.CRON.stepId;
25
- const STOPPED_STATUS = { success: false, status: "STOPPED" };
26
+ const STOPPED_STATUS = { success: true, status: "STOPPED" };
26
27
  const { cloneDeep } = require("lodash/fp");
27
28
  const env = require("../environment");
28
29
  function typecastForLooping(loopStep, input) {
@@ -248,7 +249,7 @@ class Orchestrator {
248
249
  this._context.steps[stepCount] = outputs;
249
250
  // if filter causes us to stop execution don't break the loop, set a var
250
251
  // so that we can finish iterating through the steps and record that it stopped
251
- if (step.stepId === FILTER_STEP_ID && !outputs.success) {
252
+ if (step.stepId === FILTER_STEP_ID && !outputs.result) {
252
253
  stopped = true;
253
254
  this.updateExecutionOutput(step.id, step.stepId, step.inputs, Object.assign(Object.assign({}, outputs), STOPPED_STATUS));
254
255
  continue;
@@ -289,6 +290,8 @@ class Orchestrator {
289
290
  loopSteps = null;
290
291
  }
291
292
  }
293
+ // store the logs for the automation run
294
+ yield storeLog(this._automation, this.executionOutput);
292
295
  return this.executionOutput;
293
296
  });
294
297
  }
@@ -22,6 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
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
+ };
25
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
36
  };
@@ -92,7 +101,7 @@ class Thread {
92
101
  });
93
102
  });
94
103
  }
95
- static shutdown() {
104
+ static stopThreads() {
96
105
  return new Promise(resolve => {
97
106
  if (Thread.workerRefs.length === 0) {
98
107
  resolve();
@@ -110,6 +119,11 @@ class Thread {
110
119
  Thread.workerRefs = [];
111
120
  });
112
121
  }
122
+ static shutdown() {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ yield Thread.stopThreads();
125
+ });
126
+ }
113
127
  }
114
128
  exports.Thread = Thread;
115
129
  Thread.workerRefs = [];