@budibase/server 2.0.34-alpha.1 → 2.0.34-alpha.10

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 (190) hide show
  1. package/__mocks__/node-fetch.ts +12 -2
  2. package/builder/assets/{index.cf543543.js → index.02132811.js} +201 -201
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +429 -499
  5. package/coverage/coverage-final.json +49 -51
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  7. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/cloud.js.html +13 -13
  9. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/dev.js.html +20 -20
  11. package/coverage/lcov-report/api/controllers/index.html +9 -24
  12. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  13. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  15. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  16. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  18. package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
  19. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  21. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  23. package/coverage/lcov-report/api/controllers/row/internal.js.html +2 -2
  24. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  33. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  36. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  39. package/coverage/lcov-report/api/index.html +1 -1
  40. package/coverage/lcov-report/api/index.js.html +26 -26
  41. package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
  42. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  43. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  44. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  45. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  46. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  47. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  48. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  49. package/coverage/lcov-report/api/routes/index.html +5 -20
  50. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  53. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  54. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  55. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  56. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  57. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  58. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  59. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  61. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  62. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  63. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  64. package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
  65. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  66. package/coverage/lcov-report/automations/actions.js.html +1 -1
  67. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  68. package/coverage/lcov-report/automations/bullboard.js.html +25 -10
  69. package/coverage/lcov-report/automations/index.html +16 -16
  70. package/coverage/lcov-report/automations/index.js.html +4 -4
  71. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  72. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  73. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  74. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  75. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/index.html +15 -15
  78. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
  87. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  88. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  89. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  90. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  91. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggers.js.html +23 -23
  97. package/coverage/lcov-report/constants/index.html +5 -5
  98. package/coverage/lcov-report/constants/index.js.html +4 -16
  99. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  100. package/coverage/lcov-report/constants/screens.js.html +1 -1
  101. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  102. package/coverage/lcov-report/db/index.html +1 -1
  103. package/coverage/lcov-report/db/index.js.html +1 -1
  104. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  105. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  106. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  107. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  108. package/coverage/lcov-report/db/newid.js.html +1 -1
  109. package/coverage/lcov-report/db/utils.js.html +2 -2
  110. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  111. package/coverage/lcov-report/events/index.html +1 -1
  112. package/coverage/lcov-report/events/index.js.html +2 -2
  113. package/coverage/lcov-report/events/utils.js.html +1 -1
  114. package/coverage/lcov-report/index.html +52 -52
  115. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  116. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  117. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  118. package/coverage/lcov-report/middleware/builder.js.html +9 -9
  119. package/coverage/lcov-report/middleware/currentapp.js.html +14 -14
  120. package/coverage/lcov-report/middleware/index.html +1 -1
  121. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  122. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  123. package/coverage/lcov-report/middleware/resourceId.js.html +22 -22
  124. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  125. package/coverage/lcov-report/middleware/utils.js.html +3 -3
  126. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  127. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  128. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  129. package/coverage/lcov-report/utilities/global.js.html +1 -1
  130. package/coverage/lcov-report/utilities/index.html +20 -20
  131. package/coverage/lcov-report/utilities/index.js.html +2 -2
  132. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  133. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  134. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  135. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  136. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  137. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  138. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  139. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  140. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  141. package/coverage/lcov-report/utilities/security.js.html +1 -1
  142. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  143. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  144. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  145. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  146. package/coverage/lcov-report/utilities/users.js.html +1 -1
  147. package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
  148. package/coverage/lcov.info +496 -600
  149. package/dist/api/controllers/row/index.js +34 -80
  150. package/dist/api/controllers/row/internal.js +1 -1
  151. package/dist/api/controllers/static/index.js +1 -0
  152. package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  153. package/dist/api/controllers/webhook.js +88 -89
  154. package/dist/api/routes/utils/validators.js +2 -2
  155. package/dist/api/routes/webhook.js +39 -11
  156. package/dist/app.js +2 -84
  157. package/dist/automations/bullboard.js +7 -2
  158. package/dist/automations/utils.js +5 -37
  159. package/dist/constants/index.js +0 -3
  160. package/dist/package.json +6 -6
  161. package/dist/sdk/app/automations/index.js +29 -0
  162. package/dist/sdk/app/automations/webhook.js +54 -0
  163. package/dist/sdk/app/backups/imports.js +29 -1
  164. package/dist/sdk/index.js +2 -0
  165. package/dist/startup.js +152 -0
  166. package/dist/tests/utilities/TestConfiguration.js +8 -0
  167. package/dist/tsconfig.build.tsbuildinfo +1 -1
  168. package/package.json +7 -7
  169. package/src/api/controllers/row/index.ts +42 -80
  170. package/src/api/controllers/row/internal.js +1 -1
  171. package/src/api/controllers/static/index.ts +2 -0
  172. package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  173. package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
  174. package/src/api/routes/utils/validators.js +2 -2
  175. package/src/api/routes/{webhook.js → webhook.ts} +7 -6
  176. package/src/app.ts +3 -108
  177. package/src/automations/bullboard.js +6 -1
  178. package/src/automations/utils.ts +12 -20
  179. package/src/constants/index.js +0 -4
  180. package/src/definitions/automations.ts +1 -6
  181. package/src/migrations/functions/tests/syncQuotas.spec.js +1 -3
  182. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
  183. package/src/sdk/app/automations/index.ts +5 -0
  184. package/src/sdk/app/automations/webhook.ts +43 -0
  185. package/src/sdk/app/backups/imports.ts +43 -6
  186. package/src/sdk/index.ts +2 -0
  187. package/src/startup.ts +138 -0
  188. package/src/tests/utilities/TestConfiguration.js +7 -0
  189. package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
  190. package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
