@budibase/worker 2.2.26 → 2.2.27-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 (172) hide show
  1. package/Dockerfile +1 -1
  2. package/__mocks__/node-fetch.ts +23 -0
  3. package/coverage/clover.xml +1423 -1379
  4. package/coverage/coverage-final.json +83 -77
  5. package/coverage/lcov-report/index.html +140 -140
  6. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +52 -52
  7. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +167 -224
  8. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +4 -4
  9. package/coverage/lcov-report/src/api/controllers/global/events.ts.html +136 -0
  10. package/coverage/lcov-report/src/api/controllers/global/index.html +83 -68
  11. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +16 -16
  12. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +69 -69
  13. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +20 -20
  14. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +54 -54
  15. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +83 -44
  16. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +9 -9
  17. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +5 -5
  18. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +4 -4
  19. package/coverage/lcov-report/src/api/controllers/system/index.html +11 -11
  20. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +5 -5
  21. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +4 -4
  22. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +5 -5
  23. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +7 -7
  24. package/coverage/lcov-report/src/api/index.html +1 -1
  25. package/coverage/lcov-report/src/api/index.ts.html +42 -30
  26. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +14 -14
  27. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +25 -25
  28. package/coverage/lcov-report/src/api/routes/global/email.ts.html +13 -13
  29. package/coverage/lcov-report/src/api/routes/global/events.ts.html +109 -0
  30. package/coverage/lcov-report/src/api/routes/global/index.html +37 -22
  31. package/coverage/lcov-report/src/api/routes/global/license.ts.html +9 -9
  32. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +10 -10
  33. package/coverage/lcov-report/src/api/routes/global/self.ts.html +11 -11
  34. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +14 -14
  35. package/coverage/lcov-report/src/api/routes/global/users.ts.html +62 -20
  36. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +12 -12
  37. package/coverage/lcov-report/src/api/routes/index.html +7 -7
  38. package/coverage/lcov-report/src/api/routes/index.ts.html +29 -23
  39. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +10 -10
  40. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +9 -9
  41. package/coverage/lcov-report/src/api/routes/system/index.html +15 -15
  42. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +10 -10
  43. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +9 -9
  44. package/coverage/lcov-report/src/api/routes/system/status.ts.html +9 -9
  45. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +10 -10
  46. package/coverage/lcov-report/src/api/routes/validation/index.html +3 -3
  47. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
  48. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +14 -14
  49. package/coverage/lcov-report/src/constants/index.html +17 -17
  50. package/coverage/lcov-report/src/constants/index.ts.html +77 -53
  51. package/coverage/lcov-report/src/constants/templates/index.html +18 -18
  52. package/coverage/lcov-report/src/constants/templates/index.ts.html +42 -42
  53. package/coverage/lcov-report/src/db/index.html +17 -17
  54. package/coverage/lcov-report/src/db/index.ts.html +18 -18
  55. package/coverage/lcov-report/src/environment.ts.html +45 -30
  56. package/coverage/lcov-report/src/index.html +27 -27
  57. package/coverage/lcov-report/src/index.ts.html +55 -55
  58. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +5 -5
  59. package/coverage/lcov-report/src/middleware/index.html +1 -1
  60. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +9 -9
  61. package/coverage/lcov-report/src/migrations/functions/index.html +11 -11
  62. package/coverage/lcov-report/src/migrations/index.html +15 -15
  63. package/coverage/lcov-report/src/migrations/index.ts.html +27 -27
  64. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +13 -13
  65. package/coverage/lcov-report/src/sdk/accounts/index.html +13 -13
  66. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
  67. package/coverage/lcov-report/src/sdk/index.html +5 -5
  68. package/coverage/lcov-report/src/sdk/index.ts.html +6 -6
  69. package/coverage/lcov-report/src/sdk/users/events.ts.html +82 -58
  70. package/coverage/lcov-report/src/sdk/users/index.html +28 -28
  71. package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
  72. package/coverage/lcov-report/src/sdk/users/users.ts.html +174 -120
  73. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +221 -107
  74. package/coverage/lcov-report/src/tests/api/accounts.ts.html +7 -7
  75. package/coverage/lcov-report/src/tests/api/auth.ts.html +25 -13
  76. package/coverage/lcov-report/src/tests/api/base.ts.html +5 -5
  77. package/coverage/lcov-report/src/tests/api/configs.ts.html +11 -11
  78. package/coverage/lcov-report/src/tests/api/email.ts.html +6 -6
  79. package/coverage/lcov-report/src/tests/api/environment.ts.html +6 -6
  80. package/coverage/lcov-report/src/tests/api/groups.ts.html +163 -0
  81. package/coverage/lcov-report/src/tests/api/index.html +91 -31
  82. package/coverage/lcov-report/src/tests/api/index.ts.html +62 -29
  83. package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
  84. package/coverage/lcov-report/src/tests/api/migrations.ts.html +8 -8
  85. package/coverage/lcov-report/src/tests/api/restore.ts.html +7 -7
  86. package/coverage/lcov-report/src/tests/api/roles.ts.html +181 -0
  87. package/coverage/lcov-report/src/tests/api/self.ts.html +7 -7
  88. package/coverage/lcov-report/src/tests/api/status.ts.html +6 -6
  89. package/coverage/lcov-report/src/tests/api/templates.ts.html +175 -0
  90. package/coverage/lcov-report/src/tests/api/tenants.ts.html +10 -10
  91. package/coverage/lcov-report/src/tests/api/users.ts.html +30 -27
  92. package/coverage/lcov-report/src/tests/controllers.ts.html +14 -14
  93. package/coverage/lcov-report/src/tests/index.html +34 -34
  94. package/coverage/lcov-report/src/tests/index.ts.html +19 -55
  95. package/coverage/lcov-report/src/tests/mocks/{email.js.html → email.ts.html} +5 -5
  96. package/coverage/lcov-report/src/tests/mocks/index.html +6 -6
  97. package/coverage/lcov-report/src/tests/mocks/index.ts.html +10 -10
  98. package/coverage/lcov-report/src/tests/structures/configs.ts.html +11 -11
  99. package/coverage/lcov-report/src/tests/structures/groups.ts.html +15 -15
  100. package/coverage/lcov-report/src/tests/structures/index.html +26 -26
  101. package/coverage/lcov-report/src/tests/structures/index.ts.html +16 -22
  102. package/coverage/lcov-report/src/tests/structures/users.ts.html +16 -16
  103. package/coverage/lcov-report/src/utilities/appService.ts.html +45 -18
  104. package/coverage/lcov-report/src/utilities/email.ts.html +28 -28
  105. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +4 -4
  106. package/coverage/lcov-report/src/utilities/index.html +27 -27
  107. package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
  108. package/coverage/lcov-report/src/utilities/redis.ts.html +20 -20
  109. package/coverage/lcov-report/src/utilities/templates.ts.html +6 -6
  110. package/coverage/lcov-report/src/utilities/users.ts.html +7 -7
  111. package/coverage/lcov.info +2826 -2609
  112. package/jest-testcontainers-config.js +8 -0
  113. package/jest.config.ts +10 -4
  114. package/package.json +11 -7
  115. package/scripts/dev/manage.js +2 -2
  116. package/src/api/controllers/global/auth.ts +1 -1
  117. package/src/api/controllers/global/configs.ts +112 -131
  118. package/src/api/controllers/global/events.ts +17 -0
  119. package/src/api/controllers/global/users.ts +14 -1
  120. package/src/api/index.ts +4 -0
  121. package/src/api/routes/global/auth.ts +1 -1
  122. package/src/api/routes/global/configs.ts +7 -7
  123. package/src/api/routes/global/email.ts +1 -1
  124. package/src/api/routes/global/events.ts +8 -0
  125. package/src/api/routes/global/license.ts +1 -1
  126. package/src/api/routes/global/roles.ts +1 -1
  127. package/src/api/routes/global/self.ts +1 -1
  128. package/src/api/routes/global/templates.ts +1 -1
  129. package/src/api/routes/global/tests/auth.spec.ts +30 -22
  130. package/src/api/routes/global/tests/configs.spec.ts +114 -94
  131. package/src/api/routes/global/tests/groups.spec.ts +58 -0
  132. package/src/api/routes/global/tests/license.spec.ts +0 -2
  133. package/src/api/routes/global/tests/roles.spec.ts +71 -5
  134. package/src/api/routes/global/tests/templates.spec.ts +81 -9
  135. package/src/api/routes/global/tests/users.spec.ts +35 -36
  136. package/src/api/routes/global/users.ts +15 -1
  137. package/src/api/routes/global/workspaces.ts +1 -1
  138. package/src/api/routes/index.ts +2 -0
  139. package/src/api/routes/system/accounts.ts +1 -1
  140. package/src/api/routes/system/environment.ts +1 -1
  141. package/src/api/routes/system/migrations.ts +1 -1
  142. package/src/api/routes/system/restore.ts +1 -1
  143. package/src/api/routes/system/status.ts +1 -1
  144. package/src/api/routes/system/tenants.ts +1 -1
  145. package/src/api/routes/system/tests/environment.spec.ts +1 -1
  146. package/src/constants/index.ts +13 -5
  147. package/src/db/index.ts +1 -1
  148. package/src/environment.ts +6 -1
  149. package/src/index.ts +5 -5
  150. package/src/middleware/cloudRestricted.ts +1 -1
  151. package/src/sdk/users/events.ts +8 -0
  152. package/src/sdk/users/users.ts +23 -5
  153. package/src/tests/TestConfiguration.ts +52 -14
  154. package/src/tests/api/auth.ts +7 -3
  155. package/src/tests/api/configs.ts +2 -2
  156. package/src/tests/api/groups.ts +26 -0
  157. package/src/tests/api/index.ts +12 -1
  158. package/src/tests/api/license.ts +17 -0
  159. package/src/tests/api/roles.ts +32 -0
  160. package/src/tests/api/templates.ts +30 -0
  161. package/src/tests/api/users.ts +4 -3
  162. package/src/tests/index.ts +6 -18
  163. package/src/tests/jestEnv.ts +11 -0
  164. package/src/tests/jestSetup.ts +8 -15
  165. package/src/tests/mocks/{email.js → email.ts} +1 -1
  166. package/src/tests/mocks/index.ts +4 -4
  167. package/src/tests/structures/configs.ts +2 -2
  168. package/src/tests/structures/groups.ts +1 -1
  169. package/src/tests/structures/index.ts +3 -5
  170. package/src/tests/structures/users.ts +1 -1
  171. package/src/utilities/appService.ts +12 -3
  172. package/tsconfig.json +2 -2
