@budibase/worker 2.3.18-alpha.2 → 2.3.18-alpha.21

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.
@@ -7,7 +7,7 @@ function getExpirySecondsForDB(db: string) {
7
7
  return 3600
8
8
  case redis.utils.Databases.INVITATIONS:
9
9
  // a day
10
- return 86400
10
+ return 604800
11
11
  }
12
12
  }
13
13
 
@@ -29,6 +29,20 @@ async function writeACode(db: string, value: any) {
29
29
  return code
30
30
  }
31
31
 
32
+ async function updateACode(db: string, code: string, value: any) {
33
+ const client = await getClient(db)
34
+ await client.store(code, value, getExpirySecondsForDB(db))
35
+ }
36
+
37
+ /**
38
+ * Given an invite code and invite body, allow the update an existing/valid invite in redis
39
+ * @param {string} inviteCode The invite code for an invite in redis
40
+ * @param {object} value The body of the updated user invitation
41
+ */
42
+ export async function updateInviteCode(inviteCode: string, value: string) {
43
+ await updateACode(redis.utils.Databases.INVITATIONS, inviteCode, value)
44
+ }
45
+
32
46
  async function getACode(db: string, code: string, deleteCode = true) {
33
47
  const client = await getClient(db)
34
48
  const value = await client.get(code)
@@ -113,3 +127,27 @@ export async function checkInviteCode(
113
127
  throw "Invitation is not valid or has expired, please request a new one."
114
128
  }
115
129
  }
130
+
131
+ /**
132
+ Get all currently available user invitations.
133
+ @return {Object[]} A list of all objects containing invite metadata
134
+ **/
135
+ export async function getInviteCodes(tenantIds?: string[]) {
136
+ const client = await getClient(redis.utils.Databases.INVITATIONS)
137
+ const invites: any[] = await client.scan()
138
+
139
+ const results = invites.map(invite => {
140
+ return {
141
+ ...invite.value,
142
+ code: invite.key,
143
+ }
144
+ })
145
+ return results.reduce((acc, invite) => {
146
+ if (tenantIds?.length && tenantIds.includes(invite.info.tenantId)) {
147
+ acc.push(invite)
148
+ } else {
149
+ acc.push(invite)
150
+ }
151
+ return acc
152
+ }, [])
153
+ }
@@ -1,6 +1,5 @@
1
- import { db as dbCore, tenancy } from "@budibase/backend-core"
1
+ import { tenancy, configs } from "@budibase/backend-core"
2
2
  import {
3
- Config,
4
3
  InternalTemplateBinding,
5
4
  LOGO_URL,
6
5
  EmailTemplatePurpose,
@@ -10,20 +9,16 @@ const BASE_COMPANY = "Budibase"
10
9
 
11
10
  export async function getSettingsTemplateContext(
12
11
  purpose: EmailTemplatePurpose,
13
- code?: string
12
+ code?: string | null
14
13
  ) {
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 })) || {}
14
+ let settings = await configs.getSettingsConfig()
19
15
  const URL = settings.platformUrl
20
16
  const context: any = {
21
17
  [InternalTemplateBinding.LOGO_URL]:
22
18
  checkSlashesInUrl(`${URL}/${settings.logoUrl}`) || LOGO_URL,
23
19
  [InternalTemplateBinding.PLATFORM_URL]: URL,
24
20
  [InternalTemplateBinding.COMPANY]: settings.company || BASE_COMPANY,
25
- [InternalTemplateBinding.DOCS_URL]:
26
- settings.docsUrl || "https://docs.budibase.com/",
21
+ [InternalTemplateBinding.DOCS_URL]: "https://docs.budibase.com/",
27
22
  [InternalTemplateBinding.LOGIN_URL]: checkSlashesInUrl(
28
23
  tenancy.addTenantToUrl(`${URL}/login`)
29
24
  ),