@budibase/server 2.4.41 → 2.4.42-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 (58) hide show
  1. package/__mocks__/node-fetch.ts +6 -1
  2. package/builder/assets/index.3cb1022d.css +6 -0
  3. package/builder/assets/{index.cf8e1455.js → index.73930391.js} +384 -384
  4. package/builder/index.html +7 -7
  5. package/dist/api/controllers/application.js +28 -24
  6. package/dist/api/controllers/public/metrics.js +113 -0
  7. package/dist/api/controllers/row/external.js +15 -0
  8. package/dist/api/controllers/row/utils.js +4 -3
  9. package/dist/api/controllers/static/index.js +84 -24
  10. package/dist/api/controllers/static/templates/BudibaseApp.svelte +33 -10
  11. package/dist/api/routes/public/index.js +8 -0
  12. package/dist/api/routes/public/metrics.js +30 -0
  13. package/dist/app.js +1 -0
  14. package/dist/integrations/redis.js +1 -1
  15. package/dist/package.json +13 -12
  16. package/dist/sdk/users/utils.js +2 -1
  17. package/dist/tsconfig.build.tsbuildinfo +1 -1
  18. package/dist/utilities/global.js +17 -7
  19. package/jest.config.ts +1 -0
  20. package/package.json +14 -13
  21. package/scripts/test.sh +3 -3
  22. package/specs/openapi.json +39 -0
  23. package/specs/openapi.yaml +169 -0
  24. package/specs/resources/application.ts +11 -0
  25. package/specs/resources/index.ts +2 -0
  26. package/specs/resources/metrics.ts +81 -0
  27. package/src/api/controllers/application.ts +20 -21
  28. package/src/api/controllers/public/metrics.ts +251 -0
  29. package/src/api/controllers/row/external.ts +14 -0
  30. package/src/api/controllers/row/utils.ts +4 -3
  31. package/src/api/controllers/static/index.ts +69 -26
  32. package/src/api/controllers/static/templates/BudibaseApp.svelte +33 -10
  33. package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
  34. package/src/api/routes/public/index.ts +10 -1
  35. package/src/api/routes/public/metrics.ts +28 -0
  36. package/src/api/routes/public/tests/metrics.spec.js +34 -0
  37. package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
  38. package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
  39. package/src/api/routes/tests/appSync.spec.ts +31 -0
  40. package/src/api/routes/tests/internalSearch.spec.js +8 -7
  41. package/src/app.ts +2 -1
  42. package/src/automations/automationUtils.ts +1 -1
  43. package/src/automations/tests/automation.spec.ts +99 -0
  44. package/src/definitions/openapi.ts +15 -0
  45. package/src/integration-test/postgres.spec.ts +46 -52
  46. package/src/integrations/redis.ts +1 -1
  47. package/src/integrations/tests/googlesheets.spec.ts +13 -13
  48. package/src/integrations/tests/redis.spec.ts +9 -5
  49. package/src/middleware/currentapp.ts +2 -2
  50. package/src/sdk/users/utils.ts +4 -1
  51. package/src/tests/jestEnv.ts +1 -0
  52. package/src/tests/jestSetup.ts +5 -1
  53. package/src/tests/utilities/TestConfiguration.ts +13 -0
  54. package/src/tests/utilities/structures.ts +13 -1
  55. package/src/utilities/global.ts +21 -9
  56. package/builder/assets/favicon.e7fc7733.png +0 -0
  57. package/builder/assets/index.b0e3aca6.css +0 -6
  58. package/src/automations/tests/automation.spec.js +0 -84