@@ -43,19 +43,13 @@ function patch(ctx) {
43
43
  if (body && !body._id) {
44
44
  return (0, exports.save)(ctx);
45
45
  }
46
- try {
47
- const { row, table } = yield pro_1.quotas.addQuery(() => pickApi(tableId).patch(ctx), {
48
- datasourceId: tableId,
49
- });
50
- ctx.status = 200;
51
- ctx.eventEmitter &&
52
- ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
53
- ctx.message = `${table.name} updated successfully.`;
54
- ctx.body = row;
55
- }
56
- catch (err) {
57
- ctx.throw(400, err);
58
- }
46
+ const { row, table } = yield pro_1.quotas.addQuery(() => pickApi(tableId).patch(ctx), {
47
+ datasourceId: tableId,
48
+ });
49
+ ctx.status = 200;
50
+ ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
51
+ ctx.message = `${table.name} updated successfully.`;
52
+ ctx.body = row;
59
53
  });
60
54
  }
61
55
  exports.patch = patch;
@@ -67,59 +61,39 @@ const save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
67
61
  if (body && body._id) {
68
62
  return patch(ctx);
69
63
  }
70
- try {
71
- const { row, table } = yield pro_1.quotas.addRow(() => pro_1.quotas.addQuery(() => pickApi(tableId).save(ctx), {
72
- datasourceId: tableId,
73
- }));
74
- ctx.status = 200;
75
- ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
76
- ctx.message = `${table.name} saved successfully`;
77
- ctx.body = row;
78
- }
79
- catch (err) {
80
- ctx.throw(400, err);
81
- }
64
+ const { row, table } = yield pro_1.quotas.addRow(() => pro_1.quotas.addQuery(() => pickApi(tableId).save(ctx), {
65
+ datasourceId: tableId,
66
+ }));
67
+ ctx.status = 200;
68
+ ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
69
+ ctx.message = `${table.name} saved successfully`;
70
+ ctx.body = row;
82
71
  });
83
72
  exports.save = save;
84
73
  function fetchView(ctx) {
85
74
  return __awaiter(this, void 0, void 0, function* () {
86
75
  const tableId = getTableId(ctx);
87
- try {
88
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchView(ctx), {
89
- datasourceId: tableId,
90
- });
91
- }
92
- catch (err) {
93
- ctx.throw(400, err);
94
- }
76
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchView(ctx), {
77
+ datasourceId: tableId,
78
+ });
95
79
  });
96
80
  }
97
81
  exports.fetchView = fetchView;
98
82
  function fetch(ctx) {
99
83
  return __awaiter(this, void 0, void 0, function* () {
100
84
  const tableId = getTableId(ctx);
101
- try {
102
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetch(ctx), {
103
- datasourceId: tableId,
104
- });
105
- }
106
- catch (err) {
107
- ctx.throw(400, err);
108
- }
85
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetch(ctx), {
86
+ datasourceId: tableId,
87
+ });
109
88
  });
110
89
  }
