Portal Community

AtlasFormsClient Initialisation

Initialise the client once at application startup. The singleton pattern ensures all packages share the same configuration:

import { AtlasFormsClient } from '@atlas-forms/client-js';
import { IndexedDBAdapter } from '@atlas-forms/storage-js';

// Initialise once in main.tsx or App.tsx
const client = AtlasFormsClient.getInstance({
  apiBaseUrl: 'https://api.bizfirstai.com',
  apiTimeout: 30000,            // 30 second timeout
  storageAdapter: new IndexedDBAdapter(),  // Large draft storage
  autoValidate: true,           // Validate on field change
  enableLogging: false          // Set true for development
});

Configuration Options

OptionTypeDefaultDescription
apiBaseUrlstringRequiredBase URL for all API calls. No trailing slash.
apiTimeoutnumber30000Request timeout in milliseconds.
storageAdapterStorageAdapterLocalStorageAdapterWhere drafts are stored. IndexedDB for larger forms.
controlRegistryControlRegistryBuilt-inCustom control registry (for custom controls).
themeResolverThemeResolverBuilt-in light/darkCustom theme resolver.
autoValidatebooleantrueRun validation on every field change.
enableLoggingbooleanfalseLog API calls and engine events to console.

Authentication

The Atlas Forms API uses JWT bearer tokens. Configure the token provider so the client attaches it to every request:

const client = AtlasFormsClient.getInstance({
  apiBaseUrl: 'https://api.bizfirstai.com',
  // Token provider called before each request
  getAuthToken: async () => {
    // Return current JWT token from your auth system
    return authService.getAccessToken();
  }
});

Multi-Tenant Setup

Every API call that lists or fetches forms requires a tenantId. Set the default tenant at initialisation to avoid passing it on every call:

const client = AtlasFormsClient.getInstance({
  apiBaseUrl: 'https://api.bizfirstai.com',
  defaultTenantId: 42   // Your tenant ID
});

// Now listForms() uses tenantId: 42 by default
const forms = await client.listForms();

Environment-Specific Configuration

Use environment variables (Vite-style) to switch between environments:

// vite.config.ts — set in .env files
// .env.development: VITE_API_URL=http://localhost:5000
// .env.production: VITE_API_URL=https://api.bizfirstai.com

const client = AtlasFormsClient.getInstance({
  apiBaseUrl: import.meta.env.VITE_API_URL,
  enableLogging: import.meta.env.DEV
});

Connection Health Check

The client exposes a health check method to verify the API is reachable:

const health = await client.checkHealth();
if (!health.connected) {
  console.error('Atlas Forms API unreachable:', health.error);
  // Show offline banner to user
}
Storage Fallback Chain If IndexedDBAdapter is not available in the browser, StorageManager automatically falls back to LocalStorageAdapter, then to an in-memory adapter. Your code does not need to handle this — it is transparent.