@budibase/server 1.0.199 → 1.0.200-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 (281) hide show
  1. package/Dockerfile +2 -0
  2. package/builder/assets/index.359da19e.js +1315 -0
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +2089 -2001
  5. package/coverage/coverage-final.json +121 -122
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  7. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  8. package/coverage/lcov-report/api/controllers/automation.js.html +174 -72
  9. package/coverage/lcov-report/api/controllers/backup.js.html +30 -6
  10. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
  11. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +53 -41
  13. package/coverage/lcov-report/api/controllers/dev.js.html +94 -70
  14. package/coverage/lcov-report/api/controllers/index.html +57 -72
  15. package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
  16. package/coverage/lcov-report/api/controllers/layout.js.html +28 -19
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  19. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
  22. package/coverage/lcov-report/api/controllers/role.js.html +78 -48
  23. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
  30. package/coverage/lcov-report/api/controllers/screen.js.html +56 -20
  31. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  32. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
  33. package/coverage/lcov-report/api/controllers/table/external.js.html +23 -17
  34. package/coverage/lcov-report/api/controllers/table/index.html +26 -26
  35. package/coverage/lcov-report/api/controllers/table/index.js.html +85 -49
  36. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  37. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  38. package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
  39. package/coverage/lcov-report/api/controllers/view/index.html +21 -21
  40. package/coverage/lcov-report/api/controllers/view/index.js.html +275 -65
  41. package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
  42. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
  43. package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
  44. package/coverage/lcov-report/api/index.html +15 -15
  45. package/coverage/lcov-report/api/index.js.html +39 -45
  46. package/coverage/lcov-report/api/routes/analytics.js.html +7 -13
  47. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  48. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  49. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  50. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  53. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  54. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  55. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  56. package/coverage/lcov-report/api/routes/index.html +1 -1
  57. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  58. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  60. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  61. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  62. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  63. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  64. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  65. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  66. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  68. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  69. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  70. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  71. package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
  72. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  73. package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
  74. package/coverage/lcov-report/automations/actions.js.html +25 -25
  75. package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
  76. package/coverage/lcov-report/automations/bullboard.js.html +35 -35
  77. package/coverage/lcov-report/automations/index.html +29 -29
  78. package/coverage/lcov-report/automations/index.js.html +29 -17
  79. package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
  80. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  81. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  82. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  83. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  84. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  85. package/coverage/lcov-report/automations/steps/index.html +1 -1
  86. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  87. package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
  88. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  89. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  90. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  91. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  92. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  93. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  94. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  95. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  96. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  97. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  98. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  100. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  101. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  102. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  103. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  104. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  105. package/coverage/lcov-report/constants/index.html +1 -1
  106. package/coverage/lcov-report/constants/index.js.html +30 -30
  107. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  108. package/coverage/lcov-report/constants/screens.js.html +4 -4
  109. package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
  110. package/coverage/lcov-report/db/index.html +1 -1
  111. package/coverage/lcov-report/db/index.js.html +9 -9
  112. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
  113. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  115. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
  116. package/coverage/lcov-report/db/newid.js.html +4 -4
  117. package/coverage/lcov-report/db/utils.js.html +81 -81
  118. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  119. package/coverage/lcov-report/events/index.html +1 -1
  120. package/coverage/lcov-report/events/index.js.html +7 -7
  121. package/coverage/lcov-report/events/utils.js.html +10 -10
  122. package/coverage/lcov-report/index.html +74 -74
  123. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  124. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  125. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  126. package/coverage/lcov-report/middleware/builder.js.html +20 -20
  127. package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
  128. package/coverage/lcov-report/middleware/index.html +1 -1
  129. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  130. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  131. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  132. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  133. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  134. package/coverage/lcov-report/threads/automation.js.html +1 -1
  135. package/coverage/lcov-report/threads/index.html +1 -1
  136. package/coverage/lcov-report/threads/query.js.html +1 -1
  137. package/coverage/lcov-report/threads/utils.js.html +13 -13
  138. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  139. package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
  140. package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
  141. package/coverage/lcov-report/utilities/global.js.html +28 -28
  142. package/coverage/lcov-report/utilities/index.html +25 -25
  143. package/coverage/lcov-report/utilities/index.js.html +41 -41
  144. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
  145. package/coverage/lcov-report/utilities/queue/index.html +15 -15
  146. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  147. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  148. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
  150. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
  151. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  152. package/coverage/lcov-report/utilities/security.js.html +8 -8
  153. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  154. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
  156. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  157. package/coverage/lcov-report/utilities/users.js.html +7 -7
  158. package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
  159. package/coverage/lcov.info +2903 -2762
  160. package/dist/api/controllers/analytics.js +7 -30
  161. package/dist/api/controllers/application.js +56 -16
  162. package/dist/api/controllers/automation.js +31 -2
  163. package/dist/api/controllers/backup.js +7 -0
  164. package/dist/api/controllers/datasource.js +8 -2
  165. package/dist/api/controllers/deploy/index.js +6 -2
  166. package/dist/api/controllers/dev.js +9 -2
  167. package/dist/api/controllers/layout.js +3 -0
  168. package/dist/api/controllers/query/import/index.js +12 -2
  169. package/dist/api/controllers/query/import/sources/curl.js +3 -0
  170. package/dist/api/controllers/query/import/sources/openapi2.js +3 -0
  171. package/dist/api/controllers/query/import/sources/openapi3.js +3 -0
  172. package/dist/api/controllers/query/index.js +16 -2
  173. package/dist/api/controllers/role.js +11 -0
  174. package/dist/api/controllers/screen.js +10 -1
  175. package/dist/api/controllers/static/index.js +29 -15
  176. package/dist/api/controllers/table/external.js +2 -0
  177. package/dist/api/controllers/table/index.js +12 -0
  178. package/dist/api/controllers/table/utils.js +3 -3
  179. package/dist/api/controllers/view/index.js +62 -6
  180. package/dist/api/index.js +2 -4
  181. package/dist/api/routes/analytics.js +1 -3
  182. package/dist/app.js +16 -8
  183. package/dist/automations/index.js +4 -0
  184. package/dist/environment.js +4 -2
  185. package/dist/migrations/functions/backfill/app/automations.js +31 -0
  186. package/dist/migrations/functions/backfill/app/datasources.js +28 -0
  187. package/dist/migrations/functions/backfill/app/layouts.js +33 -0
  188. package/dist/migrations/functions/backfill/app/queries.js +32 -0
  189. package/dist/migrations/functions/backfill/app/roles.js +28 -0
  190. package/dist/migrations/functions/backfill/app/screens.js +28 -0
  191. package/dist/migrations/functions/backfill/app/tables.js +40 -0
  192. package/dist/migrations/functions/backfill/app.js +175 -0
  193. package/dist/migrations/functions/backfill/global/configs.js +61 -0
  194. package/dist/migrations/functions/backfill/global/quotas.js +60 -0
  195. package/dist/migrations/functions/backfill/global/users.js +50 -0
  196. package/dist/migrations/functions/backfill/global.js +189 -0
  197. package/dist/migrations/functions/backfill/index.js +32 -0
  198. package/dist/migrations/functions/backfill/installation.js +81 -0
  199. package/dist/migrations/index.js +95 -31
  200. package/dist/migrations/tests/helpers.js +72 -0
  201. package/dist/migrations/tests/structures.js +37 -0
  202. package/dist/package.json +79 -69
  203. package/dist/tests/utilities/TestConfiguration.js +121 -93
  204. package/dist/tests/utilities/structures.js +45 -0
  205. package/dist/tsconfig.build.tsbuildinfo +1 -1
  206. package/nodemon.json +1 -1
  207. package/package.json +80 -70
  208. package/scripts/dev/manage.js +2 -0
  209. package/scripts/jestSetup.js +7 -0
  210. package/scripts/likeCypress.ts +1 -1
  211. package/src/api/controllers/analytics.ts +8 -0
  212. package/src/api/controllers/application.ts +60 -18
  213. package/src/api/controllers/automation.js +36 -2
  214. package/src/api/controllers/backup.js +8 -0
  215. package/src/api/controllers/datasource.js +8 -4
  216. package/src/api/controllers/deploy/index.ts +6 -2
  217. package/src/api/controllers/dev.js +10 -2
  218. package/src/api/controllers/layout.js +3 -0
  219. package/src/api/controllers/query/import/index.ts +16 -3
  220. package/src/api/controllers/query/import/sources/base/index.ts +2 -1
  221. package/src/api/controllers/query/import/sources/curl.ts +4 -0
  222. package/src/api/controllers/query/import/sources/openapi2.ts +4 -0
  223. package/src/api/controllers/query/import/sources/openapi3.ts +4 -0
  224. package/src/api/controllers/query/import/tests/index.spec.js +20 -7
  225. package/src/api/controllers/query/index.ts +16 -3
  226. package/src/api/controllers/role.js +10 -0
  227. package/src/api/controllers/screen.js +13 -1
  228. package/src/api/controllers/static/index.js +28 -15
  229. package/src/api/controllers/table/external.js +2 -0
  230. package/src/api/controllers/table/index.js +12 -0
  231. package/src/api/controllers/table/utils.ts +4 -4
  232. package/src/api/controllers/view/index.js +76 -6
  233. package/src/api/index.js +2 -4
  234. package/src/api/routes/analytics.js +1 -3
  235. package/src/api/routes/public/utils/Endpoint.ts +1 -1
  236. package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +5 -1
  237. package/src/api/routes/tests/application.spec.js +64 -4
  238. package/src/api/routes/tests/automation.spec.js +168 -60
  239. package/src/api/routes/tests/backup.spec.js +2 -0
  240. package/src/api/routes/tests/data/export.txt +1 -0
  241. package/src/api/routes/tests/datasource.spec.js +5 -0
  242. package/src/api/routes/tests/deployment.spec.js +25 -0
  243. package/src/api/routes/tests/dev.spec.js +40 -0
  244. package/src/api/routes/tests/layout.spec.js +4 -0
  245. package/src/api/routes/tests/query.spec.js +56 -13
  246. package/src/api/routes/tests/role.spec.js +40 -7
  247. package/src/api/routes/tests/row.spec.js +2 -3
  248. package/src/api/routes/tests/screen.spec.js +30 -4
  249. package/src/api/routes/tests/static.spec.js +120 -54
  250. package/src/api/routes/tests/table.spec.js +102 -38
  251. package/src/api/routes/tests/view.spec.js +222 -43
  252. package/src/app.ts +18 -9
  253. package/src/automations/index.js +4 -0
  254. package/src/automations/tests/delay.spec.js +4 -0
  255. package/src/environment.js +5 -2
  256. package/src/migrations/functions/backfill/app/automations.ts +26 -0
  257. package/src/migrations/functions/backfill/app/datasources.ts +22 -0
  258. package/src/migrations/functions/backfill/app/layouts.ts +29 -0
  259. package/src/migrations/functions/backfill/app/queries.ts +33 -0
  260. package/src/migrations/functions/backfill/app/roles.ts +22 -0
  261. package/src/migrations/functions/backfill/app/screens.ts +22 -0
  262. package/src/migrations/functions/backfill/app/tables.ts +36 -0
  263. package/src/migrations/functions/backfill/app.ts +148 -0
  264. package/src/migrations/functions/backfill/global/configs.ts +66 -0
  265. package/src/migrations/functions/backfill/global/quotas.ts +60 -0
  266. package/src/migrations/functions/backfill/global/users.ts +49 -0
  267. package/src/migrations/functions/backfill/global.ts +194 -0
  268. package/src/migrations/functions/backfill/index.ts +7 -0
  269. package/src/migrations/functions/backfill/installation.ts +51 -0
  270. package/src/migrations/index.ts +120 -51
  271. package/src/migrations/tests/helpers.ts +40 -0
  272. package/src/migrations/tests/index.spec.ts +132 -0
  273. package/src/migrations/tests/structures.ts +66 -0
  274. package/src/module.d.ts +0 -1
  275. package/src/tests/utilities/TestConfiguration.js +138 -90
  276. package/src/tests/utilities/structures.js +71 -0
  277. package/tsconfig.build.json +20 -5
  278. package/tsconfig.json +22 -17
  279. package/builder/assets/index.107ba2e5.js +0 -1315
  280. package/coverage/lcov-report/api/controllers/analytics.js.html +0 -202
  281. package/src/api/controllers/analytics.js +0 -39
