翻译:
DGII电子CF为多米尼加共和国开具SDK电子发票.
Bun- first, 土生土长 fetch,严格类型脚本,以及 结果模式 (永远不)
- 没有隐藏的例外。 签名 XMLDSig 文档(包括 C14N + RSA-SHA256)
用再试、断路器、超时和
一相能报.
安装
bun add @deuriib/dgii-ecf
# or
npm install @deuriib/dgii-ecf
仅限服务器侧. 绝不在浏览器中使用——它处理私钥.
快开始
import { ECF, Environment, P12Reader, Signature } from '@deuriib/dgii-ecf';
// 1. Read the certificate (.p12)
const reader = new P12Reader(process.env.CERT_PASSWORD ?? '');
const credentials = reader.getKeyFromFile('/secure/identity.p12');
if (credentials.isErr()) throw credentials.error;
// 2. Authenticate against DGII
const ecf = new ECF(credentials.value, Environment.Cert);
const auth = await ecf.authenticate();
if (auth.isErr()) throw auth.error;
// 3. Sign and submit
const signature = new Signature(
credentials.value.key!,
credentials.value.cert!,
);
const signed = signature.signXml(xml);
if (signed.isErr()) throw signed.error;
const response = await ecf.sendElectronicDocument(
signed.value,
'101672919E3100000001.xml',
);
response.match(
(invoice) => console.log('trackId', invoice.trackId),
(error) => console.error('DGII error', error.message),
);
结果模式
每个错误操作返回 a Result数字 :
const result = await ecf.statusTrackId('some-track-id');
if (result.isOk()) {
console.log(result.value.estado);
} else {
console.error(result.error.code, result.error.message);
}
复原力和免疫力
- 瞬间故障(网络、超时、408/429/5xx) 由连续故障的断路器保护.
sendElectronicDocument编号 :sendSummary键入RNC + eNCF + SHA-256(signed XML); 提供持久性IdempotencyStore生产(Redis/Postgres):
const ecf = new ECF(credentials, Environment.Prod, {
idempotencyStore: myRedisStore, // { get, set, delete }
});
模块
environment, (中文(简体) ), types, (中文(简体) ), errors, (中文(简体) ), result, (中文(简体) ), resilience, (中文(简体) ), http, (中文(简体) ), certificate, (中文(简体) ),
signing, (中文(简体) ), transformer, (中文(简体) ), reception, (中文(简体) ), reconciliation, (中文(简体) ), validation, (中文(简体) ), utils, (中文(简体) ),
client。 。 。 .
许可证
麻省理工学院 2026 Deuri Vasquez