@@ -1,48 +1,48 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`viewBuilder Calculate and filter creates a view with the calculation statistics and filter schema 1`] = `
4
- Object {
4
+ {
5
5
  "map": "function (doc) {
6
- if ((doc.tableId === \\"14f1c4e94d6a47b682ce89d35d4c78b0\\" && !(
7
- doc[\\"myField\\"] === undefined ||
8
- doc[\\"myField\\"] === null ||
9
- doc[\\"myField\\"] === \\"\\" ||
10
- (Array.isArray(doc[\\"myField\\"]) && doc[\\"myField\\"].length === 0)
11
- )) && (doc[\\"age\\"] > 17)) {
12
- emit(doc[\\"_id\\"], doc[\\"myField\\"]);
6
+ if ((doc.tableId === "14f1c4e94d6a47b682ce89d35d4c78b0" && !(
7
+ doc["myField"] === undefined ||
8
+ doc["myField"] === null ||
9
+ doc["myField"] === "" ||
10
+ (Array.isArray(doc["myField"]) && doc["myField"].length === 0)
11
+ )) && (doc["age"] > 17)) {
12
+ emit(doc["_id"], doc["myField"]);
13
13
  }
14
14
  }",
15
- "meta": Object {
15
+ "meta": {
16
16
  "calculation": "stats",
17
17
  "field": "myField",
18
- "filters": Array [
19
- Object {
18
+ "filters": [
19
+ {
20
20
  "condition": "MT",
21
21
  "key": "age",
22
22
  "value": 17,
23
23
  },
24
24
  ],
25
25
  "groupBy": undefined,
26
- "schema": Object {
27
- "avg": Object {
26
+ "schema": {
27
+ "avg": {
28
28
  "type": "number",
29
29
  },
30
- "count": Object {
30
+ "count": {
31
31
  "type": "number",
32
32
  },
33
- "field": Object {
33
+ "field": {
34
34
  "type": "string",
35
35
  },
36
- "max": Object {
36
+ "max": {
37
37
  "type": "number",
38
38
  },
39
- "min": Object {
39
+ "min": {
40
40
  "type": "number",
41
41
  },
42
- "sum": Object {
42
+ "sum": {
43
43
  "type": "number",
44
44
  },
45
- "sumsqr": Object {
45
+ "sumsqr": {
46
46
  "type": "number",
47
47
  },
48
48
  },
@@ -53,42 +53,42 @@ Object {
53
53
  `;
54
54
 
55
55
  exports[`viewBuilder Calculate creates a view with the calculation statistics schema 1`] = `
56
- Object {
56
+ {
57
57
  "map": "function (doc) {
58
- if ((doc.tableId === \\"14f1c4e94d6a47b682ce89d35d4c78b0\\" && !(
59
- doc[\\"myField\\"] === undefined ||
60
- doc[\\"myField\\"] === null ||
61
- doc[\\"myField\\"] === \\"\\" ||
62
- (Array.isArray(doc[\\"myField\\"]) && doc[\\"myField\\"].length === 0)
58
+ if ((doc.tableId === "14f1c4e94d6a47b682ce89d35d4c78b0" && !(
59
+ doc["myField"] === undefined ||
60
+ doc["myField"] === null ||
61
+ doc["myField"] === "" ||
62
+ (Array.isArray(doc["myField"]) && doc["myField"].length === 0)
63
63
  )) ) {
64
- emit(doc[\\"_id\\"], doc[\\"myField\\"]);
64
+ emit(doc["_id"], doc["myField"]);
65
65
  }
66
66
  }",
67
- "meta": Object {
67
+ "meta": {
68
68
  "calculation": "stats",
69
69
  "field": "myField",
70
- "filters": Array [],
70
+ "filters": [],
71
71
  "groupBy": undefined,
72
- "schema": Object {
73
- "avg": Object {
72
+ "schema": {
73
+ "avg": {
74
74
  "type": "number",
75
75
  },
76
- "count": Object {
76
+ "count": {
77
77
  "type": "number",
78
78
  },
79
- "field": Object {
79
+ "field": {
80
80
  "type": "string",
81
81
  },
82
- "max": Object {
82
+ "max": {
83
83
  "type": "number",
84
84
  },
85
- "min": Object {
85
+ "min": {
86
86
  "type": "number",
87
87
  },
88
- "sum": Object {
88
+ "sum": {
89
89
  "type": "number",
90
90
  },
91
- "sumsqr": Object {
91
+ "sumsqr": {
92
92
  "type": "number",
93
93
  },
94
94
  },
@@ -99,22 +99,22 @@ Object {
99
99
  `;