@@ -10,7 +10,10 @@ import { MigrationAPI } from "./migrations"
10
10
  import { StatusAPI } from "./status"
11
11
  import { RestoreAPI } from "./restore"
12
12
  import { TenantAPI } from "./tenants"
13
-
13
+ import { GroupsAPI } from "./groups"
14
+ import { RolesAPI } from "./roles"
15
+ import { TemplatesAPI } from "./templates"
16
+ import { LicenseAPI } from "./license"
14
17
  export default class API {
15
18
  accounts: AccountAPI
16
19
  auth: AuthAPI
@@ -23,6 +26,10 @@ export default class API {
23
26
  status: StatusAPI
24
27
  restore: RestoreAPI
25
28
  tenants: TenantAPI
29
+ groups: GroupsAPI
30
+ roles: RolesAPI
31
+ templates: TemplatesAPI
32
+ license: LicenseAPI
26
33
 
27
34
  constructor(config: TestConfiguration) {
28
35
  this.accounts = new AccountAPI(config)
@@ -36,5 +43,9 @@ export default class API {
36
43
  this.status = new StatusAPI(config)
37
44
  this.restore = new RestoreAPI(config)
38
45
  this.tenants = new TenantAPI(config)
46
+ this.groups = new GroupsAPI(config)
47
+ this.roles = new RolesAPI(config)
48
+ this.templates = new TemplatesAPI(config)
49
+ this.license = new LicenseAPI(config)
39
50
  }
40
51
  }
@@ -0,0 +1,17 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI } from "./base"
3
+
4
+ export class LicenseAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ activate = async (licenseKey: string) => {
10
+ return this.request
11
+ .post("/api/global/license/activate")
12
+ .send({ licenseKey: licenseKey })
13
+ .set(this.config.defaultHeaders())
14
+ .expect("Content-Type", /json/)
15
+ .expect(200)
16
+ }
17
+ }
@@ -0,0 +1,32 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
+
4
+ export class RolesAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ get = (opts?: TestAPIOpts) => {
10
+ return this.request
11
+ .get(`/api/global/roles`)
12
+ .set(this.config.defaultHeaders())
13
+ .expect("Content-Type", /json/)
14
+ .expect(opts?.status ? opts.status : 200)
15
+ }
16
+
17
+ find = (appId: string, opts?: TestAPIOpts) => {
18
+ return this.request
19
+ .get(`/api/global/roles/${appId}`)
20
+ .set(this.config.defaultHeaders())
21
+ .expect("Content-Type", /json/)
22
+ .expect(opts?.status ? opts.status : 200)
23
+ }
24
+
25
+ remove = (appId: string, opts?: TestAPIOpts) => {
26
+ return this.request
27
+ .delete(`/api/global/roles/${appId}`)
28
+ .set(this.config.defaultHeaders())
29
+ .expect("Content-Type", /json/)
30
+ .expect(opts?.status ? opts.status : 200)
31
+ }
32
+ }
@@ -0,0 +1,30 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
+
4
+ export class TemplatesAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ definitions = (opts?: TestAPIOpts) => {
10
+ return this.request
11
+ .get(`/api/global/template/definitions`)
12
+ .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
13
+ .expect(opts?.status ? opts.status : 200)
14
+ }
15
+
16
+ getTemplate = (opts?: TestAPIOpts) => {
17
+ return this.request
18
+ .get(`/api/global/template`)
19
+ .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
20
+ .expect(opts?.status ? opts.status : 200)
21
+ }
22
+
23
+ saveTemplate = (data: any, opts?: TestAPIOpts) => {
24
+ return this.request
25
+ .post(`/api/global/template`)
26
+ .send(data)
27
+ .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
28
+ .expect(opts?.status ? opts.status : 200)
29
+ }
30
+ }
@@ -5,7 +5,7 @@ import {
5
5
  User,
6
6
  CreateAdminUserRequest,
7
7
  } from "@budibase/types"
