@budibase/server 0.9.148 → 0.9.149-alpha.3

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 (173) hide show
  1. package/builder/assets/{index.6216ff9a.js → index.171bc7bc.js} +2 -2
  2. package/builder/assets/{index.bf911dc7.css → index.474ebeb3.css} +1 -1
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +126 -113
  5. package/coverage/coverage-final.json +5 -5
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +24 -9
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/application.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 +1 -1
  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 +1 -1
  15. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +11 -11
  18. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/index.html +14 -14
  27. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/internal.js.html +66 -18
  29. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/script.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/table/utils.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  44. package/coverage/lcov-report/api/index.html +1 -1
  45. package/coverage/lcov-report/api/index.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/analytics.js.html +10 -7
  47. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/index.html +7 -7
  59. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/metadata.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/row.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/user.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/createRow.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/index.html +1 -1
  90. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  99. package/coverage/lcov-report/automations/thread.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  109. package/coverage/lcov-report/automations/utils.js.html +1 -1
  110. package/coverage/lcov-report/constants/index.html +1 -1
  111. package/coverage/lcov-report/constants/index.js.html +1 -1
  112. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  113. package/coverage/lcov-report/constants/screens.js.html +1 -1
  114. package/coverage/lcov-report/db/client.js.html +1 -1
  115. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  116. package/coverage/lcov-report/db/index.html +1 -1
  117. package/coverage/lcov-report/db/index.js.html +1 -1
  118. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  119. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  120. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  121. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  122. package/coverage/lcov-report/db/newid.js.html +1 -1
  123. package/coverage/lcov-report/db/utils.js.html +1 -1
  124. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  125. package/coverage/lcov-report/events/index.html +1 -1
  126. package/coverage/lcov-report/events/index.js.html +1 -1
  127. package/coverage/lcov-report/events/utils.js.html +1 -1
  128. package/coverage/lcov-report/index.html +38 -38
  129. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  130. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  131. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  132. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  133. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  134. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  135. package/coverage/lcov-report/middleware/index.html +1 -1
  136. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  137. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  138. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  139. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  140. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  141. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  142. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  143. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  144. package/coverage/lcov-report/utilities/global.js.html +1 -1
  145. package/coverage/lcov-report/utilities/index.html +11 -11
  146. package/coverage/lcov-report/utilities/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  148. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  149. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  150. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  151. package/coverage/lcov-report/utilities/rowProcessor/index.html +15 -15
  152. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +28 -10
  153. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  154. package/coverage/lcov-report/utilities/security.js.html +1 -1
  155. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  156. package/coverage/lcov-report/utilities/users.js.html +1 -1
  157. package/coverage/lcov-report/utilities/workerRequests.js.html +10 -7
  158. package/coverage/lcov.info +194 -175
  159. package/dist/api/controllers/analytics.js +10 -8
  160. package/dist/api/controllers/deploy/index.js +17 -0
  161. package/dist/api/controllers/row/internal.js +19 -4
  162. package/dist/api/routes/analytics.js +3 -2
  163. package/dist/package.json +4 -4
  164. package/dist/tsconfig.tsbuildinfo +1 -1
  165. package/dist/utilities/rowProcessor/index.js +6 -2
  166. package/dist/utilities/workerRequests.js +2 -1
  167. package/package.json +5 -5
  168. package/src/api/controllers/analytics.js +8 -3
  169. package/src/api/controllers/deploy/index.js +18 -0
  170. package/src/api/controllers/row/internal.js +26 -10
  171. package/src/api/routes/analytics.js +3 -2
  172. package/src/utilities/rowProcessor/index.js +8 -2
  173. package/src/utilities/workerRequests.js +2 -1
