Configuration
Configuration Options
import { SpaceInvoices } from "@spaceinvoices/embed-sdk";
const _si = new SpaceInvoices({
// Required
apiKey: "ek_live_your_entity_api_key",
entityId: "ent_123",
// Optional: Custom base URL (for self-hosted)
baseUrl: "https://eu.spaceinvoices.com",
// Optional: UI language (defaults to browser detection)
locale: "en",
// Optional: Theme customization
theme: {
primary: "#6366f1",
radius: 8,
},
// Callbacks
onAction: (_action) => {},
onReady: () => {},
onError: (error) => console.error("Error:", error),
onClose: () => {},
});Required Options
| Option | Type | Description |
|---|---|---|
apiKey | string | Entity API key (ek_live_* or ek_sandbox_*) |
entityId | string | Entity ID to operate on |
Optional Options
| Option | Type | Description |
|---|---|---|
baseUrl | string | Custom base URL for self-hosted deployments |
locale | EmbedLocale | UI language (en, sl, de, it, fr, es, pt, nl, pl, hr). Defaults to browser language detection. |
theme | ThemeConfig | Theme customization options |
Callbacks
| Callback | Parameters | Description |
|---|---|---|
onAction | (action: EmbedAction) | Called when user performs an action |
onReady | () | Called when embed is fully loaded |
onError | (error: EmbedError) | Called on errors |
onClose | () | Called when embed is closed |
Open Options
When calling open() or navigate(), you can pass additional options:
// Open in a specific container
si.open("invoices", {
container: "#my-container",
});
// Open a specific invoice
si.open("invoice", {
container: "#my-container",
id: "inv_123",
});
// Pre-fill a new invoice
si.open("invoice/new", {
container: "#my-container",
prefill: {
client: { name: "Acme Corp" },
items: [{ name: "Service", price: 100 }],
},
});| Option | Type | Description |
|---|---|---|
container | string | HTMLElement | Container element or selector |
id | string | Document/customer ID for single-item views |
prefill | Record<string, unknown> | Pre-fill data for creation forms |
Methods
| Method | Description |
|---|---|
open(view, options?) | Open a view in a container |
navigate(view, options?) | Navigate to a different view |
updateTheme(theme) | Update theme dynamically |
setLocale(locale) | Change UI language dynamically |
close() | Close and unmount the embed |
ready() | Returns promise that resolves when ready |
getInstance() | Get current embed instance |
destroy() | Destroy SDK and clean up |