1
0
Fork 0
mirror of synced 2024-07-11 09:15:48 +12:00

Test airtable connection

This commit is contained in:
Adria Navarro 2023-05-16 13:21:05 +02:00
parent be6c398f53
commit 419e2de602

View file

@ -1,12 +1,12 @@
import {
DatasourceFeature,
ConnectionInfo,
DatasourceFieldType,
Integration,
IntegrationBase,
QueryType,
} from "@budibase/types"
const Airtable = require("airtable")
import Airtable from "airtable"
interface AirtableConfig {
apiKey: string
@ -83,13 +83,36 @@ const SCHEMA: Integration = {
class AirtableIntegration implements IntegrationBase {
private config: AirtableConfig
private client: any
private client
constructor(config: AirtableConfig) {
this.config = config
this.client = new Airtable(config).base(config.base)
}
async testConnection(): Promise<ConnectionInfo> {
const mockTable = Date.now().toString()
try {
await this.client.makeRequest({
path: `/${mockTable}`,
})
return { connected: true }
} catch (e: any) {
if (
e.message ===
`Could not find table ${mockTable} in application ${this.config.base}`
) {
return { connected: true }
}
return {
connected: false,
error: e.message as string,
}
}
}
async create(query: { table: any; json: any }) {
const { table, json } = query