111
90
  exports.fetch = fetch;
112
91
  function find(ctx) {
113
92
  return __awaiter(this, void 0, void 0, function* () {
114
93
  const tableId = getTableId(ctx);
115
- try {
116
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).find(ctx), {
117
- datasourceId: tableId,
118
- });
119
- }
120
- catch (err) {
121
- ctx.throw(400, err);
122
- }
94
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).find(ctx), {
95
+ datasourceId: tableId,
96
+ });
123
97
  });
124
98
  }
125
99
  exports.find = find;
@@ -158,53 +132,33 @@ exports.destroy = destroy;
158
132
  function search(ctx) {
159
133
  return __awaiter(this, void 0, void 0, function* () {
160
134
  const tableId = getTableId(ctx);
161
- try {
162
- ctx.status = 200;
163
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).search(ctx), {
164
- datasourceId: tableId,
165
- });
166
- }
167
- catch (err) {
168
- ctx.throw(400, err);
169
- }
135
+ ctx.status = 200;
136
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).search(ctx), {
137
+ datasourceId: tableId,
138
+ });
170
139
  });
171
140
  }
172
141
  exports.search = search;
173
142
  function validate(ctx) {
174
143
  return __awaiter(this, void 0, void 0, function* () {
175
144
  const tableId = getTableId(ctx);
176
- try {
177
- ctx.body = yield pickApi(tableId).validate(ctx);
178
- }
179
- catch (err) {
180
- ctx.throw(400, err);
181
- }
145
+ ctx.body = yield pickApi(tableId).validate(ctx);
182
146
  });
183
147
  }
184
148
  exports.validate = validate;
185
149
  function fetchEnrichedRow(ctx) {
186
150
  return __awaiter(this, void 0, void 0, function* () {
187
151
  const tableId = getTableId(ctx);
188
- try {
189
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchEnrichedRow(ctx), {
190
- datasourceId: tableId,
191
- });
192
- }
193
- catch (err) {
194
- ctx.throw(400, err);
195
- }
152
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).fetchEnrichedRow(ctx), {
153
+ datasourceId: tableId,
154
+ });
196
155
  });
197
156
  }
198
157
  exports.fetchEnrichedRow = fetchEnrichedRow;
199
158
  const exportRows = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
200
159
  const tableId = getTableId(ctx);
201
- try {
202
- ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).exportRows(ctx), {
203
- datasourceId: tableId,
204
- });
205
- }
206
- catch (err) {
207
- ctx.throw(400, err);
208
- }
160
+ ctx.body = yield pro_1.quotas.addQuery(() => pickApi(tableId).exportRows(ctx), {
161
+ datasourceId: tableId,
162
+ });
209
163
  });
210
164
  exports.exportRows = exportRows;
@@ -122,7 +122,7 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
122
122
  table,
123
123
  });
124
124
  if (!validateResult.valid) {
125
- throw { validation: validateResult.errors };
125
+ ctx.throw(400, { validation: validateResult.errors });
126
126
  }
127
127
  // returned row is cleaned and prepared for writing to DB
