@budibase/server 1.0.200-alpha.3 → 1.0.200

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 (285) hide show
  1. package/Dockerfile +0 -2
  2. package/builder/assets/index.f83b3433.js +1315 -0
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +1998 -2086
  5. package/coverage/coverage-final.json +122 -121
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +202 -0
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  8. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  9. package/coverage/lcov-report/api/controllers/automation.js.html +72 -174
  10. package/coverage/lcov-report/api/controllers/backup.js.html +6 -30
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
  12. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +41 -53
  14. package/coverage/lcov-report/api/controllers/dev.js.html +70 -94
  15. package/coverage/lcov-report/api/controllers/index.html +72 -57
  16. package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
  17. package/coverage/lcov-report/api/controllers/layout.js.html +19 -28
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  19. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  20. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  21. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
  23. package/coverage/lcov-report/api/controllers/role.js.html +48 -78
  24. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
  26. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
  29. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
  31. package/coverage/lcov-report/api/controllers/screen.js.html +20 -56
  32. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  33. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
  34. package/coverage/lcov-report/api/controllers/table/external.js.html +17 -23
  35. package/coverage/lcov-report/api/controllers/table/index.html +26 -26
  36. package/coverage/lcov-report/api/controllers/table/index.js.html +49 -85
  37. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  38. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
  40. package/coverage/lcov-report/api/controllers/view/index.html +21 -21
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +65 -275
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
  45. package/coverage/lcov-report/api/index.html +15 -15
  46. package/coverage/lcov-report/api/index.js.html +45 -39
  47. package/coverage/lcov-report/api/routes/analytics.js.html +13 -7
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  49. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  50. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  51. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  53. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  54. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  55. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  56. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  57. package/coverage/lcov-report/api/routes/index.html +1 -1
  58. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  60. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  61. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  62. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  63. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  64. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  65. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  66. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  67. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  69. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  70. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  71. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  72. package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
  73. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  74. package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
  75. package/coverage/lcov-report/automations/actions.js.html +25 -25
  76. package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
  77. package/coverage/lcov-report/automations/bullboard.js.html +35 -35
  78. package/coverage/lcov-report/automations/index.html +29 -29
  79. package/coverage/lcov-report/automations/index.js.html +17 -29
  80. package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
  81. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  82. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  83. package/coverage/lcov-report/automations/steps/executeQuery.js.html +7 -7
  84. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  85. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  86. package/coverage/lcov-report/automations/steps/index.html +1 -1
  87. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  88. package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
  89. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  90. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  91. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  92. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  93. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  94. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  96. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  97. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  98. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  99. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  101. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  102. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  103. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  104. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  105. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  106. package/coverage/lcov-report/constants/index.html +1 -1
  107. package/coverage/lcov-report/constants/index.js.html +30 -30
  108. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  109. package/coverage/lcov-report/constants/screens.js.html +4 -4
  110. package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
  111. package/coverage/lcov-report/db/index.html +1 -1
  112. package/coverage/lcov-report/db/index.js.html +9 -9
  113. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
  114. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  116. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
  117. package/coverage/lcov-report/db/newid.js.html +4 -4
  118. package/coverage/lcov-report/db/utils.js.html +81 -81
  119. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  120. package/coverage/lcov-report/events/index.html +1 -1
  121. package/coverage/lcov-report/events/index.js.html +7 -7
  122. package/coverage/lcov-report/events/utils.js.html +10 -10
  123. package/coverage/lcov-report/index.html +74 -74
  124. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  125. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  126. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  127. package/coverage/lcov-report/middleware/builder.js.html +20 -20
  128. package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
  129. package/coverage/lcov-report/middleware/index.html +1 -1
  130. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  131. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  132. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  133. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  134. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  135. package/coverage/lcov-report/threads/automation.js.html +1 -1
  136. package/coverage/lcov-report/threads/index.html +1 -1
  137. package/coverage/lcov-report/threads/query.js.html +1 -1
  138. package/coverage/lcov-report/threads/utils.js.html +13 -13
  139. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  140. package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
  141. package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
  142. package/coverage/lcov-report/utilities/global.js.html +28 -28
  143. package/coverage/lcov-report/utilities/index.html +25 -25
  144. package/coverage/lcov-report/utilities/index.js.html +41 -41
  145. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
  146. package/coverage/lcov-report/utilities/queue/index.html +15 -15
  147. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  148. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  149. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  150. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
  151. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
  152. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  153. package/coverage/lcov-report/utilities/security.js.html +8 -8
  154. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  156. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
  157. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  158. package/coverage/lcov-report/utilities/users.js.html +7 -7
  159. package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
  160. package/coverage/lcov.info +2762 -2903
  161. package/dist/api/controllers/analytics.js +30 -7
  162. package/dist/api/controllers/application.js +16 -56
  163. package/dist/api/controllers/automation.js +2 -31
  164. package/dist/api/controllers/backup.js +0 -7
  165. package/dist/api/controllers/datasource.js +2 -8
  166. package/dist/api/controllers/deploy/index.js +2 -6
  167. package/dist/api/controllers/dev.js +2 -9
  168. package/dist/api/controllers/layout.js +0 -3
  169. package/dist/api/controllers/query/import/index.js +2 -12
  170. package/dist/api/controllers/query/import/sources/curl.js +0 -3
  171. package/dist/api/controllers/query/import/sources/openapi2.js +0 -3
  172. package/dist/api/controllers/query/import/sources/openapi3.js +0 -3
  173. package/dist/api/controllers/query/index.js +2 -16
  174. package/dist/api/controllers/role.js +0 -11
  175. package/dist/api/controllers/screen.js +1 -10
  176. package/dist/api/controllers/static/index.js +15 -29
  177. package/dist/api/controllers/table/external.js +0 -2
  178. package/dist/api/controllers/table/index.js +0 -12
  179. package/dist/api/controllers/table/utils.js +3 -3
  180. package/dist/api/controllers/view/index.js +6 -62
  181. package/dist/api/index.js +4 -2
  182. package/dist/api/routes/analytics.js +3 -1
  183. package/dist/app.js +8 -16
  184. package/dist/automations/index.js +0 -4
  185. package/dist/automations/steps/executeQuery.js +1 -1
  186. package/dist/environment.js +2 -4
  187. package/dist/integrations/firebase.js +0 -1
  188. package/dist/migrations/index.js +31 -95
  189. package/dist/package.json +69 -79
  190. package/dist/tests/utilities/TestConfiguration.js +93 -121
  191. package/dist/tests/utilities/structures.js +0 -45
  192. package/dist/tsconfig.build.tsbuildinfo +1 -1
  193. package/nodemon.json +1 -1
  194. package/package.json +70 -80
  195. package/scripts/dev/manage.js +0 -2
  196. package/scripts/jestSetup.js +0 -7
  197. package/scripts/likeCypress.ts +1 -1
  198. package/src/api/controllers/analytics.js +39 -0
  199. package/src/api/controllers/application.ts +18 -60
  200. package/src/api/controllers/automation.js +2 -36
  201. package/src/api/controllers/backup.js +0 -8
  202. package/src/api/controllers/datasource.js +4 -8
  203. package/src/api/controllers/deploy/index.ts +2 -6
  204. package/src/api/controllers/dev.js +2 -10
  205. package/src/api/controllers/layout.js +0 -3
  206. package/src/api/controllers/query/import/index.ts +3 -16
  207. package/src/api/controllers/query/import/sources/base/index.ts +1 -2
  208. package/src/api/controllers/query/import/sources/curl.ts +0 -4
  209. package/src/api/controllers/query/import/sources/openapi2.ts +0 -4
  210. package/src/api/controllers/query/import/sources/openapi3.ts +0 -4
  211. package/src/api/controllers/query/import/tests/index.spec.js +7 -20
  212. package/src/api/controllers/query/index.ts +3 -16
  213. package/src/api/controllers/role.js +0 -10
  214. package/src/api/controllers/screen.js +1 -13
  215. package/src/api/controllers/static/index.js +15 -28
  216. package/src/api/controllers/table/external.js +0 -2
  217. package/src/api/controllers/table/index.js +0 -12
  218. package/src/api/controllers/table/utils.ts +4 -4
  219. package/src/api/controllers/view/index.js +6 -76
  220. package/src/api/index.js +4 -2
  221. package/src/api/routes/analytics.js +3 -1
  222. package/src/api/routes/public/utils/Endpoint.ts +1 -1
  223. package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +1 -5
  224. package/src/api/routes/tests/application.spec.js +4 -64
  225. package/src/api/routes/tests/automation.spec.js +60 -168
  226. package/src/api/routes/tests/backup.spec.js +0 -2
  227. package/src/api/routes/tests/datasource.spec.js +0 -5
  228. package/src/api/routes/tests/layout.spec.js +0 -4
  229. package/src/api/routes/tests/query.spec.js +13 -56
  230. package/src/api/routes/tests/role.spec.js +7 -40
  231. package/src/api/routes/tests/row.spec.js +3 -2
  232. package/src/api/routes/tests/screen.spec.js +4 -30
  233. package/src/api/routes/tests/static.spec.js +54 -120
  234. package/src/api/routes/tests/table.spec.js +38 -102
  235. package/src/api/routes/tests/view.spec.js +43 -222
  236. package/src/app.ts +9 -18
  237. package/src/automations/index.js +0 -4
  238. package/src/automations/steps/executeQuery.js +1 -1
  239. package/src/automations/tests/delay.spec.js +0 -4
  240. package/src/environment.js +2 -5
  241. package/src/integrations/firebase.ts +0 -1
  242. package/src/migrations/index.ts +51 -120
  243. package/src/module.d.ts +1 -0
  244. package/src/tests/utilities/TestConfiguration.js +90 -138
  245. package/src/tests/utilities/structures.js +0 -71
  246. package/tsconfig.build.json +5 -20
  247. package/tsconfig.json +17 -22
  248. package/builder/assets/index.05491b9d.js +0 -1315
  249. package/dist/migrations/functions/backfill/app/automations.js +0 -31
  250. package/dist/migrations/functions/backfill/app/datasources.js +0 -28
  251. package/dist/migrations/functions/backfill/app/layouts.js +0 -33
  252. package/dist/migrations/functions/backfill/app/queries.js +0 -32
  253. package/dist/migrations/functions/backfill/app/roles.js +0 -28
  254. package/dist/migrations/functions/backfill/app/screens.js +0 -28
  255. package/dist/migrations/functions/backfill/app/tables.js +0 -40
  256. package/dist/migrations/functions/backfill/app.js +0 -175
  257. package/dist/migrations/functions/backfill/global/configs.js +0 -61
  258. package/dist/migrations/functions/backfill/global/quotas.js +0 -60
  259. package/dist/migrations/functions/backfill/global/users.js +0 -50
  260. package/dist/migrations/functions/backfill/global.js +0 -189
  261. package/dist/migrations/functions/backfill/index.js +0 -32
  262. package/dist/migrations/functions/backfill/installation.js +0 -80
  263. package/dist/migrations/tests/helpers.js +0 -72
  264. package/dist/migrations/tests/structures.js +0 -37
  265. package/src/api/controllers/analytics.ts +0 -8
  266. package/src/api/routes/tests/data/export.txt +0 -1
  267. package/src/api/routes/tests/deployment.spec.js +0 -25
  268. package/src/api/routes/tests/dev.spec.js +0 -40
  269. package/src/migrations/functions/backfill/app/automations.ts +0 -26
  270. package/src/migrations/functions/backfill/app/datasources.ts +0 -22
  271. package/src/migrations/functions/backfill/app/layouts.ts +0 -29
  272. package/src/migrations/functions/backfill/app/queries.ts +0 -33
  273. package/src/migrations/functions/backfill/app/roles.ts +0 -22
  274. package/src/migrations/functions/backfill/app/screens.ts +0 -22
  275. package/src/migrations/functions/backfill/app/tables.ts +0 -36
  276. package/src/migrations/functions/backfill/app.ts +0 -148
  277. package/src/migrations/functions/backfill/global/configs.ts +0 -66
  278. package/src/migrations/functions/backfill/global/quotas.ts +0 -60
  279. package/src/migrations/functions/backfill/global/users.ts +0 -49
  280. package/src/migrations/functions/backfill/global.ts +0 -194
  281. package/src/migrations/functions/backfill/index.ts +0 -7
  282. package/src/migrations/functions/backfill/installation.ts +0 -50
  283. package/src/migrations/tests/helpers.ts +0 -40
  284. package/src/migrations/tests/index.spec.ts +0 -132
  285. package/src/migrations/tests/structures.ts +0 -66
