fiscalapi 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/LICENSE.txt +373 -0
  2. package/README.md +388 -0
  3. package/dist/cjs/abstractions/api-key-service.interface.js +3 -0
  4. package/dist/cjs/abstractions/catalog-service.interface.js +3 -0
  5. package/dist/cjs/abstractions/fiscalapi-client.interface.js +3 -0
  6. package/dist/cjs/abstractions/fiscalapi-service.interface.js +3 -0
  7. package/dist/cjs/abstractions/invoice-service.interface.js +3 -0
  8. package/dist/cjs/abstractions/person-service.interface.js +3 -0
  9. package/dist/cjs/abstractions/product-service.interface.js +3 -0
  10. package/dist/cjs/abstractions/tax-file-service.interface.js +3 -0
  11. package/dist/cjs/common/api-response.js +3 -0
  12. package/dist/cjs/common/auditable-dto.js +11 -0
  13. package/dist/cjs/common/base-dto.js +11 -0
  14. package/dist/cjs/common/catalog-dto.js +8 -0
  15. package/dist/cjs/common/file-response.js +3 -0
  16. package/dist/cjs/common/fiscalapi-settings.js +3 -0
  17. package/dist/cjs/common/paged-list.js +18 -0
  18. package/dist/cjs/common/serializable-dto.js +37 -0
  19. package/dist/cjs/http/fiscalapi-http-client-factory.js +66 -0
  20. package/dist/cjs/http/fiscalapi-http-client.interface.js +3 -0
  21. package/dist/cjs/http/fiscalapi-http-client.js +306 -0
  22. package/dist/cjs/index.js +31 -0
  23. package/dist/cjs/models/api-key.js +3 -0
  24. package/dist/cjs/models/invoice.js +3 -0
  25. package/dist/cjs/models/person.js +3 -0
  26. package/dist/cjs/models/product.js +3 -0
  27. package/dist/cjs/models/tax-file.js +3 -0
  28. package/dist/cjs/sdk-constants.js +25 -0
  29. package/dist/cjs/services/api-key-service.js +19 -0
  30. package/dist/cjs/services/base-fiscalapi-service.js +170 -0
  31. package/dist/cjs/services/catalog-service.js +51 -0
  32. package/dist/cjs/services/fiscalapi-client.js +67 -0
  33. package/dist/cjs/services/invoice-service.js +116 -0
  34. package/dist/cjs/services/person-service.js +19 -0
  35. package/dist/cjs/services/product-service.js +19 -0
  36. package/dist/cjs/services/tax-file-service.js +43 -0
  37. package/dist/cjs/utils/date-utils.js +36 -0
  38. package/dist/cjs/utils/encoding-utils.js +21 -0
  39. package/dist/cjs/utils/validation-utils.js +40 -0
  40. package/dist/esm/abstractions/api-key-service.interface.js +2 -0
  41. package/dist/esm/abstractions/catalog-service.interface.js +2 -0
  42. package/dist/esm/abstractions/fiscalapi-client.interface.js +2 -0
  43. package/dist/esm/abstractions/fiscalapi-service.interface.js +2 -0
  44. package/dist/esm/abstractions/invoice-service.interface.js +2 -0
  45. package/dist/esm/abstractions/person-service.interface.js +2 -0
  46. package/dist/esm/abstractions/product-service.interface.js +2 -0
  47. package/dist/esm/abstractions/tax-file-service.interface.js +2 -0
  48. package/dist/esm/common/api-response.js +2 -0
  49. package/dist/esm/common/auditable-dto.js +7 -0
  50. package/dist/esm/common/base-dto.js +7 -0
  51. package/dist/esm/common/catalog-dto.js +4 -0
  52. package/dist/esm/common/file-response.js +2 -0
  53. package/dist/esm/common/fiscalapi-settings.js +2 -0
  54. package/dist/esm/common/paged-list.js +14 -0
  55. package/dist/esm/common/serializable-dto.js +33 -0
  56. package/dist/esm/http/fiscalapi-http-client-factory.js +59 -0
  57. package/dist/esm/http/fiscalapi-http-client.interface.js +2 -0
  58. package/dist/esm/http/fiscalapi-http-client.js +302 -0
  59. package/dist/esm/index.js +13 -0
  60. package/dist/esm/models/api-key.js +2 -0
  61. package/dist/esm/models/invoice.js +2 -0
  62. package/dist/esm/models/person.js +2 -0
  63. package/dist/esm/models/product.js +2 -0
  64. package/dist/esm/models/tax-file.js +2 -0
  65. package/dist/esm/sdk-constants.js +22 -0
  66. package/dist/esm/services/api-key-service.js +15 -0
  67. package/dist/esm/services/base-fiscalapi-service.js +166 -0
  68. package/dist/esm/services/catalog-service.js +47 -0
  69. package/dist/esm/services/fiscalapi-client.js +63 -0
  70. package/dist/esm/services/invoice-service.js +112 -0
  71. package/dist/esm/services/person-service.js +15 -0
  72. package/dist/esm/services/product-service.js +15 -0
  73. package/dist/esm/services/tax-file-service.js +39 -0
  74. package/dist/esm/utils/date-utils.js +31 -0
  75. package/dist/esm/utils/encoding-utils.js +17 -0
  76. package/dist/esm/utils/validation-utils.js +34 -0
  77. package/dist/types/abstractions/api-key-service.interface.d.ts +7 -0
  78. package/dist/types/abstractions/catalog-service.interface.d.ts +27 -0
  79. package/dist/types/abstractions/fiscalapi-client.interface.d.ts +35 -0
  80. package/dist/types/abstractions/fiscalapi-service.interface.d.ts +94 -0
  81. package/dist/types/abstractions/invoice-service.interface.d.ts +39 -0
  82. package/dist/types/abstractions/person-service.interface.d.ts +7 -0
  83. package/dist/types/abstractions/product-service.interface.d.ts +7 -0
  84. package/dist/types/abstractions/tax-file-service.interface.d.ts +22 -0
  85. package/dist/types/common/api-response.d.ts +56 -0
  86. package/dist/types/common/auditable-dto.d.ts +9 -0
  87. package/dist/types/common/base-dto.d.ts +7 -0
  88. package/dist/types/common/catalog-dto.d.ts +8 -0
  89. package/dist/types/common/file-response.d.ts +18 -0
  90. package/dist/types/common/fiscalapi-settings.d.ts +30 -0
  91. package/dist/types/common/paged-list.d.ts +39 -0
  92. package/dist/types/common/serializable-dto.d.ts +10 -0
  93. package/dist/types/http/fiscalapi-http-client-factory.d.ts +22 -0
  94. package/dist/types/http/fiscalapi-http-client.d.ts +113 -0
  95. package/dist/types/http/fiscalapi-http-client.interface.d.ts +80 -0
  96. package/dist/types/index.d.ts +25 -0
  97. package/dist/types/models/api-key.d.ts +21 -0
  98. package/dist/types/models/invoice.d.ts +337 -0
  99. package/dist/types/models/person.d.ts +42 -0
  100. package/dist/types/models/product.d.ts +49 -0
  101. package/dist/types/models/tax-file.d.ts +23 -0
  102. package/dist/types/sdk-constants.d.ts +21 -0
  103. package/dist/types/services/api-key-service.d.ts +15 -0
  104. package/dist/types/services/base-fiscalapi-service.d.ts +72 -0
  105. package/dist/types/services/catalog-service.d.ts +34 -0
  106. package/dist/types/services/fiscalapi-client.d.ts +49 -0
  107. package/dist/types/services/invoice-service.d.ts +54 -0
  108. package/dist/types/services/person-service.d.ts +15 -0
  109. package/dist/types/services/product-service.d.ts +15 -0
  110. package/dist/types/services/tax-file-service.d.ts +30 -0
  111. package/dist/types/utils/date-utils.d.ts +17 -0
  112. package/dist/types/utils/encoding-utils.d.ts +12 -0
  113. package/dist/types/utils/validation-utils.d.ts +25 -0
  114. package/fiscalapi.ico +0 -0
  115. package/fiscalapi.png +0 -0
  116. package/package.json +64 -0
