@budibase/server 1.0.219 → 1.0.220-alpha.2

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 (284) hide show
  1. package/.yarnrc +1 -0
  2. package/__mocks__/node-fetch.ts +9 -0
  3. package/builder/assets/index.7786f497.css +6 -0
  4. package/builder/assets/index.e1885c5f.js +974 -0
  5. package/builder/assets/{vendor.9bf2fcb4.js → vendor.001dcf8c.js} +163 -163
  6. package/builder/index.html +3 -3
  7. package/coverage/clover.xml +1018 -950
  8. package/coverage/coverage-final.json +31 -31
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +111 -12
  12. package/coverage/lcov-report/api/controllers/backup.js.html +9 -6
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  16. package/coverage/lcov-report/api/controllers/dev.js.html +13 -166
  17. package/coverage/lcov-report/api/controllers/index.html +32 -32
  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/migrations.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/external.js.html +47 -17
  28. package/coverage/lcov-report/api/controllers/row/index.html +33 -33
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +159 -21
  31. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/row/utils.js.html +17 -8
  33. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  47. package/coverage/lcov-report/api/index.html +15 -15
  48. package/coverage/lcov-report/api/index.js.html +22 -13
  49. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/automation.js.html +32 -2
  53. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/dev.js.html +2 -5
  59. package/coverage/lcov-report/api/routes/index.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/migrations.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  74. package/coverage/lcov-report/api/routes/utils/validators.js.html +5 -2
  75. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  77. package/coverage/lcov-report/automations/actions.js.html +1 -1
  78. package/coverage/lcov-report/automations/automationUtils.js.html +57 -12
  79. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  80. package/coverage/lcov-report/automations/index.html +17 -17
  81. package/coverage/lcov-report/automations/index.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/executeQuery.js.html +2 -2
  86. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/filter.js.html +58 -34
  88. package/coverage/lcov-report/automations/steps/index.html +11 -11
  89. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/loop.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/triggerInfo/app.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggers.js.html +4 -4
  108. package/coverage/lcov-report/constants/index.html +1 -1
  109. package/coverage/lcov-report/constants/index.js.html +1 -1
  110. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  111. package/coverage/lcov-report/constants/screens.js.html +1 -1
  112. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  113. package/coverage/lcov-report/db/index.html +14 -14
  114. package/coverage/lcov-report/db/index.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  116. package/coverage/lcov-report/db/linkedRows/index.html +13 -13
  117. package/coverage/lcov-report/db/linkedRows/index.js.html +10 -7
  118. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  119. package/coverage/lcov-report/db/newid.js.html +2 -2
  120. package/coverage/lcov-report/db/utils.js.html +27 -51
  121. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  122. package/coverage/lcov-report/events/index.html +1 -1
  123. package/coverage/lcov-report/events/index.js.html +1 -1
  124. package/coverage/lcov-report/events/utils.js.html +1 -1
  125. package/coverage/lcov-report/index.html +83 -83
  126. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  127. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  128. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  129. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  130. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  131. package/coverage/lcov-report/middleware/index.html +1 -1
  132. package/coverage/lcov-report/middleware/joi-validator.js.html +10 -10
  133. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  134. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  135. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  136. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  137. package/coverage/lcov-report/threads/automation.js.html +18 -9
  138. package/coverage/lcov-report/threads/index.html +25 -25
  139. package/coverage/lcov-report/threads/query.js.html +301 -79
  140. package/coverage/lcov-report/threads/utils.js.html +4 -4
  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 +14 -14
  145. package/coverage/lcov-report/utilities/index.html +26 -26
  146. package/coverage/lcov-report/utilities/index.js.html +17 -32
  147. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  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 +1 -1
  152. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  153. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  154. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  155. package/coverage/lcov-report/utilities/security.js.html +2 -2
  156. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  157. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  158. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  159. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  160. package/coverage/lcov-report/utilities/users.js.html +1 -1
  161. package/coverage/lcov-report/utilities/workerRequests.js.html +57 -9
  162. package/coverage/lcov.info +1789 -1665
  163. package/dist/api/controllers/application.js +19 -16
  164. package/dist/api/controllers/automation.js +28 -2
  165. package/dist/api/controllers/backup.js +3 -2
  166. package/dist/api/controllers/dev.js +2 -40
  167. package/dist/api/controllers/public/applications.js +1 -1
  168. package/dist/api/controllers/public/utils.js +8 -1
  169. package/dist/api/controllers/query/index.js +31 -3
  170. package/dist/api/controllers/row/external.js +19 -7
  171. package/dist/api/controllers/row/internalSearch.js +47 -10
  172. package/dist/api/controllers/row/utils.js +3 -0
  173. package/dist/api/controllers/static/index.js +1 -5
  174. package/dist/api/index.js +4 -1
  175. package/dist/api/routes/automation.js +2 -0
  176. package/dist/api/routes/dev.js +1 -2
  177. package/dist/api/routes/public/rows.js +7 -2
  178. package/dist/api/routes/utils/validators.js +1 -0
  179. package/dist/app.js +20 -0
  180. package/dist/automations/automationUtils.js +16 -4
  181. package/dist/automations/logging/index.js +70 -0
  182. package/dist/automations/steps/executeQuery.js +1 -1
  183. package/dist/automations/steps/filter.js +38 -29
  184. package/dist/automations/triggers.js +1 -1
  185. package/dist/db/linkedRows/index.js +1 -0
  186. package/dist/db/utils.js +4 -31
  187. package/dist/definitions/datasource.js +1 -0
  188. package/dist/environment.js +3 -0
  189. package/dist/integrations/airtable.js +1 -0
  190. package/dist/integrations/arangodb.js +1 -0
  191. package/dist/integrations/base/sql.js +22 -3
  192. package/dist/integrations/couchdb.js +1 -0
  193. package/dist/integrations/dynamodb.js +1 -0
  194. package/dist/integrations/elasticsearch.js +1 -0
  195. package/dist/integrations/firebase.js +1 -0
  196. package/dist/integrations/googlesheets.js +1 -0
  197. package/dist/integrations/index.js +4 -0
  198. package/dist/integrations/microsoftSqlServer.js +2 -1
  199. package/dist/integrations/mongodb.js +1 -0
  200. package/dist/integrations/mysql.js +2 -1
  201. package/dist/integrations/oracle.js +1 -0
  202. package/dist/integrations/postgres.js +2 -1
  203. package/dist/integrations/queries/sql.js +3 -0
  204. package/dist/integrations/redis.js +1 -0
  205. package/dist/integrations/rest.js +2 -1
  206. package/dist/integrations/s3.js +1 -0
  207. package/dist/integrations/snowflake.js +102 -0
  208. package/dist/package.json +7 -6
  209. package/dist/tests/utilities/TestConfiguration.js +19 -6
  210. package/dist/threads/automation.js +6 -3
  211. package/dist/threads/index.js +15 -1
  212. package/dist/threads/query.js +65 -12
  213. package/dist/tsconfig.build.tsbuildinfo +1 -1
  214. package/dist/utilities/fileSystem/index.js +16 -6
  215. package/dist/utilities/index.js +1 -5
  216. package/dist/utilities/workerRequests.js +8 -0
  217. package/package.json +8 -7
  218. package/scripts/dev/manage.js +2 -0
  219. package/scripts/integrations/oracle/instantclient/linux/arm64/basiclite-19.10.zip +0 -0
  220. package/scripts/integrations/oracle/instantclient/linux/arm64/install.sh +23 -0
  221. package/scripts/integrations/oracle/instantclient/linux/install.sh +10 -0
  222. package/specs/openapi.json +9 -5
  223. package/specs/openapi.yaml +10 -4
  224. package/src/api/controllers/application.ts +19 -19
  225. package/src/api/controllers/automation.js +35 -2
  226. package/src/api/controllers/backup.js +3 -2
  227. package/src/api/controllers/dev.js +2 -53
  228. package/src/api/controllers/public/applications.ts +2 -2
  229. package/src/api/controllers/public/utils.ts +8 -1
  230. package/src/api/controllers/query/index.ts +40 -4
  231. package/src/api/controllers/row/external.js +19 -9
  232. package/src/api/controllers/row/internalSearch.js +55 -9
  233. package/src/api/controllers/row/utils.js +3 -0
  234. package/src/api/controllers/static/index.js +1 -6
  235. package/src/api/index.js +4 -1
  236. package/src/api/routes/automation.js +10 -0
  237. package/src/api/routes/dev.js +0 -1
  238. package/src/api/routes/public/rows.ts +7 -2
  239. package/src/api/routes/tests/query.spec.js +166 -1
  240. package/src/api/routes/utils/validators.js +1 -0
  241. package/src/app.ts +30 -1
  242. package/src/automations/automationUtils.js +19 -4
  243. package/src/automations/logging/index.ts +35 -0
  244. package/src/automations/steps/executeQuery.js +1 -1
  245. package/src/automations/steps/filter.js +36 -28
  246. package/src/automations/tests/filter.spec.js +2 -1
  247. package/src/automations/triggers.js +1 -1
  248. package/src/db/linkedRows/index.js +1 -0
  249. package/src/db/utils.js +5 -13
  250. package/src/definitions/common.ts +1 -0
  251. package/src/definitions/datasource.ts +2 -0
  252. package/src/definitions/openapi.ts +471 -469
  253. package/src/environment.js +3 -0
  254. package/src/integrations/airtable.ts +1 -0
  255. package/src/integrations/arangodb.ts +1 -0
  256. package/src/integrations/base/sql.ts +29 -11
  257. package/src/integrations/couchdb.ts +1 -0
  258. package/src/integrations/dynamodb.ts +1 -0
  259. package/src/integrations/elasticsearch.ts +1 -0
  260. package/src/integrations/firebase.ts +1 -0
  261. package/src/integrations/googlesheets.ts +1 -0
  262. package/src/integrations/index.ts +4 -0
  263. package/src/integrations/microsoftSqlServer.ts +2 -0
  264. package/src/integrations/mongodb.ts +1 -0
  265. package/src/integrations/mysql.ts +2 -0
  266. package/src/integrations/oracle.ts +1 -0
  267. package/src/integrations/postgres.ts +2 -0
  268. package/src/integrations/queries/sql.ts +3 -1
  269. package/src/integrations/redis.ts +1 -0
  270. package/src/integrations/rest.ts +2 -1
  271. package/src/integrations/s3.ts +1 -0
  272. package/src/integrations/snowflake.ts +99 -0
  273. package/src/integrations/tests/rest.spec.js +16 -1
  274. package/src/migrations/tests/index.spec.ts +18 -2
  275. package/src/module.d.ts +2 -0
  276. package/src/tests/utilities/TestConfiguration.js +22 -3
  277. package/src/threads/automation.js +6 -3
  278. package/src/threads/index.ts +5 -1
  279. package/src/threads/query.js +88 -14
  280. package/src/utilities/fileSystem/index.js +22 -8
  281. package/src/utilities/index.js +1 -6
  282. package/src/utilities/workerRequests.js +16 -0
  283. package/builder/assets/index.1c640a53.js +0 -1316
  284. package/builder/assets/index.24307ca0.css +0 -6
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.218",
4
+ "version": "1.0.220-alpha.1",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -77,10 +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.218",
81
- "@budibase/client": "^1.0.218",
82
- "@budibase/pro": "1.0.218",
83
- "@budibase/string-templates": "^1.0.218",
80
+ "@budibase/backend-core": "^1.0.220-alpha.1",
81
+ "@budibase/client": "^1.0.220-alpha.1",
82
+ "@budibase/pro": "1.0.220-alpha.1",
83
+ "@budibase/string-templates": "^1.0.220-alpha.1",
84
84
  "@bull-board/api": "3.7.0",