128
128
  row = yield linkRows.updateLinks({
@@ -111,6 +111,7 @@ const serveApp = function (ctx) {
111
111
  const App = require("./templates/BudibaseApp.svelte").default;
112
112
  const plugins = (0, plugins_1.enrichPluginURLs)(appInfo.usedPlugins);
113
113
  const { head, html, css } = App.render({
114
+ metaImage: "https://res.cloudinary.com/daog6scxm/image/upload/v1666109324/meta-images/budibase-meta-image_uukc1m.png",
114
115
  title: appInfo.name,
115
116
  production: env.isProd(),
116
117
  appId,
@@ -1,6 +1,8 @@
1
1
  <script>
2
2
  export let title = ""
3
3
  export let favicon = ""
4
+ export let metaImage = ""
5
+ export let url = ""
4
6
 
5
7
  export let clientLibPath
6
8
  export let usedPlugins
@@ -12,6 +14,15 @@
12
14
  name="viewport"
13
15
  content="width=device-width, initial-scale=1.0, viewport-fit=cover"
14
16
  />
17
+ <!-- Opengraph Meta Tags -->
18
+ <meta name="twitter:card" content="summary_large_image" />
19
+ <meta name="twitter:site" content="@budibase" />
20
+ <meta name="twitter:image" content={metaImage} />
21
+ <meta name="twitter:title" content="{title} - built with Budibase" />
22
+ <meta property="og:site_name" content="Budibase" />
23
+ <meta property="og:title" content="{title} - built with Budibase" />
24
+ <meta property="og:type" content="website" />
25
+ <meta property="og:image" content={metaImage} />
15
26
 
16
27
  <title>{title}</title>
17
28
  <link rel="icon" type="image/png" href={favicon} />
@@ -8,103 +8,102 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { generateWebhookID, getWebhookParams } = require("../../db/utils");
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.trigger = exports.buildSchema = exports.destroy = exports.save = exports.fetch = void 0;
16
+ const utils_1 = require("../../db/utils");
17
+ const triggers_1 = __importDefault(require("../../automations/triggers"));
18
+ const backend_core_1 = require("@budibase/backend-core");
19
+ const types_1 = require("@budibase/types");
20
+ const sdk_1 = __importDefault(require("../../sdk"));
12
21
  const toJsonSchema = require("to-json-schema");
13
22
  const validate = require("jsonschema").validate;
14
- const { WebhookType } = require("../../constants");
15
- const triggers = require("../../automations/triggers");
16
- const { getProdAppID } = require("@budibase/backend-core/db");
17
- const { getAppDB, updateAppId } = require("@budibase/backend-core/context");
18
23
  const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema";
19
- function Webhook(name, type, target) {
20
- this.live = true;
21
- this.name = name;
22
- this.action = {
23
- type,
24
- target,
25
- };
24
+ function fetch(ctx) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const db = backend_core_1.context.getAppDB();
27
+ const response = yield db.allDocs((0, utils_1.getWebhookParams)(null, {
28
+ include_docs: true,
29
+ }));
30
+ ctx.body = response.rows.map((row) => row.doc);
31
+ });
26
32
  }
27
- exports.Webhook = Webhook;
28
- exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
29
- const db = getAppDB();
30
- const response = yield db.allDocs(getWebhookParams(null, {
31
- include_docs: true,
32
- }));
33
- ctx.body = response.rows.map(row => row.doc);
34
- });
35
- exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
36
- const db = getAppDB();
37
- const webhook = ctx.request.body;
38
- webhook.appId = ctx.appId;
39
- // check that the webhook exists
40
- if (webhook._id) {
41
- yield db.get(webhook._id);
42
- }
43
- else {
44
- webhook._id = generateWebhookID();
45
- }
46
- const response = yield db.put(webhook);
47
- webhook._rev = response.rev;
48
- ctx.body = {
49
- message: "Webhook created successfully",
50
- webhook,
51
- };
52
- });
53
- exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
54
- const db = getAppDB();
55
- ctx.body = yield db.remove(ctx.params.id, ctx.params.rev);
56
- });
57
- exports.buildSchema = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
58
- yield updateAppId(ctx.params.instance);
59
- const db = getAppDB();
60
- const webhook = yield db.get(ctx.params.id);
61
- webhook.bodySchema = toJsonSchema(ctx.request.body);
62
- // update the automation outputs
63
- if (webhook.action.type === WebhookType.AUTOMATION) {
64
- let automation = yield db.get(webhook.action.target);
65
- const autoOutputs = automation.definition.trigger.schema.outputs;
66
- let properties = webhook.bodySchema.properties;
67
- // reset webhook outputs
68
- autoOutputs.properties = {
69
- body: autoOutputs.properties.body,
33
+ exports.fetch = fetch;
34
+ function save(ctx) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const webhook = yield sdk_1.default.automations.webhook.save(ctx.request.body);
37
+ ctx.body = {
38
+ message: "Webhook created successfully",
39
+ webhook,
70
40
  };
71
- for (let prop of Object.keys(properties)) {
72
- autoOutputs.properties[prop] = {
73
- type: properties[prop].type,
74
- description: AUTOMATION_DESCRIPTION,
41
+ });
42
+ }
43
+ exports.save = save;
44
+ function destroy(ctx) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ ctx.body = yield sdk_1.default.automations.webhook.destroy(ctx.params.id, ctx.params.rev);
47
+ });
48
+ }
49
+ exports.destroy = destroy;
50
+ function buildSchema(ctx) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ yield backend_core_1.context.updateAppId(ctx.params.instance);
53
+ const db = backend_core_1.context.getAppDB();
54
+ const webhook = (yield db.get(ctx.params.id));
55
+ webhook.bodySchema = toJsonSchema(ctx.request.body);
56
+ // update the automation outputs
57
+ if (webhook.action.type === types_1.WebhookActionType.AUTOMATION) {
58
+ let automation = (yield db.get(webhook.action.target));
59
+ const autoOutputs = automation.definition.trigger.schema.outputs;
60
+ let properties = webhook.bodySchema.properties;
61
+ // reset webhook outputs
62
+ autoOutputs.properties = {
63
+ body: autoOutputs.properties.body,
75
64
  };
65
+ for (let prop of Object.keys(properties)) {
66
+ autoOutputs.properties[prop] = {
67
+ type: properties[prop].type,
68
+ description: AUTOMATION_DESCRIPTION,
69
+ };
70
+ }
71
+ yield db.put(automation);
76
72
  }
