UNPKG

fql-toolkit

Version:
48 lines 1.68 kB
import FQLHTTPClient from './client.js'; import FormsManager from './FormsManager.js'; import FormContext from './FormContext.js'; import FQLError from './errors.js'; /** * Main entry point for the FQL Toolkit. * * @example * import FQLClient from 'fql-toolkit'; * * // With a static token * const client = new FQLClient({ baseURL: 'http://localhost:7645', token: 'your-jwt' }); * * // With an AuthManager (token read dynamically on each request) * const client = new FQLClient({ baseURL: 'http://localhost:7645', auth: authManager }); */ export default class FQLClient { constructor(config) { if (!config.baseURL || typeof config.baseURL !== 'string') { throw new FQLError('FQLClient: baseURL is required'); } const getToken = config.auth ? () => config.auth.getToken() ?? '' : () => config.token; this._http = new FQLHTTPClient({ url: config.baseURL, getToken, organizationId: config.organizationId, onAuthError: config.auth ? () => config.auth.emitAuthError() : undefined, retry: config.retry, }); this.forms = new FormsManager(this._http); } /** * Returns a context for record operations on the given form. */ form(formName) { return new FormContext(formName, this._http); } /** * Executes a raw FQL string. * Use this as an escape hatch when the builder API doesn't cover your needs. */ async execute(fqlString, fqlToken = null, opts) { return this._http.executeFQL(fqlString, fqlToken, opts?.organizationId); } } //# sourceMappingURL=FQLClient.js.map