@@ -55,10 +55,6 @@ class TestConfiguration {
55
55
  return this.appId
56
56
  }
57
57
 
58
- getProdAppId() {
59
- return this.prodAppId
60
- }
61
-
62
58
  async doInContext(appId, task) {
63
59
  if (!appId) {
64
60
  appId = this.appId
@@ -75,26 +71,6 @@ class TestConfiguration {
75
71
  })
76
72
  }
77
73
 
78
- // SETUP / TEARDOWN
79
-
80
- // use a new id as the name to avoid name collisions
81
- async init(appName = newid()) {
82
- await this.globalUser()
83
- return this.createApp(appName)
84
- }
85
-
86
- end() {
87
- if (!this) {
88
- return
89
- }
90
- if (this.server) {
91
- this.server.close()
92
- }
93
- cleanup(this.allApps.map(app => app.appId))
94
- }
95
-
96
- // UTILS
97
-
98
74
  async _req(config, params, controlFunc) {
99
75
  const request = {}
100
76
  // fake cookies, we don't need them
@@ -115,11 +91,24 @@ class TestConfiguration {
115
91
  })
116
92
  }
117
93
 
118
- // USER / AUTH
94
+ async generateApiKey(userId = GLOBAL_USER_ID) {
95
+ return doWithGlobalDB(TENANT_ID, async db => {
96
+ const id = generateDevInfoID(userId)
97
+ let devInfo
98
+ try {
99
+ devInfo = await db.get(id)
100
+ } catch (err) {
101
+ devInfo = { _id: id, userId }
102
+ }
103
+ devInfo.apiKey = encrypt(`${TENANT_ID}${SEPARATOR}${newid()}`)
104
+ await db.put(devInfo)
105
+ return devInfo.apiKey
106
+ })
107
+ }
108
+
119
109
  async globalUser({
120
110
  id = GLOBAL_USER_ID,
121
111
  builder = true,
122
- admin = false,
123
112
  email = EMAIL,
124
113
  roles,
125
114
  } = {}) {
@@ -146,11 +135,6 @@ class TestConfiguration {
146
135
  } else {
147
136
  user.builder = { global: false }
148
137
  }
149
- if (admin) {
150
- user.admin = { global: true }
151
- } else {
152
- user.admin = { global: false }
153
- }
154
138
  const resp = await db.put(user)
155
139
  return {
156
140
  _rev: resp._rev,
@@ -159,71 +143,20 @@ class TestConfiguration {
159
143
  })
160
144
  }
