@budibase/server 2.0.28 → 2.0.30-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 (200) hide show
  1. package/builder/assets/{index.ffdc4f66.js → index.ae93bd4f.js} +258 -258
  2. package/builder/assets/{index.dfa4073c.css → index.e56da48a.css} +2 -2
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +344 -341
  5. package/coverage/coverage-final.json +24 -24
  6. package/coverage/lcov-report/api/controllers/apikeys.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/datasource.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/dev.js.html +2 -2
  12. package/coverage/lcov-report/api/controllers/index.html +1 -1
  13. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  19. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/internal.js.html +12 -12
  25. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
  27. package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
  28. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  41. package/coverage/lcov-report/api/index.html +1 -1
  42. package/coverage/lcov-report/api/index.js.html +5 -5
  43. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  44. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  45. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/index.html +1 -1
  53. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  67. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  70. package/coverage/lcov-report/automations/actions.js.html +1 -1
  71. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  72. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  73. package/coverage/lcov-report/automations/index.html +1 -1
  74. package/coverage/lcov-report/automations/index.js.html +5 -5
  75. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/index.html +1 -1
  82. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
  90. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggers.js.html +22 -22
  101. package/coverage/lcov-report/constants/index.html +1 -1
  102. package/coverage/lcov-report/constants/index.js.html +1 -1
  103. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  104. package/coverage/lcov-report/constants/screens.js.html +1 -1
  105. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  106. package/coverage/lcov-report/db/index.html +1 -1
  107. package/coverage/lcov-report/db/index.js.html +1 -1
  108. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +11 -11
  109. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  110. package/coverage/lcov-report/db/linkedRows/index.js.html +11 -11
  111. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +3 -3
  112. package/coverage/lcov-report/db/newid.js.html +2 -2
  113. package/coverage/lcov-report/db/utils.js.html +10 -16
  114. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  115. package/coverage/lcov-report/events/index.html +1 -1
  116. package/coverage/lcov-report/events/index.js.html +2 -2
  117. package/coverage/lcov-report/events/utils.js.html +9 -9
  118. package/coverage/lcov-report/index.html +15 -15
  119. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  120. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  121. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  122. package/coverage/lcov-report/middleware/builder.js.html +11 -11
  123. package/coverage/lcov-report/middleware/currentapp.js.html +34 -34
  124. package/coverage/lcov-report/middleware/index.html +1 -1
  125. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  126. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  127. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  128. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  129. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  130. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  131. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  132. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  133. package/coverage/lcov-report/utilities/global.js.html +16 -16
  134. package/coverage/lcov-report/utilities/index.html +1 -1
  135. package/coverage/lcov-report/utilities/index.js.html +1 -1
  136. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  137. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +13 -13
  138. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  139. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  140. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  141. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  142. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +38 -38
  143. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
  144. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  145. package/coverage/lcov-report/utilities/security.js.html +1 -1
  146. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  147. package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
  148. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
  149. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  150. package/coverage/lcov-report/utilities/users.js.html +1 -1
  151. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  152. package/coverage/lcov.info +619 -614
  153. package/dist/api/controllers/application.js +2 -2
  154. package/dist/api/controllers/dev.js +1 -1
  155. package/dist/api/controllers/query/index.js +6 -2
  156. package/dist/api/controllers/row/index.js +30 -10
  157. package/dist/api/controllers/static/templates/preview.hbs +10 -0
  158. package/dist/api/controllers/table/internal.js +8 -2
  159. package/dist/api/controllers/table/utils.js +3 -1
  160. package/dist/automations/steps/updateRow.js +2 -2
  161. package/dist/automations/utils.js +5 -3
  162. package/dist/db/utils.js +1 -1
  163. package/dist/index.js +1 -0
  164. package/dist/integrations/rest.js +39 -2
  165. package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
  166. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
  167. package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
  168. package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
  169. package/dist/migrations/index.js +3 -9
  170. package/dist/package.json +7 -7
  171. package/dist/tsconfig.build.tsbuildinfo +1 -1
  172. package/dist/utilities/usageQuota/rows.js +6 -4
  173. package/package.json +8 -8
  174. package/src/api/controllers/application.ts +2 -2
  175. package/src/api/controllers/dev.js +1 -1
  176. package/src/api/controllers/query/index.ts +7 -2
  177. package/src/api/controllers/row/index.ts +36 -13
  178. package/src/api/controllers/static/templates/preview.hbs +10 -0
  179. package/src/api/controllers/table/internal.ts +5 -2
  180. package/src/api/controllers/table/utils.ts +3 -1
  181. package/src/api/routes/tests/row.spec.js +22 -27
  182. package/src/automations/steps/updateRow.js +2 -2
  183. package/src/automations/tests/automation.spec.js +1 -6
  184. package/src/automations/utils.ts +6 -4
  185. package/src/db/utils.js +0 -2
  186. package/src/definitions/datasource.ts +1 -0
  187. package/src/index.ts +1 -0
  188. package/src/integrations/rest.ts +18 -2
  189. package/src/integrations/tests/rest.spec.ts +9 -9
  190. package/src/migrations/functions/backfill/global.ts +1 -1
  191. package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
  192. package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +5 -2
  193. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
  194. package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
  195. package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
  196. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
  197. package/src/migrations/index.ts +3 -15
  198. package/src/migrations/tests/index.spec.ts +0 -1
  199. package/src/utilities/usageQuota/rows.js +7 -3
  200. package/src/migrations/functions/pluginCount.ts +0 -12
