feat(integration): ✨ Add Google Sheets integration
This commit is contained in:
28
apps/builder/libs/google-sheets.ts
Normal file
28
apps/builder/libs/google-sheets.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Prisma, Credentials as CredentialsFromDb } from 'db'
|
||||
import { OAuth2Client, Credentials } from 'google-auth-library'
|
||||
import prisma from './prisma'
|
||||
|
||||
export const oauth2Client = new OAuth2Client(
|
||||
process.env.GOOGLE_CLIENT_ID,
|
||||
process.env.GOOGLE_CLIENT_SECRET,
|
||||
`${process.env.NEXTAUTH_URL}/api/credentials/google-sheets/callback`
|
||||
)
|
||||
|
||||
export const getAuthenticatedGoogleClient = async (
|
||||
userId: string,
|
||||
credentialsId: string
|
||||
): Promise<OAuth2Client> => {
|
||||
const credentials = (await prisma.credentials.findFirst({
|
||||
where: { id: credentialsId, ownerId: userId },
|
||||
})) as CredentialsFromDb
|
||||
oauth2Client.setCredentials(credentials.data as Credentials)
|
||||
oauth2Client.on('tokens', updateTokens(credentialsId))
|
||||
return oauth2Client
|
||||
}
|
||||
|
||||
const updateTokens =
|
||||
(credentialsId: string) => async (credentials: Credentials) =>
|
||||
prisma.credentials.update({
|
||||
where: { id: credentialsId },
|
||||
data: { data: credentials as Prisma.InputJsonValue },
|
||||
})
|
@ -1,12 +1,5 @@
|
||||
import { Link } from '@chakra-ui/react'
|
||||
import {
|
||||
AutoformatRule,
|
||||
createAutoformatPlugin,
|
||||
} from '@udecode/plate-autoformat'
|
||||
import {
|
||||
MARK_BOLD,
|
||||
MARK_UNDERLINE,
|
||||
MARK_ITALIC,
|
||||
createBoldPlugin,
|
||||
createItalicPlugin,
|
||||
createUnderlinePlugin,
|
||||
@ -21,40 +14,12 @@ export const editorStyle: React.CSSProperties = {
|
||||
borderRadius: '0.25rem',
|
||||
}
|
||||
|
||||
export const autoFormatRules: AutoformatRule[] = [
|
||||
{
|
||||
mode: 'mark',
|
||||
type: MARK_BOLD,
|
||||
match: '**',
|
||||
},
|
||||
{
|
||||
mode: 'mark',
|
||||
type: MARK_UNDERLINE,
|
||||
match: '__',
|
||||
},
|
||||
{
|
||||
mode: 'mark',
|
||||
type: MARK_ITALIC,
|
||||
match: '*',
|
||||
},
|
||||
{
|
||||
mode: 'mark',
|
||||
type: MARK_ITALIC,
|
||||
match: '_',
|
||||
},
|
||||
]
|
||||
|
||||
export const platePlugins = createPlugins(
|
||||
[
|
||||
createBoldPlugin(),
|
||||
createItalicPlugin(),
|
||||
createUnderlinePlugin(),
|
||||
createLinkPlugin(),
|
||||
createAutoformatPlugin({
|
||||
options: {
|
||||
rules: autoFormatRules,
|
||||
},
|
||||
}),
|
||||
],
|
||||
{ components: { [ELEMENT_LINK]: Link } }
|
||||
)
|
||||
|
Reference in New Issue
Block a user