@budibase/server 2.5.9 → 2.5.10-alpha.1

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 (198) hide show
  1. package/builder/assets/index.24635afb.js +1794 -0
  2. package/builder/assets/index.4eae16b2.css +6 -0
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/application.js +3 -4
  5. package/dist/api/controllers/automation.js +13 -7
  6. package/dist/api/controllers/datasource.js +1 -1
  7. package/dist/api/controllers/dev.js +1 -1
  8. package/dist/api/controllers/ops.js +40 -0
  9. package/dist/api/controllers/plugin/index.js +6 -37
  10. package/dist/api/controllers/query/index.js +2 -2
  11. package/dist/api/controllers/row/ExternalRequest.js +21 -14
  12. package/dist/api/controllers/row/internal.js +5 -2
  13. package/dist/api/controllers/row/utils.js +2 -2
  14. package/dist/api/controllers/table/index.js +2 -2
  15. package/dist/api/controllers/table/utils.js +9 -3
  16. package/dist/api/controllers/user.js +1 -83
  17. package/dist/api/controllers/view/exporters.js +3 -1
  18. package/dist/api/index.js +1 -2
  19. package/dist/api/routes/index.js +2 -2
  20. package/dist/api/routes/{cloud.js → ops.js} +19 -6
  21. package/dist/api/routes/user.js +0 -1
  22. package/dist/app.js +4 -13
  23. package/dist/automations/actions.js +32 -6
  24. package/dist/automations/index.js +3 -2
  25. package/dist/automations/steps/bash.js +6 -6
  26. package/dist/automations/steps/createRow.js +11 -11
  27. package/dist/automations/steps/delay.js +3 -3
  28. package/dist/automations/steps/deleteRow.js +8 -8
  29. package/dist/automations/steps/discord.js +8 -8
  30. package/dist/automations/steps/executeQuery.js +9 -9
  31. package/dist/automations/steps/executeScript.js +6 -6
  32. package/dist/automations/steps/filter.js +6 -6
  33. package/dist/automations/steps/integromat.js +10 -10
  34. package/dist/automations/steps/loop.js +9 -9
  35. package/dist/automations/steps/outgoingWebhook.js +10 -10
  36. package/dist/automations/steps/queryRows.js +14 -14
  37. package/dist/automations/steps/sendSmtpEmail.js +9 -9
  38. package/dist/automations/steps/serverLog.js +4 -4
  39. package/dist/automations/steps/slack.js +6 -6
  40. package/dist/automations/steps/updateRow.js +11 -11
  41. package/dist/automations/steps/zapier.js +9 -9
  42. package/dist/automations/triggerInfo/app.js +5 -5
  43. package/dist/automations/triggerInfo/cron.js +4 -4
  44. package/dist/automations/triggerInfo/rowDeleted.js +5 -5
  45. package/dist/automations/triggerInfo/rowSaved.js +7 -7
  46. package/dist/automations/triggerInfo/rowUpdated.js +7 -7
  47. package/dist/automations/triggerInfo/webhook.js +6 -6
  48. package/dist/db/utils.js +3 -2
  49. package/dist/environment.js +0 -1
  50. package/dist/events/docUpdates/index.js +17 -0
  51. package/dist/events/docUpdates/processors.js +18 -0
  52. package/dist/events/docUpdates/syncUsers.js +49 -0
  53. package/dist/events/index.js +3 -0
  54. package/dist/integrations/base/sqlTable.js +9 -2
  55. package/dist/integrations/index.js +3 -3
  56. package/dist/integrations/microsoftSqlServer.js +5 -2
  57. package/dist/integrations/mysql.js +5 -3
  58. package/dist/integrations/postgres.js +7 -5
  59. package/dist/integrations/redis.js +7 -0
  60. package/dist/integrations/rest.js +4 -0
  61. package/dist/migrations/functions/syncQuotas.js +2 -0
  62. package/dist/migrations/functions/usageQuotas/syncApps.js +1 -2
  63. package/dist/migrations/functions/usageQuotas/syncRows.js +1 -2
  64. package/dist/migrations/functions/usageQuotas/syncUsers.js +21 -0
  65. package/dist/sdk/app/applications/sync.js +117 -23
  66. package/dist/sdk/app/backups/exports.js +14 -38
  67. package/dist/sdk/index.js +2 -0
  68. package/dist/sdk/plugins/index.js +27 -0
  69. package/dist/sdk/plugins/plugins.js +53 -0
  70. package/dist/sdk/users/utils.js +21 -4
  71. package/dist/startup.js +31 -28
  72. package/dist/threads/automation.js +16 -5
  73. package/dist/tsconfig.build.tsbuildinfo +1 -1
  74. package/dist/utilities/csv.js +33 -0
  75. package/dist/utilities/fileSystem/plugin.js +33 -23
  76. package/dist/utilities/global.js +17 -12
  77. package/dist/utilities/rowProcessor/utils.js +4 -5
  78. package/dist/utilities/schema.js +5 -1
  79. package/dist/watch.js +2 -2
  80. package/dist/websockets/client.js +14 -0
  81. package/dist/websockets/grid.js +60 -0
  82. package/dist/websockets/index.js +17 -0
  83. package/dist/websockets/websocket.js +78 -0
  84. package/package.json +16 -16
  85. package/scripts/dev/manage.js +2 -0
  86. package/scripts/integrations/mssql/data/entrypoint.sh +1 -0
  87. package/scripts/integrations/mssql/data/setup.sql +17 -17
  88. package/scripts/integrations/mysql/init.sql +1 -1
  89. package/scripts/integrations/postgres/init.sql +1 -0
  90. package/src/api/controllers/application.ts +4 -4
  91. package/src/api/controllers/automation.ts +12 -6
  92. package/src/api/controllers/datasource.ts +15 -5
  93. package/src/api/controllers/dev.ts +2 -2
  94. package/src/api/controllers/ops.ts +32 -0
  95. package/src/api/controllers/plugin/index.ts +8 -45
  96. package/src/api/controllers/query/index.ts +2 -2
  97. package/src/api/controllers/row/ExternalRequest.ts +21 -12
  98. package/src/api/controllers/row/internal.ts +13 -11
  99. package/src/api/controllers/row/utils.ts +4 -4
  100. package/src/api/controllers/table/index.ts +2 -2
  101. package/src/api/controllers/table/utils.ts +10 -3
  102. package/src/api/controllers/user.ts +10 -96
  103. package/src/api/controllers/view/exporters.ts +3 -1
  104. package/src/api/index.ts +2 -4
  105. package/src/api/routes/index.ts +2 -2
  106. package/src/api/routes/ops.ts +30 -0
  107. package/src/api/routes/tests/automation.spec.js +7 -4
  108. package/src/api/routes/tests/user.spec.js +48 -37
  109. package/src/api/routes/user.ts +0 -5
  110. package/src/app.ts +4 -15
  111. package/src/automations/actions.ts +56 -24
  112. package/src/automations/index.ts +1 -1
  113. package/src/automations/steps/bash.ts +10 -7
  114. package/src/automations/steps/createRow.ts +15 -12
  115. package/src/automations/steps/delay.ts +6 -4
  116. package/src/automations/steps/deleteRow.ts +12 -9
  117. package/src/automations/steps/discord.ts +10 -8
  118. package/src/automations/steps/executeQuery.ts +13 -10
  119. package/src/automations/steps/executeScript.ts +10 -7
  120. package/src/automations/steps/filter.ts +8 -6
  121. package/src/automations/steps/integromat.ts +12 -10
  122. package/src/automations/steps/loop.ts +16 -10
  123. package/src/automations/steps/outgoingWebhook.ts +14 -11
  124. package/src/automations/steps/queryRows.ts +18 -15
  125. package/src/automations/steps/sendSmtpEmail.ts +11 -9
  126. package/src/automations/steps/serverLog.ts +6 -4
  127. package/src/automations/steps/slack.ts +8 -6
  128. package/src/automations/steps/updateRow.ts +15 -12
  129. package/src/automations/steps/zapier.ts +11 -9
  130. package/src/automations/tests/utilities/index.ts +2 -2
  131. package/src/automations/triggerInfo/app.ts +8 -5
  132. package/src/automations/triggerInfo/cron.ts +7 -4
  133. package/src/automations/triggerInfo/rowDeleted.ts +8 -5
  134. package/src/automations/triggerInfo/rowSaved.ts +10 -7
  135. package/src/automations/triggerInfo/rowUpdated.ts +10 -7
  136. package/src/automations/triggerInfo/webhook.ts +9 -6
  137. package/src/db/utils.ts +1 -0
  138. package/src/environment.ts +0 -1
  139. package/src/events/docUpdates/index.ts +1 -0
  140. package/src/events/docUpdates/processors.ts +14 -0
  141. package/src/events/docUpdates/syncUsers.ts +35 -0
  142. package/src/events/index.ts +1 -0
  143. package/src/integration-test/postgres.spec.ts +3 -1
  144. package/src/integrations/base/sqlTable.ts +9 -2
  145. package/src/integrations/index.ts +3 -3
  146. package/src/integrations/microsoftSqlServer.ts +5 -2
  147. package/src/integrations/mysql.ts +5 -3
  148. package/src/integrations/postgres.ts +7 -5
  149. package/src/integrations/redis.ts +8 -0
  150. package/src/integrations/rest.ts +3 -0
  151. package/src/migrations/functions/syncQuotas.ts +2 -0
  152. package/src/migrations/functions/usageQuotas/syncApps.ts +2 -3
  153. package/src/migrations/functions/usageQuotas/syncRows.ts +2 -3
  154. package/src/migrations/functions/usageQuotas/syncUsers.ts +9 -0
  155. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +2 -2
  156. package/src/migrations/functions/usageQuotas/tests/syncUsers.spec.ts +26 -0
  157. package/src/migrations/index.ts +1 -0
  158. package/src/sdk/app/applications/sync.ts +129 -22
  159. package/src/sdk/app/applications/tests/sync.spec.ts +137 -0
  160. package/src/sdk/app/backups/exports.ts +17 -41
  161. package/src/sdk/index.ts +2 -0
  162. package/src/sdk/plugins/index.ts +5 -0
  163. package/src/sdk/plugins/plugins.ts +41 -0
  164. package/src/sdk/users/tests/utils.spec.ts +1 -32
  165. package/src/sdk/users/utils.ts +23 -5
  166. package/src/startup.ts +36 -34
  167. package/src/tests/jestEnv.ts +0 -1
  168. package/src/tests/jestSetup.ts +0 -1
  169. package/src/tests/utilities/TestConfiguration.ts +28 -0
  170. package/src/tests/utilities/structures.ts +25 -17
  171. package/src/threads/automation.ts +18 -6
  172. package/src/utilities/csv.ts +22 -0
  173. package/src/utilities/fileSystem/plugin.ts +13 -4
  174. package/src/utilities/global.ts +21 -16
  175. package/src/utilities/rowProcessor/utils.ts +9 -10
  176. package/src/utilities/schema.ts +8 -0
  177. package/src/utilities/tests/csv.spec.ts +33 -0
  178. package/src/watch.ts +2 -2
  179. package/src/websockets/client.ts +11 -0
  180. package/src/websockets/grid.ts +55 -0
  181. package/src/websockets/index.ts +14 -0
  182. package/src/websockets/websocket.ts +83 -0
  183. package/tsconfig.build.json +3 -5
  184. package/tsconfig.json +2 -1
  185. package/builder/assets/index.0b358332.js +0 -1817
  186. package/builder/assets/index.7f9a008b.css +0 -6
  187. package/dist/api/controllers/cloud.js +0 -130
  188. package/dist/elasticApm.js +0 -14
  189. package/dist/package.json +0 -180
  190. package/dist/websocket.js +0 -22
  191. package/scripts/likeCypress.ts +0 -35
  192. package/src/api/controllers/cloud.ts +0 -119
  193. package/src/api/routes/cloud.ts +0 -18
  194. package/src/api/routes/tests/cloud.spec.ts +0 -54
  195. package/src/elasticApm.ts +0 -10
  196. package/src/migrations/functions/tests/syncQuotas.spec.js +0 -26
  197. package/src/tests/logging.ts +0 -34
  198. package/src/websocket.ts +0 -26
