diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index 587616adfc..30633c9203 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -13,7 +13,7 @@ import { DataSourceOperation, FieldTypes } from "../constants" import { GoogleSpreadsheet } from "google-spreadsheet" import env from "../environment" import { tenancy, db as dbCore, constants } from "@budibase/backend-core" -const fetch = require("node-fetch") +import fetch from "node-fetch" interface GoogleSheetsConfig { spreadsheetId: string @@ -112,7 +112,7 @@ const SCHEMA: Integration = { class GoogleSheetsIntegration implements DatasourcePlus { private readonly config: GoogleSheetsConfig - private client: any + private client: GoogleSpreadsheet public tables: Record = {} public schemaErrors: Record = {} @@ -211,7 +211,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { async buildSchema(datasourceId: string) { await this.connect() - const sheets = await this.client.sheetsByIndex + const sheets = this.client.sheetsByIndex const tables: Record = {} for (let sheet of sheets) { // must fetch rows to determine schema @@ -294,7 +294,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { async updateTable(table?: any) { try { await this.connect() - const sheet = await this.client.sheetsByTitle[table.name] + const sheet = this.client.sheetsByTitle[table.name] await sheet.loadHeaderRow() if (table._rename) { @@ -329,7 +329,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { async deleteTable(sheet: any) { try { await this.connect() - const sheetToDelete = await this.client.sheetsByTitle[sheet] + const sheetToDelete = this.client.sheetsByTitle[sheet] return await sheetToDelete.delete() } catch (err) { console.error("Error deleting table in google sheets", err) @@ -340,7 +340,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { async create(query: { sheet: string; row: any }) { try { await this.connect() - const sheet = await this.client.sheetsByTitle[query.sheet] + const sheet = this.client.sheetsByTitle[query.sheet] const rowToInsert = typeof query.row === "string" ? JSON.parse(query.row) : query.row const row = await sheet.addRow(rowToInsert) @@ -356,7 +356,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { async read(query: { sheet: string }) { try { await this.connect() - const sheet = await this.client.sheetsByTitle[query.sheet] + const sheet = this.client.sheetsByTitle[query.sheet] const rows = await sheet.getRows() const headerValues = sheet.headerValues const response = [] @@ -375,7 +375,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { async update(query: { sheet: string; rowIndex: number; row: any }) { try { await this.connect() - const sheet = await this.client.sheetsByTitle[query.sheet] + const sheet = this.client.sheetsByTitle[query.sheet] const rows = await sheet.getRows() const row = rows[query.rowIndex] if (row) { @@ -399,7 +399,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { async delete(query: { sheet: string; rowIndex: number }) { await this.connect() - const sheet = await this.client.sheetsByTitle[query.sheet] + const sheet = this.client.sheetsByTitle[query.sheet] const rows = await sheet.getRows() const row = rows[query.rowIndex] if (row) {