Quickstart
Quickstart: create an invoice in TypeScript
Official @scell/sdk for Node.js and browser
The official TypeScript SDK `@scell/sdk` (npm) exposes a strictly-typed `ScellApiClient` with full DTO definitions for Factur-X / eIDAS signatures. Works on Node.js 18+ (native fetch) and browser (with `pk_*` keys client-side only). For critical operations (invoice creation), use `sk_*` server-side only. Tree-shakeable, ESM-first, dual CJS/ESM. Version 3.5.0 on npm.
Key facts
- Requirements: Node.js 18+ or evergreen browser
- Install: `npm i @scell/sdk` or `pnpm add @scell/sdk`
- Env var: `process.env.SCELL_API_KEY` (Node) or import.meta.env (Vite)
- HTTP: native fetch (Node 18+ / browser)
- Expected output: typed `Invoice` with `id`, `status`, `pdf_url`
- Error codes: `ScellApiError` with `.status` and `.code`
Code example
import { ScellApiClient } from '@scell/sdk';
const client = new ScellApiClient({ apiKey: process.env.SCELL_API_KEY! });
const seller = {
siret: '12345678901234',
name: 'Ma SAS',
address: { street: '1 rue Test', city: 'Paris', postal_code: '75001', country: 'FR' },
vat_number: 'FR12345678901',
};
// 1. Facture B2B
const b2b = await client.invoices.create({
format: 'factur-x',
profile: 'EN16931',
currency: 'EUR',
seller,
buyer: {
siret: '98765432109876',
name: 'Client SARL',
address: { street: '2 avenue Demo', city: 'Lyon', postal_code: '69001', country: 'FR' },
},
lines: [{ description: 'Prestation conseil', quantity: 1, unit_price: 1000.0, vat_rate: 20.0 }],
});
console.log(`B2B: ${b2b.id} (${b2b.status})`);
// 2. Facture B2C (particulier)
const b2c = await client.invoices.create({
format: 'factur-x',
profile: 'EN16931',
currency: 'EUR',
seller,
buyer: {
buyer_is_individual: true,
name: 'Jean Dupont',
email: 'jean@example.com',
address: { street: '3 bd Client', city: 'Marseille', postal_code: '13001', country: 'FR' },
},
lines: [{ description: 'Abonnement', quantity: 1, unit_price: 49.9, vat_rate: 20.0 }],
});
console.log(`B2C: ${b2c.id} (${b2c.status})`);
// 3. Signature simple eIDAS EU-SES
const sig = await client.signatures.create({
document_url: 'https://example.com/contrat.pdf',
signers: [{ name: 'Jean Dupont', email: 'jean@example.com', phone: '+33612345678' }],
signature_options: { signature_mode: 'drawn', timezone: 'Europe/Paris' },
});
console.log(`Signature: ${sig.id} → ${sig.signing_url}`);