@@ -4,6 +4,8 @@ import {
4
4
  AutomationActionStepId,
5
5
  AutomationStepSchema,
6
6
  AutomationStepInput,
7
+ AutomationStepType,
8
+ AutomationIOType,
7
9
  } from "@budibase/types"
8
10
 
9
11
  export const definition: AutomationStepSchema = {
@@ -11,7 +13,7 @@ export const definition: AutomationStepSchema = {
11
13
  tagline: "Send SMTP email to {{inputs.to}}",
12
14
  icon: "Email",
13
15
  name: "Send Email (SMTP)",
14
- type: "ACTION",
16
+ type: AutomationStepType.ACTION,
15
17
  internal: true,
16
18
  stepId: AutomationActionStepId.SEND_EMAIL_SMTP,
17
19
  inputs: {},
@@ -19,27 +21,27 @@ export const definition: AutomationStepSchema = {
19
21
  inputs: {
20
22
  properties: {
21
23
  to: {
22
- type: "string",
24
+ type: AutomationIOType.STRING,
23
25
  title: "Send To",
24
26
  },
25
27
  from: {
26
- type: "string",
28
+ type: AutomationIOType.STRING,
27
29
  title: "Send From",
28
30
  },
29
31
  cc: {
30
- type: "string",
32
+ type: AutomationIOType.STRING,
31
33
  title: "CC",
32
34
  },
33
35
  bcc: {
34
- type: "string",
36
+ type: AutomationIOType.STRING,
35
37
  title: "BCC",
36
38
  },
37
39
  subject: {
38
- type: "string",
40
+ type: AutomationIOType.STRING,
39
41
  title: "Email Subject",
40
42
  },
41
43
  contents: {
42
- type: "string",
44
+ type: AutomationIOType.STRING,
43
45
  title: "HTML Contents",
44
46
  },
45
47
  },
@@ -48,11 +50,11 @@ export const definition: AutomationStepSchema = {
48
50
  outputs: {
49
51
  properties: {
50
52
  success: {
51
- type: "boolean",
53
+ type: AutomationIOType.BOOLEAN,
52
54
  description: "Whether the email was sent",
53
55
  },
54
56
  response: {
55
- type: "object",
57
+ type: AutomationIOType.OBJECT,
56
58
  description: "A response from the email client, this may be an error",
57
59
  },
58
60
  },
@@ -2,6 +2,8 @@ import {
2
2
  AutomationActionStepId,
3
3
  AutomationStepSchema,
4
4
  AutomationStepInput,
5
+ AutomationStepType,
6
+ AutomationIOType,
5
7
  } from "@budibase/types"
6
8
 
7
9
  /**
@@ -15,7 +17,7 @@ export const definition: AutomationStepSchema = {
15
17
  tagline: "Console log a value in the backend",
16
18
  icon: "Monitoring",
17
19
  description: "Logs the given text to the server (using console.log)",
18
- type: "ACTION",
20
+ type: AutomationStepType.ACTION,
19
21
  internal: true,
20
22
  stepId: AutomationActionStepId.SERVER_LOG,
21
23
  inputs: {
@@ -25,7 +27,7 @@ export const definition: AutomationStepSchema = {
25
27
  inputs: {
26
28
  properties: {
27
29
  text: {
28
- type: "string",
30
+ type: AutomationIOType.STRING,
29
31
  title: "Log",
30
32
  },
31
33
  },
@@ -34,11 +36,11 @@ export const definition: AutomationStepSchema = {
34
36
  outputs: {
35
37
  properties: {
36
38
  success: {
37
- type: "boolean",
39
+ type: AutomationIOType.BOOLEAN,
38
40
  description: "Whether the action was successful",
39
41
  },
40
42
  message: {
41
- type: "string",
43
+ type: AutomationIOType.STRING,
42
44
  description: "What was output",
43
45
  },
44
46
  },
@@ -4,6 +4,8 @@ import {
4
4
  AutomationActionStepId,
5
5
  AutomationStepSchema,
6
6
  AutomationStepInput,
7
+ AutomationStepType,
8
+ AutomationIOType,
7
9
  } from "@budibase/types"
8
10
 
9
11
  export const definition: AutomationStepSchema = {
@@ -12,18 +14,18 @@ export const definition: AutomationStepSchema = {
12
14
  description: "Send a message to Slack",
13
15
  icon: "ri-slack-line",
14
16
  stepId: AutomationActionStepId.slack,
15
- type: "ACTION",
17
+ type: AutomationStepType.ACTION,
16
18
  internal: false,
17
19
  inputs: {},
18
20
  schema: {
19
21
  inputs: {
20
22
  properties: {
21
23
  url: {
22
- type: "string",
24
+ type: AutomationIOType.STRING,
23
25
  title: "Incoming Webhook URL",
24
26
  },
25
27
  text: {
26
- type: "string",
28
+ type: AutomationIOType.STRING,
27
29
  title: "Message",
28
30
  },
29
31
  },
@@ -32,15 +34,15 @@ export const definition: AutomationStepSchema = {
32
34
  outputs: {
33
35
  properties: {
34
36
  httpStatus: {
35
- type: "number",
37
+ type: AutomationIOType.NUMBER,
36
38
  description: "The HTTP status code of the request",
37
39
  },
38
40
  success: {
39
- type: "boolean",
41
+ type: AutomationIOType.BOOLEAN,
40
42
  description: "Whether the message sent successfully",
41
43
  },
42
44
  response: {
43
- type: "string",
45
+ type: AutomationIOType.STRING,
44
46
  description: "The response from the Slack Webhook",
45
47
  },
46
48
  },
@@ -3,8 +3,11 @@ import * as automationUtils from "../automationUtils"
3
3
  import { buildCtx } from "./utils"
4
4
  import {
5
5
  AutomationActionStepId,
6
- AutomationStepSchema,
6
+ AutomationCustomIOType,
7
+ AutomationIOType,
7
8
  AutomationStepInput,
9
+ AutomationStepSchema,
10
+ AutomationStepType,
8
11
  } from "@budibase/types"
9
12
 
10
13
  export const definition: AutomationStepSchema = {
@@ -12,7 +15,7 @@ export const definition: AutomationStepSchema = {
12
15
  tagline: "Update a {{inputs.enriched.table.name}} row",
13
16
  icon: "Refresh",
14
17
  description: "Update a row in your database",
15
- type: "ACTION",
18
+ type: AutomationStepType.ACTION,
16
19
  internal: true,
17
20
  stepId: AutomationActionStepId.UPDATE_ROW,
18
21
  inputs: {},
@@ -20,16 +23,16 @@ export const definition: AutomationStepSchema = {
20
23
  inputs: {
21
24
  properties: {
22
25
  meta: {
23
- type: "object",
26
+ type: AutomationIOType.OBJECT,
24
27
  title: "Field settings",
25
28
  },
26
29
  row: {
27
- type: "object",
28
- customType: "row",
30
+ type: AutomationIOType.OBJECT,
31
+ customType: AutomationCustomIOType.ROW,
29
32
  title: "Table",
30
33
  },
31
34
  rowId: {
32
- type: "string",
35
+ type: AutomationIOType.STRING,
33
36
  title: "Row ID",
34
37
  },
35
38
  },
@@ -38,24 +41,24 @@ export const definition: AutomationStepSchema = {
38
41
  outputs: {
39
42
  properties: {
40
43
  row: {
41
- type: "object",
42
- customType: "row",
44
+ type: AutomationIOType.OBJECT,
45
+ customType: AutomationCustomIOType.ROW,
43
46
  description: "The updated row",
44
47
  },
45
48
  response: {
46
- type: "object",
49
+ type: AutomationIOType.OBJECT,
47
50
  description: "The response from the table",
48
51
  },
49
52
  success: {
50
- type: "boolean",
53
+ type: AutomationIOType.BOOLEAN,
51
54
  description: "Whether the action was successful",
52
55
  },
53
56
  id: {
54
- type: "string",
57
+ type: AutomationIOType.STRING,
55
58
  description: "The identifier of the updated row",
56
59
  },
57
60
  revision: {
58
- type: "string",
61
+ type: AutomationIOType.STRING,
59
62
  description: "The revision of the updated row",
60
63
  },
61
64
  },
@@ -4,12 +4,14 @@ import {
4
4
  AutomationActionStepId,
5
5
  AutomationStepSchema,
6
6
  AutomationStepInput,
7
+ AutomationStepType,
8
+ AutomationIOType,
7
9
  } from "@budibase/types"
8
10
 
9
11
  export const definition: AutomationStepSchema = {
10
12
  name: "Zapier Webhook",
11
13
  stepId: AutomationActionStepId.zapier,
12
- type: "ACTION",
14
+ type: AutomationStepType.ACTION,
13
15
  internal: false,
14
16
  description: "Trigger a Zapier Zap via webhooks",
15
17
  tagline: "Trigger a Zapier Zap",
@@ -19,27 +21,27 @@ export const definition: AutomationStepSchema = {
19
21
  inputs: {
20
22
  properties: {
21
23
  url: {
22
- type: "string",
24
+ type: AutomationIOType.STRING,
23
25
  title: "Webhook URL",
24
26
  },
25
27
  value1: {
26
- type: "string",
28
+ type: AutomationIOType.STRING,
27
29
  title: "Payload Value 1",
28
30
  },
29
31
  value2: {
30
- type: "string",
32
+ type: AutomationIOType.STRING,
31
33
  title: "Payload Value 2",
32
34
  },
33
35
  value3: {
34
- type: "string",
36
+ type: AutomationIOType.STRING,
35
37
  title: "Payload Value 3",
36
38
  },
37
39
  value4: {
38
- type: "string",
40
+ type: AutomationIOType.STRING,
39
41
  title: "Payload Value 4",
40
42
  },
41
43
  value5: {
42
- type: "string",
44
+ type: AutomationIOType.STRING,
43
45
  title: "Payload Value 5",
44
46
  },
45
47
  },
@@ -48,11 +50,11 @@ export const definition: AutomationStepSchema = {
48
50
  outputs: {
49
51
  properties: {
50
52
  httpStatus: {
51
- type: "number",
53
+ type: AutomationIOType.NUMBER,
52
54
  description: "The HTTP status code of the request",
53
55
  },
54
56
  response: {
55
- type: "string",
57
+ type: AutomationIOType.STRING,
56
58
  description: "The response from Zapier",
57
59
  },
58
60
  },
@@ -1,6 +1,6 @@
1
1
  import TestConfig from "../../../tests/utilities/TestConfiguration"
2
2
  import { context } from "@budibase/backend-core"
3
- import { ACTION_DEFINITIONS, getAction } from "../../actions"
3
+ import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
4
4
  import emitter from "../../../events/index"
5
5
  import env from "../../../environment"
6
6
 
@@ -57,4 +57,4 @@ export async function runStep(stepId: string, inputs: any, stepContext?: any) {
57
57
  }
58
58
 
59
59
  export const apiKey = "test"
60
- export const actions = ACTION_DEFINITIONS
60
+ export const actions = BUILTIN_ACTION_DEFINITIONS
@@ -1,4 +1,7 @@
1
1
  import {
2
+ AutomationCustomIOType,
3
+ AutomationIOType,
4
+ AutomationStepType,
2
5
  AutomationTriggerSchema,
3
6
  AutomationTriggerStepId,
4
7
  } from "@budibase/types"
@@ -15,8 +18,8 @@ export const definition: AutomationTriggerSchema = {
15
18
  inputs: {
16
19
  properties: {
17
20
  fields: {
18
- type: "object",
19
- customType: "triggerSchema",
21
+ type: AutomationIOType.OBJECT,
22
+ customType: AutomationCustomIOType.TRIGGER_SCHEMA,
20
23
  title: "Fields",
21
24
  },
22
25
  },
@@ -25,13 +28,13 @@ export const definition: AutomationTriggerSchema = {
25
28
  outputs: {
26
29
  properties: {
27
30
  fields: {
28
- type: "object",
31
+ type: AutomationIOType.OBJECT,
29
32
  description: "Fields submitted from the app frontend",
30
- customType: "triggerSchema",
33
+ customType: AutomationCustomIOType.TRIGGER_SCHEMA,
31
34
  },
32
35
  },
33
36
  required: ["fields"],
34
37
  },
35
38
  },
36
- type: "TRIGGER",
39
+ type: AutomationStepType.TRIGGER,
37
40
  }
@@ -1,4 +1,7 @@
1
1
  import {
2
+ AutomationCustomIOType,
3
+ AutomationIOType,
4
+ AutomationStepType,
2
5
  AutomationTriggerSchema,
3
6
  AutomationTriggerStepId,
4
7
  } from "@budibase/types"
@@ -15,8 +18,8 @@ export const definition: AutomationTriggerSchema = {
15
18
  inputs: {
16
19
  properties: {
17
20
  cron: {
18
- type: "string",
19
- customType: "cron",
21
+ type: AutomationIOType.STRING,
22
+ customType: AutomationCustomIOType.CRON,
20
23
  title: "Expression",
21
24
  },
22
25
  },
@@ -25,12 +28,12 @@ export const definition: AutomationTriggerSchema = {
25
28
  outputs: {
26
29
  properties: {
27
30
  timestamp: {
28
- type: "number",
31
+ type: AutomationIOType.NUMBER,
29
32
  description: "Timestamp the cron was executed",
30
33
  },
31
34
  },
32
35
  required: ["timestamp"],
33
36
  },
34
37
  },
35
- type: "TRIGGER",
38
+ type: AutomationStepType.TRIGGER,
36
39
  }
@@ -1,4 +1,7 @@
1
1
  import {
2
+ AutomationCustomIOType,
3
+ AutomationIOType,
4
+ AutomationStepType,
2
5
  AutomationTriggerSchema,
3
6
  AutomationTriggerStepId,
4
7
  } from "@budibase/types"
@@ -15,8 +18,8 @@ export const definition: AutomationTriggerSchema = {
15
18
  inputs: {
16
19
  properties: {
17
20
  tableId: {
18
- type: "string",
19
- customType: "table",
21
+ type: AutomationIOType.STRING,
22
+ customType: AutomationCustomIOType.TABLE,
20
23
  title: "Table",
21
24
  },
22
25
  },
@@ -25,13 +28,13 @@ export const definition: AutomationTriggerSchema = {
25
28
  outputs: {
26
29
  properties: {
27
30
  row: {
28
- type: "object",
29
- customType: "row",
31
+ type: AutomationIOType.OBJECT,
32
+ customType: AutomationCustomIOType.ROW,
30
33
  description: "The row that was deleted",
31
34
  },
32
35
  },
33
36
  required: ["row"],
34
37
  },
35
38
  },
36
- type: "TRIGGER",
39
+ type: AutomationStepType.TRIGGER,
37
40
  }
@@ -1,4 +1,7 @@
1
1
  import {
2
+ AutomationCustomIOType,
3
+ AutomationIOType,
4
+ AutomationStepType,
2
5
  AutomationTriggerSchema,
3
6
  AutomationTriggerStepId,
4
7
  } from "@budibase/types"
@@ -15,8 +18,8 @@ export const definition: AutomationTriggerSchema = {
15
18
  inputs: {
16
19
  properties: {
17
20
  tableId: {
18
- type: "string",
19
- customType: "table",
21
+ type: AutomationIOType.STRING,
22
+ customType: AutomationCustomIOType.TABLE,
20
23
  title: "Table",
21
24
  },
22
25
  },
@@ -25,21 +28,21 @@ export const definition: AutomationTriggerSchema = {
25
28
  outputs: {
26
29
  properties: {
27
30
  row: {
28
- type: "object",
29
- customType: "row",
31
+ type: AutomationIOType.OBJECT,
32
+ customType: AutomationCustomIOType.ROW,
30
33
  description: "The new row that was created",
31
34
  },
32
35
  id: {
33
- type: "string",
36
+ type: AutomationIOType.STRING,
34
37
  description: "Row ID - can be used for updating",
35
38
  },
36
39
  revision: {
37
- type: "string",
40
+ type: AutomationIOType.STRING,
38
41
  description: "Revision of row",
39
42
  },
40
43
  },
41
44
  required: ["row", "id"],
42
45
  },
43
46
  },
44
- type: "TRIGGER",
47
+ type: AutomationStepType.TRIGGER,
45
48
  }
@@ -1,4 +1,7 @@
1
1
  import {
2
+ AutomationCustomIOType,
3
+ AutomationIOType,
4
+ AutomationStepType,
2
5
  AutomationTriggerSchema,
3
6
  AutomationTriggerStepId,
4
7
  } from "@budibase/types"
@@ -15,8 +18,8 @@ export const definition: AutomationTriggerSchema = {
15
18
  inputs: {
16
19
  properties: {
17
20
  tableId: {
18
- type: "string",
19
- customType: "table",
21
+ type: AutomationIOType.STRING,
22
+ customType: AutomationCustomIOType.TABLE,
20
23
  title: "Table",
21
24
  },
22
25
  },
@@ -25,21 +28,21 @@ export const definition: AutomationTriggerSchema = {
25
28
  outputs: {
26
29
  properties: {
27
30
  row: {
28
- type: "object",
29
- customType: "row",
31
+ type: AutomationIOType.OBJECT,
32
+ customType: AutomationCustomIOType.ROW,
30
33
  description: "The row that was updated",
31
34
  },
32
35
  id: {
33
- type: "string",
36
+ type: AutomationIOType.STRING,
34
37
  description: "Row ID - can be used for updating",
35
38
  },
36
39
  revision: {
37
- type: "string",
40
+ type: AutomationIOType.STRING,
38
41
  description: "Revision of row",
39
42
  },
40
43
  },
41
44
  required: ["row", "id"],
42
45
  },
43
46
  },
44
- type: "TRIGGER",
47
+ type: AutomationStepType.TRIGGER,
45
48
  }
@@ -1,4 +1,7 @@
1
1
  import {
2
+ AutomationCustomIOType,
3
+ AutomationIOType,
4
+ AutomationStepType,
2
5
  AutomationTriggerSchema,
3
6
  AutomationTriggerStepId,
4
7
  } from "@budibase/types"
@@ -15,13 +18,13 @@ export const definition: AutomationTriggerSchema = {
15
18
  inputs: {
16
19
  properties: {
17
20
  schemaUrl: {
18
- type: "string",
19
- customType: "webhookUrl",
21
+ type: AutomationIOType.STRING,
22
+ customType: AutomationCustomIOType.WEBHOOK_URL,
20
23
  title: "Schema URL",
21
24
  },
22
25
  triggerUrl: {
23
- type: "string",
24
- customType: "webhookUrl",
26
+ type: AutomationIOType.STRING,
27
+ customType: AutomationCustomIOType.WEBHOOK_URL,
25
28
  title: "Trigger URL",
26
29
  },
27
30
  },
@@ -30,12 +33,12 @@ export const definition: AutomationTriggerSchema = {
30
33
  outputs: {
31
34
  properties: {
32
35
  body: {
33
- type: "object",
36
+ type: AutomationIOType.OBJECT,
34
37
  description: "Body of the request which hit the webhook",
35
38
  },
36
39
  },
37
40
  required: ["body"],
38
41
  },
39
42
  },
40
- type: "TRIGGER",
43
+ type: AutomationStepType.TRIGGER,
41
44
  }
package/src/db/utils.ts CHANGED
@@ -27,6 +27,7 @@ export const isProdAppID = dbCore.isProdAppID
27
27
  export const USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${dbCore.InternalTable.USER_METADATA}${SEPARATOR}`
28
28
  export const LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${dbCore.InternalTable.USER_METADATA}${SEPARATOR}`
29
29
  export const TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`
30
+ export const AUTOMATION_LOG_PREFIX = `${DocumentType.AUTOMATION_LOG}${SEPARATOR}`
30
31
  export const ViewName = dbCore.ViewName
31
32
  export const InternalTables = dbCore.InternalTable
32
33
  export const UNICODE_MAX = dbCore.UNICODE_MAX
@@ -62,7 +62,6 @@ const environment = {
62
62
  // minor
63
63
  SALT_ROUNDS: process.env.SALT_ROUNDS,
64
64
  LOGGER: process.env.LOGGER,
65
- LOG_LEVEL: process.env.LOG_LEVEL,
66
65
  ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
67
66
  AUTOMATION_MAX_ITERATIONS:
68
67
  parseIntSafe(process.env.AUTOMATION_MAX_ITERATIONS) || 200,
@@ -0,0 +1 @@
1
+ export * from "./processors"
@@ -0,0 +1,14 @@
1
+ import userGroupProcessor from "./syncUsers"
2
+ import { docUpdates } from "@budibase/backend-core"
3
+
4
+ export type UpdateCallback = (docId: string) => void
5
+ let started = false
6
+
7
+ export function init(updateCb?: UpdateCallback) {
8
+ if (started) {
9
+ return
10
+ }
11
+ const processors = [userGroupProcessor(updateCb)]
12
+ docUpdates.init(processors)
13
+ started = true
14
+ }
@@ -0,0 +1,35 @@
1
+ import { constants, logging } from "@budibase/backend-core"
2
+ import { sdk as proSdk } from "@budibase/pro"
3
+ import { DocUpdateEvent, UserGroupSyncEvents } from "@budibase/types"
4
+ import { syncUsersToAllApps } from "../../sdk/app/applications/sync"
5
+ import { UpdateCallback } from "./processors"
6
+
7
+ export default function process(updateCb?: UpdateCallback) {
8
+ const processor = async (update: DocUpdateEvent) => {
9
+ try {
10
+ const docId = update.id
11
+ const isGroup = docId.startsWith(constants.DocumentType.GROUP)
12
+ let userIds: string[]
13
+ if (isGroup) {
14
+ const group = await proSdk.groups.get(docId)
15
+ userIds = group.users?.map(user => user._id) || []
16
+ } else {
17
+ userIds = [docId]
18
+ }
19
+ if (userIds.length > 0) {
20
+ await syncUsersToAllApps(userIds)
21
+ }
22
+ if (updateCb) {
23
+ updateCb(docId)
24
+ }
25
+ } catch (err: any) {
26
+ // if something not found - no changes to perform
27
+ if (err?.status === 404) {
28
+ return
29
+ } else {
30
+ logging.logAlert("Failed to perform user/group app sync", err)
31
+ }
32
+ }
33
+ }
34
+ return { events: UserGroupSyncEvents, processor }
35
+ }
@@ -2,4 +2,5 @@ import BudibaseEmitter from "./BudibaseEmitter"
2
2
 
3
3
  const emitter = new BudibaseEmitter()
4
4
 
5
+ export { init } from "./docUpdates"
5
6
  export default emitter
@@ -349,7 +349,7 @@ describe("row api - postgres", () => {
349
349
  },
350
350
  plus: true,
351
351
  source: "POSTGRES",
352
- type: "datasource",
352
+ type: "datasource_plus",
353
353
  _id: expect.any(String),
354
354
  _rev: expect.any(String),
355
355
  createdAt: expect.any(String),
@@ -921,6 +921,7 @@ describe("row api - postgres", () => {
921
921
  [m2mFieldName]: [
922
922
  {
923
923
  _id: row._id,
924
+ primaryDisplay: "Invalid display column",
924
925
  },
925
926
  ],
926
927
  })
@@ -929,6 +930,7 @@ describe("row api - postgres", () => {
929
930
  [m2mFieldName]: [
930
931
  {
931
932
  _id: row._id,
933
+ primaryDisplay: "Invalid display column",
932
934
  },
933
935
  ],
934
936
  })
@@ -79,10 +79,17 @@ function generateSchema(
79
79
  if (!relatedTable) {
80
80
  throw "Referenced table doesn't exist"
81
81
  }
82
- schema.integer(column.foreignKey).unsigned()
82
+ const relatedPrimary = relatedTable.primary[0]
83
+ const externalType = relatedTable.schema[relatedPrimary].externalType
84
+ if (externalType) {
85
+ schema.specificType(column.foreignKey, externalType)
86
+ } else {
87
+ schema.integer(column.foreignKey).unsigned()
88
+ }
89
+
83
90
  schema
84
91
  .foreign(column.foreignKey)
85
- .references(`${tableName}.${relatedTable.primary[0]}`)
92
+ .references(`${tableName}.${relatedPrimary}`)
86
93
  }
87
94
  break
88
95
  }