@@ -315,7 +315,7 @@ const appPostCreate = (ctx, app) => __awaiter(void 0, void 0, void 0, function*
315
315
  yield creationEvents(ctx.request, app);
316
316
  // app import & template creation
317
317
  if (ctx.request.body.useTemplate === "true") {
318
- const rows = yield (0, rows_1.getUniqueRows)([app.appId]);
318
+ const { rows } = yield (0, rows_1.getUniqueRows)([app.appId]);
319
319
  const rowCount = rows ? rows.length : 0;
320
320
  if (rowCount) {
321
321
  try {
@@ -440,7 +440,7 @@ const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
440
440
  return result;
441
441
  });
442
442
  const preDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
443
- const rows = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
443
+ const { rows } = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
444
444
  ctx.rowCount = rows.length;
445
445
  });
446
446
  const postDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
@@ -99,7 +99,7 @@ exports.revert = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
99
99
  target: appId,
100
100
  });
101
101
  try {
102
- if (!env.isTest()) {
102
+ if (env.COUCH_DB_URL) {
103
103
  // in-memory db stalls on rollback
104
104
  yield replication.rollback();
105
105
  }
@@ -149,7 +149,9 @@ function preview(ctx) {
149
149
  auth: Object.assign({}, authConfigCtx),
150
150
  },
151
151
  });
152
- const { rows, keys, info, extra } = yield pro_1.quotas.addQuery(runFn);
152
+ const { rows, keys, info, extra } = yield pro_1.quotas.addQuery(runFn, {
153
+ datasourceId: datasource._id,
154
+ });
153
155
  const schemaFields = {};
154
156
  if ((rows === null || rows === void 0 ? void 0 : rows.length) > 0) {
155
157
  for (let key of [...new Set(keys)]) {
@@ -226,7 +228,9 @@ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
226
228
  auth: Object.assign({}, authConfigCtx),
227
229
  },
228
230
  });
229
- const { rows, pagination, extra } = yield pro_1.quotas.addQuery(runFn);
231
+ const { rows, pagination, extra } = yield pro_1.quotas.addQuery(runFn, {
232
+ datasourceId: datasource._id,
233
+ });
230
234
  // remove the raw from execution incase transformer being used to hide data
