feat(editor): ✨ Add send email integration
This commit is contained in:
@ -11,14 +11,14 @@ import { NextApiRequest, NextApiResponse } from 'next'
|
||||
const providers: Provider[] = [
|
||||
EmailProvider({
|
||||
server: {
|
||||
host: process.env.EMAIL_SERVER_HOST,
|
||||
port: Number(process.env.EMAIL_SERVER_PORT),
|
||||
host: process.env.AUTH_EMAIL_SERVER_HOST,
|
||||
port: Number(process.env.AUTH_EMAIL_SERVER_PORT),
|
||||
auth: {
|
||||
user: process.env.EMAIL_SERVER_USER,
|
||||
pass: process.env.EMAIL_SERVER_PASSWORD,
|
||||
user: process.env.AUTH_EMAIL_SERVER_USER,
|
||||
pass: process.env.AUTH_EMAIL_SERVER_PASSWORD,
|
||||
},
|
||||
},
|
||||
from: process.env.EMAIL_FROM,
|
||||
from: `"${process.env.AUTH_EMAIL_FROM_NAME}" <${process.env.AUTH_EMAIL_FROM_EMAIL}>`,
|
||||
}),
|
||||
]
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
import { oauth2Client } from 'libs/google-sheets'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react'
|
||||
import { CredentialsType, Prisma, User } from 'db'
|
||||
import { Prisma, User } from 'db'
|
||||
import prisma from 'libs/prisma'
|
||||
import { googleSheetsScopes } from './consent-url'
|
||||
import { stringify } from 'querystring'
|
||||
import { CredentialsType } from 'models'
|
||||
import { encrypt } from 'utils'
|
||||
import { oauth2Client } from 'libs/google-sheets'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getSession({ req })
|
||||
@ -35,12 +37,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res
|
||||
.status(400)
|
||||
.send({ message: "User didn't accepted required scopes" })
|
||||
const { encryptedData, iv } = encrypt(tokens)
|
||||
const credentials = {
|
||||
name: email,
|
||||
type: CredentialsType.GOOGLE_SHEETS,
|
||||
ownerId: user.id,
|
||||
data: tokens as Prisma.InputJsonValue,
|
||||
}
|
||||
data: encryptedData,
|
||||
iv,
|
||||
} as Prisma.CredentialsUncheckedCreateInput
|
||||
const { id: credentialsId } = await prisma.credentials.upsert({
|
||||
create: credentials,
|
||||
update: credentials,
|
||||
|
@ -47,17 +47,17 @@ const executeWebhook = async (
|
||||
const contentType = headers ? headers['Content-Type'] : undefined
|
||||
try {
|
||||
const response = await got(
|
||||
parseVariables({ text: webhook.url + `?${queryParams}`, variables }),
|
||||
parseVariables(variables)(webhook.url + `?${queryParams}`),
|
||||
{
|
||||
method: webhook.method as Method,
|
||||
headers,
|
||||
json:
|
||||
contentType !== 'x-www-form-urlencoded' && webhook.body
|
||||
? JSON.parse(parseVariables({ text: webhook.body, variables }))
|
||||
? JSON.parse(parseVariables(variables)(webhook.body))
|
||||
: undefined,
|
||||
form:
|
||||
contentType === 'x-www-form-urlencoded' && webhook.body
|
||||
? JSON.parse(parseVariables({ text: webhook.body, variables }))
|
||||
? JSON.parse(parseVariables(variables)(webhook.body))
|
||||
: undefined,
|
||||
}
|
||||
)
|
||||
@ -96,7 +96,7 @@ const convertKeyValueTableToObject = (
|
||||
if (!item.key) return {}
|
||||
return {
|
||||
...object,
|
||||
[item.key]: parseVariables({ text: item.value, variables }),
|
||||
[item.key]: parseVariables(variables)(item.value ?? ''),
|
||||
}
|
||||
}, {})
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { User } from 'db'
|
||||
import { Prisma, User } from 'db'
|
||||
import prisma from 'libs/prisma'
|
||||
import { Credentials } from 'models'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react'
|
||||
import { methodNotAllowed } from 'utils'
|
||||
import { encrypt, methodNotAllowed } from 'utils'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const session = await getSession({ req })
|
||||
@ -16,6 +17,20 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method === 'GET') {
|
||||
const credentials = await prisma.credentials.findMany({
|
||||
where: { ownerId: user.id },
|
||||
select: { name: true, type: true, ownerId: true, id: true },
|
||||
})
|
||||
return res.send({ credentials })
|
||||
}
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body) as Omit<Credentials, 'ownerId'>
|
||||
const { encryptedData, iv } = encrypt(data.data)
|
||||
const credentials = await prisma.credentials.create({
|
||||
data: {
|
||||
...data,
|
||||
data: encryptedData,
|
||||
iv,
|
||||
ownerId: user.id,
|
||||
} as Prisma.CredentialsUncheckedCreateInput,
|
||||
})
|
||||
return res.send({ credentials })
|
||||
}
|
||||
|
Reference in New Issue
Block a user