100
100
 
101
101
  exports[`viewBuilder Filter creates a view with multiple filters and conjunctions 1`] = `
102
- Object {
102
+ {
103
103
  "map": "function (doc) {
104
- if (doc.tableId === \\"14f1c4e94d6a47b682ce89d35d4c78b0\\" && (doc[\\"Name\\"] === \\"Test\\" || doc[\\"Yes\\"] > \\"Value\\")) {
105
- emit(doc[\\"_id\\"], doc[\\"undefined\\"]);
104
+ if (doc.tableId === "14f1c4e94d6a47b682ce89d35d4c78b0" && (doc["Name"] === "Test" || doc["Yes"] > "Value")) {
105
+ emit(doc["_id"], doc["undefined"]);
106
106
  }
107
107
  }",
108
- "meta": Object {
108
+ "meta": {
109
109
  "calculation": undefined,
110
110
  "field": undefined,
111
- "filters": Array [
112
- Object {
111
+ "filters": [
112
+ {
113
113
  "condition": "EQUALS",
114
114
  "key": "Name",
115
115
  "value": "Test",
116
116
  },
117
- Object {
117
+ {
118
118
  "condition": "MT",
119
119
  "conjunction": "OR",
120
120
  "key": "Yes",
@@ -129,16 +129,16 @@ Object {
129
129
  `;
130
130
 
