@budibase/server 1.0.219-alpha.8 → 1.0.220-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 (190) hide show
  1. package/builder/assets/{index.7e1f2be1.js → index.530f60fc.js} +153 -152
  2. package/builder/index.html +1 -1
  3. package/coverage/clover.xml +283 -262
  4. package/coverage/coverage-final.json +5 -5
  5. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  6. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/index.html +1 -1
  14. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/index.html +15 -15
  25. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +78 -24
  27. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  34. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  43. package/coverage/lcov-report/api/index.html +1 -1
  44. package/coverage/lcov-report/api/index.js.html +1 -1
  45. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/index.html +1 -1
  56. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  70. package/coverage/lcov-report/api/routes/utils/validators.js.html +5 -2
  71. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  73. package/coverage/lcov-report/automations/actions.js.html +1 -1
  74. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  75. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  76. package/coverage/lcov-report/automations/index.html +1 -1
  77. package/coverage/lcov-report/automations/index.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/executeQuery.js.html +2 -2
  82. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/index.html +1 -1
  85. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  104. package/coverage/lcov-report/constants/index.html +1 -1
  105. package/coverage/lcov-report/constants/index.js.html +1 -1
  106. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  107. package/coverage/lcov-report/constants/screens.js.html +1 -1
  108. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  109. package/coverage/lcov-report/db/index.html +1 -1
  110. package/coverage/lcov-report/db/index.js.html +1 -1
  111. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  112. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  115. package/coverage/lcov-report/db/newid.js.html +1 -1
  116. package/coverage/lcov-report/db/utils.js.html +1 -1
  117. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  118. package/coverage/lcov-report/events/index.html +1 -1
  119. package/coverage/lcov-report/events/index.js.html +1 -1
  120. package/coverage/lcov-report/events/utils.js.html +1 -1
  121. package/coverage/lcov-report/index.html +30 -30
  122. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  123. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  124. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  125. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  126. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  127. package/coverage/lcov-report/middleware/index.html +1 -1
  128. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  129. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  130. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  131. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  132. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  133. package/coverage/lcov-report/threads/automation.js.html +1 -1
  134. package/coverage/lcov-report/threads/index.html +14 -14
  135. package/coverage/lcov-report/threads/query.js.html +40 -25
  136. package/coverage/lcov-report/threads/utils.js.html +1 -1
  137. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  138. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  139. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  140. package/coverage/lcov-report/utilities/global.js.html +1 -1
  141. package/coverage/lcov-report/utilities/index.html +16 -16
  142. package/coverage/lcov-report/utilities/index.js.html +1 -1
  143. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  144. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  145. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  146. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  148. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  150. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  151. package/coverage/lcov-report/utilities/security.js.html +1 -1
  152. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  153. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  154. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  156. package/coverage/lcov-report/utilities/users.js.html +1 -1
  157. package/coverage/lcov-report/utilities/workerRequests.js.html +57 -9
  158. package/coverage/lcov.info +501 -462
  159. package/dist/api/controllers/public/applications.js +1 -1
  160. package/dist/api/controllers/public/utils.js +8 -1
  161. package/dist/api/controllers/query/index.js +7 -4
  162. package/dist/api/controllers/row/internalSearch.js +26 -10
  163. package/dist/api/routes/public/rows.js +7 -2
  164. package/dist/api/routes/utils/validators.js +1 -0
  165. package/dist/app.js +20 -0
  166. package/dist/automations/steps/executeQuery.js +1 -1
  167. package/dist/environment.js +2 -0
  168. package/dist/integrations/base/sql.js +4 -2
  169. package/dist/package.json +6 -6
  170. package/dist/threads/query.js +20 -13
  171. package/dist/tsconfig.build.tsbuildinfo +1 -1
  172. package/dist/utilities/workerRequests.js +8 -0
  173. package/package.json +7 -7
  174. package/scripts/dev/manage.js +2 -0
  175. package/specs/openapi.json +9 -5
  176. package/specs/openapi.yaml +10 -4
  177. package/src/api/controllers/public/applications.ts +2 -2
  178. package/src/api/controllers/public/utils.ts +8 -1
  179. package/src/api/controllers/query/index.ts +13 -5
  180. package/src/api/controllers/row/internalSearch.js +27 -9
  181. package/src/api/routes/public/rows.ts +7 -2
  182. package/src/api/routes/tests/query.spec.js +0 -1
  183. package/src/api/routes/utils/validators.js +1 -0
  184. package/src/app.ts +30 -1
  185. package/src/automations/steps/executeQuery.js +1 -1
  186. package/src/definitions/openapi.ts +471 -469
  187. package/src/environment.js +2 -0
  188. package/src/integrations/base/sql.ts +6 -2
  189. package/src/threads/query.js +20 -15
  190. package/src/utilities/workerRequests.js +16 -0
