Installation
dte-sdk is a single package with zero runtime dependencies. It ships ESM and CommonJS builds with bundled types, and it's fully tree-shakeable (sideEffects: false), so you only pay for the functions you import. The full bundle is about 8.4 KB min+gzip.
Installing today gives you 0.0.2, a placeholder release that only
exports hello(). The functions on these pages are the planned 1.0 API and
may change before release.
Requirements#
- Node.js 20 or later (
engines: node >=20), Deno, Bun, or any modern browser - A package manager: npm, pnpm, bun or yarn
- TypeScript is optional: types are bundled (there's no
@typespackage to install), and the library works in plain JavaScript too
Add the package#
npm install dte-sdkVerify the installation#
Import a function
Imports are named and tree-shakeable. calculateTotals() is a pure
function (no CAF, certificate or network involved), which makes it a
good smoke test.
import { calculateTotals } from 'dte-sdk'Run it
One line at 120.000 CLP net, with 19% IVA on top.
const totals = calculateTotals([
{ name: 'Licencia anual', quantity: 1, unitPrice: 120000 },
])
console.log(totals.vat) // 22800
console.log(totals.total) // 142800You're set
If both lines log as above, the package is wired correctly. Continue with the Quick Start.
Module formats#
dte-sdk works with both module systems without configuration:
// ESM / TypeScript
import { createDte, signDte } from 'dte-sdk'// CommonJS
const { createDte, signDte } = require('dte-sdk')Runtime support#
The same code runs on Node, Deno, Bun and the browser. Signing uses the
Web Crypto API (crypto.subtle), which every supported runtime provides:
no native modules, no crypto bindings, no polyfills.
| Environment | Supported | Notes |
|---|---|---|
| Node.js (>=20) | ✅ | ESM and CommonJS |
| Bun | ✅ | Native ESM |
| Deno | ✅ | Import with the npm:dte-sdk specifier |
| Browsers | ✅ | Bundle with any tool; tree-shakeable |
Running in the browser is supported, but signing there means the certificate's private key is in the browser too. For most apps, build and preview documents on the client and stamp, sign and send on the server. See Security.
What you'll need besides the package#
dte-sdk handles the document format, the cryptography and the conversation with the SII. To issue documents the SII accepts, you also need three things the package can't give you:
| You need | What it is | Where it comes from |
|---|---|---|
| A CAF per document type | An XML file that authorizes a range of folios, with the private key used to stamp them | Requested from the SII, one per document type |
| A digital certificate | A .pfx or .p12 file and its password, issued to a person authorized to sign for the company | An accredited certification provider |
| An SII resolution | The number and date of the resolution that authorizes the company as an electronic issuer | Granted by the SII after certification (use number 0 in the certification environment) |
You don't need any of them to try createDte(), calculateTotals() or toXml(): they're pure functions. Core Concepts explains how the pieces fit together.