Aller au contenu principal

Démarrage rapide

Quickstart : créer une facture en TypeScript

SDK officiel @scell/sdk pour Node.js et navigateur

Le SDK TypeScript officiel `@scell/sdk` (npm) expose `ScellApiClient` typé strict avec définitions complètes des DTO Factur-X / signature eIDAS. Fonctionne en Node.js 18+ (via fetch natif) et navigateur (uniquement avec `pk_*` côté client). Pour les opérations critiques (création de facture), utiliser exclusivement `sk_*` côté serveur. Tree-shakeable, ESM-first, dual CJS/ESM. Version 3.5.0 sur npm.

À retenir

  • Prérequis : Node.js 18+ ou navigateur evergreen
  • Installation : `npm i @scell/sdk` ou `pnpm add @scell/sdk`
  • Variable d'env : `process.env.SCELL_API_KEY` (Node) ou import.meta.env (Vite)
  • HTTP : fetch natif (Node 18+ / browser)
  • Output attendu : `Invoice` typé avec `id`, `status`, `pdf_url`
  • Codes erreur : `ScellApiError` avec `.status` et `.code`

Exemple de code

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}`);

Voir aussi

Vos préférences cookies

Nous utilisons des cookies pour améliorer votre expérience. Les cookies essentiels sont toujours actifs. Politique cookies.