@@ -84,7 +84,7 @@ function read(ctx, next) {
84
84
  exports.read = read;
85
85
  function update(ctx, next) {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
- ctx.request.body = fixAppID(ctx.request.body, ctx.params);
87
+ ctx.request.body = yield (0, utils_1.addRev)(fixAppID(ctx.request.body, ctx.params));
88
88
  updateAppId(ctx.params.appId);
89
89
  yield controller.update(ctx);
90
90
  yield setResponseApp(ctx);
@@ -12,14 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.search = exports.addRev = void 0;
13
13
  const { getAppDB } = require("@budibase/backend-core/context");
14
14
  const utils_1 = require("../../../integrations/utils");
15
+ const utils_2 = require("../../../db/utils");
15
16
  function addRev(body, tableId) {
16
17
  return __awaiter(this, void 0, void 0, function* () {
17
18
  if (!body._id || (tableId && (0, utils_1.isExternalTable)(tableId))) {
18
19
  return body;
19
20
  }
21
+ let id = body._id;
22
+ if (body._id.startsWith(utils_2.APP_PREFIX)) {
23
+ id = utils_2.DocumentTypes.APP_METADATA;
24
+ }
20
25
  const db = getAppDB();
21
- const dbDoc = yield db.get(body._id);
26
+ const dbDoc = yield db.get(id);
22
27
  body._rev = dbDoc._rev;
28
+ // update ID in case it is an app ID
29
+ body._id = id;
23
30
  return body;
24
31
  });
25
32
  }
@@ -164,12 +164,15 @@ function preview(ctx) {
164
164
  });
165
165
  }
166
166
  exports.preview = preview;
