Email API typing.

This commit is contained in:
mike12345567 2024-12-05 14:59:15 +00:00
parent 60e4d3f0e6
commit cbab77ea24
13 changed files with 57 additions and 37 deletions

View File

@ -0,0 +1,28 @@
import { EmailAttachment, EmailInvite } from "../../../documents"
export enum EmailTemplatePurpose {
CORE = "core",
BASE = "base",
PASSWORD_RECOVERY = "password_recovery",
INVITATION = "invitation",
WELCOME = "welcome",
CUSTOM = "custom",
}
export interface SendEmailRequest {
workspaceId?: string
email: string
userId: string
purpose: EmailTemplatePurpose
contents?: string
from?: string
subject: string
cc?: boolean
bcc?: boolean
automation?: boolean
invite?: EmailInvite
attachments?: EmailAttachment[]
}
export interface SendEmailResponse extends Record<string, any> {
message: string
}

View File

@ -5,3 +5,4 @@ export * from "./configs"
export * from "./scim"
export * from "./license"
export * from "./oldMigration"
export * from "./email"

View File

@ -1,8 +1,15 @@
import { sendEmail as sendEmailFn } from "../../../utilities/email"
import { tenancy } from "@budibase/backend-core"
import { BBContext, User } from "@budibase/types"
import {
UserCtx,
User,
SendEmailRequest,
SendEmailResponse,
} from "@budibase/types"
export async function sendEmail(ctx: BBContext) {
export async function sendEmail(
ctx: UserCtx<SendEmailRequest, SendEmailResponse>
) {
let {
workspaceId,
email,

View File

@ -1,7 +1,7 @@
import Router from "@koa/router"
import * as controller from "../../controllers/global/email"
import { EmailTemplatePurpose } from "../../../constants"
import { auth } from "@budibase/backend-core"
import { EmailTemplatePurpose } from "@budibase/types"
import Joi from "joi"
const router: Router = new Router()

View File

@ -1,8 +1,8 @@
jest.mock("nodemailer")
import { EmailTemplatePurpose } from "@budibase/types"
import { TestConfiguration, mocks } from "../../../../tests"
const sendMailMock = mocks.email.mock()
import { EmailTemplatePurpose } from "../../../../constants"
describe("/api/global/email", () => {
const config = new TestConfiguration()

View File

@ -1,11 +1,10 @@
jest.unmock("node-fetch")
import { TestConfiguration } from "../../../../tests"
import { EmailTemplatePurpose } from "../../../../constants"
import { objectStore } from "@budibase/backend-core"
import { helpers } from "@budibase/shared-core"
import tk from "timekeeper"
import { EmailAttachment } from "@budibase/types"
import { EmailAttachment, EmailTemplatePurpose } from "@budibase/types"
const fetch = require("node-fetch")

View File

@ -1,9 +1,6 @@
import {
EmailTemplatePurpose,
TemplateMetadata,
TemplateType,
} from "../../../../constants"
import { TemplateMetadata, TemplateType } from "../../../../constants"
import { TestConfiguration } from "../../../../tests"
import { EmailTemplatePurpose } from "@budibase/types"
// TODO

View File

@ -1,4 +1,5 @@
import { constants } from "@budibase/backend-core"
import { EmailTemplatePurpose } from "@budibase/types"
export const LOGO_URL =
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
@ -19,15 +20,6 @@ export enum TemplateType {
EMAIL = "email",
}
export enum EmailTemplatePurpose {
CORE = "core",
BASE = "base",
PASSWORD_RECOVERY = "password_recovery",
INVITATION = "invitation",
WELCOME = "welcome",
CUSTOM = "custom",
}
export enum TemplateMetadataNames {
BASE = "Base format",
PASSWORD_RECOVERY = "Password recovery",

View File

@ -1,13 +1,8 @@
import { readStaticFile } from "../../utilities/fileSystem"
import {
EmailTemplatePurpose,
TemplateType,
TemplatePurpose,
GLOBAL_OWNER,
} from "../index"
import { TemplateType, TemplatePurpose, GLOBAL_OWNER } from "../index"
import { join } from "path"
import { db as dbCore, tenancy } from "@budibase/backend-core"
import { Template } from "@budibase/types"
import { Template, EmailTemplatePurpose } from "@budibase/types"
export const EmailTemplates = {
[EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile(

View File

@ -8,11 +8,10 @@ import {
utils as coreUtils,
cache,
} from "@budibase/backend-core"
import { PlatformLogoutOpts, User } from "@budibase/types"
import { PlatformLogoutOpts, User, EmailTemplatePurpose } from "@budibase/types"
import jwt from "jsonwebtoken"
import * as userSdk from "../users"
import * as emails from "../../utilities/email"
import { EmailTemplatePurpose } from "../../constants"
// LOGIN / LOGOUT

View File

@ -3,9 +3,9 @@ import {
InviteUserRequest,
InviteUsersRequest,
InviteUsersResponse,
EmailTemplatePurpose,
} from "@budibase/types"
import { sendEmail } from "../../utilities/email"
import { EmailTemplatePurpose } from "../../constants"
export async function invite(
users: InviteUsersRequest

View File

@ -1,9 +1,14 @@
import env from "../environment"
import { EmailTemplatePurpose, TemplateType } from "../constants"
import { TemplateType } from "../constants"
import { getTemplateByPurpose, EmailTemplates } from "../constants/templates"
import { getSettingsTemplateContext } from "./templates"
import { processString } from "@budibase/string-templates"
import { User, SendEmailOpts, SMTPInnerConfig } from "@budibase/types"
import {
User,
SendEmailOpts,
SMTPInnerConfig,
EmailTemplatePurpose,
} from "@budibase/types"
import { configs, cache, objectStore } from "@budibase/backend-core"
import ical from "ical-generator"
import _ from "lodash"

View File

@ -1,9 +1,6 @@
import { tenancy, configs } from "@budibase/backend-core"
import {
InternalTemplateBinding,
LOGO_URL,
EmailTemplatePurpose,
} from "../constants"
import { EmailTemplatePurpose } from "@budibase/types"
import { InternalTemplateBinding, LOGO_URL } from "../constants"
import { checkSlashesInUrl } from "./index"
const BASE_COMPANY = "Budibase"