Skip to content

Configuration

Basic Configuration

Basic Configurationtypescript
import SpaceInvoices from "@spaceinvoices/js-sdk";

const _sdk = new SpaceInvoices({
  accessToken: "YOUR_API_KEY",
});

Configuration Options

OptionTypeDescription
accessTokenstring | () => Promise<string>API key or async token provider
basePathstringCustom API URL (default: https://eu.spaceinvoices.com)
onUnauthorized(response) => voidCallback for 401 responses

Dynamic Tokens

For applications that refresh tokens, provide an async function:

Dynamic Tokentypescript
const _sdk = new SpaceInvoices({
  accessToken: async () => {
    // Fetch token from your auth system
    const session = await getSession();
    return session.accessToken;
  },
});

Handling Token Expiry

Use onUnauthorized to handle expired tokens:

Handle Unauthorizedtypescript
const _sdk = new SpaceInvoices({
  accessToken: "YOUR_API_KEY",
  onUnauthorized: async (_response) => {
    // Token expired - refresh and retry
    await refreshToken();
    window.location.reload();
  },
});

Custom Base URL

For self-hosted or regional deployments:

Custom Base URLtypescript
const _sdk = new SpaceInvoices({
  accessToken: "YOUR_API_KEY",
  basePath: "https://eu.spaceinvoices.com",
});

Tree-Shakeable Configuration

When using tree-shakeable imports, call initSDK once at startup:

Tree-Shakeable Inittypescript
import { initSDK, invoices } from "@spaceinvoices/js-sdk";

// Initialize once at app startup
initSDK({
  accessToken: "YOUR_API_KEY",
  basePath: "https://eu.spaceinvoices.com",
});

// Now use individual modules anywhere
const _result = await invoices.list({ entity_id: "ent_123" });

Next Steps