@@ -55,6 +55,10 @@ class TestConfiguration {
55
55
  return this.appId
56
56
  }
57
57
 
58
+ getProdAppId() {
59
+ return this.prodAppId
60
+ }
61
+
58
62
  async doInContext(appId, task) {
59
63
  if (!appId) {
60
64
  appId = this.appId
@@ -71,6 +75,26 @@ class TestConfiguration {
71
75
  })
72
76
  }
73
77
 
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
+
74
98
  async _req(config, params, controlFunc) {
75
99
  const request = {}
76
100
  // fake cookies, we don't need them
@@ -91,24 +115,11 @@ class TestConfiguration {
91
115
  })
92
116
  }
93
117
 
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
-
118
+ // USER / AUTH
109
119
  async globalUser({
110
120
  id = GLOBAL_USER_ID,
111
121
  builder = true,
122
+ admin = false,
112
123
  email = EMAIL,
113
124
  roles,
114
125
  } = {}) {
@@ -135,6 +146,11 @@ class TestConfiguration {
135
146
  } else {
136
147
  user.builder = { global: false }
137
148
  }
149
+ if (admin) {
150
+ user.admin = { global: true }
151
+ } else {
152
+ user.admin = { global: false }
153
+ }
138
154
  const resp = await db.put(user)
139
155
  return {
140
156
  _rev: resp._rev,
@@ -143,20 +159,71 @@ class TestConfiguration {
143
159
  })
144
160
  }