161
145
 
162
- async createUser(
163
- id = null,
164
- email = EMAIL,
165
- builder = true,
166
- admin = false,
167
- roles = {}
168
- ) {
169
- const globalId = !id ? `us_${Math.random()}` : `us_${id}`
170
- const resp = await this.globalUser({
171
- id: globalId,
172
- email,
173
- builder,
174
- admin,
175
- roles,
176
- })
177
- await userCache.invalidateUser(globalId)
178
- return {
179
- ...resp,
180
- globalId,
181
- }
146
+ // use a new id as the name to avoid name collisions
147
+ async init(appName = newid()) {
148
+ await this.globalUser()
149
+ return this.createApp(appName)
182
150
  }
183
151
 
184
- async login({ roleId, userId, builder, prodApp = false } = {}) {
185
- const appId = prodApp ? this.prodAppId : this.appId
186
- return context.doInAppContext(appId, async () => {
187
- userId = !userId ? `us_uuid1` : userId
188
- if (!this.request) {
189
- throw "Server has not been opened, cannot login."
190
- }
191
- // make sure the user exists in the global DB
192
- if (roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
193
- await this.globalUser({
194
- id: userId,
195
- builder,
196
- roles: { [this.prodAppId]: roleId },
197
- })
198
- }
199
- await createASession(userId, {
200
- sessionId: "sessionid",
201
- tenantId: TENANT_ID,
202
- })
203
- // have to fake this
204
- const auth = {
205
- userId,
206
- sessionId: "sessionid",
207
- tenantId: TENANT_ID,
208
- }
209
- const app = {
210
- roleId: roleId,
211
- appId,
212
- }
213
- const authToken = jwt.sign(auth, env.JWT_SECRET)
214
- const appToken = jwt.sign(app, env.JWT_SECRET)
215
-
216
- // returning necessary request headers
217
- await userCache.invalidateUser(userId)
218
- return {
219
- Accept: "application/json",
220
- Cookie: [
221
- `${Cookies.Auth}=${authToken}`,
222
- `${Cookies.CurrentApp}=${appToken}`,
223
- ],
224
- [Headers.APP_ID]: appId,
225
- }
226
- })
152
+ end() {
153
+ if (!this) {
154
+ return
155
+ }
156
+ if (this.server) {
157
+ this.server.close()
158
+ }
159
+ cleanup(this.allApps.map(app => app.appId))
227
160
  }
228
161
 
229
162
  defaultHeaders(extras = {}) {
@@ -274,25 +207,6 @@ class TestConfiguration {
274
207
  return this.login({ email, roleId, builder, prodApp })
275
208
  }
276
209
 
277
- // API
278
-
279
- async generateApiKey(userId = GLOBAL_USER_ID) {
280
- return doWithGlobalDB(TENANT_ID, async db => {
281
- const id = generateDevInfoID(userId)
282
- let devInfo
283
- try {
284
- devInfo = await db.get(id)
285
- } catch (err) {
286
- devInfo = { _id: id, userId }
287
- }
288
- devInfo.apiKey = encrypt(`${TENANT_ID}${SEPARATOR}${newid()}`)
289
- await db.put(devInfo)
290
- return devInfo.apiKey
291
- })
292
- }
293
-
294
- // APP
295
-
296
210
  async createApp(appName) {
297
211
  // create dev app
298
212
  // clear any old app
@@ -325,8 +239,6 @@ class TestConfiguration {
325
239
  })
326
240
  }
327
241
 
328
- // TABLE
329
-
330
242
  async updateTable(config = null) {
331
243
  config = config || basicTable()
332
244
  this.table = await this._req(config, null, controllers.table.save)
@@ -375,8 +287,6 @@ class TestConfiguration {
375
287
  return this.createTable(table)
376
288
  }
377
289
 
378
- // ROW
379
-
380
290
  async createRow(config = null) {
381
291
  if (!this.table) {
382
292
  throw "Test requires table to be configured."
@@ -397,8 +307,6 @@ class TestConfiguration {
397
307
  return this._req(null, { tableId }, controllers.row.fetch)
398
308
  }
399
309
 
400
- // ROLE
401
-
402
310
  async createRole(config = null) {
403
311
  config = config || basicRole()
404
312
  return this._req(config, null, controllers.role.save)
@@ -416,21 +324,18 @@ class TestConfiguration {
416
324
  )
417
325
  }
418
326
 
419
- // VIEW
420
-
421
327
  async createView(config) {
422
328
  if (!this.table) {
423
329
  throw "Test requires table to be configured."
424
330
  }
425
331
  const view = config || {
332
+ map: "function(doc) { emit(doc[doc.key], doc._id); } ",
426
333
  tableId: this.table._id,
427
334
  name: "ViewTest",
428
335
  }
429
336
  return this._req(view, null, controllers.view.save)
430
337
  }
431
338
 
432
- // AUTOMATION
433
-
434
339
  async createAutomation(config) {
435
340
  config = config || basicAutomation()
436
341
  if (config._rev) {
@@ -458,16 +363,6 @@ class TestConfiguration {
458
363
  )
459
364
  }
460
365
 
461
- async createWebhook(config = null) {
462
- if (!this.automation) {
463
- throw "Must create an automation before creating webhook."
464
- }
465
- config = config || basicWebhook(this.automation._id)
466
- return (await this._req(config, null, controllers.webhook.save)).webhook
467
- }
468
-
469
- // DATASOURCE
470
-
471
366
  async createDatasource(config = null) {
472
367
  config = config || basicDatasource()
473
368
  const response = await this._req(config, null, controllers.datasource.save)
@@ -518,8 +413,6 @@ class TestConfiguration {
518
413
  return { datasource, query: basedOnQuery }
519
414
  }
520
415
 
521
- // QUERY
522
-
523
416
  async previewQuery(request, config, datasource, fields) {
524
417
  return request
525
418
  .post(`/api/queries/preview`)
@@ -543,19 +436,78 @@ class TestConfiguration {
543
436
  return this._req(config, null, controllers.query.save)
544
437
  }
545
438
 
546
- // SCREEN
547
-
548
439
  async createScreen(config = null) {
549
440
  config = config || basicScreen()
550
441
  return this._req(config, null, controllers.screen.save)
551
442
  }
552
443
 
553
- // LAYOUT
444
+ async createWebhook(config = null) {
445
+ if (!this.automation) {
446
+ throw "Must create an automation before creating webhook."
447
+ }
448
+ config = config || basicWebhook(this.automation._id)
449
+ return (await this._req(config, null, controllers.webhook.save)).webhook
450
+ }
554
451
 
555
452
  async createLayout(config = null) {
556
453
  config = config || basicLayout()
557
454
  return await this._req(config, null, controllers.layout.save)
558
455
  }
456
+
457
+ async createUser(id = null, email = EMAIL) {
458
+ const globalId = !id ? `us_${Math.random()}` : `us_${id}`
459
+ const resp = await this.globalUser({ id: globalId, email })
460
+ await userCache.invalidateUser(globalId)
461
+ return {
462
+ ...resp,
463
+ globalId,
464
+ }
465
+ }
466
+
467
+ async login({ roleId, userId, builder, prodApp = false } = {}) {
468
+ const appId = prodApp ? this.prodAppId : this.appId
469
+ return context.doInAppContext(appId, async () => {
470
+ userId = !userId ? `us_uuid1` : userId
471
+ if (!this.request) {
472
+ throw "Server has not been opened, cannot login."
473
+ }
474
+ // make sure the user exists in the global DB
475
+ if (roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
476
+ await this.globalUser({
477
+ id: userId,
478
+ builder,
479
+ roles: { [this.prodAppId]: roleId },
480
+ })
481
+ }
482
+ await createASession(userId, {
483
+ sessionId: "sessionid",
484
+ tenantId: TENANT_ID,
485
+ })
486
+ // have to fake this
487
+ const auth = {
488
+ userId,
489
+ sessionId: "sessionid",
490
+ tenantId: TENANT_ID,
491
+ }
492
+ const app = {
493
+ roleId: roleId,
494
+ appId,
495
+ }
496
+ const authToken = jwt.sign(auth, env.JWT_SECRET)
497
+ const appToken = jwt.sign(app, env.JWT_SECRET)
498
+
499
+ // returning necessary request headers
500
+ await userCache.invalidateUser(userId)
501
+ return {
502
+ Accept: "application/json",
503
+ Cookie: [
504
+ `${Cookies.Auth}=${authToken}`,
505
+ `${Cookies.CurrentApp}=${appToken}`,
506
+ ],
507
+ [Headers.APP_ID]: appId,
508
+ }
509
+ })
510
+ }
559
511
  }
560
512
 
561
513
  module.exports = TestConfiguration
@@ -3,8 +3,6 @@ const { BUILTIN_PERMISSION_IDS } = require("@budibase/backend-core/permissions")
3
3
  const { createHomeScreen } = require("../../constants/screens")
4
4
  const { EMPTY_LAYOUT } = require("../../constants/layouts")
5
5
  const { cloneDeep } = require("lodash/fp")
6
- const { v4: uuidv4 } = require("uuid")
7
- const { TRIGGER_DEFINITIONS, ACTION_DEFINITIONS } = require("../../automations")
8
6
 
9
7
  exports.TENANT_ID = "default"
10
8
 
@@ -30,75 +28,6 @@ exports.basicTable = () => {
30
28
  }
31
29
  }
32
30
 
33
- exports.basicView = tableId => {
34
- return {
35
- tableId,
36
- name: "ViewTest",
37
- }
38
- }
39
-
40
- exports.filterView = tableId => {
41
- return {
42
- ...this.basicView(tableId),
43
- filters: [
44
- {
45
- value: 0,
46
- condition: "MT",
47
- key: "count",
48
- },
49
- ],
50
- }
51
- }
52
-
53
- exports.calculationView = tableId => {
54
- return {
55
- ...this.basicView(tableId),
56
- field: "count",
57
- calculation: "sum",
58
- }
59
- }
60
-
61
- exports.view = tableId => {
62
- return {
63
- ...this.filterView(tableId),
64
- ...this.calculationView(tableId),
65
- }
66
- }
67
-
68
- exports.automationStep = (actionDefinition = ACTION_DEFINITIONS.CREATE_ROW) => {
69
- return {
70
- id: uuidv4(),
71
- ...actionDefinition,
72
- }
73
- }
74
-
75
- exports.automationTrigger = (
76
- triggerDefinition = TRIGGER_DEFINITIONS.ROW_SAVED
77
- ) => {
78
- return {
79
- id: uuidv4(),
80
- ...triggerDefinition,
81
- }
82
- }
83
-
84
- exports.newAutomation = ({ steps, trigger } = {}) => {
85
- const automation = exports.basicAutomation()
86
-
87
- if (trigger) {
88
- automation.definition.trigger = trigger
89
- } else {
90
- automation.definition.trigger = exports.automationTrigger()
91
- }
92
-
93
- if (steps) {
94
- automation.definition.steps = steps
95
- } else {
96
- automation.definition.steps = [exports.automationStep()]
97
- }
98
-
99
- return automation
100
- }
101
-
102
31
  exports.basicAutomation = () => {
103
32
  return {
104
33
  name: "My Automation",
@@ -1,25 +1,10 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "module": "commonjs",
5
- "lib": ["es2020"],
6
- "allowJs": true,
7
- "strict": true,
8
- "noImplicitAny": true,
9
- "esModuleInterop": true,
10
- "resolveJsonModule": true,
11
- "incremental": true,
12
- "types": [ "node", "jest" ],
13
- "outDir": "dist",
14
- "skipLibCheck": true
15
- },
16
- "include": [
17
- "src/**/*"
18
- ],
2
+ // Used for building with tsc
3
+ "extends": "./tsconfig.json",
19
4
  "exclude": [
20
5
  "node_modules",
21
- "dist",
22
- "**/*.spec.ts",
23
- "**/*.spec.js"
6
+ "**/*.json",
7
+ "**/*.spec.js",
8
+ "**/*.spec.ts"
24
9
  ]
25
10
  }
package/tsconfig.json CHANGED
@@ -1,30 +1,25 @@
1
1
  {
2
- "extends": "./tsconfig.build.json",
3
2
  "compilerOptions": {
4
- "composite": true,
5
- "declaration": true,
6
- "sourceMap": true,
7
- "baseUrl": ".",
8
- "paths": {
9
- "@budibase/types": ["../types/src"],
10
- "@budibase/backend-core": ["../backend-core/src"],
11
- "@budibase/backend-core/*": ["../backend-core/*"]
12
- }
3
+ "target": "es6",
4
+ "module": "commonjs",
5
+ "lib": ["es2019"],
6
+ "allowJs": true,
7
+ "outDir": "dist",
8
+ "strict": true,
9
+ "noImplicitAny": true,
10
+ "esModuleInterop": true,
11
+ "resolveJsonModule": true,
12
+ "incremental": true,
13
+ "types": [ "node", "jest"],
13
14
  },
14
- "ts-node": {
15
- "require": ["tsconfig-paths/register"]
16
- },
17
- "references": [
18
- { "path": "../types" },
19
- { "path": "../backend-core" },
20
- ],
21
15
  "include": [
22
- "src/**/*",
23
- "specs",
24
- "package.json"
16
+ "./src/**/*",
17
+ "./src/module.d.ts"
25
18
  ],
26
19
  "exclude": [
27
20
  "node_modules",
28
- "dist"
21
+ "**/*.json",
22
+ "**/*.spec.js",
23
+ // "**/*.spec.ts" // don't exclude spec.ts files for editor support
29
24
  ]
30
- }
25
+ }