BREAKING CHANGE: The Google Picker API needs to be enabled in the Google Cloud console. You also need to enable it in your NEXT_PUBLIC_GOOGLE_API_KEY. You also need to add the drive.file OAuth scope.
25 lines
717 B
TypeScript
25 lines
717 B
TypeScript
import { TRPCError } from '@trpc/server'
|
|
import { GoogleSpreadsheet } from 'google-spreadsheet'
|
|
import { getAuthenticatedGoogleClient } from '@typebot.io/lib/google'
|
|
|
|
export const getAuthenticatedGoogleDoc = async ({
|
|
credentialsId,
|
|
spreadsheetId,
|
|
}: {
|
|
credentialsId?: string
|
|
spreadsheetId?: string
|
|
}) => {
|
|
if (!credentialsId || !spreadsheetId)
|
|
throw new TRPCError({
|
|
code: 'BAD_REQUEST',
|
|
message: 'Missing credentialsId or spreadsheetId',
|
|
})
|
|
const auth = await getAuthenticatedGoogleClient(credentialsId)
|
|
if (!auth)
|
|
throw new TRPCError({
|
|
code: 'NOT_FOUND',
|
|
message: "Couldn't find credentials in database",
|
|
})
|
|
return new GoogleSpreadsheet(spreadsheetId, auth)
|
|
}
|