167
- function execute(ctx, opts = { rowsOnly: false }) {
167
+ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
168
168
  return __awaiter(this, void 0, void 0, function* () {
169
169
  const db = (0, context_1.getAppDB)();
170
170
  const query = yield db.get(ctx.params.queryId);
171
171
  const datasource = yield db.get(query.datasourceId);
172
- const authConfigCtx = getAuthConfig(ctx);
172
+ let authConfigCtx = {};
173
+ if (!opts.isAutomation) {
174
+ authConfigCtx = getAuthConfig(ctx);
175
+ }
173
176
  const enrichedParameters = ctx.request.body.parameters || {};
174
177
  // make sure parameters are fully enriched with defaults
175
178
  if (query && query.parameters) {
@@ -214,9 +217,9 @@ function executeV1(ctx) {
214
217
  });
215
218
  }
216
219
  exports.executeV1 = executeV1;
217
- function executeV2(ctx) {
220
+ function executeV2(ctx, { isAutomation } = {}) {
218
221
  return __awaiter(this, void 0, void 0, function* () {
219
- return execute(ctx, { rowsOnly: false });
222
+ return execute(ctx, { rowsOnly: false, isAutomation });
220
223
  });
221
224
  }
222
225
  exports.executeV2 = executeV2;
@@ -18,7 +18,7 @@ const { getAppId } = require("@budibase/backend-core/context");
18
18
  */
19
19
  class QueryBuilder {
20
20
  constructor(base) {
21
- this.query = Object.assign({ string: {}, fuzzy: {}, range: {}, equal: {}, notEqual: {}, empty: {}, notEmpty: {}, oneOf: {} }, base);
21
+ this.query = Object.assign({ allOr: false, string: {}, fuzzy: {}, range: {}, equal: {}, notEqual: {}, empty: {}, notEmpty: {}, oneOf: {} }, base);
22
22
  this.limit = 50;
23
23
  this.sortOrder = "ascending";
24
24
  this.sortType = "string";
@@ -127,8 +127,21 @@ class QueryBuilder {
127
127
  }
128
128
  buildSearchQuery() {
129
129
  const builder = this;
130
- let query = "*:*";
130
+ let allOr = this.query && this.query.allOr;
131
+ let query = allOr ? "" : "*:*";
131
132
  const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true };
133
+ let tableId;
134
+ if (this.query.equal.tableId) {
135
+ tableId = this.query.equal.tableId;
136
+ delete this.query.equal.tableId;
137
+ }
138
+ const equal = (key, value) => {
139
+ // 0 evaluates to false, which means we would return all rows if we don't check it
140
+ if (!value && value !== 0) {
141
+ return null;
142
+ }
143
+ return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
144
+ };
132
145
  function build(structure, queryFn) {
133
146
  for (let [key, value] of Object.entries(structure)) {
134
147
  key = builder.preprocess(key.replace(/ /g, "_"), {
@@ -138,7 +151,10 @@ class QueryBuilder {
138
151
  if (expression == null) {
139
152
  continue;
140
153
  }
141
- query += ` AND ${expression}`;
154
+ if (query.length > 0) {
155
+ query += ` ${allOr ? "OR" : "AND"} `;
156
+ }
157
+ query += expression;
142
158
  }
143
159
  }
144
160
  // Construct the actual lucene search query string from JSON structure
@@ -183,13 +199,7 @@ class QueryBuilder {
183
199
  });
184
200
  }
185
201
  if (this.query.equal) {
186
- build(this.query.equal, (key, value) => {
187
- // 0 evaluates to false, which means we would return all rows if we don't check it
188
- if (!value && value !== 0) {
189
- return null;
190
- }
191
- return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
192
- });
202
+ build(this.query.equal, equal);
193
203
  }
194
204
  if (this.query.notEqual) {
195
205
  build(this.query.notEqual, (key, value) => {
@@ -222,6 +232,12 @@ class QueryBuilder {
222
232
  return `${key}:(${orStatement})`;
223
233
  });
224
234
  }
235
+ // make sure table ID is always added as an AND
236
+ if (tableId) {
237
+ query = `(${query})`;
238
+ allOr = false;
239
+ build({ tableId }, equal);
240
+ }
225
241
  return query;
226
242
  }
227
243
  buildSearchBody() {
@@ -144,6 +144,11 @@ read.push(new Endpoint_1.default("get", "/tables/:tableId/rows/:rowId", rows_1.d
144
144
  * query:
145
145
  * type: object
146
146
  * properties:
147
+ * allOr:
148
+ * type: boolean
149
+ * description: Specifies that a row should be returned if it satisfies
150
+ * any of the specified options, rather than requiring it to fulfill all
151
+ * the search parameters. This defaults to false, meaning AND logic will be used.
147
152
  * string:
148
153
  * type: object
149
154
  * example:
@@ -161,9 +166,9 @@ read.push(new Endpoint_1.default("get", "/tables/:tableId/rows/:rowId", rows_1.d
161
166
  * range:
162
167
  * type: object
163
168
  * description: Searches within a range, the format of this must be
164
- * columnName -> [low, high].
169
+ * in the format of an object with a "low" and "high" property.
165
170
  * example:
166
- * columnName1: [10, 20]
171
+ * columnName1: { low: 10, high: 20 }
167
172
  * equal:
168
173
  * type: object
169
174
  * description: Searches for rows that have a column value that is
@@ -51,6 +51,7 @@ function filterObject() {
51
51
  oneOf: Joi.object().optional(),
52
52
  contains: Joi.object().optional(),
53
53
  notContains: Joi.object().optional(),
54
+ allOr: Joi.boolean().optional(),
54
55
  }).unknown(true);
55
56
  }
56
57
  exports.internalSearchValidator = () => {
package/dist/app.js CHANGED
@@ -54,6 +54,7 @@ const { Thread } = require("./threads");
54
54
  const redis_1 = __importDefault(require("./utilities/redis"));
55
55
  const migrations = __importStar(require("./migrations"));
56
56
  const backend_core_1 = require("@budibase/backend-core");
57
+ const workerRequests_1 = require("./utilities/workerRequests");
57
58
  const app = new Koa();
58
59
  // set up top level koa middleware
59
60
  app.use(koaBody({
@@ -112,6 +113,7 @@ server.on("close", () => __awaiter(void 0, void 0, void 0, function* () {
112
113
  }
113
114
  }));
114
115
  module.exports = server.listen(env.PORT || 0, () => __awaiter(void 0, void 0, void 0, function* () {
116
+ var _a;
115
117
  console.log(`Budibase running on ${JSON.stringify(server.address())}`);
116
118
  env._set("PORT", server.address().port);
117
119
  eventEmitter.emitPort(env.PORT);
@@ -128,6 +130,24 @@ module.exports = server.listen(env.PORT || 0, () => __awaiter(void 0, void 0, vo
128
130
  shutdown();
129
131
  }
130
132
  }
133
+ // check and create admin user if required
134
+ if (env.SELF_HOSTED &&
135
+ !env.MULTI_TENANCY &&
136
+ env.BB_ADMIN_USER_EMAIL &&
137
+ env.BB_ADMIN_USER_PASSWORD) {
138
+ const checklist = yield (0, workerRequests_1.getChecklist)();
139
+ if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
140
+ try {
141
+ const tenantId = backend_core_1.tenancy.getTenantId();
142
+ yield (0, workerRequests_1.createAdminUser)(env.BB_ADMIN_USER_EMAIL, env.BB_ADMIN_USER_PASSWORD, tenantId);
143
+ console.log("Admin account automatically created for", env.BB_ADMIN_USER_EMAIL);
144
+ }
145
+ catch (e) {
146
+ logAlert("Error creating initial admin user. Exiting.", e);
147
+ shutdown();
148
+ }
149
+ }
150
+ }
131
151
  // check for version updates
132
152
  yield backend_core_1.installation.checkInstallVersion();
133
153
  // done last - this will never complete
@@ -88,7 +88,7 @@ exports.run = function ({ inputs, appId, emitter }) {
88
88
  },
89
89
  });
90
90
  try {
91
- yield queryController.executeV2(ctx);
91
+ yield queryController.executeV2(ctx, { isAutomation: true });
92
92
  const _b = ctx.body, { data } = _b, rest = __rest(_b, ["data"]);
93
93
  return {
94
94
  response: data,
@@ -62,6 +62,8 @@ module.exports = {
62
62
  DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
63
63
  QUERY_THREAD_TIMEOUT: parseIntSafe(process.env.QUERY_THREAD_TIMEOUT),
64
64
  SQL_MAX_ROWS: process.env.SQL_MAX_ROWS,
65
+ BB_ADMIN_USER_EMAIL: process.env.BB_ADMIN_USER_EMAIL,
66
+ BB_ADMIN_USER_PASSWORD: process.env.BB_ADMIN_USER_PASSWORD,
65
67
  // flags
66
68
  ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
67
69
  DISABLE_THREADING: process.env.DISABLE_THREADING,
@@ -97,8 +97,10 @@ function generateSelectStatement(json, knex) {
97
97
  const fieldNames = field.split(/\./g);
98
98
  const tableName = fieldNames[0];
99
99
  const columnName = fieldNames[1];
100
- if (columnName && knex.client.config.client === utils_1.SqlClients.POSTGRES) {
101
- const externalType = schema === null || schema === void 0 ? void 0 : schema[columnName].externalType;
100
+ if (columnName &&
101
+ (schema === null || schema === void 0 ? void 0 : schema[columnName]) &&
102
+ knex.client.config.client === utils_1.SqlClients.POSTGRES) {
103
+ const externalType = schema[columnName].externalType;
102
104
  if (externalType === null || externalType === void 0 ? void 0 : externalType.includes("money")) {
103
105
  return knex.raw(`"${tableName}"."${columnName}"::money::numeric as "${field}"`);
104
106
  }
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.219-alpha.7",
4
+ "version": "1.0.219",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -77,11 +77,10 @@
77
77
  "license": "GPL-3.0",
78
78
  "dependencies": {
79
79
  "@apidevtools/swagger-parser": "10.0.3",
80
- "@budibase/backend-core": "^1.0.219-alpha.7",
81
- "@budibase/client": "^1.0.219-alpha.7",
82
- "@budibase/pro": "1.0.219-alpha.7",
83
- "@budibase/string-templates": "^1.0.219-alpha.7",
84
- "@budibase/types": "^1.0.219-alpha.7",
80
+ "@budibase/backend-core": "^1.0.219",
81
+ "@budibase/client": "^1.0.219",
82
+ "@budibase/pro": "1.0.219",
83
+ "@budibase/string-templates": "^1.0.219",
85
84
  "@bull-board/api": "3.7.0",
86
85
  "@bull-board/koa": "3.9.4",
87
86
  "@elastic/elasticsearch": "7.10.0",
@@ -152,6 +151,7 @@
152
151
  "@babel/core": "7.17.4",
153
152
  "@babel/preset-env": "7.16.11",
154
153
  "@budibase/standard-components": "^0.9.139",
154
+ "@budibase/types": "^1.0.219",
155
155
  "@jest/test-sequencer": "24.9.0",
156
156
  "@types/apidoc": "0.50.0",
157
157
  "@types/bson": "4.2.0",
@@ -17,6 +17,7 @@ const { doInAppContext, getAppDB } = require("@budibase/backend-core/context");
17
17
  const { refreshOAuthToken, updateUserOAuth, } = require("@budibase/backend-core/auth");
18
18
  const { user: userCache } = require("@budibase/backend-core/cache");
19
19
  const { getGlobalIDFromUserMetadataID } = require("../db/utils");
20
+ const { cloneDeep } = require("lodash/fp");
20
21
  const { isSQL } = require("../integrations/utils");
21
22
  const { enrichQueryFields, interpolateSQL, } = require("../integrations/queries/sql");
22
23
  class QueryRunner {
@@ -43,16 +44,19 @@ class QueryRunner {
43
44
  var _a;
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
46
  let { datasource, fields, queryVerb, transformer } = this;
46
- const Integration = integrations[datasource.source];
47
+ let datasourceClone = cloneDeep(datasource);
48
+ let fieldsClone = cloneDeep(fields);
49
+ const Integration = integrations[datasourceClone.source];
47
50
  if (!Integration) {
48
51
  throw "Integration type does not exist.";
49
52
  }
50
- if (datasource.config.authConfigs) {
51
- datasource.config.authConfigs = datasource.config.authConfigs.map(config => {
52
- return enrichQueryFields(config, this.ctx);
53
- });
53
+ if (datasourceClone.config.authConfigs) {
54
+ datasourceClone.config.authConfigs =
55
+ datasourceClone.config.authConfigs.map(config => {
56
+ return enrichQueryFields(config, this.ctx);
57
+ });
54
58
  }
55
- const integration = new Integration(datasource.config);
59
+ const integration = new Integration(datasourceClone.config);
56
60
  // pre-query, make sure datasource variables are added to parameters
57
61
  const parameters = yield this.addDatasourceVariables();
58
62
  // Enrich the parameters with the addition context items.
@@ -60,16 +64,16 @@ class QueryRunner {
60
64
  const enrichedParameters = enrichQueryFields(parameters, this.ctx);
61
65
  const enrichedContext = Object.assign(Object.assign({}, enrichedParameters), this.ctx);
62
66
  // Parse global headers
63
- if (datasource.config.defaultHeaders) {
64
- datasource.config.defaultHeaders = enrichQueryFields(datasource.config.defaultHeaders, enrichedContext);
67
+ if (datasourceClone.config.defaultHeaders) {
68
+ datasourceClone.config.defaultHeaders = enrichQueryFields(datasourceClone.config.defaultHeaders, enrichedContext);
65
69
  }
66
70
  let query;
67
71
  // handle SQL injections by interpolating the variables
68
- if (isSQL(datasource)) {
69
- query = interpolateSQL(fields, enrichedParameters, integration);
72
+ if (isSQL(datasourceClone)) {
73
+ query = interpolateSQL(fieldsClone, enrichedParameters, integration);
70
74
  }
71
75
  else {
72
- query = enrichQueryFields(fields, enrichedContext);
76
+ query = enrichQueryFields(fieldsClone, enrichedContext);
73
77
  }
74
78
  // Add pagination values for REST queries
75
79
  if (this.pagination) {
@@ -100,7 +104,9 @@ class QueryRunner {
100
104
  // Attempt to refresh the access token from the provider
101
105
  this.hasRefreshedOAuth = true;
102
106
  }
103
- this.hasRerun = true;
107
+ else {
108
+ this.hasRerun = true;
109
+ }
104
110
  yield threadUtils.invalidateDynamicVariables(this.cachedVariables);
105
111
  return this.execute();
106
112
  }
@@ -156,7 +162,8 @@ class QueryRunner {
156
162
  else {
157
163
  // In this event the user may have oAuth issues that
158
164
  // could require re-authenticating with their provider.
159
- throw new Error("OAuth2 access token could not be refreshed: " + resp.err.toString());
165
+ let errorMessage = resp.err.data ? resp.err.data : resp.err.toString();
166
+ throw new Error("OAuth2 access token could not be refreshed: " + errorMessage);
160
167
  }
161
168
  return resp;
162
169
  });