77
- yield db.put(automation);
78
- }
79
- ctx.body = yield db.put(webhook);
80
- });
81
- exports.trigger = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
82
- const prodAppId = getProdAppID(ctx.params.instance);
83
- yield updateAppId(prodAppId);
84
- try {
85
- const db = getAppDB();
86
- const webhook = yield db.get(ctx.params.id);
87
- // validate against the schema
88
- if (webhook.bodySchema) {
89
- validate(ctx.request.body, webhook.bodySchema);
90
- }
91
- const target = yield db.get(webhook.action.target);
92
- if (webhook.action.type === WebhookType.AUTOMATION) {
93
- // trigger with both the pure request and then expand it
94
- // incase the user has produced a schema to bind to
95
- yield triggers.externalTrigger(target, Object.assign(Object.assign({ body: ctx.request.body }, ctx.request.body), { appId: prodAppId }));
96
- }
97
- ctx.status = 200;
98
- ctx.body = {
99
- message: "Webhook trigger fired successfully",
100
- };
101
- }
102
- catch (err) {
103
- if (err.status === 404) {
73
+ ctx.body = yield db.put(webhook);
74
+ });
75
+ }
76
+ exports.buildSchema = buildSchema;
77
+ function trigger(ctx) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const prodAppId = backend_core_1.db.getProdAppID(ctx.params.instance);
80
+ yield backend_core_1.context.updateAppId(prodAppId);
81
+ try {
82
+ const db = backend_core_1.context.getAppDB();
83
+ const webhook = (yield db.get(ctx.params.id));
84
+ // validate against the schema
85
+ if (webhook.bodySchema) {
86
+ validate(ctx.request.body, webhook.bodySchema);
87
+ }
88
+ const target = yield db.get(webhook.action.target);
89
+ if (webhook.action.type === types_1.WebhookActionType.AUTOMATION) {
90
+ // trigger with both the pure request and then expand it
91
+ // incase the user has produced a schema to bind to
92
+ yield triggers_1.default.externalTrigger(target, Object.assign(Object.assign({ body: ctx.request.body }, ctx.request.body), { appId: prodAppId }));
93
+ }
104
94
  ctx.status = 200;
105
95
  ctx.body = {
106
- message: "Application not deployed yet.",
96
+ message: "Webhook trigger fired successfully",
107
97
  };
108
98
  }
109
- }
110
- });
99
+ catch (err) {
100
+ if (err.status === 404) {
101
+ ctx.status = 200;
102
+ ctx.body = {
103
+ message: "Application not deployed yet.",
104
+ };
105
+ }
106
+ }
107
+ });
108
+ }
109
+ exports.trigger = trigger;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  const { joiValidator } = require("@budibase/backend-core/auth");
3
3
  const { DataSourceOperation } = require("../../../constants");
4
- const { WebhookType } = require("../../../constants");
5
4
  const { BUILTIN_PERMISSION_IDS, PermissionLevels, } = require("@budibase/backend-core/permissions");
5
+ const { WebhookActionType } = require("@budibase/types");
6
6
  const Joi = require("joi");
7
7
  const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("");
8
8
  const OPTIONAL_NUMBER = Joi.number().optional().allow(null);
@@ -113,7 +113,7 @@ exports.webhookValidator = () => {
113
113
  name: Joi.string().required(),
114
114
  bodySchema: Joi.object().optional(),
115
115
  action: Joi.object({
116
- type: Joi.string().required().valid(WebhookType.AUTOMATION),
116
+ type: Joi.string().required().valid(WebhookActionType.AUTOMATION),
117
117
  target: Joi.string().required(),
118
118
  }).required(),
119
119
  }).unknown(true));