131
131
  exports[`viewBuilder Group By creates a view emitting the group by field 1`] = `
132
- Object {
132
+ {
133
133
  "map": "function (doc) {
134
- if (doc.tableId === \\"14f1c4e94d6a47b682ce89d35d4c78b0\\" ) {
135
- emit(doc[\\"age\\"], doc[\\"score\\"]);
134
+ if (doc.tableId === "14f1c4e94d6a47b682ce89d35d4c78b0" ) {
135
+ emit(doc["age"], doc["score"]);
136
136
  }
137
137
  }",
138
- "meta": Object {
138
+ "meta": {
139
139
  "calculation": undefined,
140
140
  "field": "score",
141
- "filters": Array [],
141
+ "filters": [],
142
142
  "groupBy": "age",
143
143
  "schema": null,
144
144
  "tableId": "14f1c4e94d6a47b682ce89d35d4c78b0",
@@ -1,4 +1,5 @@
1
1
  import appEndpoints from "./applications"
2
+ import metricEndpoints from "./metrics"
2
3
  import queryEndpoints from "./queries"
3
4
  import tableEndpoints from "./tables"
4
5
  import rowEndpoints from "./rows"
@@ -12,7 +13,7 @@ import env from "../../../environment"
12
13
  // below imports don't have declaration files
13
14
  const Router = require("@koa/router")
14
15
  const { RateLimit, Stores } = require("koa2-ratelimit")
15
- import { redis, permissions } from "@budibase/backend-core"
16
+ import { middleware, redis, permissions } from "@budibase/backend-core"
16
17
  const { PermissionType, PermissionLevel } = permissions
17
18
 
18
19
  const PREFIX = "/api/public/v1"
@@ -91,6 +92,13 @@ function addToRouter(endpoints: any) {
91
92
  }
92
93
  }
93
94
 
95
+ function applyAdminRoutes(endpoints: any) {
96
+ addMiddleware(endpoints.read, middleware.builderOrAdmin)
97
+ addMiddleware(endpoints.write, middleware.builderOrAdmin)
98
+ addToRouter(endpoints.read)
99
+ addToRouter(endpoints.write)
100
+ }
101
+
94
102
  function applyRoutes(
95
103
  endpoints: any,
96
104
  permType: string,
@@ -119,6 +127,7 @@ function applyRoutes(
119
127
  addToRouter(endpoints.write)
120
128
  }
121
129
 
130
+ applyAdminRoutes(metricEndpoints)
122
131
  applyRoutes(appEndpoints, PermissionType.APP, "appId")
123
132
  applyRoutes(tableEndpoints, PermissionType.TABLE, "tableId")
124
133
  applyRoutes(userEndpoints, PermissionType.USER, "userId")
@@ -0,0 +1,28 @@
1
+ import controller from "../../controllers/public/metrics"
2
+ import Endpoint from "./utils/Endpoint"
3
+
4
+ const read = []
5
+
6
+ /**
7
+ * @openapi
8
+ * /metrics:
9
+ * get:
10
+ * operationId: metricsGet
11
+ * summary: Retrieve Budibase tenant metrics
12
+ * description: Output metrics in OpenMetrics format compatible with Prometheus
13
+ * tags:
14
+ * - metrics
15
+ * responses:
16
+ * 200:
17
+ * description: Returns tenant metrics.
18
+ * content:
19
+ * text/plain:
20
+ * schema:
21
+ * type: string
22
+ * examples:
23
+ * metrics:
24
+ * $ref: '#/components/examples/metrics'
25
+ */
26
+ read.push(new Endpoint("get", "/metrics", controller.fetch))
27
+
28
+ export default { read }
@@ -0,0 +1,34 @@
1
+ const setup = require("../../tests/utilities")
2
+
3
+ jest.setTimeout(30000)
4
+
5
+ describe("/metrics", () => {
6
+ let request = setup.getRequest()
7
+ let config = setup.getConfig()
8
+
9
+ afterAll(setup.afterAll)
10
+
11
+ // For some reason this cannot be a beforeAll or the test "should be able to update the user" fail
12
+ beforeEach(async () => {
13
+ await config.init()
14
+ })
15
+
16
+ describe("get", () => {
17
+ it("returns a list of metrics", async () => {
18
+ const res = await request
19
+ .get(`/api/public/v1/metrics`)
20
+ .set(config.defaultHeaders())
21
+ .expect("Content-Type", /text\/plain/)
22
+ .expect(200)
23
+ expect(res.text).toContain("budibase_tenant_user_count")
24
+ })
25
+
26
+ it("endpoint should not be publicly exposed", async () => {
27
+ await request
28
+ .get(`/api/public/v1/metrics`)
29
+ .set(config.publicHeaders())
30
+ .expect(403)
31
+ })
32
+ })
33
+
34
+ })
@@ -1,21 +1,21 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`/datasources fetch returns all the datasources from the server 1`] = `
4
- Array [
5
- Object {
6
- "config": Object {},
7
- "entities": Array [
8
- Object {
4
+ [
5
+ {
6
+ "config": {},
7
+ "entities": [
8
+ {
9
9
  "_id": "ta_users",
10
10
  "_rev": "1-2375e1bc58aeec664dc1b1f04ad43e44",
11
11
  "createdAt": "2020-01-01T00:00:00.000Z",
12
12
  "name": "Users",
13
13
  "primaryDisplay": "email",
14
- "schema": Object {
15
- "email": Object {
16
- "constraints": Object {
14
+ "schema": {
15
+ "email": {
16
+ "constraints": {
17
17
  "email": true,
18
- "length": Object {
18
+ "length": {
19
19
  "maximum": "",
20
20
  },
21
21
  "presence": true,
@@ -25,8 +25,8 @@ Array [
25
25
  "name": "email",
26
26
  "type": "string",
27
27
  },
28
- "firstName": Object {
29
- "constraints": Object {
28
+ "firstName": {
29
+ "constraints": {
30
30
  "presence": false,
31
31
  "type": "string",
32
32
  },
@@ -34,8 +34,8 @@ Array [
34
34
  "name": "firstName",
35
35
  "type": "string",
36
36
  },
37
- "lastName": Object {
38
- "constraints": Object {
37
+ "lastName": {
38
+ "constraints": {
39
39
  "presence": false,
40
40
  "type": "string",
41
41
  },
@@ -43,9 +43,9 @@ Array [
43
43
  "name": "lastName",
44
44
  "type": "string",
45
45
  },
46
- "roleId": Object {
47
- "constraints": Object {
48
- "inclusion": Array [
46
+ "roleId": {
47
+ "constraints": {
48
+ "inclusion": [
49
49
  "ADMIN",
50
50
  "POWER",
51
51
  "BASIC",
@@ -58,9 +58,9 @@ Array [
58
58
  "name": "roleId",
59
59
  "type": "options",
60
60
  },
61
- "status": Object {
62
- "constraints": Object {
63
- "inclusion": Array [
61
+ "status": {
62
+ "constraints": {
63
+ "inclusion": [
64
64
  "active",
65
65
  "inactive",
66
66
  ],
@@ -74,15 +74,15 @@ Array [
74
74
  },
75
75
  "type": "table",
76
76
  "updatedAt": "2020-01-01T00:00:00.000Z",
77
- "views": Object {},
77
+ "views": {},
78
78
  },
79
79
  ],
80
80
  "name": "Budibase DB",
81
81
  "source": "BUDIBASE",
82
82
  "type": "budibase",
83
83
  },
84
- Object {
85
- "config": Object {},
84
+ {
85
+ "config": {},
86
86
  "createdAt": "2020-01-01T00:00:00.000Z",
87
87
  "name": "Test",
88
88
  "source": "POSTGRES",
@@ -1,8 +1,8 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`/views query returns data for the created view 1`] = `
4
- Array [
5
- Object {
4
+ [
5
+ {
6
6
  "avg": 2333.3333333333335,
7
7
  "count": 3,
8
8
  "group": null,
@@ -15,8 +15,8 @@ Array [
15
15
  `;
16
16
 
17
17
  exports[`/views query returns data for the created view using a group by 1`] = `
18
- Array [
19
- Object {
18
+ [
19
+ {
20
20
  "avg": 1500,
21
21
  "count": 2,
22
22
  "group": "One",
@@ -25,7 +25,7 @@ Array [
25
25
  "sum": 3000,
26
26
  "sumsqr": 5000000,
27
27
  },
28
- Object {
28
+ {
29
29
  "avg": 4000,
30
30
  "count": 1,
31
31
  "group": "Two",
@@ -0,0 +1,31 @@
1
+ import * as setup from "./utilities"
2
+ import { roles, db as dbCore } from "@budibase/backend-core"
3
+
4
+ describe("/api/applications/:appId/sync", () => {
5
+ let request = setup.getRequest()
6
+ let config = setup.getConfig()
7
+ let app
8
+
9
+ afterAll(setup.afterAll)
10
+
11
+ beforeAll(async () => {
12
+ app = await config.init()
13
+ // create some users which we will use throughout the tests
14
+ await config.createUser({
15
+ email: "sync1@test.com",
16
+ roles: {
17
+ [app._id!]: roles.BUILTIN_ROLE_IDS.BASIC,
18
+ },
19
+ })
20
+ })
21
+
22
+ async function getUserMetadata() {
23
+ const { rows } = await config.searchRows(dbCore.InternalTable.USER_METADATA)
24
+ return rows
25
+ }
26
+
27
+ it("make sure that user metadata is correctly sync'd", async () => {
28
+ const rows = await getUserMetadata()
29
+ expect(rows.length).toBe(1)
30
+ })
31
+ })
@@ -1,6 +1,7 @@
1
+ const fetch = require("node-fetch")
2
+ fetch.mockSearch()
1
3
  const search = require("../../controllers/row/internalSearch")
2
4
  // this will be mocked out for _search endpoint
3
- const fetch = require("node-fetch")
4
5
  const PARAMS = {
5
6
  tableId: "ta_12345679abcdef",
6
7
  version: "1",
@@ -20,7 +21,7 @@ function checkLucene(resp, expected, params = PARAMS) {
20
21
  expect(json.bookmark).toBe(PARAMS.bookmark)
21
22
  }
22
23
  expect(json.include_docs).toBe(true)
23
- expect(json.q).toBe(`(${expected}) AND tableId:"${params.tableId}"`)
24
+ expect(json.q).toBe(`${expected} AND tableId:"${params.tableId}"`)
24
25
  expect(json.limit).toBe(params.limit || 50)
25
26
  }
26
27
 
@@ -59,7 +60,7 @@ describe("internal search", () => {
59
60
  "column": "1",
60
61
  }
61
62
  }, PARAMS)
62
- checkLucene(response, `column:"2" OR !column:"1"`)
63
+ checkLucene(response, `(column:"2" OR !column:"1")`)
63
64
  })
64
65
 
65
66
  it("test AND query", async () => {
@@ -71,7 +72,7 @@ describe("internal search", () => {
71
72
  "column": "1",
72
73
  }
73
74
  }, PARAMS)
74
- checkLucene(response, `*:* AND column:"2" AND !column:"1"`)
75
+ checkLucene(response, `(*:* AND column:"2" AND !column:"1")`)
75
76
  })
76
77
 
77
78
  it("test pagination query", async () => {
@@ -132,7 +133,7 @@ describe("internal search", () => {
132
133
  "colArr": [1, 2, 3],
133
134
  },
134
135
  }, PARAMS)
135
- checkLucene(response, `*:* AND column:a AND colArr:(1 AND 2 AND 3)`, PARAMS)
136
+ checkLucene(response, `(*:* AND column:a AND colArr:(1 AND 2 AND 3))`, PARAMS)
136
137
  })
137
138
 
138
139
  it("test multiple of same column", async () => {
@@ -144,7 +145,7 @@ describe("internal search", () => {
144
145
  "3:column": "c",
145
146
  },
146
147
  }, PARAMS)
147
- checkLucene(response, `column:"a" OR column:"b" OR column:"c"`, PARAMS)
148
+ checkLucene(response, `(column:"a" OR column:"b" OR column:"c")`, PARAMS)
148
149
  })
149
150
 
150
151
  it("check a weird case for lucene building", async () => {
@@ -191,6 +192,6 @@ describe("internal search", () => {
191
192
  expect(json.bookmark).toBe(PARAMS.bookmark)
192
193
  }
193
194
  expect(json.include_docs).toBe(true)
194
- expect(json.q).toBe(`(*:* AND column:"1") AND tableId:${PARAMS.tableId}`)
195
+ expect(json.q).toBe(`*:* AND column:"1" AND tableId:${PARAMS.tableId}`)
195
196
  })
196
197
  })
package/src/app.ts CHANGED
@@ -27,7 +27,7 @@ import * as api from "./api"
27
27
  import * as automations from "./automations"
28
28
  import { Thread } from "./threads"
29
29
  import * as redis from "./utilities/redis"
30
- import { events, logging, middleware } from "@budibase/backend-core"
30
+ import { events, logging, middleware, timers } from "@budibase/backend-core"
31
31
  import { initialise as initialiseWebsockets } from "./websocket"
32
32
  import { startup } from "./startup"
33
33
  const Sentry = require("@sentry/node")
@@ -84,6 +84,7 @@ server.on("close", async () => {
84
84
  }
85
85
  shuttingDown = true
86
86
  console.log("Server Closed")
87
+ timers.cleanup()
87
88
  await automations.shutdown()
88
89
  await redis.shutdown()
89
90
  events.shutdown()
@@ -23,7 +23,7 @@ import { LoopStep, LoopStepType, LoopInput } from "../definitions/automations"
23
23
  * @returns {object} The inputs object which has had all the various types supported by this function converted to their
24
24
  * primitive types.
25
25
  */
26
- export function cleanInputValues(inputs: Record<string, any>, schema: any) {
26
+ export function cleanInputValues(inputs: Record<string, any>, schema?: any) {
27
27
  if (schema == null) {
28
28
  return inputs
29
29
  }
@@ -0,0 +1,99 @@
1
+ jest.mock("../../threads/automation")
2
+ jest.mock("../../utilities/redis", () => ({
3
+ init: jest.fn(),
4
+ checkTestFlag: () => {
5
+ return false
6
+ },
7
+ }))
8
+
9
+ jest.spyOn(global.console, "error")
10
+
11
+ import "../../environment"
12
+ import * as automation from "../index"
13
+ import * as thread from "../../threads/automation"
14
+ import * as triggers from "../triggers"
15
+ import { basicAutomation } from "../../tests/utilities/structures"
16
+ import { wait } from "../../utilities"
17
+ import { makePartial } from "../../tests/utilities"
18
+ import { cleanInputValues } from "../automationUtils"
19
+ import * as setup from "./utilities"
20
+ import { Automation } from "@budibase/types"
21
+
22
+ describe("Run through some parts of the automations system", () => {
23
+ let config = setup.getConfig()
24
+
25
+ beforeAll(async () => {
26
+ await automation.init()
27
+ await config.init()
28
+ })
29
+
30
+ afterAll(async () => {
31
+ await automation.shutdown()
32
+ setup.afterAll()
33
+ })
34
+
35
+ it("should be able to init in builder", async () => {
36
+ const automation: Automation = {
37
+ ...basicAutomation(),
38
+ appId: config.appId,
39
+ }
40
+ const fields: any = { a: 1, appId: config.appId }
41
+ await triggers.externalTrigger(automation, fields)
42
+ await wait(100)
43
+ expect(thread.execute).toHaveBeenCalled()
44
+ })
45
+
46
+ it("should check coercion", async () => {
47
+ const table = await config.createTable()
48
+ const automation: any = basicAutomation()
49
+ automation.definition.trigger.inputs.tableId = table._id
50
+ automation.definition.trigger.stepId = "APP"
51
+ automation.definition.trigger.inputs.fields = { a: "number" }
52
+ const fields: any = {
53
+ appId: config.getAppId(),
54
+ fields: {
55
+ a: "1",
56
+ },
57
+ }
58
+ await triggers.externalTrigger(automation, fields)
59
+ await wait(100)
60
+ expect(thread.execute).toHaveBeenCalledWith(
61
+ makePartial({
62
+ data: {
63
+ event: {
64
+ fields: {
65
+ a: 1,
66
+ },
67
+ },
68
+ },
69
+ }),
70
+ expect.any(Function)
71
+ )
72
+ })
73
+
74
+ it("should be able to clean inputs with the utilities", () => {
75
+ // can't clean without a schema
76
+ let output = cleanInputValues({ a: "1" })
77
+ expect(output.a).toBe("1")
78
+ output = cleanInputValues(
79
+ { a: "1", b: "true", c: "false", d: 1, e: "help" },
80
+ {
81
+ properties: {
82
+ a: {
83
+ type: "number",
84
+ },
85
+ b: {
86
+ type: "boolean",
87
+ },
88
+ c: {
89
+ type: "boolean",
90
+ },
91
+ },
92
+ }
93
+ )
94
+ expect(output.a).toBe(1)
95
+ expect(output.b).toBe(true)
96
+ expect(output.c).toBe(false)
97
+ expect(output.d).toBe(1)
98
+ })
99
+ })
@@ -22,6 +22,10 @@ export interface paths {
22
22
  /** Based on application properties (currently only name) search for applications. */
23
23
  post: operations["appSearch"];
24
24
  };
25
+ "/metrics": {
26
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
27
+ get: operations["metricsGet"];
28
+ };
25
29
  "/queries/{queryId}": {
26
30
  /** Queries which have been created within a Budibase app can be executed using this, */
27
31
  post: operations["queryExecute"];
@@ -844,6 +848,17 @@ export interface operations {
844
848
  };
845
849
  };
846
850
  };
851
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
852
+ metricsGet: {
853
+ responses: {
854
+ /** Returns tenant metrics. */
855
+ 200: {
856
+ content: {
857
+ "text/plain": string;
858
+ };
859
+ };
860
+ };
861
+ };
847
862
  /** Queries which have been created within a Budibase app can be executed using this, */
848
863
  queryExecute: {
849
864
  parameters: {