@@ -101,6 +101,7 @@ const TYPE_TRANSFORM_MAP = {
101
101
  * for automatic ID purposes.
102
102
  */
103
103
  function processAutoColumn(user, table, row, opts = { reprocessing: false, noAutoRelationships: false }) {
104
+ let noUser = !user || !user.userId;
104
105
  let now = new Date().toISOString();
105
106
  // if a row doesn't have a revision then it doesn't exist yet
106
107
  const creating = !row._rev;
@@ -110,7 +111,10 @@ function processAutoColumn(user, table, row, opts = { reprocessing: false, noAut
110
111
  }
111
112
  switch (schema.subtype) {
112
113
  case AutoFieldSubTypes.CREATED_BY:
113
- if (creating && !opts.reprocessing && !opts.noAutoRelationships) {
114
+ if (creating &&
115
+ !opts.reprocessing &&
116
+ !opts.noAutoRelationships &&
117
+ !noUser) {
114
118
  row[key] = [user.userId];
115
119
  }
116
120
  break;
@@ -120,7 +124,7 @@ function processAutoColumn(user, table, row, opts = { reprocessing: false, noAut
120
124
  }
121
125
  break;
122
126
  case AutoFieldSubTypes.UPDATED_BY:
123
- if (!opts.reprocessing && !opts.noAutoRelationships) {
127
+ if (!opts.reprocessing && !opts.noAutoRelationships && !noUser) {
124
128
  row[key] = [user.userId];
125
129
  }
126
130
  break;
@@ -56,7 +56,8 @@ exports.sendSmtpEmail = (to, from, subject, contents, automation) => __awaiter(v
56
56
  },
57
57
  }));
58
58
  if (response.status !== 200) {
59
- throw "Unable to send email.";
59
+ const error = yield response.text();
60
+ throw `Unable to send email - ${error}`;
60
61
  }
61
62
  return response.json();
62
63
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "0.9.148",
4
+ "version": "0.9.149-alpha.3",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.js",
7
7
  "repository": {
@@ -64,9 +64,9 @@
64
64
  "author": "Budibase",
65
65
  "license": "AGPL-3.0-or-later",
66
66
  "dependencies": {
67
- "@budibase/auth": "^0.9.148",
68
- "@budibase/client": "^0.9.148",
69
- "@budibase/string-templates": "^0.9.148",
67
+ "@budibase/auth": "^0.9.149-alpha.3",
68
+ "@budibase/client": "^0.9.149-alpha.3",
69
+ "@budibase/string-templates": "^0.9.149-alpha.3",
70
70
  "@elastic/elasticsearch": "7.10.0",
71
71
  "@koa/router": "8.0.0",
72
72
  "@sendgrid/mail": "7.1.1",
@@ -144,5 +144,5 @@
144
144
  "typescript": "^4.3.5",
145
145
  "update-dotenv": "^1.1.1"
146
146
  },
147
- "gitHead": "423728a8a6c1e7131ac0b3ab5ec3ee8b1dbcee61"
147
+ "gitHead": "7d621a36f09b6f0b3f45a8de37b3a93d08ad5c17"
148
148
  }
@@ -7,14 +7,19 @@ if (env.POSTHOG_TOKEN && env.ENABLE_ANALYTICS && !env.SELF_HOSTED) {
7
7
  posthogClient = new PostHog(env.POSTHOG_TOKEN)
8
8
  }
9
9
 
10
- exports.isEnabled = async function (ctx) {
10
+ exports.isEnabled = async ctx => {
11
11
  ctx.body = {
12
12
  enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true",
13
13
  }
14
14
  }
15
15
 
16
- exports.endUserPing = async (ctx, next) => {
17
- if (!posthogClient) return next()
16
+ exports.endUserPing = async ctx => {
17
+ if (!posthogClient) {
18
+ ctx.body = {
19
+ ping: false,
20
+ }
21
+ return
22
+ }
18
23
 
19
24
  posthogClient.capture("budibase:end_user_ping", {
20
25
  userId: ctx.user && ctx.user._id,
@@ -64,6 +64,7 @@ async function storeDeploymentHistory(deployment) {
64
64
 
65
65
  async function initDeployedApp(prodAppId) {
66
66
  const db = new CouchDB(prodAppId)
67
+ console.log("Reading automation docs")
67
68
  const automations = (
68
69
  await db.allDocs(
69
70
  getAutomationParams(null, {
@@ -71,12 +72,17 @@ async function initDeployedApp(prodAppId) {
71
72
  })
72
73
  )
73
74
  ).rows.map(row => row.doc)
75
+ console.log("You have " + automations.length + " automations")
74
76
  const promises = []
77
+ console.log("Disabling prod crons..")
75
78
  await disableAllCrons(prodAppId)
79
+ console.log("Prod Cron triggers disabled..")
80
+ console.log("Enabling cron triggers for deployed app..")
76
81
  for (let automation of automations) {
77
82
  promises.push(enableCronTrigger(prodAppId, automation))
78
83
  }
79
84
  await Promise.all(promises)
85
+ console.log("Enabled cron triggers for deployed app..")
80
86
  }
81
87
 
82
88
  async function deployApp(deployment) {
@@ -88,13 +94,18 @@ async function deployApp(deployment) {
88
94
  target: productionAppId,
89
95
  })
90
96
 
97
+ console.log("Replication object created")
98
+
91
99
  await replication.replicate()
100
+ console.log("replication complete.. replacing app meta doc")
92
101
  const db = new CouchDB(productionAppId)
93
102
  const appDoc = await db.get(DocumentTypes.APP_METADATA)
94
103
  appDoc.appId = productionAppId
95
104
  appDoc.instance._id = productionAppId
96
105
  await db.put(appDoc)
106
+ console.log("New app doc written successfully.")
97
107
 
108
+ console.log("Setting up live repl between dev and prod")
98
109
  // Set up live sync between the live and dev instances
99
110
  const liveReplication = new Replication({
100
111
  source: productionAppId,
@@ -105,8 +116,11 @@ async function deployApp(deployment) {
105
116
  return doc._id !== DocumentTypes.APP_METADATA
106
117
  },
107
118
  })
119
+ console.log("Set up live repl between dev and prod")
108
120
 
121
+ console.log("Initialising deployed app")
109
122
  await initDeployedApp(productionAppId)
123
+ console.log("Init complete, setting deployment to successful")
110
124
  deployment.setStatus(DeploymentStatus.SUCCESS)
111
125
  await storeDeploymentHistory(deployment)
112
126
  } catch (err) {
@@ -153,9 +167,13 @@ exports.deploymentProgress = async function (ctx) {
153
167
 
154
168
  exports.deployApp = async function (ctx) {
155
169
  let deployment = new Deployment(ctx.appId)
170
+ console.log("Deployment object created")
156
171
  deployment.setStatus(DeploymentStatus.PENDING)
172
+ console.log("Deployment object set to pending")
157
173
  deployment = await storeDeploymentHistory(deployment)
174
+ console.log("Stored deployment history")
158
175
 
176
+ console.log("Deploying app...")
159
177
  await deployApp(deployment)
160
178
 
161
179
  ctx.body = deployment
@@ -403,16 +403,32 @@ exports.fetchEnrichedRow = async ctx => {
403
403
  rowId,
404
404
  })
405
405
  // look up the actual rows based on the ids
406
- const response = await db.allDocs({
407
- include_docs: true,
408
- keys: linkVals.map(linkVal => linkVal.id),
409
- })
410
- // need to include the IDs in these rows for any links they may have
411
- let linkedRows = await outputProcessing(
412
- ctx,
413
- table,
414
- response.rows.map(row => row.doc)
415
- )
406
+ let response = (
407
+ await db.allDocs({
408
+ include_docs: true,
409
+ keys: linkVals.map(linkVal => linkVal.id),
410
+ })
411
+ ).rows.map(row => row.doc)
412
+ // group responses by table
413
+ let groups = {},
414
+ tables = {}
415
+ for (let row of response) {
416
+ const linkedTableId = row.tableId
417
+ if (groups[linkedTableId] == null) {
418
+ groups[linkedTableId] = [row]
419
+ tables[linkedTableId] = await db.get(linkedTableId)
420
+ } else {
421
+ groups[linkedTableId].push(row)
422
+ }
423
+ }
424
+ let linkedRows = []
425
+ for (let [tableId, rows] of Object.entries(groups)) {
426
+ // need to include the IDs in these rows for any links they may have
427
+ linkedRows = linkedRows.concat(
428
+ await outputProcessing(ctx, tables[tableId], rows)
429
+ )
430
+ }
431
+
416
432
  // insert the link rows in the correct place throughout the main row
417
433
  for (let fieldName of Object.keys(table.schema)) {
418
434
  let field = table.schema[fieldName]
@@ -3,7 +3,8 @@ const controller = require("../controllers/analytics")
3
3
 
4
4
  const router = Router()
5
5
 
6
- router.get("/api/analytics", controller.isEnabled)
7
- router.post("/api/analytics/ping", controller.endUserPing)
6
+ router
7
+ .get("/api/analytics", controller.isEnabled)
8
+ .post("/api/analytics/ping", controller.endUserPing)
8
9
 
9
10
  module.exports = router
@@ -99,6 +99,7 @@ function processAutoColumn(
99
99
  row,
100
100
  opts = { reprocessing: false, noAutoRelationships: false }
101
101
  ) {
102
+ let noUser = !user || !user.userId
102
103
  let now = new Date().toISOString()
103
104
  // if a row doesn't have a revision then it doesn't exist yet
104
105
  const creating = !row._rev
@@ -108,7 +109,12 @@ function processAutoColumn(
108
109
  }
109
110
  switch (schema.subtype) {
110
111
  case AutoFieldSubTypes.CREATED_BY:
111
- if (creating && !opts.reprocessing && !opts.noAutoRelationships) {
112
+ if (
113
+ creating &&
114
+ !opts.reprocessing &&
115
+ !opts.noAutoRelationships &&
116
+ !noUser
117
+ ) {
112
118
  row[key] = [user.userId]
113
119
  }
114
120
  break
@@ -118,7 +124,7 @@ function processAutoColumn(
118
124
  }
119
125
  break
120
126
  case AutoFieldSubTypes.UPDATED_BY:
121
- if (!opts.reprocessing && !opts.noAutoRelationships) {
127
+ if (!opts.reprocessing && !opts.noAutoRelationships && !noUser) {
122
128
  row[key] = [user.userId]
123
129
  }
124
130
  break
@@ -52,7 +52,8 @@ exports.sendSmtpEmail = async (to, from, subject, contents, automation) => {
52
52
  )
53
53
 
54
54
  if (response.status !== 200) {
55
- throw "Unable to send email."
55
+ const error = await response.text()
56
+ throw `Unable to send email - ${error}`
56
57
  }
57
58
  return response.json()
58
59
  }