From d98e217c6c1ba90ccddfc9833609e145ed6785f5 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 10 Nov 2023 11:21:36 +0000 Subject: [PATCH] Fix backend-core redis imports. --- packages/backend-core/src/redis/index.ts | 5 +++-- .../src/api/controllers/global/users.ts | 19 +++++++------------ packages/worker/src/sdk/auth/auth.ts | 2 +- packages/worker/src/utilities/email.ts | 4 ++-- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/backend-core/src/redis/index.ts b/packages/backend-core/src/redis/index.ts index 8d153ea5a1..419f1db700 100644 --- a/packages/backend-core/src/redis/index.ts +++ b/packages/backend-core/src/redis/index.ts @@ -4,5 +4,6 @@ export { default as Client } from "./redis" export * as utils from "./utils" export * as clients from "./init" export * as locks from "./redlockImpl" -export * as invite from "./invite" -export * as passwordReset from "./passwordReset" + +export * from "./invite" +export * from "./passwordReset" diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index e904567674..cd11fc74b6 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -1,9 +1,4 @@ -import { - getInviteCode, - deleteInviteCode, - getInviteCodes, - updateInviteCode, -} from "@budibase/backend-core/src/redis/invite" +import { redis } from "@budibase/backend-core" import * as userSdk from "../../../sdk/users" import env from "../../../environment" import { @@ -313,7 +308,7 @@ export const checkInvite = async (ctx: any) => { const { code } = ctx.params let invite try { - invite = await getInviteCode(code) + invite = await redis.getInviteCode(code) } catch (e) { console.warn("Error getting invite from code", e) ctx.throw(400, "There was a problem with the invite") @@ -327,7 +322,7 @@ export const checkInvite = async (ctx: any) => { export const getUserInvites = async (ctx: any) => { try { // Restricted to the currently authenticated tenant - ctx.body = await getInviteCodes() + ctx.body = await redis.getInviteCodes() } catch (e) { ctx.throw(400, "There was a problem fetching invites") } @@ -341,7 +336,7 @@ export const updateInvite = async (ctx: any) => { let invite try { - invite = await getInviteCode(code) + invite = await redis.getInviteCode(code) } catch (e) { ctx.throw(400, "There was a problem with the invite") return @@ -369,7 +364,7 @@ export const updateInvite = async (ctx: any) => { } } - await updateInviteCode(code, updated) + await redis.updateInviteCode(code, updated) ctx.body = { ...invite } } @@ -379,8 +374,8 @@ export const inviteAccept = async ( const { inviteCode, password, firstName, lastName } = ctx.request.body try { // info is an extension of the user object that was stored by global - const { email, info }: any = await getInviteCode(inviteCode) - await deleteInviteCode(inviteCode) + const { email, info }: any = await redis.getInviteCode(inviteCode) + await redis.deleteInviteCode(inviteCode) const user = await tenancy.doInTenant(info.tenantId, async () => { let request: any = { firstName, diff --git a/packages/worker/src/sdk/auth/auth.ts b/packages/worker/src/sdk/auth/auth.ts index 57131294b3..2140b89ce3 100644 --- a/packages/worker/src/sdk/auth/auth.ts +++ b/packages/worker/src/sdk/auth/auth.ts @@ -73,7 +73,7 @@ export const reset = async (email: string) => { * Perform the user password update if the provided reset code is valid. */ export const resetUpdate = async (resetCode: string, password: string) => { - const { userId } = await redis.passwordReset.getResetPasswordCode(resetCode) + const { userId } = await redis.getResetPasswordCode(resetCode) let user = await userSdk.db.getUser(userId) user.password = password diff --git a/packages/worker/src/utilities/email.ts b/packages/worker/src/utilities/email.ts index f3f1fd40c4..a4d2c296e5 100644 --- a/packages/worker/src/utilities/email.ts +++ b/packages/worker/src/utilities/email.ts @@ -4,7 +4,7 @@ import { getTemplateByPurpose, EmailTemplates } from "../constants/templates" import { getSettingsTemplateContext } from "./templates" import { processString } from "@budibase/string-templates" import { createResetPasswordCode } from "@budibase/backend-core/src/redis/passwordReset" -import { createInviteCode } from "@budibase/backend-core/src/redis/invite" +import { redis } from "@budibase/backend-core" import { User, SendEmailOpts, SMTPInnerConfig } from "@budibase/types" import { configs } from "@budibase/backend-core" import ical from "ical-generator" @@ -64,7 +64,7 @@ async function getLinkCode( case EmailTemplatePurpose.PASSWORD_RECOVERY: return createResetPasswordCode(user._id!, info) case EmailTemplatePurpose.INVITATION: - return createInviteCode(email, info) + return redis.createInviteCode(email, info) default: return null }