@budibase/worker 2.1.22-alpha.6 → 2.1.22-alpha.7

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 (123) hide show
  1. package/coverage/clover.xml +326 -305
  2. package/coverage/coverage-final.json +13 -13
  3. package/coverage/lcov-report/index.html +34 -34
  4. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +50 -38
  5. package/coverage/lcov-report/src/api/controllers/global/configs.js.html +18 -18
  6. package/coverage/lcov-report/src/api/controllers/global/email.js.html +1 -1
  7. package/coverage/lcov-report/src/api/controllers/global/index.html +10 -10
  8. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +1 -1
  9. package/coverage/lcov-report/src/api/controllers/global/roles.js.html +1 -1
  10. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +3 -3
  11. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +1 -1
  12. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +1 -1
  13. package/coverage/lcov-report/src/api/controllers/global/workspaces.js.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +1 -1
  15. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +1 -1
  18. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +1 -1
  19. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +1 -1
  20. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +1 -1
  21. package/coverage/lcov-report/src/api/index.html +1 -1
  22. package/coverage/lcov-report/src/api/index.ts.html +1 -1
  23. package/coverage/lcov-report/src/api/routes/global/auth.js.html +1 -1
  24. package/coverage/lcov-report/src/api/routes/global/configs.js.html +10 -10
  25. package/coverage/lcov-report/src/api/routes/global/email.js.html +1 -1
  26. package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
  27. package/coverage/lcov-report/src/api/routes/global/license.ts.html +1 -1
  28. package/coverage/lcov-report/src/api/routes/global/roles.js.html +1 -1
  29. package/coverage/lcov-report/src/api/routes/global/self.ts.html +1 -1
  30. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +3 -3
  31. package/coverage/lcov-report/src/api/routes/global/users.js.html +1 -1
  32. package/coverage/lcov-report/src/api/routes/global/workspaces.js.html +1 -1
  33. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  34. package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
  35. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +1 -1
  36. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +1 -1
  37. package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
  38. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +1 -1
  39. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/routes/system/status.ts.html +1 -1
  41. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
  43. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +1 -1
  45. package/coverage/lcov-report/src/constants/index.html +10 -10
  46. package/coverage/lcov-report/src/constants/{index.js.html → index.ts.html} +92 -113
  47. package/coverage/lcov-report/src/constants/templates/index.html +1 -1
  48. package/coverage/lcov-report/src/constants/templates/index.js.html +3 -3
  49. package/coverage/lcov-report/src/db/index.html +1 -1
  50. package/coverage/lcov-report/src/db/index.ts.html +1 -1
  51. package/coverage/lcov-report/src/environment.ts.html +1 -1
  52. package/coverage/lcov-report/src/index.html +1 -1
  53. package/coverage/lcov-report/src/index.ts.html +1 -1
  54. package/coverage/lcov-report/src/middleware/cloudRestricted.js.html +3 -3
  55. package/coverage/lcov-report/src/middleware/index.html +1 -1
  56. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +1 -1
  57. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  58. package/coverage/lcov-report/src/migrations/index.html +1 -1
  59. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  60. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +1 -1
  61. package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
  62. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +1 -1
  63. package/coverage/lcov-report/src/sdk/index.html +1 -1
  64. package/coverage/lcov-report/src/sdk/index.ts.html +1 -1
  65. package/coverage/lcov-report/src/sdk/users/events.ts.html +1 -1
  66. package/coverage/lcov-report/src/sdk/users/index.html +1 -1
  67. package/coverage/lcov-report/src/sdk/users/index.ts.html +1 -1
  68. package/coverage/lcov-report/src/sdk/users/users.ts.html +1 -1
  69. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +31 -22
  70. package/coverage/lcov-report/src/tests/api/accounts.ts.html +1 -1
  71. package/coverage/lcov-report/src/tests/api/auth.ts.html +1 -1
  72. package/coverage/lcov-report/src/tests/api/base.ts.html +1 -1
  73. package/coverage/lcov-report/src/tests/api/configs.ts.html +1 -1
  74. package/coverage/lcov-report/src/tests/api/email.ts.html +1 -1
  75. package/coverage/lcov-report/src/tests/api/environment.ts.html +1 -1
  76. package/coverage/lcov-report/src/tests/api/index.html +1 -1
  77. package/coverage/lcov-report/src/tests/api/index.ts.html +1 -1
  78. package/coverage/lcov-report/src/tests/api/migrations.ts.html +1 -1
  79. package/coverage/lcov-report/src/tests/api/restore.ts.html +1 -1
  80. package/coverage/lcov-report/src/tests/api/self.ts.html +1 -1
  81. package/coverage/lcov-report/src/tests/api/status.ts.html +1 -1
  82. package/coverage/lcov-report/src/tests/api/tenants.ts.html +1 -1
  83. package/coverage/lcov-report/src/tests/api/users.ts.html +1 -1
  84. package/coverage/lcov-report/src/tests/controllers.js.html +1 -1
  85. package/coverage/lcov-report/src/tests/index.html +15 -15
  86. package/coverage/lcov-report/src/tests/index.ts.html +1 -1
  87. package/coverage/lcov-report/src/tests/mocks/email.js.html +1 -1
  88. package/coverage/lcov-report/src/tests/mocks/index.html +1 -1
  89. package/coverage/lcov-report/src/tests/mocks/index.ts.html +1 -1
  90. package/coverage/lcov-report/src/tests/structures/configs.js.html +7 -7
  91. package/coverage/lcov-report/src/tests/structures/groups.ts.html +1 -1
  92. package/coverage/lcov-report/src/tests/structures/index.html +1 -1
  93. package/coverage/lcov-report/src/tests/structures/index.ts.html +1 -1
  94. package/coverage/lcov-report/src/tests/structures/users.ts.html +1 -1
  95. package/coverage/lcov-report/src/utilities/appService.js.html +4 -4
  96. package/coverage/lcov-report/src/utilities/{email.js.html → email.ts.html} +160 -61
  97. package/coverage/lcov-report/src/utilities/fileSystem.js.html +1 -1
  98. package/coverage/lcov-report/src/utilities/index.html +23 -23
  99. package/coverage/lcov-report/src/utilities/index.js.html +1 -1
  100. package/coverage/lcov-report/src/utilities/{redis.js.html → redis.ts.html} +53 -38
  101. package/coverage/lcov-report/src/utilities/{templates.js.html → templates.ts.html} +38 -38
  102. package/coverage/lcov-report/src/utilities/users.js.html +1 -1
  103. package/coverage/lcov.info +593 -529
  104. package/jest.config.ts +1 -0
  105. package/package.json +6 -6
  106. package/src/api/controllers/global/auth.ts +34 -30
  107. package/src/api/controllers/global/configs.js +17 -17
  108. package/src/api/controllers/global/self.ts +2 -2
  109. package/src/api/routes/global/configs.js +9 -9
  110. package/src/api/routes/global/templates.ts +2 -2
  111. package/src/api/routes/global/tests/configs.spec.ts +29 -29
  112. package/src/constants/{index.js → index.ts} +57 -64
  113. package/src/constants/templates/index.js +2 -2
  114. package/src/middleware/cloudRestricted.js +2 -2
  115. package/src/middleware/tests/tenancy.spec.ts +7 -7
  116. package/src/tests/TestConfiguration.ts +15 -12
  117. package/src/tests/structures/configs.js +6 -6
  118. package/src/utilities/appService.js +3 -3
  119. package/src/utilities/{email.js → email.ts} +78 -45
  120. package/src/utilities/{redis.js → redis.ts} +29 -24
  121. package/src/utilities/templates.ts +49 -0
  122. package/tsconfig.build.json +3 -3
  123. package/src/utilities/templates.js +0 -49