231
235
  if (extra === null || extra === void 0 ? void 0 : extra.raw) {
232
236
  delete extra.raw;
@@ -44,7 +44,9 @@ function patch(ctx) {
44
44
  return (0, exports.save)(ctx);
45
45
  }
46
46
  try {
47
- const { row, table } = yield pro_1.quotas.addQuery(() => pickApi(tableId).patch(ctx));
47
+ const { row, table } = yield pro_1.quotas.addQuery(() => pickApi(tableId).patch(ctx), {
48
+ datasourceId: tableId,
49
+ });
48
50
  ctx.status = 200;
49
51
  ctx.eventEmitter &&
50
52
  ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
@@ -66,7 +68,9 @@ const save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
66
68
  return patch(ctx);
67
69
  }
68
70
  try {
69
- const { row, table } = yield pro_1.quotas.addRow(() => pro_1.quotas.addQuery(() => pickApi(tableId).save(ctx)));
71
+ const { row, table } = yield pro_1.quotas.addRow(() => pro_1.quotas.addQuery(() => pickApi(tableId).save(ctx), {
72
+ datasourceId: tableId,
73
+ }));
70
74
  ctx.status = 200;
71
75
  ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
72
76
  ctx.message = `${table.name} saved successfully`;
@@ -81,7 +85,9 @@ function fetchView(ctx) {
81
85
  return __awaiter(this, void 0, void 0, function* () {
82
86
  const tableId = getTableId(ctx);
83
87
  try {
84
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchView(ctx));
88
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchView(ctx), {
89
+ datasourceId: tableId,
90
+ });
85
91
  }
86
92
  catch (err) {
87
93
  ctx.throw(400, err);
@@ -93,7 +99,9 @@ function fetch(ctx) {
93
99
  return __awaiter(this, void 0, void 0, function* () {
94
100
  const tableId = getTableId(ctx);
95
101
  try {
96
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetch(ctx));
102
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetch(ctx), {
103
+ datasourceId: tableId,
104
+ });
97
105
  }
98
106
  catch (err) {
99
107
  ctx.throw(400, err);
@@ -105,7 +113,9 @@ function find(ctx) {
105
113
  return __awaiter(this, void 0, void 0, function* () {
106
114
  const tableId = getTableId(ctx);
107
115
  try {
108
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).find(ctx));
116
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).find(ctx), {
117
+ datasourceId: tableId,
118
+ });
109
119
  }
110
120
  catch (err) {
111
121
  ctx.throw(400, err);
@@ -120,7 +130,9 @@ function destroy(ctx) {
120
130
  const tableId = getTableId(ctx);
121
131
  let response, row;
122
132
  if (inputs.rows) {
123
- let { rows } = yield pro_1.quotas.addQuery(() => pickApi(tableId).bulkDestroy(ctx));
133
+ let { rows } = yield pro_1.quotas.addQuery(() => pickApi(tableId).bulkDestroy(ctx), {
134
+ datasourceId: tableId,
135
+ });
124
136
  yield pro_1.quotas.removeRows(rows.length);
125
137
  response = rows;
126
138
  for (let row of rows) {
@@ -128,7 +140,9 @@ function destroy(ctx) {
128
140
  }
129
141
  }
130
142
  else {
131
- let resp = yield pro_1.quotas.addQuery(() => pickApi(tableId).destroy(ctx));
143
+ let resp = yield pro_1.quotas.addQuery(() => pickApi(tableId).destroy(ctx), {
144
+ datasourceId: tableId,
145
+ });
132
146
  yield pro_1.quotas.removeRow();
133
147
  response = resp.response;
134
148
  row = resp.row;
@@ -146,7 +160,9 @@ function search(ctx) {
146
160
  const tableId = getTableId(ctx);
147
161
  try {
148
162
  ctx.status = 200;
149
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).search(ctx));
163
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).search(ctx), {
164
+ datasourceId: tableId,
165
+ });
150
166
  }
151
167
  catch (err) {
152
168
  ctx.throw(400, err);
@@ -170,7 +186,9 @@ function fetchEnrichedRow(ctx) {
170
186
  return __awaiter(this, void 0, void 0, function* () {
171
187
  const tableId = getTableId(ctx);
172
188
  try {
173
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchEnrichedRow(ctx));
189
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchEnrichedRow(ctx), {
190
+ datasourceId: tableId,
191
+ });
174
192
  }
175
193
  catch (err) {
176
194
  ctx.throw(400, err);
@@ -181,7 +199,9 @@ exports.fetchEnrichedRow = fetchEnrichedRow;
181
199
  const exportRows = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
182
200
  const tableId = getTableId(ctx);
183
201
  try {
184
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).exportRows(ctx));
202
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).exportRows(ctx), {
203
+ datasourceId: tableId,
204
+ });
185
205
  }
186
206
  catch (err) {
187
207
  ctx.throw(400, err);
@@ -56,6 +56,16 @@
56
56
  return
57
57
  }
58
58
 
59
+ // If this is a custom event, try and handle it
60
+ if (parsed.runtimeEvent) {
61
+ const { name, payload } = parsed
62
+ if (window.handleBuilderRuntimeEvent) {
63
+ window.handleBuilderRuntimeEvent(name, payload)
64
+ }
65
+ return
66
+ }
67
+
68
+ // Otherwise this is a full reload message
59
69
  // Extract data from message
60
70
  const {
61
71
  selectedComponentId,
@@ -19,6 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
26
  exports.bulkImport = exports.destroy = exports.save = void 0;
24
27
  const linkedRows_1 = require("../../../db/linkedRows");
@@ -32,6 +35,7 @@ const bulkFormula_1 = require("./bulkFormula");
32
35
  const pro_1 = require("@budibase/pro");
33
36
  const lodash_1 = require("lodash");
34
37
  const fp_1 = require("lodash/fp");
38
+ const environment_2 = __importDefault(require("../../../environment"));
35
39
  function checkAutoColumns(table, oldTable) {
36
40
  if (!table.schema) {
37
41
  return table;
@@ -150,7 +154,9 @@ function destroy(ctx) {
150
154
  include_docs: true,
151
155
  }));
152
156
  yield db.bulkDocs(rows.rows.map((row) => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
153
- yield pro_1.quotas.removeRows(rows.rows.length);
157
+ yield pro_1.quotas.removeRows(rows.rows.length, {
158
+ tableId: ctx.params.tableId,
159
+ });
154
160
  // update linked rows
155
161
  yield (0, linkedRows_1.updateLinks)({
156
162
  eventType: linkedRows_1.EventType.TABLE_DELETE,
@@ -159,7 +165,7 @@ function destroy(ctx) {
159
165
  // don't remove the table itself until very end
160
166
  yield db.remove(tableToDelete);
161
167
  // remove table search index
162
- if (!(0, environment_1.isTest)()) {
168
+ if (!(0, environment_1.isTest)() || environment_2.default.COUCH_DB_URL) {
163
169
  const currentIndexes = yield db.getIndexes();
164
170
  const existingIndex = currentIndexes.indexes.find((existing) => existing.name === `search:${ctx.params.tableId}`);
165
171
  if (existingIndex) {
@@ -130,7 +130,9 @@ function handleDataImport(user, table, dataImport) {
130
130
  }
131
131
  finalData.push(row);
132
132
  }
133
- yield pro_1.quotas.addRows(finalData.length, () => db.bulkDocs(finalData));
133
+ yield pro_1.quotas.addRows(finalData.length, () => db.bulkDocs(finalData), {
134
+ tableId: table._id,
135
+ });
134
136
  yield backend_core_1.events.rows.imported(table, "csv", finalData.length);
135
137
  return table;
136
138
  });
@@ -74,9 +74,9 @@ exports.run = function ({ inputs, appId, emitter }) {
74
74
  };
75
75
  }
76
76
  const tableId = inputs.row.tableId;
77
- // clear any falsy properties so that they aren't updated
77
+ // clear any undefined, null or empty string properties so that they aren't updated
78
78
  for (let propKey of Object.keys(inputs.row)) {
79
- if (!inputs.row[propKey] || inputs.row[propKey] === "") {
79
+ if (inputs.row[propKey] == null || inputs.row[propKey] === "") {
80
80
  delete inputs.row[propKey];
81
81
  }
82
82
  }
@@ -59,12 +59,14 @@ const jobMessage = (job, message) => {
59
59
  function processEvent(job) {
60
60
  return __awaiter(this, void 0, void 0, function* () {
61
61
  try {
62
+ const automationId = job.data.automation._id;
62
63
  console.log(jobMessage(job, "running"));
63
64
  // need to actually await these so that an error can be captured properly
64
- const tenantId = backend_core_1.tenancy.getTenantIDFromAppID(job.data.event.appId);
65
- return yield backend_core_1.tenancy.doInTenant(tenantId, () => __awaiter(this, void 0, void 0, function* () {
65
+ return yield backend_core_1.context.doInContext(job.data.event.appId, () => __awaiter(this, void 0, void 0, function* () {
66
66
  const runFn = () => Runner.run(job);
67
- return pro_1.quotas.addAutomation(runFn);
67
+ return pro_1.quotas.addAutomation(runFn, {
68
+ automationId,
69
+ });
68
70
  }));
69
71
  }
70
72
  catch (err) {
package/dist/db/utils.js CHANGED
@@ -7,7 +7,7 @@ const AppStatus = {
7
7
  ALL: "all",
8
8
  DEPLOYED: "published",
9
9
  };
10
- const DocumentType = 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", AUTOMATION_METADATA: "meta_au" });
10
+ const DocumentType = Object.assign(Object.assign({}, CoreDocTypes), { TABLE: "ta", ROW: "ro", USER: "us", AUTOMATION: "au", LINK: "li", WEBHOOK: "wh", INSTANCE: "inst", LAYOUT: "layout", SCREEN: "screen", QUERY: "query", DEPLOYMENTS: "deployments", METADATA: "metadata", MEM_VIEW: "view", USER_FLAG: "flag", AUTOMATION_METADATA: "meta_au" });
11
11
  const InternalTables = {
12
12
  USER_METADATA: "ta_users",
13
13
  };
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ function runServer() {
9
9
  checkDevelopmentEnvironment();
10
10
  fixPath();
11
11
  // this will setup http and https proxies form env variables
12
+ process.env.GLOBAL_AGENT_FORCE_GLOBAL_AGENT = "false";
12
13
  (0, global_agent_1.bootstrap)();
13
14
  require("./app");
14
15
  }
@@ -1,4 +1,27 @@
1
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
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,6 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
38
  const types_1 = require("@budibase/types");
16
39
  const datasource_1 = require("../definitions/datasource");
17
40
  const lodash_1 = require("lodash");
41
+ const https = __importStar(require("https"));
18
42
  const querystring_1 = __importDefault(require("querystring"));
19
43
  const fetch = require("node-fetch");
20
44
  const { formatBytes } = require("../utilities");
@@ -72,6 +96,11 @@ const SCHEMA = {
72
96
  required: false,
73
97
  default: {},
74
98
  },
99
+ rejectUnauthorized: {
100
+ type: types_1.DatasourceFieldType.BOOLEAN,
101
+ default: true,
102
+ required: false,
103
+ },
75
104
  legacyHttpParser: {
76
105
  display: "Legacy HTTP Support",
77
106
  type: types_1.DatasourceFieldType.BOOLEAN,
@@ -197,8 +226,11 @@ class RestIntegration {
197
226
  queryString = `${paginationString}&${queryString}`;
198
227
  }
199
228
  }
200
- // make sure the query string is fully encoded
201
- const main = `${path}?${querystring_1.default.encode(querystring_1.default.decode(queryString))}`;
229
+ if (queryString) {
230
+ // make sure the query string is fully encoded
231
+ queryString = "?" + querystring_1.default.encode(querystring_1.default.decode(queryString));
232
+ }
233
+ const main = `${path}${queryString}`;
202
234
  let complete = main;
203
235
  if (this.config.url && !main.startsWith("http")) {
204
236
  complete = !this.config.url ? main : `${this.config.url}/${main}`;
@@ -318,6 +350,11 @@ class RestIntegration {
318
350
  }
319
351
  let input = { method, headers: this.headers };
320
352
  input = this.addBody(bodyType, requestBody, input, pagination, paginationValues);
353
+ if (this.config.rejectUnauthorized == false) {
354
+ input.agent = new https.Agent({
355
+ rejectUnauthorized: false,
356
+ });
357
+ }
321
358
  if (this.config.legacyHttpParser) {
322
359
  // https://github.com/nodejs/node/issues/43798
323
360
  input.extraHttpOptions = { insecureHTTPParser: true };
@@ -36,19 +36,15 @@ exports.run = void 0;
36
36
  const usageQuotas_1 = require("./usageQuotas");
37
37
  const syncApps = __importStar(require("./usageQuotas/syncApps"));
38
38
  const syncRows = __importStar(require("./usageQuotas/syncRows"));
39
+ const syncPlugins = __importStar(require("./usageQuotas/syncPlugins"));
39
40
  /**
40
- * Date:
41
- * January 2022
42
- *
43
- * Description:
44
- * Synchronise the app and row quotas to the state of the db after it was
45
- * discovered that the quota resets were still in place and the row quotas
46
- * weren't being decremented correctly.
41
+ * Synchronise quotas to the state of the db.
47
42
  */
48
43
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
49
44
  yield (0, usageQuotas_1.runQuotaMigration)(() => __awaiter(void 0, void 0, void 0, function* () {
50
45
  yield syncApps.run();
51
46
  yield syncRows.run();
47
+ yield syncPlugins.run();
52
48
  }));
53
49
  });
54
50
  exports.run = run;
@@ -16,7 +16,6 @@ const pro_1 = require("@budibase/pro");
16
16
  const types_1 = require("@budibase/types");
17
17
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
18
18
  // get app count
19
- // @ts-ignore
20
19
  const devApps = yield (0, db_1.getAllApps)({ dev: true });
21
20
  const appCount = devApps ? devApps.length : 0;
22
21
  // sync app count
@@ -14,9 +14,7 @@ const backend_core_1 = require("@budibase/backend-core");
14
14
  const pro_1 = require("@budibase/pro");
15
15
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
16
16
  try {
17
- yield backend_core_1.tenancy.doInTenant(backend_core_1.tenancy.DEFAULT_TENANT_ID, () => __awaiter(void 0, void 0, void 0, function* () {
18
- yield pro_1.plugins.checkPluginQuotas();
19
- }));
17
+ yield pro_1.plugins.checkPluginQuotas();
20
18
  }
21
19
  catch (err) {
22
20
  backend_core_1.logging.logAlert("Failed to update plugin quotas", err);
@@ -17,15 +17,19 @@ const pro_1 = require("@budibase/pro");
17
17
  const types_1 = require("@budibase/types");
18
18
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
19
19
  // get all rows in all apps
20
- // @ts-ignore
21
20
  const allApps = yield (0, db_1.getAllApps)({ all: true });
22
- // @ts-ignore
23
21
  const appIds = allApps ? allApps.map((app) => app.appId) : [];
24
- const rows = yield (0, rows_1.getUniqueRows)(appIds);
25
- const rowCount = rows ? rows.length : 0;
22
+ const { appRows } = yield (0, rows_1.getUniqueRows)(appIds);
23
+ // get the counts per app
24
+ const counts = {};
25
+ let rowCount = 0;
26
+ Object.entries(appRows).forEach(([appId, rows]) => {
27
+ counts[appId] = rows.length;
28
+ rowCount += rows.length;
29
+ });
26
30
  // sync row count
27
31
  const tenantId = (0, tenancy_1.getTenantId)();
28
32
  console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`);
29
- yield pro_1.quotas.setUsage(rowCount, types_1.StaticQuotaName.ROWS, types_1.QuotaUsageType.STATIC);
33
+ yield pro_1.quotas.setUsagePerApp(counts, types_1.StaticQuotaName.ROWS, types_1.QuotaUsageType.STATIC);
30
34
  });
31
35
  exports.run = run;
@@ -41,10 +41,9 @@ const types_1 = require("@budibase/types");
41
41
  const environment_1 = __importDefault(require("../environment"));
42
42
  // migration functions
43
43
  const userEmailViewCasing = __importStar(require("./functions/userEmailViewCasing"));
44
- const quota1 = __importStar(require("./functions/quotas1"));
44
+ const syncQuotas = __importStar(require("./functions/syncQuotas"));
45
45
  const appUrls = __importStar(require("./functions/appUrls"));
46
46
  const backfill = __importStar(require("./functions/backfill"));
47
- const pluginCount = __importStar(require("./functions/pluginCount"));
48
47
  /**
49
48
  * Populate the migration function and additional configuration from
50
49
  * the static migration definitions.
@@ -58,8 +57,8 @@ const buildMigrations = () => {
58
57
  serverMigrations.push(Object.assign(Object.assign({}, definition), { fn: userEmailViewCasing.run }));
59
58
  break;
60
59
  }
61
- case types_1.MigrationName.QUOTAS_1: {
62
- serverMigrations.push(Object.assign(Object.assign({}, definition), { fn: quota1.run }));
60
+ case types_1.MigrationName.SYNC_QUOTAS: {
61
+ serverMigrations.push(Object.assign(Object.assign({}, definition), { fn: syncQuotas.run }));
63
62
  break;
64
63
  }
65
64
  case types_1.MigrationName.APP_URLS: {
@@ -78,11 +77,6 @@ const buildMigrations = () => {
78
77
  serverMigrations.push(Object.assign(Object.assign({}, definition), { fn: backfill.installation.run, silent: !!environment_1.default.SELF_HOSTED, preventRetry: !!environment_1.default.SELF_HOSTED }));
79
78
  break;
80
79
  }
81
- case types_1.MigrationName.PLUGIN_COUNT: {
82
- if (environment_1.default.SELF_HOSTED) {
83
- serverMigrations.push(Object.assign(Object.assign({}, definition), { fn: pluginCount.run, silent: !!environment_1.default.SELF_HOSTED, preventRetry: false }));
84
- }
85
- }
86
80
  }
87
81
  }
88
82
  return serverMigrations;
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.0.27",
4
+ "version": "2.0.29",
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": "^2.0.27",
81
- "@budibase/client": "^2.0.27",
82
- "@budibase/pro": "2.0.27",
83
- "@budibase/string-templates": "^2.0.27",
84
- "@budibase/types": "^2.0.27",
80
+ "@budibase/backend-core": "^2.0.29",
81
+ "@budibase/client": "^2.0.29",
82
+ "@budibase/pro": "2.0.29",
83
+ "@budibase/string-templates": "^2.0.29",
84
+ "@budibase/types": "^2.0.29",
85
85
  "@bull-board/api": "3.7.0",
86
86
  "@bull-board/koa": "3.9.4",
87
87
  "@elastic/elasticsearch": "7.10.0",
@@ -146,7 +146,7 @@
146
146
  "to-json-schema": "0.2.5",
147
147
  "uuid": "3.3.2",
148
148
  "validate.js": "0.13.1",
149
- "vm2": "3.9.6",
149
+ "vm2": "3.9.11",
150
150
  "worker-farm": "1.7.0",
151
151
  "xml2js": "0.4.23",
152
152
  "yargs": "13.2.4",