From 43bcee156eb41d853707a0dbc3c64cae78ff2add Mon Sep 17 00:00:00 2001 From: "raul@facturapi.io" Date: Wed, 1 Jul 2026 16:30:59 -0600 Subject: [PATCH] chore(retentions): add new retentions method for support drafts --- CHANGELOG.md | 6 ++++ package.json | 2 +- src/resources/retentions.ts | 56 +++++++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52628eb..ebf7067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [4.19.0] 2026-07-01 + +### Added + +- Add draft support methods for retentions: `retentions.updateDraft`, `retentions.copyToDraft`, and `retentions.stampDraft`. + ## [4.18.0] 2026-06-06 ### Added - Expose structured API error metadata through `FacturapiError`, including `status`, `code`, `path`, `location`, `errors`, `logId`, and response `headers`. diff --git a/package.json b/package.json index b6c17f7..d8f7cf6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "facturapi", - "version": "4.18.0", + "version": "4.19.0", "description": "SDK oficial de Facturapi para Node.js y navegadores. Integra facturación electrónica en México (CFDI) de forma simple y obtén una perspectiva fiscal completa de tu operación, con búsquedas indexadas, envío de documentos y trazabilidad.", "main": "dist/index.cjs.js", "module": "dist/index.es.js", diff --git a/src/resources/retentions.ts b/src/resources/retentions.ts index 660be17..92f5cb1 100644 --- a/src/resources/retentions.ts +++ b/src/resources/retentions.ts @@ -4,13 +4,13 @@ import { Retention, SearchResult, SendEmailBody, -} from '../types'; -import { WrapperClient } from '../wrapper'; +} from '../types' +import { WrapperClient } from '../wrapper' export default class Retentions { - client: WrapperClient; + client: WrapperClient constructor(client: WrapperClient) { - this.client = client; + this.client = client } /** @@ -19,7 +19,7 @@ export default class Retentions { * @returns */ create(data: Record): Promise { - return this.client.post('/retentions', { body: data }); + return this.client.post('/retentions', { body: data }) } /** @@ -28,8 +28,8 @@ export default class Retentions { * @returns */ list(params?: Record | null): Promise> { - if (!params) params = {}; - return this.client.get('/retentions', { params }); + if (!params) params = {} + return this.client.get('/retentions', { params }) } /** @@ -38,8 +38,8 @@ export default class Retentions { * @returns */ retrieve(id: string): Promise { - if (!id) return Promise.reject(new Error('id is required')); - return this.client.get('/retentions/' + id); + if (!id) return Promise.reject(new Error('id is required')) + return this.client.get('/retentions/' + id) } /** @@ -49,7 +49,35 @@ export default class Retentions { * @returns */ cancel(id: string, params?: Record): Promise { - return this.client.delete('/retentions/' + id, { params }); + return this.client.delete('/retentions/' + id, { params }) + } + + /** + * Edits a retention with "draft" status. + * @param id Retention Id + * @param data Retention data to edit + * @returns Edited retention + */ + updateDraft(id: string, data: Record): Promise { + return this.client.put('/retentions/' + id, { body: data }) + } + + /** + * Stamps a retention with "draft" status. + * @param id Retention Id + * @returns Stamped retention + */ + stampDraft(id: string): Promise { + return this.client.post('/retentions/' + id + '/stamp') + } + + /** + * Creates a draft retention from any other retention. + * @param id Retention Id + * @returns Draft retention + */ + copyToDraft(id: string): Promise { + return this.client.post('/retentions/' + id + '/copy') } /** @@ -60,7 +88,7 @@ export default class Retentions { * @returns */ sendByEmail(id: string, data?: SendEmailBody): Promise { - return this.client.post('/retentions/' + id + '/email', { body: data }); + return this.client.post('/retentions/' + id + '/email', { body: data }) } /** @@ -69,7 +97,7 @@ export default class Retentions { * @returns PDF file in a stream (Node.js) or Blob (browser) */ downloadPdf(id: string): Promise { - return this.client.get('/retentions/' + id + '/pdf'); + return this.client.get('/retentions/' + id + '/pdf') } /** @@ -78,7 +106,7 @@ export default class Retentions { * @returns XML file in a stream (Node.js) or Blob (browser) */ downloadXml(id: string): Promise { - return this.client.get('/retentions/' + id + '/xml'); + return this.client.get('/retentions/' + id + '/xml') } /** @@ -87,6 +115,6 @@ export default class Retentions { * @returns ZIP file in a stream (Node.js) or Blob (browser) */ downloadZip(id: string): Promise { - return this.client.get('/retentions/' + id + '/zip'); + return this.client.get('/retentions/' + id + '/zip') } }