@@ -1,15 +1,43 @@
1
1
  "use strict";
2
- const Router = require("@koa/router");
3
- const controller = require("../controllers/webhook");
4
- const authorized = require("../../middleware/authorized");
5
- const { BUILDER } = require("@budibase/backend-core/permissions");
6
- const { webhookValidator } = require("./utils/validators");
7
- const router = new Router();
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const router_1 = __importDefault(require("@koa/router"));
30
+ const controller = __importStar(require("../controllers/webhook"));
31
+ const authorized_1 = __importDefault(require("../../middleware/authorized"));
32
+ const backend_core_1 = require("@budibase/backend-core");
33
+ const validators_1 = require("./utils/validators");
34
+ const BUILDER = backend_core_1.permissions.BUILDER;
35
+ const router = new router_1.default();
8
36
  router
9
- .get("/api/webhooks", authorized(BUILDER), controller.fetch)
10
- .put("/api/webhooks", authorized(BUILDER), webhookValidator(), controller.save)
11
- .delete("/api/webhooks/:id/:rev", authorized(BUILDER), controller.destroy)
12
- .post("/api/webhooks/schema/:instance/:id", authorized(BUILDER), controller.buildSchema)
37
+ .get("/api/webhooks", (0, authorized_1.default)(BUILDER), controller.fetch)
38
+ .put("/api/webhooks", (0, authorized_1.default)(BUILDER), (0, validators_1.webhookValidator)(), controller.save)
39
+ .delete("/api/webhooks/:id/:rev", (0, authorized_1.default)(BUILDER), controller.destroy)
40
+ .post("/api/webhooks/schema/:instance/:id", (0, authorized_1.default)(BUILDER), controller.buildSchema)
13
41
  // this shouldn't have authorisation, right now its always public
14
42
  .post("/api/webhooks/trigger/:instance/:id", controller.trigger);
15
- module.exports = router;
43
+ exports.default = router;
package/dist/app.js CHANGED
@@ -49,26 +49,16 @@ db_1.default.init();
49
49
  const Koa = require("koa");
50
50
  const destroyable = require("server-destroy");
51
51
  const koaBody = require("koa-body");
52
- const pino = require("koa-pino-logger");
53
52
  const http = require("http");
54
53
  const api = require("./api");
55
- const eventEmitter = require("./events");
56
54
  const automations = require("./automations/index");
57
55
  const Sentry = require("@sentry/node");
58
- const fileSystem = require("./utilities/fileSystem");
59
- const bullboard = require("./automations/bullboard");
60
56
  const { logAlert } = require("@budibase/backend-core/logging");
61
- const { pinoSettings } = require("@budibase/backend-core");
62
57
  const { Thread } = require("./threads");
63
- const fs = require("fs");
64
58
  const redis_1 = __importDefault(require("./utilities/redis"));
65
- const migrations = __importStar(require("./migrations"));
66
59
  const backend_core_1 = require("@budibase/backend-core");
67
- const workerRequests_1 = require("./utilities/workerRequests");
68
- const watch_1 = require("./watch");
69
60
  const websocket_1 = require("./websocket");
70
- const sdk_1 = __importDefault(require("./sdk"));
71
- const pro = __importStar(require("@budibase/pro"));
61
+ const startup_1 = require("./startup");
72
62
  const app = new Koa();
73
63
  // set up top level koa middleware