8
- import * as structures from "../structures"
8
+ import structures from "../structures"
9
9
  import { generator } from "@budibase/backend-core/tests"
10
10
  import TestConfiguration from "../TestConfiguration"
11
11
  import { TestAPI, TestAPIOpts } from "./base"
@@ -26,8 +26,8 @@ export class UserAPI extends TestAPI {
26
26
  email,
27
27
  })
28
28
  .set(this.config.defaultHeaders())
29
- .expect("Content-Type", /json/)
30
29
  .expect(status)
30
+ .expect("Content-Type", /json/)
31
31
 
32
32
  if (status !== 200) {
33
33
  return { code: undefined, res }
@@ -48,6 +48,7 @@ export class UserAPI extends TestAPI {
48
48
  .send({
49
49
  password: "newpassword",
50
50
  inviteCode: code,
51
+ firstName: "Ted",
51
52
  })
52
53
  .expect("Content-Type", /json/)
53
54
  .expect(200)
@@ -99,7 +100,7 @@ export class UserAPI extends TestAPI {
99
100
  request = {
100
101
  email: structures.email(),
101
102
  password: generator.string(),
102
- tenantId: structures.uuid(),
103
+ tenantId: structures.tenant.id(),
103
104
  }
104
105
  }
105
106
  const res = await this.request
@@ -1,18 +1,6 @@
1
- import mocks from "./mocks"
2
- import { generator } from "@budibase/backend-core/tests"
3
- import TestConfiguration from "./TestConfiguration"
4
- import structures from "./structures"
5
- import API from "./api"
6
- import { v4 as uuid } from "uuid"
7
-
8
- const pkg = {
9
- structures,
10
- generator,
11
- uuid,
12
- TENANT_1: structures.TENANT_1,
13
- mocks,
14
- TestConfiguration,
15
- API,
16
- }
17
-
18
- export = pkg
1
+ export { default as mocks } from "./mocks"
2
+ export { generator } from "@budibase/backend-core/tests"
3
+ export { default as TestConfiguration } from "./TestConfiguration"
4
+ export { default as structures } from "./structures"
5
+ export { default as API } from "./api"
6
+ export { v4 as uuid } from "uuid"
@@ -0,0 +1,11 @@
1
+ process.env.SELF_HOSTED = "0"
2
+ process.env.NODE_ENV = "jest"
3
+ process.env.JWT_SECRET = "test-jwtsecret"
4
+ process.env.LOG_LEVEL = "silent"
5
+ process.env.MULTI_TENANCY = "1"
6
+ process.env.MINIO_URL = "http://localhost"
7
+ process.env.MINIO_ACCESS_KEY = "test"
8
+ process.env.MINIO_SECRET_KEY = "test"
9
+ process.env.PLATFORM_URL = "http://localhost:10000"
10
+ process.env.INTERNAL_API_KEY = "tet"
11
+ process.env.DISABLE_ACCOUNT_PORTAL = "0"
@@ -1,18 +1,7 @@
1
- import env from "../environment"
2
-
3
- env._set("SELF_HOSTED", "0")
4
- env._set("NODE_ENV", "jest")
5
- env._set("JWT_SECRET", "test-jwtsecret")
6
- env._set("LOG_LEVEL", "silent")
7
- env._set("MULTI_TENANCY", true)
8
- env._set("MINIO_URL", "http://localhost")
9
- env._set("MINIO_ACCESS_KEY", "test")
10
- env._set("MINIO_SECRET_KEY", "test")
11
- env._set("PLATFORM_URL", "http://localhost:10000")
12
- env._set("INTERNAL_API_KEY", "test")
13
- env._set("DISABLE_ACCOUNT_PORTAL", false)
1
+ import { mocks, testContainerUtils } from "@budibase/backend-core/tests"
14
2
 
15
- import { mocks } from "@budibase/backend-core/tests"
3
+ import env from "../environment"
4
+ import { env as coreEnv } from "@budibase/backend-core"
16
5
 
17
6
  // must explicitly enable fetch mock
18
7
  mocks.fetch.enable()
@@ -22,10 +11,14 @@ mocks.fetch.enable()
22
11
  const tk = require("timekeeper")
23
12
  tk.freeze(mocks.date.MOCK_DATE)
24
13
 
25
- global.console.log = jest.fn() // console.log are ignored in tests
14
+ if (!process.env.DEBUG) {
15
+ global.console.log = jest.fn() // console.log are ignored in tests
16
+ }
26
17
 
27
18
  if (!process.env.CI) {
28
19
  // set a longer timeout in dev for debugging
29
20
  // 100 seconds
30
21
  jest.setTimeout(100000)
31
22
  }
23
+
24
+ testContainerUtils.setupEnv(env, coreEnv)
@@ -1,4 +1,4 @@
1
- exports.mock = () => {
1
+ export function mock() {
2
2
  // mock the email system
3
3
  const sendMailMock = jest.fn()
4
4
  const nodemailer = require("nodemailer")
@@ -1,7 +1,7 @@
1
- const email = require("./email")
2
- import { mocks as coreMocks } from "@budibase/backend-core/tests"
1
+ import * as email from "./email"
2
+ import { mocks } from "@budibase/backend-core/tests"
3
3
 
4
- export = {
4
+ export default {
5
5
  email,
6
- ...coreMocks,
6
+ ...mocks,
7
7
  }
@@ -1,5 +1,5 @@
1
- const { Config } = require("../../constants")
2
- const { utils } = require("@budibase/backend-core")
1
+ import { Config } from "../../constants"
2
+ import { utils } from "@budibase/backend-core"
3
3
 
4
4
  export function oidc(conf?: any) {
5
5
  return {
@@ -4,7 +4,7 @@ export const UserGroup = () => {
4
4
  color: "var(--spectrum-global-color-blue-600)",
5
5
  icon: "UserGroup",
6
6
  name: "New group",
7
- roles: {},
7
+ roles: { app_uuid1: "ADMIN", app_uuid2: "POWER" },
8
8
  users: [],
9
9
  }
10
10
  return group
@@ -4,9 +4,8 @@ import * as users from "./users"
4
4
  import * as groups from "./groups"
5
5
  import { v4 as uuid } from "uuid"
6
6
 
7
- const TENANT_ID = "default"
8
- const TENANT_1 = "tenant1"
9
- const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
7
+ export const TENANT_ID = "default"
8
+ export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
10
9
 
11
10
  const pkg = {
12
11
  ...structures,
@@ -14,9 +13,8 @@ const pkg = {
14
13
  configs,
15
14
  users,
16
15
  TENANT_ID,
17
- TENANT_1,
18
16
  CSRF_TOKEN,
19
17
  groups,
20
18
  }
21
19
 
22
- export = pkg
20
+ export default pkg
@@ -10,7 +10,7 @@ export const user = (userProps?: any): User => {
10
10
  return {
11
11
  email: newEmail(),
12
12
  password: "test",
13
- roles: {},
13
+ roles: { app_test: "admin" },
14
14
  ...userProps,
15
15
  }
16
16
  }
@@ -1,7 +1,8 @@
1
1
  import fetch from "node-fetch"
2
- import { constants, tenancy } from "@budibase/backend-core"
2
+ import { constants, tenancy, logging } from "@budibase/backend-core"
3
3
  import { checkSlashesInUrl } from "../utilities"
4
4
  import env from "../environment"
5
+ import { SyncUserRequest, User } from "@budibase/types"
5
6
 
6
7
  async function makeAppRequest(url: string, method: string, body: any) {
7
8
  if (env.isTest()) {
@@ -17,14 +18,22 @@ async function makeAppRequest(url: string, method: string, body: any) {
17
18
  request.body = JSON.stringify(body)
18
19
  }
19
20
  request.method = method
21
+
22
+ // add x-budibase-correlation-id header
23
+ logging.correlation.setHeader(request.headers)
24
+
20
25
  return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
21
26
  }
22
27
 
23
- export async function syncUserInApps(userId: string) {
28
+ export async function syncUserInApps(userId: string, previousUser?: User) {
29
+ const body: SyncUserRequest = {
30
+ previousUser,
31
+ }
32
+
24
33
  const response = await makeAppRequest(
25
34
  `/api/users/metadata/sync/${userId}`,
26
35
  "POST",
27
- {}
36
+ body
28
37
  )
29
38
  if (response && response.status !== 200) {
30
39
  throw "Unable to sync user."
package/tsconfig.json CHANGED
@@ -13,7 +13,8 @@
13
13
  }
14
14
  },
15
15
  "ts-node": {
16
- "require": ["tsconfig-paths/register"]
16
+ "require": ["tsconfig-paths/register"],
17
+ "swc": true
17
18
  },
18
19
  "references": [
19
20
  { "path": "../types" },
@@ -25,7 +26,6 @@
25
26
  "package.json"
26
27
  ],
27
28
  "exclude": [
28
- "node_modules",
29
29
  "dist"
30
30
  ]
31
31
  }