145
161
 
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)
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
+ }
150
182
  }
151
183
 
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))
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
+ })
160
227
  }
161
228
 
162
229
  defaultHeaders(extras = {}) {
@@ -207,6 +274,25 @@ class TestConfiguration {
207
274
  return this.login({ email, roleId, builder, prodApp })
208
275
  }
209
276
 
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
+
210
296
  async createApp(appName) {
211
297
  // create dev app
212
298
  // clear any old app
@@ -239,6 +325,8 @@ class TestConfiguration {
239
325
  })
240
326
  }
241
327
 
328
+ // TABLE
329
+
242
330
  async updateTable(config = null) {
243
331
  config = config || basicTable()
244
332
  this.table = await this._req(config, null, controllers.table.save)
@@ -287,6 +375,8 @@ class TestConfiguration {
287
375
  return this.createTable(table)
288
376
  }
289
377
 
378
+ // ROW
379
+
290
380
  async createRow(config = null) {
291
381
  if (!this.table) {
292
382
  throw "Test requires table to be configured."
@@ -307,6 +397,8 @@ class TestConfiguration {
307
397
  return this._req(null, { tableId }, controllers.row.fetch)
308
398
  }
309
399
 
400
+ // ROLE
401
+
310
402
  async createRole(config = null) {
311
403
  config = config || basicRole()
312
404
  return this._req(config, null, controllers.role.save)
@@ -324,18 +416,21 @@ class TestConfiguration {
324
416
  )
325
417
  }
326
418
 
419
+ // VIEW
420
+
327
421
  async createView(config) {
328
422
  if (!this.table) {
329
423
  throw "Test requires table to be configured."
330
424
  }
331
425
  const view = config || {
332
- map: "function(doc) { emit(doc[doc.key], doc._id); } ",
333
426
  tableId: this.table._id,
334
427
  name: "ViewTest",
335
428
  }
336
429
  return this._req(view, null, controllers.view.save)
337
430
  }
338
431
 
432
+ // AUTOMATION
433
+
339
434
  async createAutomation(config) {
340
435
  config = config || basicAutomation()
341
436
  if (config._rev) {
@@ -363,6 +458,16 @@ class TestConfiguration {
363
458
  )
364
459
  }
365
460
 
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
+
366
471
  async createDatasource(config = null) {
367
472
  config = config || basicDatasource()
368
473
  const response = await this._req(config, null, controllers.datasource.save)
@@ -413,6 +518,8 @@ class TestConfiguration {
413
518
  return { datasource, query: basedOnQuery }
414
519
  }
415
520
 
521
+ // QUERY
522
+
416
523
  async previewQuery(request, config, datasource, fields) {
417
524
  return request
418
525
  .post(`/api/queries/preview`)
@@ -436,78 +543,19 @@ class TestConfiguration {
436
543
  return this._req(config, null, controllers.query.save)
437
544
  }
438
545
 
546
+ // SCREEN
547
+
439
548
  async createScreen(config = null) {
440
549
  config = config || basicScreen()
441
550
  return this._req(config, null, controllers.screen.save)
442
551
  }
443
552
 
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
- }
553
+ // LAYOUT
451
554
 
452
555
  async createLayout(config = null) {
453
556
  config = config || basicLayout()
454
557
  return await this._req(config, null, controllers.layout.save)
455
558
  }
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
- }
511
559
  }
512
560
 
513
561
  module.exports = TestConfiguration
@@ -3,6 +3,8 @@ 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")
6
8
 
7
9
  exports.TENANT_ID = "default"
8
10
 
@@ -28,6 +30,75 @@ exports.basicTable = () => {
28
30
  }
29
31
  }
30
32
 
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
+
31
102
  exports.basicAutomation = () => {
32
103
  return {
33
104
  name: "My Automation",
@@ -1,10 +1,25 @@
1
1
  {
2
- // Used for building with tsc
3
- "extends": "./tsconfig.json",
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
+ ],
4
19
  "exclude": [
5
20
  "node_modules",
6
- "**/*.json",
7
- "**/*.spec.js",
8
- "**/*.spec.ts"
21
+ "dist",
22
+ "**/*.spec.ts",
23
+ "**/*.spec.js"
9
24
  ]
10
25
  }
package/tsconfig.json CHANGED
@@ -1,25 +1,30 @@
1
1
  {
2
+ "extends": "./tsconfig.build.json",
2
3
  "compilerOptions": {
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"],
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
+ }
14
13
  },
14
+ "ts-node": {
15
+ "require": ["tsconfig-paths/register"]
16
+ },
17
+ "references": [
18
+ { "path": "../types" },
19
+ { "path": "../backend-core" },
20
+ ],
15
21
  "include": [
16
- "./src/**/*",
17
- "./src/module.d.ts"
22
+ "src/**/*",
23
+ "specs",
24
+ "package.json"
18
25
  ],
19
26
  "exclude": [
20
27
  "node_modules",
21
- "**/*.json",
22
- "**/*.spec.js",
23
- // "**/*.spec.ts" // don't exclude spec.ts files for editor support
28
+ "dist"
24
29
  ]
25
- }
30
+ }