@@ -0,0 +1,49 @@
1
+ import { IFiscalapiClient, IInvoiceService, IProductService, IPersonService, IApiKeyService, ICatalogService, ITaxFileService } from '..';
2
+ import { FiscalapiSettings } from '../common/fiscalapi-settings';
3
+ /**
4
+ * Cliente principal para FiscalAPI
5
+ */
6
+ export declare class FiscalapiClient implements IFiscalapiClient {
7
+ /**
8
+ * Servicio de facturas
9
+ */
10
+ readonly invoices: IInvoiceService;
11
+ /**
12
+ * Servicio de productos
13
+ */
14
+ readonly products: IProductService;
15
+ /**
16
+ * Servicio de personas
17
+ */
18
+ readonly persons: IPersonService;
19
+ /**
20
+ * Servicio de claves de API
21
+ */
22
+ readonly apiKeys: IApiKeyService;
23
+ /**
24
+ * Servicio de catálogos
25
+ */
26
+ readonly catalogs: ICatalogService;
27
+ /**
28
+ * Servicio de archivos fiscales
29
+ */
30
+ readonly taxFiles: ITaxFileService;
31
+ /**
32
+ * Crea una nueva instancia del cliente de FiscalAPI
33
+ * @param {FiscalapiSettings} settings - Configuración
34
+ * @private
35
+ */
36
+ private constructor();
37
+ /**
38
+ * Crea una nueva instancia del cliente de FiscalAPI
39
+ * @param {FiscalapiSettings} settings - Configuración
40
+ * @returns {IFiscalapiClient} Instancia del cliente de FiscalAPI
41
+ */
42
+ static create(settings: FiscalapiSettings): IFiscalapiClient;
43
+ /**
44
+ * Valida la configuración
45
+ * @param {FiscalapiSettings} settings - Configuración
46
+ * @private
47
+ */
48
+ private static validateSettings;
49
+ }
@@ -0,0 +1,54 @@
1
+ import { IFiscalapiHttpClient } from '../http/fiscalapi-http-client.interface';
2
+ import { ApiResponse } from '../common/api-response';
3
+ import { FileResponse } from '../common/file-response';
4
+ import { BaseFiscalapiService } from './base-fiscalapi-service';
5
+ import { IInvoiceService } from '../abstractions/invoice-service.interface';
6
+ import { Invoice, CancelInvoiceRequest, CancelInvoiceResponse, CreatePdfRequest, SendInvoiceRequest, InvoiceStatusRequest, InvoiceStatusResponse } from '../models/invoice';
7
+ /**
8
+ * Implementación del servicio de facturas
9
+ */
10
+ export declare class InvoiceService extends BaseFiscalapiService<Invoice> implements IInvoiceService {
11
+ private readonly INCOME_ENDPOINT;
12
+ private readonly CREDIT_NOTE_ENDPOINT;
13
+ private readonly PAYMENT_ENDPOINT;
14
+ /**
15
+ * Crea una nueva instancia del servicio de facturas
16
+ * @param {IFiscalapiHttpClient} httpClient - Cliente HTTP
17
+ * @param {string} apiVersion - Versión de la API
18
+ */
19
+ constructor(httpClient: IFiscalapiHttpClient, apiVersion: string);
20
+ /**
21
+ * @inheritdoc
22
+ */
23
+ create(requestModel: Invoice): Promise<ApiResponse<Invoice>>;
24
+ /**
25
+ * Cancela una factura
26
+ * @param {CancelInvoiceRequest} request - Solicitud para cancelar factura
27
+ * @returns {Promise<ApiResponse<CancelInvoiceResponse>>} Respuesta de la cancelación
28
+ */
29
+ cancel(request: CancelInvoiceRequest): Promise<ApiResponse<CancelInvoiceResponse>>;
30
+ /**
31
+ * Obtiene el PDF de una factura
32
+ * @param {CreatePdfRequest} request - Solicitud para crear PDF
33
+ * @returns {Promise<ApiResponse<FileResponse>>} Respuesta con el archivo PDF
34
+ */
35
+ getPdf(request: CreatePdfRequest): Promise<ApiResponse<FileResponse>>;
36
+ /**
37
+ * Obtiene el XML de una factura
38
+ * @param {string} id - ID de la factura
39
+ * @returns {Promise<ApiResponse<FileResponse>>} Respuesta con el archivo XML
40
+ */
41
+ getXml(id: string): Promise<ApiResponse<FileResponse>>;
42
+ /**
43
+ * Envía una factura por correo electrónico
44
+ * @param {SendInvoiceRequest} request - Solicitud para enviar factura
45
+ * @returns {Promise<ApiResponse<boolean>>} Resultado de la operación
46
+ */
47
+ send(request: SendInvoiceRequest): Promise<ApiResponse<boolean>>;
48
+ /**
49
+ * Obtiene el estado de una factura
50
+ * @param {InvoiceStatusRequest} request - Solicitud para consultar estado
51
+ * @returns {Promise<ApiResponse<InvoiceStatusResponse>>} Respuesta con el estado de la factura
52
+ */
53
+ getStatus(request: InvoiceStatusRequest): Promise<ApiResponse<InvoiceStatusResponse>>;
54
+ }
@@ -0,0 +1,15 @@
1
+ import { Person } from '../models/person';
2
+ import { IFiscalapiHttpClient } from '../http/fiscalapi-http-client.interface';
3
+ import { BaseFiscalapiService } from './base-fiscalapi-service';
4
+ import { IPersonService } from '..';
5
+ /**
6
+ * Implementación del servicio de personas
7
+ */
8
+ export declare class PersonService extends BaseFiscalapiService<Person> implements IPersonService {
9
+ /**
10
+ * Crea una nueva instancia del servicio de personas
11
+ * @param {IFiscalapiHttpClient} httpClient - Cliente HTTP
12
+ * @param {string} apiVersion - Versión de la API
13
+ */
14
+ constructor(httpClient: IFiscalapiHttpClient, apiVersion: string);
15
+ }
@@ -0,0 +1,15 @@
1
+ import { Product } from '../models/product';
2
+ import { IFiscalapiHttpClient } from '../http/fiscalapi-http-client.interface';
3
+ import { BaseFiscalapiService } from './base-fiscalapi-service';
4
+ import { IProductService } from '..';
5
+ /**
6
+ * Implementación del servicio de productos
7
+ */
8
+ export declare class ProductService extends BaseFiscalapiService<Product> implements IProductService {
9
+ /**
10
+ * Crea una nueva instancia del servicio de productos
11
+ * @param {IFiscalapiHttpClient} httpClient - Cliente HTTP
12
+ * @param {string} apiVersion - Versión de la API
13
+ */
14
+ constructor(httpClient: IFiscalapiHttpClient, apiVersion: string);
15
+ }
@@ -0,0 +1,30 @@
1
+ import { TaxFile } from '../models/tax-file';
2
+ import { IFiscalapiHttpClient } from '../http/fiscalapi-http-client.interface';
3
+ import { ApiResponse } from '../common/api-response';
4
+ import { BaseFiscalapiService } from './base-fiscalapi-service';
5
+ import { ITaxFileService } from '..';
6
+ /**
7
+ * Implementación del servicio de archivos fiscales
8
+ */
9
+ export declare class TaxFileService extends BaseFiscalapiService<TaxFile> implements ITaxFileService {
10
+ /**
11
+ * Crea una nueva instancia del servicio de archivos fiscales
12
+ * @param {IFiscalapiHttpClient} httpClient - Cliente HTTP
13
+ * @param {string} apiVersion - Versión de la API
14
+ */
15
+ constructor(httpClient: IFiscalapiHttpClient, apiVersion: string);
16
+ /**
17
+ * Obtiene el último par de ids de certificados válidos y vigente de una persona. Es decir sus certificados por defecto (ids)
18
+ *
19
+ * @param personId - Id de la persona propietaria de los certificados
20
+ * @returns Promise que resuelve en una respuesta API con una lista de un par de certificados, pero sin contenido, solo sus Ids
21
+ */
22
+ getDefaultReferences(personId: string): Promise<ApiResponse<TaxFile[]>>;
23
+ /**
24
+ * Obtiene el último par de certificados válidos y vigente de una persona. Es decir sus certificados por defecto
25
+ *
26
+ * @param personId - Id de la persona dueña de los certificados
27
+ * @returns Promise que resuelve en una respuesta API con una lista de un par de certificados
28
+ */
29
+ getDefaultValues(personId: string): Promise<ApiResponse<TaxFile[]>>;
30
+ }
@@ -0,0 +1,17 @@
1
+ import { DateTime } from 'luxon';
2
+ /**
3
+ * Formato de fecha SAT (para facturas mexicanas)
4
+ */
5
+ export declare const SAT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
6
+ /**
7
+ * Formatea una fecha de acuerdo al formato de fecha SAT
8
+ * @param {Date|string|DateTime} date - Fecha a formatear
9
+ * @returns {string} Cadena de fecha formateada
10
+ */
11
+ export declare function formatSatDate(date: Date | string | DateTime): string;
12
+ /**
13
+ * Analiza una cadena de formato de fecha SAT en un objeto DateTime
14
+ * @param {string} dateStr - Cadena de fecha en formato SAT
15
+ * @returns {DateTime} Objeto DateTime
16
+ */
17
+ export declare function parseSatDate(dateStr: string): DateTime;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Codifica una cadena a base64
3
+ * @param {string} text - Texto a codificar
4
+ * @returns {string} Cadena codificada en base64
5
+ */
6
+ export declare function encodeToBase64(text: string): string;
7
+ /**
8
+ * Decodifica una cadena base64
9
+ * @param {string} base64Text - Cadena codificada en base64
10
+ * @returns {string} Cadena decodificada
11
+ */
12
+ export declare function decodeFromBase64(base64Text: string): string;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Comprueba si un valor es nulo o indefinido
3
+ * @param {any} value - Valor a comprobar
4
+ * @returns {boolean} Verdadero si el valor es nulo o indefinido, falso en caso contrario
5
+ */
6
+ export declare function isNullOrUndefined(value: any): boolean;
7
+ /**
8
+ * Comprueba si una cadena es nula, indefinida o vacía
9
+ * @param {string|null|undefined} value - Cadena a comprobar
10
+ * @returns {boolean} Verdadero si la cadena es nula, indefinida o vacía, falso en caso contrario
11
+ */
12
+ export declare function isNullOrEmpty(value: string | null | undefined): boolean;
13
+ /**
14
+ * Comprueba si un array es nulo, indefinido o vacío
15
+ * @param {T[]|null|undefined} value - Array a comprobar
16
+ * @returns {boolean} Verdadero si el array es nulo, indefinido o vacío, falso en caso contrario
17
+ * @template T
18
+ */
19
+ export declare function isArrayNullOrEmpty<T>(value: T[] | null | undefined): boolean;
20
+ /**
21
+ * Comprueba si un objeto es nulo, indefinido o no tiene propiedades
22
+ * @param {object|null|undefined} value - Objeto a comprobar
23
+ * @returns {boolean} Verdadero si el objeto es nulo, indefinido o no tiene propiedades, falso en caso contrario
24
+ */
25
+ export declare function isObjectEmpty(value: object | null | undefined): boolean;
package/fiscalapi.ico ADDED
Binary file
package/fiscalapi.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "fiscalapi",
3
+ "version": "1.0.0",
4
+ "description": "SDK de Node.js para FiscalAPI",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "files": [
9
+ "dist/",
10
+ "fiscalapi.ico",
11
+ "fiscalapi.png",
12
+ "LICENSE.txt"
13
+ ],
14
+ "scripts": {
15
+ "clean": "rimraf dist",
16
+ "build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:types",
17
+ "build:esm": "tsc -p tsconfig.esm.json",
18
+ "build:cjs": "tsc -p tsconfig.cjs.json",
19
+ "build:types": "tsc -p tsconfig.types.json",
20
+ "test": "jest",
21
+ "lint": "eslint 'src/**/*.ts'",
22
+ "prepare": "npm run build",
23
+ "main": "ts-node examples/main.ts"
24
+ },
25
+ "keywords": [
26
+ "fiscalapi",
27
+ "cfdi",
28
+ "factura",
29
+ "facturación",
30
+ "sat",
31
+ "mexico"
32
+ ],
33
+ "author": "FISCAL API S DE R.L DE C.V",
34
+ "license": "MPL-2.0",
35
+ "engines": {
36
+ "node": ">=12.0.0"
37
+ },
38
+ "exports": {
39
+ ".": {
40
+ "import": "./dist/esm/index.js",
41
+ "require": "./dist/cjs/index.js",
42
+ "types": "./dist/types/index.d.ts"
43
+ }
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/FiscalAPI/fiscalapi-node"
48
+ },
49
+ "homepage": "https://www.fiscalapi.com",
50
+ "bugs": {
51
+ "url": "https://github.com/FiscalAPI/fiscalapi-node/issues"
52
+ },
53
+ "dependencies": {
54
+ "axios": "^1.8.4",
55
+ "luxon": "^3.6.0"
56
+ },
57
+ "devDependencies": {
58
+ "@types/luxon": "^3.4.2",
59
+ "@types/node": "^22.13.14",
60
+ "rimraf": "^6.0.1",
61
+ "ts-node": "^10.9.2",
62
+ "typescript": "^5.8.2"
63
+ }
64
+ }