mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 13:37:28 +00:00
Improve SeaTable connector reliability
- Use dtable_server from token response instead of hardcoded URL - Remove convert_keys from createRow (not supported on batch write endpoints) - Cache SeaTable client across operations to avoid redundant token exchanges
This commit is contained in:
parent
141b5ddd20
commit
318da348fd
2 changed files with 15 additions and 5 deletions
|
|
@ -1,13 +1,22 @@
|
|||
import { SeaTableClient } from './seatable_client';
|
||||
import { SourceOptions, QueryOptions } from './types';
|
||||
|
||||
let cachedClient: SeaTableClient | null = null;
|
||||
let cachedKey = '';
|
||||
|
||||
function getClient(sourceOptions: SourceOptions): SeaTableClient {
|
||||
const serverUrl = sourceOptions.server_url;
|
||||
const apiToken = sourceOptions.api_token;
|
||||
if (!serverUrl || !apiToken) {
|
||||
throw new Error('Missing server_url or api_token in connection settings');
|
||||
}
|
||||
return new SeaTableClient(serverUrl, apiToken);
|
||||
const key = `${serverUrl}::${apiToken}`;
|
||||
if (cachedClient && cachedKey === key) {
|
||||
return cachedClient;
|
||||
}
|
||||
cachedClient = new SeaTableClient(serverUrl, apiToken);
|
||||
cachedKey = key;
|
||||
return cachedClient;
|
||||
}
|
||||
|
||||
function parseJson(value: string | Record<string, unknown>): Record<string, unknown> {
|
||||
|
|
|
|||
|
|
@ -43,16 +43,18 @@ export class SeaTableClient {
|
|||
|
||||
this.baseToken = res.data.access_token;
|
||||
this.baseUuid = res.data.dtable_uuid;
|
||||
const dtableServer: string = res.data.dtable_server ?? '';
|
||||
|
||||
if (!this.baseToken || !this.baseUuid) {
|
||||
throw new Error('SeaTable token exchange failed – missing access_token or dtable_uuid');
|
||||
if (!this.baseToken || !this.baseUuid || !dtableServer) {
|
||||
throw new Error('SeaTable token exchange failed – missing access_token, dtable_uuid, or dtable_server');
|
||||
}
|
||||
|
||||
// Renew 1 minute before expiry (default token lifetime = 1h)
|
||||
this.tokenExpiresAt = Date.now() + 59 * 60 * 1000;
|
||||
|
||||
const baseURL = `${dtableServer.replace(/\/$/, '')}/api/v2/dtables/${this.baseUuid}`;
|
||||
this.http = axios.create({
|
||||
baseURL: `${this.serverUrl}/api-gateway/api/v2/dtables/${this.baseUuid}`,
|
||||
baseURL,
|
||||
timeout: 30000,
|
||||
headers: { Authorization: `Bearer ${this.baseToken}` },
|
||||
});
|
||||
|
|
@ -99,7 +101,6 @@ export class SeaTableClient {
|
|||
const res = await http.post('/rows/', {
|
||||
table_name: tableName,
|
||||
rows: [row],
|
||||
convert_keys: true,
|
||||
});
|
||||
return res.data.first_row ?? res.data;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue