Merge pull request #10606 from Budibase/budi-6932/verify_airtable
Verify airtable connection
This commit is contained in:
commit
af234c189c
|
@ -1,12 +1,12 @@
|
||||||
import {
|
import {
|
||||||
DatasourceFeature,
|
ConnectionInfo,
|
||||||
DatasourceFieldType,
|
DatasourceFieldType,
|
||||||
Integration,
|
Integration,
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
QueryType,
|
QueryType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
const Airtable = require("airtable")
|
import Airtable from "airtable"
|
||||||
|
|
||||||
interface AirtableConfig {
|
interface AirtableConfig {
|
||||||
apiKey: string
|
apiKey: string
|
||||||
|
@ -83,13 +83,37 @@ const SCHEMA: Integration = {
|
||||||
|
|
||||||
class AirtableIntegration implements IntegrationBase {
|
class AirtableIntegration implements IntegrationBase {
|
||||||
private config: AirtableConfig
|
private config: AirtableConfig
|
||||||
private client: any
|
private client
|
||||||
|
|
||||||
constructor(config: AirtableConfig) {
|
constructor(config: AirtableConfig) {
|
||||||
this.config = config
|
this.config = config
|
||||||
this.client = new Airtable(config).base(config.base)
|
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}`
|
||||||
|
) {
|
||||||
|
// The request managed to check the application, so the credentials are valid
|
||||||
|
return { connected: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
connected: false,
|
||||||
|
error: e.message as string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async create(query: { table: any; json: any }) {
|
async create(query: { table: any; json: any }) {
|
||||||
const { table, json } = query
|
const { table, json } = query
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue