Email API typing.
This commit is contained in:
parent
60e4d3f0e6
commit
cbab77ea24
|
@ -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
|
||||||
|
}
|
|
@ -5,3 +5,4 @@ export * from "./configs"
|
||||||
export * from "./scim"
|
export * from "./scim"
|
||||||
export * from "./license"
|
export * from "./license"
|
||||||
export * from "./oldMigration"
|
export * from "./oldMigration"
|
||||||
|
export * from "./email"
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
import { sendEmail as sendEmailFn } from "../../../utilities/email"
|
import { sendEmail as sendEmailFn } from "../../../utilities/email"
|
||||||
import { tenancy } from "@budibase/backend-core"
|
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 {
|
let {
|
||||||
workspaceId,
|
workspaceId,
|
||||||
email,
|
email,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Router from "@koa/router"
|
import Router from "@koa/router"
|
||||||
import * as controller from "../../controllers/global/email"
|
import * as controller from "../../controllers/global/email"
|
||||||
import { EmailTemplatePurpose } from "../../../constants"
|
|
||||||
import { auth } from "@budibase/backend-core"
|
import { auth } from "@budibase/backend-core"
|
||||||
|
import { EmailTemplatePurpose } from "@budibase/types"
|
||||||
import Joi from "joi"
|
import Joi from "joi"
|
||||||
|
|
||||||
const router: Router = new Router()
|
const router: Router = new Router()
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
jest.mock("nodemailer")
|
jest.mock("nodemailer")
|
||||||
|
import { EmailTemplatePurpose } from "@budibase/types"
|
||||||
import { TestConfiguration, mocks } from "../../../../tests"
|
import { TestConfiguration, mocks } from "../../../../tests"
|
||||||
|
|
||||||
const sendMailMock = mocks.email.mock()
|
const sendMailMock = mocks.email.mock()
|
||||||
import { EmailTemplatePurpose } from "../../../../constants"
|
|
||||||
|
|
||||||
describe("/api/global/email", () => {
|
describe("/api/global/email", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
jest.unmock("node-fetch")
|
jest.unmock("node-fetch")
|
||||||
import { TestConfiguration } from "../../../../tests"
|
import { TestConfiguration } from "../../../../tests"
|
||||||
import { EmailTemplatePurpose } from "../../../../constants"
|
|
||||||
import { objectStore } from "@budibase/backend-core"
|
import { objectStore } from "@budibase/backend-core"
|
||||||
import { helpers } from "@budibase/shared-core"
|
import { helpers } from "@budibase/shared-core"
|
||||||
|
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
import { EmailAttachment } from "@budibase/types"
|
import { EmailAttachment, EmailTemplatePurpose } from "@budibase/types"
|
||||||
|
|
||||||
const fetch = require("node-fetch")
|
const fetch = require("node-fetch")
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import {
|
import { TemplateMetadata, TemplateType } from "../../../../constants"
|
||||||
EmailTemplatePurpose,
|
|
||||||
TemplateMetadata,
|
|
||||||
TemplateType,
|
|
||||||
} from "../../../../constants"
|
|
||||||
import { TestConfiguration } from "../../../../tests"
|
import { TestConfiguration } from "../../../../tests"
|
||||||
|
import { EmailTemplatePurpose } from "@budibase/types"
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { constants } from "@budibase/backend-core"
|
import { constants } from "@budibase/backend-core"
|
||||||
|
import { EmailTemplatePurpose } from "@budibase/types"
|
||||||
|
|
||||||
export const LOGO_URL =
|
export const LOGO_URL =
|
||||||
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
|
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
|
||||||
|
@ -19,15 +20,6 @@ export enum TemplateType {
|
||||||
EMAIL = "email",
|
EMAIL = "email",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum EmailTemplatePurpose {
|
|
||||||
CORE = "core",
|
|
||||||
BASE = "base",
|
|
||||||
PASSWORD_RECOVERY = "password_recovery",
|
|
||||||
INVITATION = "invitation",
|
|
||||||
WELCOME = "welcome",
|
|
||||||
CUSTOM = "custom",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum TemplateMetadataNames {
|
export enum TemplateMetadataNames {
|
||||||
BASE = "Base format",
|
BASE = "Base format",
|
||||||
PASSWORD_RECOVERY = "Password recovery",
|
PASSWORD_RECOVERY = "Password recovery",
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
import { readStaticFile } from "../../utilities/fileSystem"
|
import { readStaticFile } from "../../utilities/fileSystem"
|
||||||
import {
|
import { TemplateType, TemplatePurpose, GLOBAL_OWNER } from "../index"
|
||||||
EmailTemplatePurpose,
|
|
||||||
TemplateType,
|
|
||||||
TemplatePurpose,
|
|
||||||
GLOBAL_OWNER,
|
|
||||||
} from "../index"
|
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import { db as dbCore, tenancy } from "@budibase/backend-core"
|
import { db as dbCore, tenancy } from "@budibase/backend-core"
|
||||||
import { Template } from "@budibase/types"
|
import { Template, EmailTemplatePurpose } from "@budibase/types"
|
||||||
|
|
||||||
export const EmailTemplates = {
|
export const EmailTemplates = {
|
||||||
[EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile(
|
[EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile(
|
||||||
|
|
|
@ -8,11 +8,10 @@ import {
|
||||||
utils as coreUtils,
|
utils as coreUtils,
|
||||||
cache,
|
cache,
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
import { PlatformLogoutOpts, User } from "@budibase/types"
|
import { PlatformLogoutOpts, User, EmailTemplatePurpose } from "@budibase/types"
|
||||||
import jwt from "jsonwebtoken"
|
import jwt from "jsonwebtoken"
|
||||||
import * as userSdk from "../users"
|
import * as userSdk from "../users"
|
||||||
import * as emails from "../../utilities/email"
|
import * as emails from "../../utilities/email"
|
||||||
import { EmailTemplatePurpose } from "../../constants"
|
|
||||||
|
|
||||||
// LOGIN / LOGOUT
|
// LOGIN / LOGOUT
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ import {
|
||||||
InviteUserRequest,
|
InviteUserRequest,
|
||||||
InviteUsersRequest,
|
InviteUsersRequest,
|
||||||
InviteUsersResponse,
|
InviteUsersResponse,
|
||||||
|
EmailTemplatePurpose,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { sendEmail } from "../../utilities/email"
|
import { sendEmail } from "../../utilities/email"
|
||||||
import { EmailTemplatePurpose } from "../../constants"
|
|
||||||
|
|
||||||
export async function invite(
|
export async function invite(
|
||||||
users: InviteUsersRequest
|
users: InviteUsersRequest
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { EmailTemplatePurpose, TemplateType } from "../constants"
|
import { TemplateType } from "../constants"
|
||||||
import { getTemplateByPurpose, EmailTemplates } from "../constants/templates"
|
import { getTemplateByPurpose, EmailTemplates } from "../constants/templates"
|
||||||
import { getSettingsTemplateContext } from "./templates"
|
import { getSettingsTemplateContext } from "./templates"
|
||||||
import { processString } from "@budibase/string-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 { configs, cache, objectStore } from "@budibase/backend-core"
|
||||||
import ical from "ical-generator"
|
import ical from "ical-generator"
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import { tenancy, configs } from "@budibase/backend-core"
|
import { tenancy, configs } from "@budibase/backend-core"
|
||||||
import {
|
import { EmailTemplatePurpose } from "@budibase/types"
|
||||||
InternalTemplateBinding,
|
import { InternalTemplateBinding, LOGO_URL } from "../constants"
|
||||||
LOGO_URL,
|
|
||||||
EmailTemplatePurpose,
|
|
||||||
} from "../constants"
|
|
||||||
import { checkSlashesInUrl } from "./index"
|
import { checkSlashesInUrl } from "./index"
|
||||||
|
|
||||||
const BASE_COMPANY = "Budibase"
|
const BASE_COMPANY = "Budibase"
|
||||||
|
|
Loading…
Reference in New Issue