74
64
  app.use(koaBody({
@@ -79,15 +69,6 @@ app.use(koaBody({
79
69
  enableTypes: ["json", "form", "text"],
80
70
  parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
81
71
  }));
82
- app.use(pino(pinoSettings()));
83
- if (!env.isTest()) {
84
- const plugin = bullboard.init();
85
- app.use(plugin);
86
- }
87
- app.context.eventEmitter = eventEmitter;
88
- app.context.auth = {};
89
- // api routes
90
- app.use(api.router.routes());
91
72
  if (env.isProd()) {
92
73
  env._set("NODE_ENV", "production");
93
74
  Sentry.init();
@@ -120,71 +101,8 @@ server.on("close", () => __awaiter(void 0, void 0, void 0, function* () {
120
101
  process.exit(errCode);
121
102
  }
122
103
  }));
123
- const initPro = () => __awaiter(void 0, void 0, void 0, function* () {
124
- yield pro.init({
125
- backups: {
126
- processing: {
127
- exportAppFn: sdk_1.default.backups.exportApp,
128
- importAppFn: sdk_1.default.backups.importApp,
129
- statsFn: sdk_1.default.backups.calculateBackupStats,
130
- },
131
- },
132
- });
133
- });
134
104
  module.exports = server.listen(env.PORT || 0, () => __awaiter(void 0, void 0, void 0, function* () {
135
- var _a;
136
- console.log(`Budibase running on ${JSON.stringify(server.address())}`);
137
- env._set("PORT", server.address().port);
138
- eventEmitter.emitPort(env.PORT);
139
- fileSystem.init();
140
- yield redis_1.default.init();
141
- // run migrations on startup if not done via http
142
- // not recommended in a clustered environment
143
- if (!env.HTTP_MIGRATIONS && !env.isTest()) {
144
- try {
145
- yield migrations.migrate();
146
- }
147
- catch (e) {
148
- logAlert("Error performing migrations. Exiting.", e);
149
- shutdown();
150
- }
151
- }
152
- // check and create admin user if required
153
- if (env.SELF_HOSTED &&
154
- !env.MULTI_TENANCY &&
155
- env.BB_ADMIN_USER_EMAIL &&
156
- env.BB_ADMIN_USER_PASSWORD) {
157
- const checklist = yield (0, workerRequests_1.getChecklist)();
158
- if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
159
- try {
160
- const tenantId = backend_core_1.tenancy.getTenantId();
161
- const user = yield (0, workerRequests_1.createAdminUser)(env.BB_ADMIN_USER_EMAIL, env.BB_ADMIN_USER_PASSWORD, tenantId);
162
- // Need to set up an API key for automated integration tests
163
- if (env.isTest()) {
164
- yield (0, workerRequests_1.generateApiKey)(user._id);
165
- }
166
- console.log("Admin account automatically created for", env.BB_ADMIN_USER_EMAIL);
167
- }
168
- catch (e) {
169
- logAlert("Error creating initial admin user. Exiting.", e);
170
- shutdown();
171
- }
172
- }
173
- }
174
- // monitor plugin directory if required
175
- if (env.SELF_HOSTED &&
176
- !env.MULTI_TENANCY &&
177
- env.PLUGINS_DIR &&
178
- fs.existsSync(env.PLUGINS_DIR)) {
179
- (0, watch_1.watch)();
180
- }
181
- // check for version updates
182
- yield backend_core_1.installation.checkInstallVersion();
183
- // done last - these will never complete
184
- let promises = [];
185
- promises.push(automations.init());
186
- promises.push(initPro());
187
- yield Promise.all(promises);
105
+ yield (0, startup_1.startup)(app, server);
188
106
  }));
189
107
  const shutdown = () => {
190
108
  server.close();
@@ -13,11 +13,16 @@ const { BullAdapter } = require("@bull-board/api/bullAdapter");
13
13
  const { KoaAdapter } = require("@bull-board/koa");
14
14
  const { queue } = require("@budibase/backend-core");
15
15
  const automation = require("../threads/automation");
16
+ const { backups } = require("@budibase/pro");
16
17
  let automationQueue = queue.createQueue(queue.JobQueue.AUTOMATION, automation.removeStalled);
17
18
  const PATH_PREFIX = "/bulladmin";
18
- exports.init = () => {
19
+ exports.init = () => __awaiter(void 0, void 0, void 0, function* () {
19
20
  // Set up queues for bull board admin
21
+ const backupQueue = yield backups.getBackupQueue();
20
22
  const queues = [automationQueue];
23
+ if (backupQueue) {
24
+ queues.push(backupQueue);
25
+ }
21
26
  const adapters = [];
22
27
  const serverAdapter = new KoaAdapter();
23
28
  for (let queue of queues) {
@@ -29,7 +34,7 @@ exports.init = () => {
29
34
  });
30
35
  serverAdapter.setBasePath(PATH_PREFIX);
31
36
  return serverAdapter.registerPlugin();
32
- };
37
+ });
33
38
  exports.shutdown = () => __awaiter(void 0, void 0, void 0, function* () {
34
39
  yield queue.shutdown();
35
40
  });