85
85
  "@bull-board/koa": "3.9.4",
86
86
  "@elastic/elasticsearch": "7.10.0",
@@ -135,6 +135,7 @@
135
135
  "pouchdb-replication-stream": "1.2.9",
136
136
  "redis": "4",
137
137
  "server-destroy": "1.0.1",
138
+ "snowflake-promise": "^4.5.0",
138
139
  "svelte": "3.44.1",
139
140
  "swagger-parser": "10.0.3",
140
141
  "to-json-schema": "0.2.5",
@@ -150,7 +151,7 @@
150
151
  "@babel/core": "7.17.4",
151
152
  "@babel/preset-env": "7.16.11",
152
153
  "@budibase/standard-components": "^0.9.139",
153
- "@budibase/types": "^1.0.218",
154
+ "@budibase/types": "^1.0.220-alpha.1",
154
155
  "@jest/test-sequencer": "24.9.0",
155
156
  "@types/apidoc": "0.50.0",
156
157
  "@types/bson": "4.2.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) {
@@ -195,7 +196,7 @@ class Orchestrator {
195
196
  }
196
197
  }
197
198
  }
198
- if (index === parseInt(env.AUTOMATION_MAX_ITERATIONS) ||
199
+ if (index === env.AUTOMATION_MAX_ITERATION ||
199
200
  index === parseInt(loopStep.inputs.iterations)) {
200
201
  this.updateContextAndOutput(loopStepNumber, step, tempOutput, {
201
202
  status: AutomationErrors.MAX_ITERATIONS,
@@ -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 = [];
@@ -14,6 +14,10 @@ const ScriptRunner = require("../utilities/scriptRunner");
14
14
  const { integrations } = require("../integrations");
15
15
  const { processStringSync } = require("@budibase/string-templates");
16
16
  const { doInAppContext, getAppDB } = require("@budibase/backend-core/context");
17
+ const { refreshOAuthToken, updateUserOAuth, } = require("@budibase/backend-core/auth");
18
+ const { user: userCache } = require("@budibase/backend-core/cache");
19
+ const { getGlobalIDFromUserMetadataID } = require("../db/utils");
20
+ const { cloneDeep } = require("lodash/fp");
17
21
  const { isSQL } = require("../integrations/utils");
18
22
  const { enrichQueryFields, interpolateSQL, } = require("../integrations/queries/sql");
19
23
  class QueryRunner {
@@ -27,29 +31,49 @@ class QueryRunner {
27
31
  this.queryId = input.queryId;
28
32
  this.noRecursiveQuery = flags.noRecursiveQuery;
29
33
  this.cachedVariables = [];
34
+ // Additional context items for enrichment
35
+ this.ctx = input.ctx;
30
36
  // allows the response from a query to be stored throughout this
31
37
  // execution so that if it needs to be re-used for another variable
32
38
  // it can be
33
39
  this.queryResponse = {};
34
40
  this.hasRerun = false;
41
+ this.hasRefreshedOAuth = false;
35
42
  }
36
43
  execute() {
44
+ var _a;
37
45
  return __awaiter(this, void 0, void 0, function* () {
38
46
  let { datasource, fields, queryVerb, transformer } = this;
39
- const Integration = integrations[datasource.source];
47
+ let datasourceClone = cloneDeep(datasource);
48
+ let fieldsClone = cloneDeep(fields);
49
+ const Integration = integrations[datasourceClone.source];
40
50
  if (!Integration) {
41
51
  throw "Integration type does not exist.";
42
52
  }
43
- const integration = new Integration(datasource.config);
53
+ if (datasourceClone.config.authConfigs) {
54
+ datasourceClone.config.authConfigs =
55
+ datasourceClone.config.authConfigs.map(config => {
56
+ return enrichQueryFields(config, this.ctx);
57
+ });
58
+ }
59
+ const integration = new Integration(datasourceClone.config);
44
60
  // pre-query, make sure datasource variables are added to parameters
45
61
  const parameters = yield this.addDatasourceVariables();
62
+ // Enrich the parameters with the addition context items.
63
+ // 'user' is now a reserved variable key in mapping parameters
64
+ const enrichedParameters = enrichQueryFields(parameters, this.ctx);
65
+ const enrichedContext = Object.assign(Object.assign({}, enrichedParameters), this.ctx);
66
+ // Parse global headers
67
+ if (datasourceClone.config.defaultHeaders) {
68
+ datasourceClone.config.defaultHeaders = enrichQueryFields(datasourceClone.config.defaultHeaders, enrichedContext);
69
+ }
46
70
  let query;
47
71
  // handle SQL injections by interpolating the variables
48
- if (isSQL(datasource)) {
49
- query = interpolateSQL(fields, parameters, integration);
72
+ if (isSQL(datasourceClone)) {
73
+ query = interpolateSQL(fieldsClone, enrichedParameters, integration);
50
74
  }
51
75
  else {
52
- query = enrichQueryFields(fields, parameters);
76
+ query = enrichQueryFields(fieldsClone, enrichedContext);
53
77
  }
54
78
  // Add pagination values for REST queries
55
79
  if (this.pagination) {
@@ -67,17 +91,22 @@ class QueryRunner {
67
91
  if (transformer) {
68
92
  const runner = new ScriptRunner(transformer, {
69
93
  data: rows,
70
- params: parameters,
94
+ params: enrichedParameters,
71
95
  });
72
96
  rows = runner.execute();
73
97
  }
74
98
  // if the request fails we retry once, invalidating the cached value
75
- if (info &&
76
- info.code >= 400 &&
77
- this.cachedVariables.length > 0 &&
78
- !this.hasRerun) {
79
- this.hasRerun = true;
80
- // invalidate the cache value
99
+ if (info && info.code >= 400 && !this.hasRerun) {
100
+ if (((_a = this.ctx.user) === null || _a === void 0 ? void 0 : _a.provider) &&
101
+ info.code === 401 &&
102
+ !this.hasRefreshedOAuth) {
103
+ yield this.refreshOAuth2(this.ctx);
104
+ // Attempt to refresh the access token from the provider
105
+ this.hasRefreshedOAuth = true;
106
+ }
107
+ else {
108
+ this.hasRerun = true;
109
+ }
81
110
  yield threadUtils.invalidateDynamicVariables(this.cachedVariables);
82
111
  return this.execute();
83
112
  }
@@ -115,6 +144,30 @@ class QueryRunner {
115
144
  }, { noRecursiveQuery: true }).execute();
116
145
  });
117
146
  }
147
+ refreshOAuth2(ctx) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ const { oauth2, providerType, _id } = ctx.user;
150
+ const { configId } = ctx.auth;
151
+ if (!providerType || !(oauth2 === null || oauth2 === void 0 ? void 0 : oauth2.refreshToken)) {
152
+ throw new Error("No refresh token found for authenticated user");
153
+ }
154
+ const resp = yield refreshOAuthToken(oauth2.refreshToken, providerType, configId);
155
+ // Refresh session flow. Should be in same location as refreshOAuthToken
156
+ // There are several other properties available in 'resp'
157
+ if (!resp.err) {
158
+ const globalUserId = getGlobalIDFromUserMetadataID(_id);
159
+ yield updateUserOAuth(globalUserId, resp);
160
+ this.ctx.user = yield userCache.getUser(globalUserId);
161
+ }
162
+ else {
163
+ // In this event the user may have oAuth issues that
164
+ // could require re-authenticating with their provider.
165
+ let errorMessage = resp.err.data ? resp.err.data : resp.err.toString();
166
+ throw new Error("OAuth2 access token could not be refreshed: " + errorMessage);
167
+ }
168
+ return resp;
169
+ });
170
+ }
118
171
  getDynamicVariable(variable) {
119
172
  return __awaiter(this, void 0, void 0, function* () {
120
173
  let { parameters } = this;