Skip to main content

Authentication

The Farseer Client supports three authentication methods.

When running inside a Farseer environment (remote jobs, Farseer Apps), the client auto-configures from environment variables:

const client = new FarseerClient();

Required environment variables:

VariableDescriptionExample
TENANT_IDYour Farseer tenant identifiermy-company
FARSEER_API_KEYAPI authentication keyfsk_a1b2c3d4...
FARSEER_URLBase URL for Farseer serverhttps://my-company.farseer.io

Method 2: Constructor Parameters

Pass credentials directly:

const client = new FarseerClient(
'my-tenant-id', // tenantId
'my-api-key', // apiKey
'https://my-company.farseer.io' // basePath
);

Method 3: Custom Configuration

For advanced use cases (custom headers, middleware, etc.):

const client = new FarseerClient({
basePath: 'https://my-company.farseer.io/api/v3',
headers: {
'X-TENANT-ID': 'my-tenant-id',
'X-API-KEY': 'my-api-key',
'Custom-Header': 'value',
},
});

Configuration Options

interface ConfigurationParameters {
basePath?: string; // Server URL
headers?: Record<string, string>; // Custom headers
apiKey?: string | ((name: string) => string);
accessToken?: string | Promise<string>;
middleware?: Middleware[]; // Request/response middleware
fetchApi?: FetchAPI; // Custom fetch implementation
credentials?: RequestCredentials;
}

Development vs Production Pattern

A common pattern for switching between development and production:

import * as farseer from 'farseer-client';

const isDevelopment =
process.env.FARSEER_URL === undefined &&
process.env.FARSEER_API_KEY === undefined;

const DEV_TENANT_ID = 'your-tenant-dev';
const DEV_API_KEY = 'your_dev_api_key_here';
const DEV_URL = 'https://your-tenant-dev.farseer.io/api/v3';

let client: farseer.FarseerClient;

if (isDevelopment) {
console.log('Running in DEVELOPMENT mode');
client = new farseer.FarseerClient(DEV_TENANT_ID, DEV_API_KEY, DEV_URL);
} else {
console.log('Running in PRODUCTION mode');
client = new farseer.FarseerClient();
}
caution

Always test against a development Farseer instance before deploying to production. This prevents accidental data modifications in production environments.

API Key Management

API keys are created through the Farseer API:

const apiKey = await client.apiKeys.create({
serviceUserId: serviceUser.id
});

// The key value is only shown once!
console.log('API Key:', apiKey.value);

Headers Sent Automatically

The client automatically includes these headers:

HeaderValueDescription
X-TENANT-IDYour tenant IDIdentifies the tenant
X-API-KEYYour API keyAuthentication
X-API-VERSIONSDK versionAPI compatibility