@@ -1,36 +1,35 @@
1
- const { Client, utils } = require("@budibase/backend-core/redis")
2
- const { newid } = require("@budibase/backend-core/utils")
1
+ import { redis, utils } from "@budibase/backend-core"
3
2
 
4
- function getExpirySecondsForDB(db) {
3
+ function getExpirySecondsForDB(db: string) {
5
4
  switch (db) {
6
- case utils.Databases.PW_RESETS:
5
+ case redis.utils.Databases.PW_RESETS:
7
6
  // a hour
8
7
  return 3600
9
- case utils.Databases.INVITATIONS:
8
+ case redis.utils.Databases.INVITATIONS:
10
9
  // a day
11
10
  return 86400
12
11
  }
13
12
  }
14
13
 
15
- let pwResetClient, invitationClient
14
+ let pwResetClient: any, invitationClient: any
16
15
 
17
- function getClient(db) {
16
+ function getClient(db: string) {
18
17
  switch (db) {
19
- case utils.Databases.PW_RESETS:
18
+ case redis.utils.Databases.PW_RESETS:
20
19
  return pwResetClient
21
- case utils.Databases.INVITATIONS:
20
+ case redis.utils.Databases.INVITATIONS:
22
21
  return invitationClient
23
22
  }
24
23
  }
25
24
 
26
- async function writeACode(db, value) {
25
+ async function writeACode(db: string, value: any) {
27
26
  const client = await getClient(db)
28
- const code = newid()
27
+ const code = utils.newid()
29
28
  await client.store(code, value, getExpirySecondsForDB(db))
30
29
  return code
31
30
  }
32
31
 
33
- async function getACode(db, code, deleteCode = true) {
32
+ async function getACode(db: string, code: string, deleteCode = true) {
34
33
  const client = await getClient(db)
35
34
  const value = await client.get(code)
36
35
  if (!value) {
@@ -42,9 +41,9 @@ async function getACode(db, code, deleteCode = true) {
42
41
  return value
43
42
  }
44
43
 
45
- exports.init = async () => {
46
- pwResetClient = new Client(utils.Databases.PW_RESETS)
47
- invitationClient = new Client(utils.Databases.INVITATIONS)
44
+ export async function init() {
45
+ pwResetClient = new redis.Client(redis.utils.Databases.PW_RESETS)
46
+ invitationClient = new redis.Client(redis.utils.Databases.INVITATIONS)
48
47
  await pwResetClient.init()
49
48
  await invitationClient.init()
50
49
  }
@@ -52,7 +51,7 @@ exports.init = async () => {
52
51
  /**
53
52
  * make sure redis connection is closed.
54
53
  */
55
- exports.shutdown = async () => {
54
+ export async function shutdown() {
56
55
  if (pwResetClient) await pwResetClient.finish()
57
56
  if (invitationClient) await invitationClient.finish()
58
57
  console.log("Redis shutdown")
@@ -65,8 +64,8 @@ exports.shutdown = async () => {
65
64
  * @param {object} info Info about the user/the reset process.
66
65
  * @return {Promise<string>} returns the code that was stored to redis.
67
66
  */
68
- exports.getResetPasswordCode = async (userId, info) => {
69
- return writeACode(utils.Databases.PW_RESETS, { userId, info })
67
+ export async function getResetPasswordCode(userId: string, info: any) {
68
+ return writeACode(redis.utils.Databases.PW_RESETS, { userId, info })
70
69
  }
71
70
 
72
71
  /**
@@ -75,9 +74,12 @@ exports.getResetPasswordCode = async (userId, info) => {
75
74
  * @param {boolean} deleteCode If the code is used/finished with this will delete it - defaults to true.
76
75
  * @return {Promise<string>} returns the user ID if it is found
77
76
  */
78
- exports.checkResetPasswordCode = async (resetCode, deleteCode = true) => {
77
+ export async function checkResetPasswordCode(
78
+ resetCode: string,
79
+ deleteCode = true
80
+ ) {
79
81
  try {
80
- return getACode(utils.Databases.PW_RESETS, resetCode, deleteCode)
82
+ return getACode(redis.utils.Databases.PW_RESETS, resetCode, deleteCode)
81
83
  } catch (err) {
82
84
  throw "Provided information is not valid, cannot reset password - please try again."
83
85
  }
@@ -89,8 +91,8 @@ exports.checkResetPasswordCode = async (resetCode, deleteCode = true) => {
89
91
  * @param {object|null} info Information to be carried along with the invitation.
90
92
  * @return {Promise<string>} returns the code that was stored to redis.
91
93
  */
92
- exports.getInviteCode = async (email, info) => {
93
- return writeACode(utils.Databases.INVITATIONS, { email, info })
94
+ export async function getInviteCode(email: string, info: any) {
95
+ return writeACode(redis.utils.Databases.INVITATIONS, { email, info })
94
96
  }
95
97
 
96
98
  /**
@@ -99,9 +101,12 @@ exports.getInviteCode = async (email, info) => {
99
101
  * @param {boolean} deleteCode whether or not the code should be deleted after retrieval - defaults to true.
100
102
  * @return {Promise<object>} If the code is valid then an email address will be returned.
101
103
  */
102
- exports.checkInviteCode = async (inviteCode, deleteCode = true) => {
104
+ export async function checkInviteCode(
105
+ inviteCode: string,
106
+ deleteCode: boolean = true
107
+ ) {
103
108
  try {
104
- return getACode(utils.Databases.INVITATIONS, inviteCode, deleteCode)
109
+ return getACode(redis.utils.Databases.INVITATIONS, inviteCode, deleteCode)
105
110
  } catch (err) {
106
111
  throw "Invitation is not valid or has expired, please request a new one."
107
112
  }
@@ -0,0 +1,49 @@
1
+ import { db as dbCore, tenancy } from "@budibase/backend-core"
2
+ import {
3
+ Config,
4
+ InternalTemplateBinding,
5
+ LOGO_URL,
6
+ EmailTemplatePurpose,
7
+ } from "../constants"
8
+ import { checkSlashesInUrl } from "./index"
9
+ const BASE_COMPANY = "Budibase"
10
+
11
+ export async function getSettingsTemplateContext(
12
+ purpose: EmailTemplatePurpose,
13
+ code?: string
14
+ ) {
15
+ const db = tenancy.getGlobalDB()
16
+ // TODO: use more granular settings in the future if required
17
+ let settings =
18
+ (await dbCore.getScopedConfig(db, { type: Config.SETTINGS })) || {}
19
+ const URL = settings.platformUrl
20
+ const context: any = {
21
+ [InternalTemplateBinding.LOGO_URL]:
22
+ checkSlashesInUrl(`${URL}/${settings.logoUrl}`) || LOGO_URL,
23
+ [InternalTemplateBinding.PLATFORM_URL]: URL,
24
+ [InternalTemplateBinding.COMPANY]: settings.company || BASE_COMPANY,
25
+ [InternalTemplateBinding.DOCS_URL]:
26
+ settings.docsUrl || "https://docs.budibase.com/",
27
+ [InternalTemplateBinding.LOGIN_URL]: checkSlashesInUrl(
28
+ tenancy.addTenantToUrl(`${URL}/login`)
29
+ ),
30
+ [InternalTemplateBinding.CURRENT_DATE]: new Date().toISOString(),
31
+ [InternalTemplateBinding.CURRENT_YEAR]: new Date().getFullYear(),
32
+ }
33
+ // attach purpose specific context
34
+ switch (purpose) {
35
+ case EmailTemplatePurpose.PASSWORD_RECOVERY:
36
+ context[InternalTemplateBinding.RESET_CODE] = code
37
+ context[InternalTemplateBinding.RESET_URL] = checkSlashesInUrl(
38
+ tenancy.addTenantToUrl(`${URL}/builder/auth/reset?code=${code}`)
39
+ )
40
+ break
41
+ case EmailTemplatePurpose.INVITATION:
42
+ context[InternalTemplateBinding.INVITE_CODE] = code
43
+ context[InternalTemplateBinding.INVITE_URL] = checkSlashesInUrl(
44
+ tenancy.addTenantToUrl(`${URL}/builder/invite?code=${code}`)
45
+ )
46
+ break
47
+ }
48
+ return context
49
+ }
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "es6",
4
- "skipLibCheck": true,
5
4
  "module": "commonjs",
6
5
  "lib": ["es2020"],
7
6
  "allowJs": true,
8
- "outDir": "dist",
9
7
  "strict": true,
10
8
  "noImplicitAny": true,
11
9
  "esModuleInterop": true,
12
10
  "resolveJsonModule": true,
13
11
  "incremental": true,
14
- "types": [ "node", "jest"],
12
+ "types": [ "node", "jest" ],
13
+ "outDir": "dist",
14
+ "skipLibCheck": true
15
15
  },
16
16
  "include": [
17
17
  "src/**/*"
@@ -1,49 +0,0 @@
1
- const { getScopedConfig } = require("@budibase/backend-core/db")
2
- const {
3
- Configs,
4
- InternalTemplateBindings,
5
- LOGO_URL,
6
- EmailTemplatePurpose,
7
- } = require("../constants")
8
- const { checkSlashesInUrl } = require("./index")
9
- const {
10
- getGlobalDB,
11
- addTenantToUrl,
12
- } = require("@budibase/backend-core/tenancy")
13
- const BASE_COMPANY = "Budibase"
14
-
15
- exports.getSettingsTemplateContext = async (purpose, code = null) => {
16
- const db = getGlobalDB()
17
- // TODO: use more granular settings in the future if required
18
- let settings = (await getScopedConfig(db, { type: Configs.SETTINGS })) || {}
19
- const URL = settings.platformUrl
20
- const context = {
21
- [InternalTemplateBindings.LOGO_URL]:
22
- checkSlashesInUrl(`${URL}/${settings.logoUrl}`) || LOGO_URL,
23
- [InternalTemplateBindings.PLATFORM_URL]: URL,
24
- [InternalTemplateBindings.COMPANY]: settings.company || BASE_COMPANY,
25
- [InternalTemplateBindings.DOCS_URL]:
26
- settings.docsUrl || "https://docs.budibase.com/",
27
- [InternalTemplateBindings.LOGIN_URL]: checkSlashesInUrl(
28
- addTenantToUrl(`${URL}/login`)
29
- ),
30
- [InternalTemplateBindings.CURRENT_DATE]: new Date().toISOString(),
31
- [InternalTemplateBindings.CURRENT_YEAR]: new Date().getFullYear(),
32
- }
33
- // attach purpose specific context
34
- switch (purpose) {
35
- case EmailTemplatePurpose.PASSWORD_RECOVERY:
36
- context[InternalTemplateBindings.RESET_CODE] = code
37
- context[InternalTemplateBindings.RESET_URL] = checkSlashesInUrl(
38
- addTenantToUrl(`${URL}/builder/auth/reset?code=${code}`)
39
- )
40
- break
41
- case EmailTemplatePurpose.INVITATION:
42
- context[InternalTemplateBindings.INVITE_CODE] = code
43
- context[InternalTemplateBindings.INVITE_URL] = checkSlashesInUrl(
44
- addTenantToUrl(`${URL}/builder/invite?code=${code}`)
45
- )
46
- break
47
- }
48
- return context
49
- }