facturas 0.4.2 → 0.5.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.
- package/README.md +2 -0
- package/dist/errors.d.ts +27 -1
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -1
- package/dist/{index-BLq3d6xg.d.ts → index-CqXVyU0E.d.ts} +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +373 -56
- package/dist/index.js.map +1 -1
- package/dist/padron.d.ts +2 -2
- package/dist/padron.js.map +1 -1
- package/dist/{types-SloiIQkT.d.ts → types-CKKe1Oo4.d.ts} +13 -1
- package/dist/types.d.ts +1 -1
- package/dist/wsfe.d.ts +2 -2
- package/dist/wsfe.js.map +1 -1
- package/dist/wsmtxca.d.ts +2 -2
- package/dist/wsmtxca.js.map +1 -1
- package/package.json +14 -15
package/dist/padron.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WsaaAuthModule, S as SoapTransport } from './index-
|
|
1
|
+
import { f as ArcaClientConfig } from './types-CKKe1Oo4.js';
|
|
2
|
+
import { W as WsaaAuthModule, S as SoapTransport } from './index-CqXVyU0E.js';
|
|
3
3
|
|
|
4
4
|
/** Result of a taxpayer lookup via Padron A5. */
|
|
5
5
|
type PadronTaxpayerResult = {
|
package/dist/padron.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/services/padron.ts"],"sourcesContent":["/** Base error class for all ARCA-related errors. */\nexport class ArcaError extends Error {\n readonly code: string;\n override readonly name: string = \"ArcaError\";\n\n constructor(message: string, code = \"ARCA_ERROR\", options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n }\n}\n\n/** Thrown when the ARCA client configuration is missing or invalid. */\nexport class ArcaConfigurationError extends ArcaError {\n override readonly name: string = \"ArcaConfigurationError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_CONFIGURATION_ERROR\", options);\n }\n}\n\n/** Thrown when caller-provided input data is missing or invalid. */\nexport class ArcaInputError extends ArcaError {\n override readonly name: string = \"ArcaInputError\";\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_INPUT_ERROR\", options);\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */\nexport class ArcaTransportError extends ArcaError {\n override readonly name: string = \"ArcaTransportError\";\n readonly statusCode?: number;\n readonly responseBody?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n statusCode?: number;\n responseBody?: string;\n }\n ) {\n super(message, \"ARCA_TRANSPORT_ERROR\", options);\n this.statusCode = options?.statusCode;\n this.responseBody = options?.responseBody;\n }\n}\n\n/** Thrown when the SOAP response contains a Fault element. */\nexport class ArcaSoapFaultError extends ArcaError {\n override readonly name: string = \"ArcaSoapFaultError\";\n readonly faultCode?: string;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n faultCode?: string;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SOAP_FAULT\", options);\n this.faultCode = options?.faultCode;\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */\nexport class ArcaServiceError extends ArcaError {\n override readonly name: string = \"ArcaServiceError\";\n readonly serviceCode?: string | number;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n serviceCode?: string | number;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SERVICE_ERROR\", options);\n this.serviceCode = options?.serviceCode;\n this.detail = options?.detail;\n }\n}\n","import { ArcaSoapFaultError } from \"../errors\";\nimport type {\n ArcaClientConfig,\n ArcaPadronServiceName,\n} from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\n\n/** Result of a taxpayer lookup via Padron A5. */\nexport type PadronTaxpayerResult = {\n taxId: string;\n personType?: string;\n name?: string;\n raw: Record<string, unknown>;\n};\n\n/** Result of a tax ID lookup by document number via Padron A13. */\nexport type PadronTaxIdLookupResult = {\n taxIds: string[];\n raw: Record<string, unknown>;\n};\n\n/** Padron taxpayer registry service. */\nexport type PadronService = {\n /** Looks up taxpayer details by CUIT. Returns `null` if the taxpayer does not exist. */\n getTaxpayerDetails(\n taxId: number | string\n ): Promise<PadronTaxpayerResult | null>;\n /** Looks up CUITs associated with a document number. Returns `null` if not found. */\n getTaxIdByDocument(\n documentNumber: number | string\n ): Promise<PadronTaxIdLookupResult | null>;\n};\n\nexport type CreatePadronServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\n/** Creates a Padron service instance wired with authentication and SOAP transport. */\nexport function createPadronService(\n options: CreatePadronServiceOptions\n): PadronService {\n return {\n async getTaxpayerDetails(taxId) {\n const raw = await executePadronOperation(\n options,\n \"padron-a5\",\n \"getPersona_v2\",\n {\n idPersona: Number.parseInt(String(taxId), 10),\n }\n );\n if (!raw) {\n return null;\n }\n const record = raw as Record<string, unknown>;\n const datosGenerales = record.datosGenerales as\n | Record<string, unknown>\n | undefined;\n return {\n taxId: String(record.idPersona ?? \"\"),\n ...(record.tipoPersona === undefined\n ? {}\n : { personType: String(record.tipoPersona) }),\n ...(datosGenerales ? { name: extractPadronName(datosGenerales) } : {}),\n raw: record,\n };\n },\n async getTaxIdByDocument(documentNumber) {\n const raw = await executePadronOperation(\n options,\n \"padron-a13\",\n \"getIdPersonaListByDocumento\",\n {\n documento: String(documentNumber),\n }\n );\n if (!raw) {\n return null;\n }\n const record = raw as Record<string, unknown>;\n const idPersona = record.idPersona;\n const taxIds = Array.isArray(idPersona)\n ? idPersona.map(String)\n : idPersona === undefined\n ? []\n : [String(idPersona)];\n return {\n taxIds,\n raw: record,\n };\n },\n };\n}\n\nfunction extractPadronName(\n datosGenerales: Record<string, unknown>\n): string | undefined {\n if (typeof datosGenerales.razonSocial === \"string\") {\n return datosGenerales.razonSocial;\n }\n const nombre = datosGenerales.nombre;\n const apellido = datosGenerales.apellido;\n if (typeof apellido === \"string\" && typeof nombre === \"string\") {\n return `${apellido} ${nombre}`.trim();\n }\n if (typeof apellido === \"string\") {\n return apellido;\n }\n if (typeof nombre === \"string\") {\n return nombre;\n }\n return undefined;\n}\n\nasync function executePadronOperation(\n options: CreatePadronServiceOptions,\n service: ArcaPadronServiceName,\n operation: string,\n body: Record<string, unknown>\n) {\n const auth = await options.auth.login(\n service === \"padron-a5\"\n ? \"ws_sr_constancia_inscripcion\"\n : \"ws_sr_padron_a13\"\n );\n\n try {\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service,\n operation,\n bodyElementNamespaceMode: \"prefix\",\n body: {\n token: auth.token,\n sign: auth.sign,\n cuitRepresentada: Number.parseInt(options.config.taxId, 10),\n ...body,\n },\n });\n\n const operationResponse = response.result as Record<string, unknown>;\n\n if (operation === \"getPersona_v2\") {\n return operationResponse.personaReturn ?? null;\n }\n\n if (operation === \"getIdPersonaListByDocumento\") {\n return operationResponse.idPersonaListReturn ?? null;\n }\n\n return operationResponse.return ?? null;\n } catch (error) {\n if (\n error instanceof ArcaSoapFaultError &&\n // Public Padron A5/A13 WSDLs expose only a generic validation fault, so\n // there is no documented not-found-specific fault code to match here.\n // Keep the current message fallback, but treat it as fragile.\n error.message.toLowerCase().includes(\"no existe\")\n ) {\n return null;\n }\n\n throw error;\n }\n}\n"],"mappings":";AACO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACS,OAAe;AAAA,EAEjC,YAAY,SAAiB,OAAO,cAAc,SAAwB;AACxE,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AA+CO,IAAM,qBAAN,cAAiC,UAAU;AAAA,EAC9B,OAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAET,YACE,SACA,SAIA;AACA,UAAM,SAAS,mB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,OAAO,WAAW,UAAU;AAC9D,WAAO,GAAG,QAAQ,IAAI,MAAM,GAAG,KAAK;AAAA,EACtC;AACA,MAAI,OAAO,aAAa,UAAU;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,eAAe,uBACb,SACA,SACA,WACA,MACA;AACA,QAAM,OAAO,MAAM,QAAQ,KAAK;AAAA,IAC9B,YAAY,cACR,iCACA;AAAA,EACN;AAEA,MAAI;AACF,UAAM,WAAW,MAAM,QAAQ,KAAK,QAGlC;AAAA,MACA;AAAA,MACA;AAAA,MACA,0BAA0B;AAAA,MAC1B,MAAM;AAAA,QACJ,OAAO,KAAK;AAAA,QACZ,MAAM,KAAK;AAAA,QACX,kBAAkB,OAAO,SAAS,QAAQ,OAAO,OAAO,EAAE;AAAA,QAC1D,GAAG;AAAA,MACL;AAAA,IACF,CAAC;AAED,UAAM,oBAAoB,SAAS;AAEnC,QAAI,cAAc,iBAAiB;AACjC,aAAO,kBAAkB,iBAAiB;AAAA,IAC5C;AAEA,QAAI,cAAc,+BAA+B;AAC/C,aAAO,kBAAkB,uBAAuB;AAAA,IAClD;AAEA,WAAO,kBAAkB,UAAU;AAAA,EACrC,SAAS,OAAO;AACd,QACE,iBAAiB;AAAA;AAAA;AAAA,IAIjB,MAAM,QAAQ,YAAY,EAAE,SAAS,WAAW,GAChD;AACA,aAAO;AAAA,IACT;AAEA,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/services/padron.ts"],"sourcesContent":["import type { ArcaServiceName } from \"./internal/types\";\n\n/** Base error class for all ARCA-related errors. */\nexport class ArcaError extends Error {\n readonly code: string;\n override readonly name: string = \"ArcaError\";\n\n constructor(message: string, code = \"ARCA_ERROR\", options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n }\n}\n\n/** Thrown when the ARCA client configuration is missing or invalid. */\nexport class ArcaConfigurationError extends ArcaError {\n override readonly name: string = \"ArcaConfigurationError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_CONFIGURATION_ERROR\", options);\n }\n}\n\n/** Thrown when caller-provided input data is missing or invalid. */\nexport class ArcaInputError extends ArcaError {\n override readonly name: string = \"ArcaInputError\";\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_INPUT_ERROR\", options);\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */\nexport class ArcaTransportError extends ArcaError {\n override readonly name: string = \"ArcaTransportError\";\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBody?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n statusCode?: number;\n contentType?: string;\n responseBody?: string;\n }\n ) {\n super(message, \"ARCA_TRANSPORT_ERROR\", options);\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBody = options?.responseBody;\n }\n}\n\n/** Thrown when the SOAP response contains a Fault element. */\nexport class ArcaSoapFaultError extends ArcaError {\n override readonly name: string = \"ArcaSoapFaultError\";\n readonly faultCode?: string;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n faultCode?: string;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SOAP_FAULT\", options);\n this.faultCode = options?.faultCode;\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when a response cannot be parsed as a valid SOAP envelope. */\nexport class ArcaInvalidSoapResponseError extends ArcaError {\n override readonly name: string = \"ArcaInvalidSoapResponseError\";\n readonly service?: ArcaServiceName;\n readonly operation?: string;\n readonly endpointUrl?: string;\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBodyLength?: number;\n readonly responseBodyPreview?: string;\n readonly parsedDetail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n service?: ArcaServiceName;\n operation?: string;\n endpointUrl?: string;\n statusCode?: number;\n contentType?: string;\n responseBodyLength?: number;\n responseBodyPreview?: string;\n parsedDetail?: unknown;\n }\n ) {\n super(message, \"ARCA_INVALID_SOAP_RESPONSE\", options);\n this.service = options?.service;\n this.operation = options?.operation;\n this.endpointUrl = options?.endpointUrl;\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBodyLength = options?.responseBodyLength;\n this.responseBodyPreview = options?.responseBodyPreview;\n this.parsedDetail = options?.parsedDetail;\n }\n}\n\n/** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */\nexport class ArcaServiceError extends ArcaError {\n override readonly name: string = \"ArcaServiceError\";\n readonly serviceCode?: string | number;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n serviceCode?: string | number;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SERVICE_ERROR\", options);\n this.serviceCode = options?.serviceCode;\n this.detail = options?.detail;\n }\n}\n","import { ArcaSoapFaultError } from \"../errors\";\nimport type {\n ArcaClientConfig,\n ArcaPadronServiceName,\n} from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\n\n/** Result of a taxpayer lookup via Padron A5. */\nexport type PadronTaxpayerResult = {\n taxId: string;\n personType?: string;\n name?: string;\n raw: Record<string, unknown>;\n};\n\n/** Result of a tax ID lookup by document number via Padron A13. */\nexport type PadronTaxIdLookupResult = {\n taxIds: string[];\n raw: Record<string, unknown>;\n};\n\n/** Padron taxpayer registry service. */\nexport type PadronService = {\n /** Looks up taxpayer details by CUIT. Returns `null` if the taxpayer does not exist. */\n getTaxpayerDetails(\n taxId: number | string\n ): Promise<PadronTaxpayerResult | null>;\n /** Looks up CUITs associated with a document number. Returns `null` if not found. */\n getTaxIdByDocument(\n documentNumber: number | string\n ): Promise<PadronTaxIdLookupResult | null>;\n};\n\nexport type CreatePadronServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\n/** Creates a Padron service instance wired with authentication and SOAP transport. */\nexport function createPadronService(\n options: CreatePadronServiceOptions\n): PadronService {\n return {\n async getTaxpayerDetails(taxId) {\n const raw = await executePadronOperation(\n options,\n \"padron-a5\",\n \"getPersona_v2\",\n {\n idPersona: Number.parseInt(String(taxId), 10),\n }\n );\n if (!raw) {\n return null;\n }\n const record = raw as Record<string, unknown>;\n const datosGenerales = record.datosGenerales as\n | Record<string, unknown>\n | undefined;\n return {\n taxId: String(record.idPersona ?? \"\"),\n ...(record.tipoPersona === undefined\n ? {}\n : { personType: String(record.tipoPersona) }),\n ...(datosGenerales ? { name: extractPadronName(datosGenerales) } : {}),\n raw: record,\n };\n },\n async getTaxIdByDocument(documentNumber) {\n const raw = await executePadronOperation(\n options,\n \"padron-a13\",\n \"getIdPersonaListByDocumento\",\n {\n documento: String(documentNumber),\n }\n );\n if (!raw) {\n return null;\n }\n const record = raw as Record<string, unknown>;\n const idPersona = record.idPersona;\n const taxIds = Array.isArray(idPersona)\n ? idPersona.map(String)\n : idPersona === undefined\n ? []\n : [String(idPersona)];\n return {\n taxIds,\n raw: record,\n };\n },\n };\n}\n\nfunction extractPadronName(\n datosGenerales: Record<string, unknown>\n): string | undefined {\n if (typeof datosGenerales.razonSocial === \"string\") {\n return datosGenerales.razonSocial;\n }\n const nombre = datosGenerales.nombre;\n const apellido = datosGenerales.apellido;\n if (typeof apellido === \"string\" && typeof nombre === \"string\") {\n return `${apellido} ${nombre}`.trim();\n }\n if (typeof apellido === \"string\") {\n return apellido;\n }\n if (typeof nombre === \"string\") {\n return nombre;\n }\n return undefined;\n}\n\nasync function executePadronOperation(\n options: CreatePadronServiceOptions,\n service: ArcaPadronServiceName,\n operation: string,\n body: Record<string, unknown>\n) {\n const auth = await options.auth.login(\n service === \"padron-a5\"\n ? \"ws_sr_constancia_inscripcion\"\n : \"ws_sr_padron_a13\"\n );\n\n try {\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service,\n operation,\n bodyElementNamespaceMode: \"prefix\",\n body: {\n token: auth.token,\n sign: auth.sign,\n cuitRepresentada: Number.parseInt(options.config.taxId, 10),\n ...body,\n },\n });\n\n const operationResponse = response.result as Record<string, unknown>;\n\n if (operation === \"getPersona_v2\") {\n return operationResponse.personaReturn ?? null;\n }\n\n if (operation === \"getIdPersonaListByDocumento\") {\n return operationResponse.idPersonaListReturn ?? null;\n }\n\n return operationResponse.return ?? null;\n } catch (error) {\n if (\n error instanceof ArcaSoapFaultError &&\n // Public Padron A5/A13 WSDLs expose only a generic validation fault, so\n // there is no documented not-found-specific fault code to match here.\n // Keep the current message fallback, but treat it as fragile.\n error.message.toLowerCase().includes(\"no existe\")\n ) {\n return null;\n }\n\n throw error;\n }\n}\n"],"mappings":";AAGO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACS,OAAe;AAAA,EAEjC,YAAY,SAAiB,OAAO,cAAc,SAAwB;AACxE,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAkDO,IAAM,qBAAN,cAAiC,UAAU;AAAA,EAC9B,OAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAET,YACE,SACA,SAIA;AACA,UAAM,SAAS,mBAAmB,OAAO;AACzC,SAAK,YAAY,SAAS;AAC1B,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;;;ACpCO,SAAS,oBACd,SACe;AACf,SAAO;AAAA,IACL,MAAM,mBAAmB,OAAO;AAC9B,YAAM,MAAM,MAAM;AAAA,QAChB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,UACE,WAAW,OAAO,SAAS,OAAO,KAAK,GAAG,EAAE;AAAA,QAC9C;AAAA,MACF;AACA,UAAI,CAAC,KAAK;AACR,eAAO;AAAA,MACT;AACA,YAAM,SAAS;AACf,YAAM,iBAAiB,OAAO;AAG9B,aAAO;AAAA,QACL,OAAO,OAAO,OAAO,aAAa,EAAE;AAAA,QACpC,GAAI,OAAO,gBA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QACZ,MAAM,KAAK;AAAA,QACX,kBAAkB,OAAO,SAAS,QAAQ,OAAO,OAAO,EAAE;AAAA,QAC1D,GAAG;AAAA,MACL;AAAA,IACF,CAAC;AAED,UAAM,oBAAoB,SAAS;AAEnC,QAAI,cAAc,iBAAiB;AACjC,aAAO,kBAAkB,iBAAiB;AAAA,IAC5C;AAEA,QAAI,cAAc,+BAA+B;AAC/C,aAAO,kBAAkB,uBAAuB;AAAA,IAClD;AAEA,WAAO,kBAAkB,UAAU;AAAA,EACrC,SAAS,OAAO;AACd,QACE,iBAAiB;AAAA;AAAA;AAAA,IAIjB,MAAM,QAAQ,YAAY,EAAE,SAAS,WAAW,GAChD;AACA,aAAO;AAAA,IACT;AAEA,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -14,6 +14,17 @@ type ArcaLoggerConfig = {
|
|
|
14
14
|
level?: ArcaLogLevel;
|
|
15
15
|
log?: (level: ArcaLogLevel, message: string, ...args: unknown[]) => void;
|
|
16
16
|
};
|
|
17
|
+
type ArcaWsaaSessionKey = {
|
|
18
|
+
environment: ArcaEnvironment;
|
|
19
|
+
service: ArcaWsaaServiceId;
|
|
20
|
+
certificateFingerprint: string;
|
|
21
|
+
};
|
|
22
|
+
type ArcaWsaaSessionStore = {
|
|
23
|
+
get(key: ArcaWsaaSessionKey): Promise<ArcaAuthCredentials | null>;
|
|
24
|
+
set(key: ArcaWsaaSessionKey, credentials: ArcaAuthCredentials): Promise<void>;
|
|
25
|
+
delete?(key: ArcaWsaaSessionKey): Promise<void>;
|
|
26
|
+
withLock?<T>(key: ArcaWsaaSessionKey, fn: () => Promise<T>): Promise<T>;
|
|
27
|
+
};
|
|
17
28
|
/** Configuration required to create an ARCA client. */
|
|
18
29
|
type ArcaClientConfig = {
|
|
19
30
|
taxId: string;
|
|
@@ -24,6 +35,7 @@ type ArcaClientConfig = {
|
|
|
24
35
|
retries?: number;
|
|
25
36
|
retryDelay?: number;
|
|
26
37
|
logger?: ArcaLoggerConfig;
|
|
38
|
+
wsaaSessionStore?: ArcaWsaaSessionStore;
|
|
27
39
|
};
|
|
28
40
|
/** Credentials returned by a WSAA login. */
|
|
29
41
|
type ArcaAuthCredentials = {
|
|
@@ -50,4 +62,4 @@ type ArcaSoapExecutionOptions<TBody> = {
|
|
|
50
62
|
body: TBody;
|
|
51
63
|
};
|
|
52
64
|
|
|
53
|
-
export type {
|
|
65
|
+
export type { ArcaServiceName as A, ArcaSoapExecutionOptions as a, ArcaSoapResponse as b, ArcaWsaaServiceId as c, ArcaAuthOptions as d, ArcaAuthCredentials as e, ArcaClientConfig as f, ArcaEnvironment as g, ArcaWsaaSessionStore as h, ArcaLogLevel as i, ArcaLoggerConfig as j, ArcaPadronServiceName as k, ArcaRepresentedTaxId as l, ArcaServiceTarget as m, ArcaWsaaSessionKey as n };
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { e as ArcaAuthCredentials, d as ArcaAuthOptions, f as ArcaClientConfig, g as ArcaEnvironment, i as ArcaLogLevel, j as ArcaLoggerConfig, k as ArcaPadronServiceName, l as ArcaRepresentedTaxId, A as ArcaServiceName, m as ArcaServiceTarget, c as ArcaWsaaServiceId, n as ArcaWsaaSessionKey, h as ArcaWsaaSessionStore } from './types-CKKe1Oo4.js';
|
package/dist/wsfe.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WsaaAuthModule, S as SoapTransport } from './index-
|
|
1
|
+
import { f as ArcaClientConfig } from './types-CKKe1Oo4.js';
|
|
2
|
+
import { W as WsaaAuthModule, S as SoapTransport } from './index-CqXVyU0E.js';
|
|
3
3
|
|
|
4
4
|
/** Accepted public date inputs for WSFE request fields. */
|
|
5
5
|
type WsfeDateInput = `${number}${number}${number}${number}-${number}${number}-${number}${number}` | `${number}${number}${number}${number}${number}${number}${number}${number}`;
|
package/dist/wsfe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/services/wsfe.ts"],"sourcesContent":["/** Base error class for all ARCA-related errors. */\nexport class ArcaError extends Error {\n readonly code: string;\n override readonly name: string = \"ArcaError\";\n\n constructor(message: string, code = \"ARCA_ERROR\", options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n }\n}\n\n/** Thrown when the ARCA client configuration is missing or invalid. */\nexport class ArcaConfigurationError extends ArcaError {\n override readonly name: string = \"ArcaConfigurationError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_CONFIGURATION_ERROR\", options);\n }\n}\n\n/** Thrown when caller-provided input data is missing or invalid. */\nexport class ArcaInputError extends ArcaError {\n override readonly name: string = \"ArcaInputError\";\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_INPUT_ERROR\", options);\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */\nexport class ArcaTransportError extends ArcaError {\n override readonly name: string = \"ArcaTransportError\";\n readonly statusCode?: number;\n readonly responseBody?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n statusCode?: number;\n responseBody?: string;\n }\n ) {\n super(message, \"ARCA_TRANSPORT_ERROR\", options);\n this.statusCode = options?.statusCode;\n this.responseBody = options?.responseBody;\n }\n}\n\n/** Thrown when the SOAP response contains a Fault element. */\nexport class ArcaSoapFaultError extends ArcaError {\n override readonly name: string = \"ArcaSoapFaultError\";\n readonly faultCode?: string;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n faultCode?: string;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SOAP_FAULT\", options);\n this.faultCode = options?.faultCode;\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */\nexport class ArcaServiceError extends ArcaError {\n override readonly name: string = \"ArcaServiceError\";\n readonly serviceCode?: string | number;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n serviceCode?: string | number;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SERVICE_ERROR\", options);\n this.serviceCode = options?.serviceCode;\n this.detail = options?.detail;\n }\n}\n","import { ArcaInputError, ArcaServiceError } from \"../errors\";\nimport type { ArcaClientConfig, ArcaRepresentedTaxId } from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\n\n/** Accepted public date inputs for WSFE request fields. */\nexport type WsfeDateInput =\n | `${number}${number}${number}${number}-${number}${number}-${number}${number}`\n | `${number}${number}${number}${number}${number}${number}${number}${number}`;\n\n/** An associated voucher referenced by a WSFE invoice request. */\nexport type WsfeAssociatedVoucher = {\n type: number;\n salesPoint: number;\n number: number;\n taxId?: string;\n voucherDate?: WsfeDateInput;\n};\n\n/** An associated period used by WSFE credit/debit notes without associated vouchers. */\nexport type WsfeAssociatedPeriod = {\n startDate: WsfeDateInput;\n endDate: WsfeDateInput;\n};\n\n/** A tax (tributo) item in a WSFE invoice request. */\nexport type WsfeTax = {\n id: number;\n description?: string;\n baseAmount: number;\n rate: number;\n amount: number;\n};\n\n/** A VAT rate (alícuota IVA) item in a WSFE invoice request. */\nexport type WsfeVatRate = {\n id: number;\n baseAmount: number;\n amount: number;\n};\n\n/** An optional field (campo opcional) in a WSFE invoice request. */\nexport type WsfeOptionalField = {\n id: string;\n value: string;\n};\n\n/** A buyer (comprador) in a WSFE invoice request. */\nexport type WsfeBuyer = {\n documentType: number;\n documentNumber: number;\n percentage: number;\n};\n\n/** An activity associated with a WSFE invoice request. */\nexport type WsfeActivity = {\n id: number;\n};\n\n/** Input data for authorizing a WSFE voucher. */\nexport type WsfeVoucherInput = {\n salesPoint: number;\n voucherType: number;\n concept: number;\n documentType: number;\n documentNumber: number;\n receiverVatConditionId?: number;\n voucherDate: WsfeDateInput;\n totalAmount: number;\n nonTaxableAmount: number;\n netAmount: number;\n exemptAmount: number;\n taxAmount: number;\n vatAmount: number;\n currencyId: string;\n exchangeRate?: number;\n sameCurrencyForeignCancellation?: \"S\" | \"N\";\n serviceStartDate?: WsfeDateInput;\n serviceEndDate?: WsfeDateInput;\n paymentDueDate?: WsfeDateInput;\n associatedVouchers?: WsfeAssociatedVoucher[];\n associatedPeriod?: WsfeAssociatedPeriod;\n taxes?: WsfeTax[];\n vatRates?: WsfeVatRate[];\n optionalFields?: WsfeOptionalField[];\n buyers?: WsfeBuyer[];\n activities?: WsfeActivity[];\n};\n\n/** Input for authorizing a WSFE voucher with an explicit voucher number. */\nexport type WsfeAuthorizeVoucherInput = {\n representedTaxId?: number | string;\n data: WsfeVoucherInput;\n voucherNumber: number;\n};\n\n/** Result of a successful WSFE voucher authorization. */\nexport type WsfeAuthorizationResult = {\n cae: string;\n caeExpiry: string;\n voucherNumber: number;\n raw: Record<string, unknown>;\n};\n\n/** A point-of-sale entry returned by {@link WsfeService.getSalesPoints}. */\nexport type WsfeSalesPoint = {\n number: number;\n emissionType?: string;\n blocked?: string;\n deletedSince?: string;\n};\n\n/** Voucher details returned by {@link WsfeService.getVoucherInfo}. */\nexport type WsfeVoucherInfo = {\n voucherNumber: number;\n voucherDate?: string;\n salesPoint?: number;\n voucherType?: number;\n totalAmount?: number;\n result?: string;\n cae?: string;\n caeExpiry?: string;\n raw: Record<string, unknown>;\n};\n\nexport type WsfeCatalogEntry = {\n id: number;\n description: string;\n};\n\nexport type WsfeActivityType = WsfeCatalogEntry & {\n order: number;\n};\n\nexport type WsfeReceiverVatCondition = WsfeCatalogEntry & {\n voucherClass: string;\n};\n\nexport type WsfeCurrencyType = {\n id: string;\n description: string;\n validFrom: string;\n validTo: string;\n};\n\nexport type WsfeServerStatus = {\n appServer: string;\n dbServer: string;\n authServer: string;\n};\n\nexport type WsfeQuotation = {\n currencyId: string;\n rate: number;\n date: string;\n};\n\n/** WSFE electronic invoicing service. */\nexport type WsfeService = {\n /** Authorizes a voucher with the explicit number sent as `CbteDesde` and `CbteHasta`. */\n authorizeVoucher(\n input: WsfeAuthorizeVoucherInput\n ): Promise<WsfeAuthorizationResult>;\n /** Authorizes a new voucher by fetching the next number and requesting a CAE. */\n createNextVoucher(input: {\n representedTaxId?: number | string;\n data: WsfeVoucherInput;\n }): Promise<WsfeAuthorizationResult>;\n /** Returns the next available voucher number for the given sales point and type. */\n getNextVoucherNumber(input: {\n representedTaxId?: number | string;\n salesPoint: number;\n voucherType: number;\n forceAuthRefresh?: boolean;\n }): Promise<number>;\n /**\n * @deprecated Use `getNextVoucherNumber()` instead.\n * Returns the next available voucher number, not the last authorized one.\n */\n getLastVoucher(input: {\n representedTaxId?: number | string;\n salesPoint: number;\n voucherType: number;\n forceAuthRefresh?: boolean;\n }): Promise<number>;\n /** Lists all configured points of sale for the taxpayer. */\n getSalesPoints(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeSalesPoint[]>;\n /** Lists voucher types accepted by WSFE. */\n getVoucherTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists document types accepted by WSFE. */\n getDocumentTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists concept types accepted by WSFE. */\n getConceptTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists supported currency types. */\n getCurrencyTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCurrencyType[]>;\n /** Lists VAT rates accepted by WSFE. */\n getVatRates(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists tax types accepted by WSFE. */\n getTaxTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists optional field types accepted by WSFE. */\n getOptionalTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists activities enabled for the taxpayer. */\n getActivities(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeActivityType[]>;\n /** Lists receiver VAT condition values accepted by WSFE. */\n getReceiverVatConditions(input: {\n representedTaxId?: number | string;\n voucherClass?: string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeReceiverVatCondition[]>;\n /** Reports WSFE backend status without requiring taxpayer authorization. */\n getServerStatus(): Promise<WsfeServerStatus>;\n /** Returns the exchange rate for a given currency. */\n getQuotation(input: {\n currencyId: string;\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeQuotation>;\n /** Retrieves details for a specific voucher. Returns `null` if not found. */\n getVoucherInfo(input: {\n representedTaxId?: number | string;\n number: number;\n salesPoint: number;\n voucherType: number;\n }): Promise<WsfeVoucherInfo | null>;\n};\n\nexport type CreateWsfeServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\ntype NormalizedWsfeAssociatedVoucher = Omit<\n WsfeAssociatedVoucher,\n \"voucherDate\"\n> & {\n voucherDate?: string;\n};\n\ntype NormalizedWsfeAssociatedPeriod = {\n startDate: string;\n endDate: string;\n};\n\ntype NormalizedWsfeVoucherInput = Omit<\n WsfeVoucherInput,\n | \"voucherDate\"\n | \"serviceStartDate\"\n | \"serviceEndDate\"\n | \"paymentDueDate\"\n | \"associatedVouchers\"\n | \"associatedPeriod\"\n> & {\n voucherDate: string;\n serviceStartDate?: string;\n serviceEndDate?: string;\n paymentDueDate?: string;\n associatedVouchers?: NormalizedWsfeAssociatedVoucher[];\n associatedPeriod?: NormalizedWsfeAssociatedPeriod;\n};\n\n/** Creates a WSFE service instance wired with authentication and SOAP transport. */\nexport function createWsfeService(\n options: CreateWsfeServiceOptions\n): WsfeService {\n async function executeWsfeAuthenticatedOperation(\n operation: string,\n input: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceAuthRefresh?: boolean;\n },\n body: Record<string, unknown> = {}\n ) {\n const auth = await options.auth.login(\"wsfe\", {\n representedTaxId: input.representedTaxId,\n forceRefresh: input.forceAuthRefresh,\n });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsfe\",\n operation,\n body: {\n Auth: createWsfeAuth(\n input.representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n ...body,\n },\n });\n\n return unwrapWsfeOperationResult(operation, response.result);\n }\n\n async function executeWsfeOperation(\n operation: string,\n body: Record<string, unknown> = {}\n ) {\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsfe\",\n operation,\n body,\n });\n\n return unwrapWsfeOperationResult(operation, response.result);\n }\n\n async function getNextVoucherNumber({\n representedTaxId,\n salesPoint,\n voucherType,\n forceAuthRefresh,\n }: {\n representedTaxId?: number | string;\n salesPoint: number;\n voucherType: number;\n forceAuthRefresh?: boolean;\n }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FECompUltimoAutorizado\",\n {\n representedTaxId,\n forceAuthRefresh,\n },\n {\n PtoVta: salesPoint,\n CbteTipo: voucherType,\n }\n );\n return Number(result.CbteNro ?? 0) + 1;\n }\n\n async function getWsfeCatalog(\n operation: string,\n resultKey: string,\n input: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceAuthRefresh?: boolean;\n }\n ): Promise<WsfeCatalogEntry[]> {\n const result = await executeWsfeAuthenticatedOperation(operation, {\n representedTaxId: input.representedTaxId,\n forceAuthRefresh: input.forceAuthRefresh,\n });\n return getWsfeResultEntries(result, resultKey).map(mapWsfeCatalogEntry);\n }\n\n function authorizeVoucher({\n representedTaxId,\n data,\n voucherNumber,\n }: WsfeAuthorizeVoucherInput): Promise<WsfeAuthorizationResult> {\n const normalizedInput = normalizeWsfeVoucherInput(data);\n return authorizeNormalizedVoucher({\n representedTaxId,\n data: normalizedInput,\n voucherNumber,\n });\n }\n\n async function authorizeNormalizedVoucher({\n representedTaxId,\n data: normalizedInput,\n voucherNumber,\n }: {\n representedTaxId?: number | string;\n data: NormalizedWsfeVoucherInput;\n voucherNumber: number;\n }): Promise<WsfeAuthorizationResult> {\n const requestData = mapWsfeVoucherInput(normalizedInput, voucherNumber);\n\n const auth = await options.auth.login(\"wsfe\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsfe\",\n operation: \"FECAESolicitar\",\n body: {\n Auth: createWsfeAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n FeCAEReq: {\n FeCabReq: {\n CantReg: 1,\n PtoVta: normalizedInput.salesPoint,\n CbteTipo: normalizedInput.voucherType,\n },\n FeDetReq: {\n FECAEDetRequest: requestData,\n },\n },\n },\n });\n\n const result = unwrapWsfeOperationResult(\"FECAESolicitar\", response.result);\n const detailResponse = normalizeWsfeDetailResponse(result);\n const cae = detailResponse.CAE;\n const caeExpiry = detailResponse.CAEFchVto;\n\n if (typeof cae !== \"string\" || typeof caeExpiry !== \"string\") {\n throw new ArcaServiceError(\"WSFE did not return CAE authorization data\", {\n detail: result,\n });\n }\n\n return {\n cae,\n caeExpiry: String(caeExpiry),\n voucherNumber,\n raw: result,\n };\n }\n\n return {\n authorizeVoucher,\n async createNextVoucher({ representedTaxId, data }) {\n const normalizedInput = normalizeWsfeVoucherInput(data);\n\n const voucherNumber = await getNextVoucherNumber({\n representedTaxId,\n salesPoint: normalizedInput.salesPoint,\n voucherType: normalizedInput.voucherType,\n });\n\n return authorizeNormalizedVoucher({\n representedTaxId,\n data: normalizedInput,\n voucherNumber,\n });\n },\n getNextVoucherNumber,\n getLastVoucher(input) {\n return getNextVoucherNumber(input);\n },\n async getSalesPoints({ representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetPtosVenta\",\n {\n representedTaxId,\n forceAuthRefresh,\n }\n );\n const rawPoints = (\n result.ResultGet as Record<string, unknown> | undefined\n )?.PtoVenta;\n if (!rawPoints) {\n return [];\n }\n const entries = Array.isArray(rawPoints) ? rawPoints : [rawPoints];\n return entries.map(mapWsfeSalesPoint);\n },\n getVoucherTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposCbte\", \"CbteTipo\", input);\n },\n getDocumentTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposDoc\", \"DocTipo\", input);\n },\n getConceptTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposConcepto\", \"ConceptoTipo\", input);\n },\n async getCurrencyTypes({ representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetTiposMonedas\",\n {\n representedTaxId,\n forceAuthRefresh,\n }\n );\n return getWsfeResultEntries(result, \"Moneda\").map(mapWsfeCurrencyType);\n },\n getVatRates(input) {\n return getWsfeCatalog(\"FEParamGetTiposIva\", \"IvaTipo\", input);\n },\n getTaxTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposTributos\", \"TributoTipo\", input);\n },\n getOptionalTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposOpcional\", \"OpcionalTipo\", input);\n },\n async getActivities({ representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetActividades\",\n {\n representedTaxId,\n forceAuthRefresh,\n }\n );\n return getWsfeResultEntries(result, \"ActividadesTipo\").map(\n mapWsfeActivityType\n );\n },\n async getReceiverVatConditions({\n representedTaxId,\n voucherClass,\n forceAuthRefresh,\n }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetCondicionIvaReceptor\",\n {\n representedTaxId,\n forceAuthRefresh,\n },\n {\n ...(voucherClass === undefined ? {} : { ClaseCmp: voucherClass }),\n }\n );\n return getWsfeResultEntries(result, \"CondicionIvaReceptor\").map(\n mapWsfeReceiverVatCondition\n );\n },\n async getServerStatus() {\n const result = await executeWsfeOperation(\"FEDummy\");\n return mapWsfeServerStatus(result);\n },\n async getQuotation({ currencyId, representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetCotizacion\",\n {\n representedTaxId,\n forceAuthRefresh,\n },\n {\n MonId: currencyId,\n }\n );\n const raw =\n (result.ResultGet as Record<string, unknown> | undefined) ?? {};\n return mapWsfeQuotation(raw);\n },\n async getVoucherInfo({\n representedTaxId,\n number,\n salesPoint,\n voucherType,\n }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FECompConsultar\",\n {\n representedTaxId,\n },\n {\n FeCompConsReq: {\n CbteNro: number,\n PtoVta: salesPoint,\n CbteTipo: voucherType,\n },\n }\n );\n const raw = (result.ResultGet as Record<string, unknown> | null) ?? null;\n if (!raw) {\n return null;\n }\n return mapWsfeVoucherInfo(raw);\n },\n };\n}\n\nfunction mapWsfeVoucherInput(\n input: NormalizedWsfeVoucherInput,\n voucherNumber: number\n): Record<string, unknown> {\n const sendsSameForeignCurrencyCancellation =\n input.currencyId !== \"PES\" && input.sameCurrencyForeignCancellation === \"S\";\n\n if (\n input.exchangeRate === undefined &&\n !sendsSameForeignCurrencyCancellation\n ) {\n throw new ArcaInputError(\n \"exchangeRate is required unless sameCurrencyForeignCancellation is S for a foreign-currency voucher.\"\n );\n }\n\n const data: Record<string, unknown> = {\n Concepto: input.concept,\n DocTipo: input.documentType,\n DocNro: input.documentNumber,\n CbteDesde: voucherNumber,\n CbteHasta: voucherNumber,\n CbteFch: input.voucherDate,\n ImpTotal: input.totalAmount,\n ImpTotConc: input.nonTaxableAmount,\n ImpNeto: input.netAmount,\n ImpOpEx: input.exemptAmount,\n ImpTrib: input.taxAmount,\n ImpIVA: input.vatAmount,\n MonId: input.currencyId,\n PtoVta: input.salesPoint,\n CbteTipo: input.voucherType,\n };\n\n if (!sendsSameForeignCurrencyCancellation) {\n data.MonCotiz = input.exchangeRate;\n }\n\n if (input.receiverVatConditionId !== undefined) {\n data.CondicionIVAReceptorId = input.receiverVatConditionId;\n }\n\n if (\n input.currencyId !== \"PES\" &&\n input.sameCurrencyForeignCancellation !== undefined\n ) {\n data.CanMisMonExt = input.sameCurrencyForeignCancellation;\n }\n\n if (input.serviceStartDate !== undefined) {\n data.FchServDesde = input.serviceStartDate;\n }\n if (input.serviceEndDate !== undefined) {\n data.FchServHasta = input.serviceEndDate;\n }\n if (input.paymentDueDate !== undefined) {\n data.FchVtoPago = input.paymentDueDate;\n }\n\n if (input.associatedVouchers) {\n data.CbtesAsoc = {\n CbteAsoc: input.associatedVouchers.map((v) => ({\n Tipo: v.type,\n PtoVta: v.salesPoint,\n Nro: v.number,\n ...(v.taxId === undefined ? {} : { Cuit: v.taxId }),\n ...(v.voucherDate === undefined ? {} : { CbteFch: v.voucherDate }),\n })),\n };\n }\n\n if (input.associatedPeriod) {\n data.PeriodoAsoc = {\n FchDesde: input.associatedPeriod.startDate,\n FchHasta: input.associatedPeriod.endDate,\n };\n }\n\n if (input.taxes) {\n data.Tributos = {\n Tributo: input.taxes.map((t) => ({\n Id: t.id,\n ...(t.description === undefined ? {} : { Desc: t.description }),\n BaseImp: t.baseAmount,\n Alic: t.rate,\n Importe: t.amount,\n })),\n };\n }\n\n if (input.vatRates) {\n data.Iva = {\n AlicIva: input.vatRates.map((v) => ({\n Id: v.id,\n BaseImp: v.baseAmount,\n Importe: v.amount,\n })),\n };\n }\n\n if (input.optionalFields) {\n data.Opcionales = {\n Opcional: input.optionalFields.map((o) => ({\n Id: o.id,\n Valor: o.value,\n })),\n };\n }\n\n if (input.buyers) {\n data.Compradores = {\n Comprador: input.buyers.map((b) => ({\n DocTipo: b.documentType,\n DocNro: b.documentNumber,\n Porcentaje: b.percentage,\n })),\n };\n }\n\n if (input.activities) {\n data.Actividades = {\n Actividad: input.activities.map((a) => ({\n Id: a.id,\n })),\n };\n }\n\n return data;\n}\n\nfunction normalizeWsfeVoucherInput(\n input: WsfeVoucherInput\n): NormalizedWsfeVoucherInput {\n const {\n voucherDate,\n serviceStartDate,\n serviceEndDate,\n paymentDueDate,\n associatedVouchers,\n associatedPeriod,\n ...rest\n } = input;\n\n return {\n ...rest,\n voucherDate: normalizeWsfeDateInput(voucherDate, \"voucherDate\"),\n ...(serviceStartDate === undefined\n ? {}\n : {\n serviceStartDate: normalizeWsfeDateInput(\n serviceStartDate,\n \"serviceStartDate\"\n ),\n }),\n ...(serviceEndDate === undefined\n ? {}\n : {\n serviceEndDate: normalizeWsfeDateInput(\n serviceEndDate,\n \"serviceEndDate\"\n ),\n }),\n ...(paymentDueDate === undefined\n ? {}\n : {\n paymentDueDate: normalizeWsfeDateInput(\n paymentDueDate,\n \"paymentDueDate\"\n ),\n }),\n ...(associatedVouchers === undefined\n ? {}\n : {\n associatedVouchers: associatedVouchers.map((voucher, index) => {\n const { voucherDate: associatedVoucherDate, ...associatedRest } =\n voucher;\n\n return {\n ...associatedRest,\n ...(associatedVoucherDate === undefined\n ? {}\n : {\n voucherDate: normalizeWsfeDateInput(\n associatedVoucherDate,\n `associatedVouchers[${index}].voucherDate`\n ),\n }),\n };\n }),\n }),\n ...(associatedPeriod === undefined\n ? {}\n : {\n associatedPeriod: {\n startDate: normalizeWsfeDateInput(\n associatedPeriod.startDate,\n \"associatedPeriod.startDate\"\n ),\n endDate: normalizeWsfeDateInput(\n associatedPeriod.endDate,\n \"associatedPeriod.endDate\"\n ),\n },\n }),\n };\n}\n\nfunction normalizeWsfeDateInput(\n value: WsfeDateInput,\n fieldName: string\n): string {\n if (typeof value !== \"string\") {\n throw new ArcaInputError(\n `Invalid WSFE ${fieldName}: expected a YYYY-MM-DD or YYYYMMDD string`,\n {\n detail: { field: fieldName, value },\n }\n );\n }\n\n const normalizedValue = value.trim();\n const afipMatch = normalizedValue.match(/^(\\d{4})(\\d{2})(\\d{2})$/);\n if (afipMatch) {\n const [, year, month, day] = afipMatch;\n assertValidCalendarDate(year, month, day, fieldName, normalizedValue);\n return normalizedValue;\n }\n\n const isoMatch = normalizedValue.match(/^(\\d{4})-(\\d{2})-(\\d{2})$/);\n if (isoMatch) {\n const [, year, month, day] = isoMatch;\n assertValidCalendarDate(year, month, day, fieldName, normalizedValue);\n return `${year}${month}${day}`;\n }\n\n throw new ArcaInputError(\n `Invalid WSFE ${fieldName}: expected a YYYY-MM-DD or YYYYMMDD string`,\n {\n detail: { field: fieldName, value: normalizedValue },\n }\n );\n}\n\nfunction assertValidCalendarDate(\n yearInput: string,\n monthInput: string,\n dayInput: string,\n fieldName: string,\n value: string\n) {\n const year = Number(yearInput);\n const month = Number(monthInput);\n const day = Number(dayInput);\n const candidate = new Date(Date.UTC(year, month - 1, day));\n\n if (\n candidate.getUTCFullYear() !== year ||\n candidate.getUTCMonth() !== month - 1 ||\n candidate.getUTCDate() !== day\n ) {\n throw new ArcaInputError(\n `Invalid WSFE ${fieldName}: received a non-existent calendar date`,\n {\n detail: { field: fieldName, value },\n }\n );\n }\n}\n\nfunction mapWsfeSalesPoint(raw: unknown): WsfeSalesPoint {\n const record = raw as Record<string, unknown>;\n return {\n number: Number(record.Nro ?? 0),\n ...(record.EmisionTipo === undefined\n ? {}\n : { emissionType: String(record.EmisionTipo) }),\n ...(record.Bloqueado === undefined\n ? {}\n : { blocked: String(record.Bloqueado) }),\n ...(record.FchBaja === undefined\n ? {}\n : { deletedSince: String(record.FchBaja) }),\n };\n}\n\nfunction mapWsfeCatalogEntry(raw: unknown): WsfeCatalogEntry {\n const record = raw as Record<string, unknown>;\n return {\n id: Number(record.Id ?? 0),\n description: String(record.Desc ?? \"\"),\n };\n}\n\nfunction mapWsfeActivityType(raw: unknown): WsfeActivityType {\n const record = raw as Record<string, unknown>;\n return {\n id: Number(record.Id ?? 0),\n description: String(record.Desc ?? \"\"),\n order: Number(record.Orden ?? 0),\n };\n}\n\nfunction mapWsfeReceiverVatCondition(raw: unknown): WsfeReceiverVatCondition {\n const record = raw as Record<string, unknown>;\n return {\n id: Number(record.Id ?? 0),\n description: String(record.Desc ?? \"\"),\n voucherClass: String(record.Cmp_Clase ?? \"\"),\n };\n}\n\nfunction mapWsfeCurrencyType(raw: unknown): WsfeCurrencyType {\n const record = raw as Record<string, unknown>;\n return {\n id: String(record.Id ?? \"\"),\n description: String(record.Desc ?? \"\"),\n validFrom: String(record.FchDesde ?? \"\"),\n validTo: String(record.FchHasta ?? \"\"),\n };\n}\n\nfunction mapWsfeServerStatus(raw: Record<string, unknown>): WsfeServerStatus {\n return {\n appServer: String(raw.AppServer ?? \"\"),\n dbServer: String(raw.DbServer ?? \"\"),\n authServer: String(raw.AuthServer ?? \"\"),\n };\n}\n\nfunction mapWsfeQuotation(raw: Record<string, unknown>): WsfeQuotation {\n return {\n currencyId: String(raw.MonId ?? \"\"),\n rate: Number(raw.MonCotiz ?? 0),\n date: String(raw.FchCotiz ?? \"\"),\n };\n}\n\nfunction mapWsfeVoucherInfo(raw: Record<string, unknown>): WsfeVoucherInfo {\n return {\n voucherNumber: Number(raw.CbteDesde ?? raw.CbteHasta ?? 0),\n ...(raw.CbteFch === undefined ? {} : { voucherDate: String(raw.CbteFch) }),\n ...(raw.PtoVta === undefined ? {} : { salesPoint: Number(raw.PtoVta) }),\n ...(raw.CbteTipo === undefined\n ? {}\n : { voucherType: Number(raw.CbteTipo) }),\n ...(raw.ImpTotal === undefined\n ? {}\n : { totalAmount: Number(raw.ImpTotal) }),\n ...(raw.Resultado === undefined ? {} : { result: String(raw.Resultado) }),\n ...(raw.CAE === undefined ? {} : { cae: String(raw.CAE) }),\n ...(raw.CAEFchVto === undefined\n ? {}\n : { caeExpiry: String(raw.CAEFchVto) }),\n raw,\n };\n}\n\nfunction createWsfeAuth(\n representedTaxId: number | string,\n token: string,\n sign: string\n) {\n return {\n Token: token,\n Sign: sign,\n Cuit: Number.parseInt(String(representedTaxId), 10),\n };\n}\n\nfunction unwrapWsfeOperationResult(\n operation: string,\n response: Record<string, unknown>\n) {\n const operationResponse = response[`${operation}Response`] as\n | Record<string, unknown>\n | undefined;\n const result = (operationResponse?.[`${operation}Result`] ??\n response[`${operation}Result`] ??\n response) as Record<string, unknown>;\n\n if (operation === \"FECAESolicitar\") {\n const detailResponse = normalizeWsfeDetailResponse(result);\n const resultCode = detailResponse.Resultado;\n if (resultCode && resultCode !== \"A\") {\n const observationsContainer = detailResponse.Observaciones as\n | Record<string, unknown>\n | undefined;\n const observations = normalizeWsfeErrors(observationsContainer?.Obs);\n if (observations.length > 0) {\n const firstObservation = observations[0];\n if (!firstObservation) {\n throw new ArcaServiceError(\n \"WSFE returned an empty observation list\",\n {\n detail: result,\n }\n );\n }\n throw new ArcaServiceError(firstObservation.message, {\n serviceCode: firstObservation.code,\n detail: result,\n });\n }\n }\n }\n\n const errorsContainer = result.Errors as Record<string, unknown> | undefined;\n const errors = normalizeWsfeErrors(errorsContainer?.Err);\n if (errors.length > 0) {\n const firstError = errors[0];\n if (!firstError) {\n throw new ArcaServiceError(\"WSFE returned an empty error list\", {\n detail: result,\n });\n }\n throw new ArcaServiceError(firstError.message, {\n serviceCode: firstError.code,\n detail: result,\n });\n }\n\n return result;\n}\n\nfunction normalizeWsfeDetailResponse(result: Record<string, unknown>) {\n const detailResponse = result.FeDetResp as\n | Record<string, unknown>\n | undefined;\n const rawDetail = detailResponse?.FECAEDetResponse;\n\n if (Array.isArray(rawDetail)) {\n return (rawDetail[0] as Record<string, unknown>) ?? {};\n }\n\n return (rawDetail as Record<string, unknown> | undefined) ?? {};\n}\n\nfunction normalizeWsfeErrors(rawErrors: unknown) {\n const entries = Array.isArray(rawErrors)\n ? rawErrors\n : rawErrors\n ? [rawErrors]\n : [];\n\n return entries\n .map((entry) => entry as Record<string, unknown>)\n .map((entry) => {\n const code = entry.Code ?? entry.code ?? \"N/A\";\n const message = entry.Msg ?? entry.msg ?? \"Unknown WSFE error\";\n return {\n code: String(code),\n message: `(${String(code)}) ${String(message)}`,\n };\n });\n}\n\nfunction getWsfeResultEntries(\n result: Record<string, unknown>,\n key: string\n): Record<string, unknown>[] {\n const rawEntries = (\n result.ResultGet as Record<string, unknown> | undefined\n )?.[key];\n if (!rawEntries) {\n return [];\n }\n\n return (Array.isArray(rawEntries) ? rawEntries : [rawEntries]).map(\n (entry) => entry as Record<string, unknown>\n );\n}\n"],"mappings":";AACO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACS,OAAe;AAAA,EAEjC,YAAY,SAAiB,OAAO,cAAc,SAAwB;AACxE,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAYO,IAAM,iBAAN,cAA6B,UAAU;AAAA,EAC1B,OAAe;AAAA,EACxB;AAAA,EAET,YACE,SACA,SAGA;AACA,UAAM,SAAS,oBAAoB,OAAO;AAC1C,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;AAyCO,IAAM,mBAAN,cAA+B,UAAU;AAAA,EAC5B,OAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAET,YACE,SACA,SAIA;AACA,UAAM,SAAS,sBAAsB,OAAO;AAC5C,SAAK,cAAc,SAAS;AAC5B,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;;;ACsMO,SAAS,kBACd,SACa;AACb,iBAAe,kCACb,WACA,OAIA,OAAgC,CAAC,GACjC;AACA,UAAM,OAAO,MAAM,QAAQ,KAAK,MAAM,QAAQ;AAAA,MAC5C,kBAAkB,MAAM;AAAA,MACxB,cAAc,MAAM;AAAA,IACtB,CAAC;AACD,UAAM,WAAW,MAAM,QAAQ,KAAK,QAGlC;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA,MAAM;AAAA,QACJ,MAAM;AAAA,UACJ,MAAM,oBAAoB,QAAQ,OAAO;AAAA,UACzC,KAAK;AAAA,UACL,KAAK;AAAA,QACP;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF,CAAC;AAED,WAAO,0BAA0B,WAAW,SAAS,MAAM;AAAA,EAC7D;AAEA,iBAAe,qBACb,WACA,OAAgC,CAAC,GACjC;AACA,UAAM,WAAW,MAAM,QAAQ,KAAK,QAGlC;AAAA,MACA,S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AAiB,GAAG;AACvD,MAAI,OAAO,SAAS,GAAG;AACrB,UAAM,aAAa,OAAO,CAAC;AAC3B,QAAI,CAAC,YAAY;AACf,YAAM,IAAI,iBAAiB,qCAAqC;AAAA,QAC9D,QAAQ;AAAA,MACV,CAAC;AAAA,IACH;AACA,UAAM,IAAI,iBAAiB,WAAW,SAAS;AAAA,MAC7C,aAAa,WAAW;AAAA,MACxB,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAEA,SAAS,4BAA4B,QAAiC;AACpE,QAAM,iBAAiB,OAAO;AAG9B,QAAM,YAAY,gBAAgB;AAElC,MAAI,MAAM,QAAQ,SAAS,GAAG;AAC5B,WAAQ,UAAU,CAAC,KAAiC,CAAC;AAAA,EACvD;AAEA,SAAQ,aAAqD,CAAC;AAChE;AAEA,SAAS,oBAAoB,WAAoB;AAC/C,QAAM,UAAU,MAAM,QAAQ,SAAS,IACnC,YACA,YACE,CAAC,SAAS,IACV,CAAC;AAEP,SAAO,QACJ,IAAI,CAAC,UAAU,KAAgC,EAC/C,IAAI,CAAC,UAAU;AACd,UAAM,OAAO,MAAM,QAAQ,MAAM,QAAQ;AACzC,UAAM,UAAU,MAAM,OAAO,MAAM,OAAO;AAC1C,WAAO;AAAA,MACL,MAAM,OAAO,IAAI;AAAA,MACjB,SAAS,IAAI,OAAO,IAAI,CAAC,KAAK,OAAO,OAAO,CAAC;AAAA,IAC/C;AAAA,EACF,CAAC;AACL;AAEA,SAAS,qBACP,QACA,KAC2B;AAC3B,QAAM,aACJ,OAAO,YACL,GAAG;AACP,MAAI,CAAC,YAAY;AACf,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU,GAAG;AAAA,IAC7D,CAAC,UAAU;AAAA,EACb;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/services/wsfe.ts"],"sourcesContent":["import type { ArcaServiceName } from \"./internal/types\";\n\n/** Base error class for all ARCA-related errors. */\nexport class ArcaError extends Error {\n readonly code: string;\n override readonly name: string = \"ArcaError\";\n\n constructor(message: string, code = \"ARCA_ERROR\", options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n }\n}\n\n/** Thrown when the ARCA client configuration is missing or invalid. */\nexport class ArcaConfigurationError extends ArcaError {\n override readonly name: string = \"ArcaConfigurationError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_CONFIGURATION_ERROR\", options);\n }\n}\n\n/** Thrown when caller-provided input data is missing or invalid. */\nexport class ArcaInputError extends ArcaError {\n override readonly name: string = \"ArcaInputError\";\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_INPUT_ERROR\", options);\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */\nexport class ArcaTransportError extends ArcaError {\n override readonly name: string = \"ArcaTransportError\";\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBody?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n statusCode?: number;\n contentType?: string;\n responseBody?: string;\n }\n ) {\n super(message, \"ARCA_TRANSPORT_ERROR\", options);\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBody = options?.responseBody;\n }\n}\n\n/** Thrown when the SOAP response contains a Fault element. */\nexport class ArcaSoapFaultError extends ArcaError {\n override readonly name: string = \"ArcaSoapFaultError\";\n readonly faultCode?: string;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n faultCode?: string;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SOAP_FAULT\", options);\n this.faultCode = options?.faultCode;\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when a response cannot be parsed as a valid SOAP envelope. */\nexport class ArcaInvalidSoapResponseError extends ArcaError {\n override readonly name: string = \"ArcaInvalidSoapResponseError\";\n readonly service?: ArcaServiceName;\n readonly operation?: string;\n readonly endpointUrl?: string;\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBodyLength?: number;\n readonly responseBodyPreview?: string;\n readonly parsedDetail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n service?: ArcaServiceName;\n operation?: string;\n endpointUrl?: string;\n statusCode?: number;\n contentType?: string;\n responseBodyLength?: number;\n responseBodyPreview?: string;\n parsedDetail?: unknown;\n }\n ) {\n super(message, \"ARCA_INVALID_SOAP_RESPONSE\", options);\n this.service = options?.service;\n this.operation = options?.operation;\n this.endpointUrl = options?.endpointUrl;\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBodyLength = options?.responseBodyLength;\n this.responseBodyPreview = options?.responseBodyPreview;\n this.parsedDetail = options?.parsedDetail;\n }\n}\n\n/** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */\nexport class ArcaServiceError extends ArcaError {\n override readonly name: string = \"ArcaServiceError\";\n readonly serviceCode?: string | number;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n serviceCode?: string | number;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SERVICE_ERROR\", options);\n this.serviceCode = options?.serviceCode;\n this.detail = options?.detail;\n }\n}\n","import { ArcaInputError, ArcaServiceError } from \"../errors\";\nimport type { ArcaClientConfig, ArcaRepresentedTaxId } from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\n\n/** Accepted public date inputs for WSFE request fields. */\nexport type WsfeDateInput =\n | `${number}${number}${number}${number}-${number}${number}-${number}${number}`\n | `${number}${number}${number}${number}${number}${number}${number}${number}`;\n\n/** An associated voucher referenced by a WSFE invoice request. */\nexport type WsfeAssociatedVoucher = {\n type: number;\n salesPoint: number;\n number: number;\n taxId?: string;\n voucherDate?: WsfeDateInput;\n};\n\n/** An associated period used by WSFE credit/debit notes without associated vouchers. */\nexport type WsfeAssociatedPeriod = {\n startDate: WsfeDateInput;\n endDate: WsfeDateInput;\n};\n\n/** A tax (tributo) item in a WSFE invoice request. */\nexport type WsfeTax = {\n id: number;\n description?: string;\n baseAmount: number;\n rate: number;\n amount: number;\n};\n\n/** A VAT rate (alícuota IVA) item in a WSFE invoice request. */\nexport type WsfeVatRate = {\n id: number;\n baseAmount: number;\n amount: number;\n};\n\n/** An optional field (campo opcional) in a WSFE invoice request. */\nexport type WsfeOptionalField = {\n id: string;\n value: string;\n};\n\n/** A buyer (comprador) in a WSFE invoice request. */\nexport type WsfeBuyer = {\n documentType: number;\n documentNumber: number;\n percentage: number;\n};\n\n/** An activity associated with a WSFE invoice request. */\nexport type WsfeActivity = {\n id: number;\n};\n\n/** Input data for authorizing a WSFE voucher. */\nexport type WsfeVoucherInput = {\n salesPoint: number;\n voucherType: number;\n concept: number;\n documentType: number;\n documentNumber: number;\n receiverVatConditionId?: number;\n voucherDate: WsfeDateInput;\n totalAmount: number;\n nonTaxableAmount: number;\n netAmount: number;\n exemptAmount: number;\n taxAmount: number;\n vatAmount: number;\n currencyId: string;\n exchangeRate?: number;\n sameCurrencyForeignCancellation?: \"S\" | \"N\";\n serviceStartDate?: WsfeDateInput;\n serviceEndDate?: WsfeDateInput;\n paymentDueDate?: WsfeDateInput;\n associatedVouchers?: WsfeAssociatedVoucher[];\n associatedPeriod?: WsfeAssociatedPeriod;\n taxes?: WsfeTax[];\n vatRates?: WsfeVatRate[];\n optionalFields?: WsfeOptionalField[];\n buyers?: WsfeBuyer[];\n activities?: WsfeActivity[];\n};\n\n/** Input for authorizing a WSFE voucher with an explicit voucher number. */\nexport type WsfeAuthorizeVoucherInput = {\n representedTaxId?: number | string;\n data: WsfeVoucherInput;\n voucherNumber: number;\n};\n\n/** Result of a successful WSFE voucher authorization. */\nexport type WsfeAuthorizationResult = {\n cae: string;\n caeExpiry: string;\n voucherNumber: number;\n raw: Record<string, unknown>;\n};\n\n/** A point-of-sale entry returned by {@link WsfeService.getSalesPoints}. */\nexport type WsfeSalesPoint = {\n number: number;\n emissionType?: string;\n blocked?: string;\n deletedSince?: string;\n};\n\n/** Voucher details returned by {@link WsfeService.getVoucherInfo}. */\nexport type WsfeVoucherInfo = {\n voucherNumber: number;\n voucherDate?: string;\n salesPoint?: number;\n voucherType?: number;\n totalAmount?: number;\n result?: string;\n cae?: string;\n caeExpiry?: string;\n raw: Record<string, unknown>;\n};\n\nexport type WsfeCatalogEntry = {\n id: number;\n description: string;\n};\n\nexport type WsfeActivityType = WsfeCatalogEntry & {\n order: number;\n};\n\nexport type WsfeReceiverVatCondition = WsfeCatalogEntry & {\n voucherClass: string;\n};\n\nexport type WsfeCurrencyType = {\n id: string;\n description: string;\n validFrom: string;\n validTo: string;\n};\n\nexport type WsfeServerStatus = {\n appServer: string;\n dbServer: string;\n authServer: string;\n};\n\nexport type WsfeQuotation = {\n currencyId: string;\n rate: number;\n date: string;\n};\n\n/** WSFE electronic invoicing service. */\nexport type WsfeService = {\n /** Authorizes a voucher with the explicit number sent as `CbteDesde` and `CbteHasta`. */\n authorizeVoucher(\n input: WsfeAuthorizeVoucherInput\n ): Promise<WsfeAuthorizationResult>;\n /** Authorizes a new voucher by fetching the next number and requesting a CAE. */\n createNextVoucher(input: {\n representedTaxId?: number | string;\n data: WsfeVoucherInput;\n }): Promise<WsfeAuthorizationResult>;\n /** Returns the next available voucher number for the given sales point and type. */\n getNextVoucherNumber(input: {\n representedTaxId?: number | string;\n salesPoint: number;\n voucherType: number;\n forceAuthRefresh?: boolean;\n }): Promise<number>;\n /**\n * @deprecated Use `getNextVoucherNumber()` instead.\n * Returns the next available voucher number, not the last authorized one.\n */\n getLastVoucher(input: {\n representedTaxId?: number | string;\n salesPoint: number;\n voucherType: number;\n forceAuthRefresh?: boolean;\n }): Promise<number>;\n /** Lists all configured points of sale for the taxpayer. */\n getSalesPoints(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeSalesPoint[]>;\n /** Lists voucher types accepted by WSFE. */\n getVoucherTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists document types accepted by WSFE. */\n getDocumentTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists concept types accepted by WSFE. */\n getConceptTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists supported currency types. */\n getCurrencyTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCurrencyType[]>;\n /** Lists VAT rates accepted by WSFE. */\n getVatRates(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists tax types accepted by WSFE. */\n getTaxTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists optional field types accepted by WSFE. */\n getOptionalTypes(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeCatalogEntry[]>;\n /** Lists activities enabled for the taxpayer. */\n getActivities(input: {\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeActivityType[]>;\n /** Lists receiver VAT condition values accepted by WSFE. */\n getReceiverVatConditions(input: {\n representedTaxId?: number | string;\n voucherClass?: string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeReceiverVatCondition[]>;\n /** Reports WSFE backend status without requiring taxpayer authorization. */\n getServerStatus(): Promise<WsfeServerStatus>;\n /** Returns the exchange rate for a given currency. */\n getQuotation(input: {\n currencyId: string;\n representedTaxId?: number | string;\n forceAuthRefresh?: boolean;\n }): Promise<WsfeQuotation>;\n /** Retrieves details for a specific voucher. Returns `null` if not found. */\n getVoucherInfo(input: {\n representedTaxId?: number | string;\n number: number;\n salesPoint: number;\n voucherType: number;\n }): Promise<WsfeVoucherInfo | null>;\n};\n\nexport type CreateWsfeServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\ntype NormalizedWsfeAssociatedVoucher = Omit<\n WsfeAssociatedVoucher,\n \"voucherDate\"\n> & {\n voucherDate?: string;\n};\n\ntype NormalizedWsfeAssociatedPeriod = {\n startDate: string;\n endDate: string;\n};\n\ntype NormalizedWsfeVoucherInput = Omit<\n WsfeVoucherInput,\n | \"voucherDate\"\n | \"serviceStartDate\"\n | \"serviceEndDate\"\n | \"paymentDueDate\"\n | \"associatedVouchers\"\n | \"associatedPeriod\"\n> & {\n voucherDate: string;\n serviceStartDate?: string;\n serviceEndDate?: string;\n paymentDueDate?: string;\n associatedVouchers?: NormalizedWsfeAssociatedVoucher[];\n associatedPeriod?: NormalizedWsfeAssociatedPeriod;\n};\n\n/** Creates a WSFE service instance wired with authentication and SOAP transport. */\nexport function createWsfeService(\n options: CreateWsfeServiceOptions\n): WsfeService {\n async function executeWsfeAuthenticatedOperation(\n operation: string,\n input: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceAuthRefresh?: boolean;\n },\n body: Record<string, unknown> = {}\n ) {\n const auth = await options.auth.login(\"wsfe\", {\n representedTaxId: input.representedTaxId,\n forceRefresh: input.forceAuthRefresh,\n });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsfe\",\n operation,\n body: {\n Auth: createWsfeAuth(\n input.representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n ...body,\n },\n });\n\n return unwrapWsfeOperationResult(operation, response.result);\n }\n\n async function executeWsfeOperation(\n operation: string,\n body: Record<string, unknown> = {}\n ) {\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsfe\",\n operation,\n body,\n });\n\n return unwrapWsfeOperationResult(operation, response.result);\n }\n\n async function getNextVoucherNumber({\n representedTaxId,\n salesPoint,\n voucherType,\n forceAuthRefresh,\n }: {\n representedTaxId?: number | string;\n salesPoint: number;\n voucherType: number;\n forceAuthRefresh?: boolean;\n }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FECompUltimoAutorizado\",\n {\n representedTaxId,\n forceAuthRefresh,\n },\n {\n PtoVta: salesPoint,\n CbteTipo: voucherType,\n }\n );\n return Number(result.CbteNro ?? 0) + 1;\n }\n\n async function getWsfeCatalog(\n operation: string,\n resultKey: string,\n input: {\n representedTaxId?: ArcaRepresentedTaxId;\n forceAuthRefresh?: boolean;\n }\n ): Promise<WsfeCatalogEntry[]> {\n const result = await executeWsfeAuthenticatedOperation(operation, {\n representedTaxId: input.representedTaxId,\n forceAuthRefresh: input.forceAuthRefresh,\n });\n return getWsfeResultEntries(result, resultKey).map(mapWsfeCatalogEntry);\n }\n\n function authorizeVoucher({\n representedTaxId,\n data,\n voucherNumber,\n }: WsfeAuthorizeVoucherInput): Promise<WsfeAuthorizationResult> {\n const normalizedInput = normalizeWsfeVoucherInput(data);\n return authorizeNormalizedVoucher({\n representedTaxId,\n data: normalizedInput,\n voucherNumber,\n });\n }\n\n async function authorizeNormalizedVoucher({\n representedTaxId,\n data: normalizedInput,\n voucherNumber,\n }: {\n representedTaxId?: number | string;\n data: NormalizedWsfeVoucherInput;\n voucherNumber: number;\n }): Promise<WsfeAuthorizationResult> {\n const requestData = mapWsfeVoucherInput(normalizedInput, voucherNumber);\n\n const auth = await options.auth.login(\"wsfe\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsfe\",\n operation: \"FECAESolicitar\",\n body: {\n Auth: createWsfeAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n FeCAEReq: {\n FeCabReq: {\n CantReg: 1,\n PtoVta: normalizedInput.salesPoint,\n CbteTipo: normalizedInput.voucherType,\n },\n FeDetReq: {\n FECAEDetRequest: requestData,\n },\n },\n },\n });\n\n const result = unwrapWsfeOperationResult(\"FECAESolicitar\", response.result);\n const detailResponse = normalizeWsfeDetailResponse(result);\n const cae = detailResponse.CAE;\n const caeExpiry = detailResponse.CAEFchVto;\n\n if (typeof cae !== \"string\" || typeof caeExpiry !== \"string\") {\n throw new ArcaServiceError(\"WSFE did not return CAE authorization data\", {\n detail: result,\n });\n }\n\n return {\n cae,\n caeExpiry: String(caeExpiry),\n voucherNumber,\n raw: result,\n };\n }\n\n return {\n authorizeVoucher,\n async createNextVoucher({ representedTaxId, data }) {\n const normalizedInput = normalizeWsfeVoucherInput(data);\n\n const voucherNumber = await getNextVoucherNumber({\n representedTaxId,\n salesPoint: normalizedInput.salesPoint,\n voucherType: normalizedInput.voucherType,\n });\n\n return authorizeNormalizedVoucher({\n representedTaxId,\n data: normalizedInput,\n voucherNumber,\n });\n },\n getNextVoucherNumber,\n getLastVoucher(input) {\n return getNextVoucherNumber(input);\n },\n async getSalesPoints({ representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetPtosVenta\",\n {\n representedTaxId,\n forceAuthRefresh,\n }\n );\n const rawPoints = (\n result.ResultGet as Record<string, unknown> | undefined\n )?.PtoVenta;\n if (!rawPoints) {\n return [];\n }\n const entries = Array.isArray(rawPoints) ? rawPoints : [rawPoints];\n return entries.map(mapWsfeSalesPoint);\n },\n getVoucherTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposCbte\", \"CbteTipo\", input);\n },\n getDocumentTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposDoc\", \"DocTipo\", input);\n },\n getConceptTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposConcepto\", \"ConceptoTipo\", input);\n },\n async getCurrencyTypes({ representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetTiposMonedas\",\n {\n representedTaxId,\n forceAuthRefresh,\n }\n );\n return getWsfeResultEntries(result, \"Moneda\").map(mapWsfeCurrencyType);\n },\n getVatRates(input) {\n return getWsfeCatalog(\"FEParamGetTiposIva\", \"IvaTipo\", input);\n },\n getTaxTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposTributos\", \"TributoTipo\", input);\n },\n getOptionalTypes(input) {\n return getWsfeCatalog(\"FEParamGetTiposOpcional\", \"OpcionalTipo\", input);\n },\n async getActivities({ representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetActividades\",\n {\n representedTaxId,\n forceAuthRefresh,\n }\n );\n return getWsfeResultEntries(result, \"ActividadesTipo\").map(\n mapWsfeActivityType\n );\n },\n async getReceiverVatConditions({\n representedTaxId,\n voucherClass,\n forceAuthRefresh,\n }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetCondicionIvaReceptor\",\n {\n representedTaxId,\n forceAuthRefresh,\n },\n {\n ...(voucherClass === undefined ? {} : { ClaseCmp: voucherClass }),\n }\n );\n return getWsfeResultEntries(result, \"CondicionIvaReceptor\").map(\n mapWsfeReceiverVatCondition\n );\n },\n async getServerStatus() {\n const result = await executeWsfeOperation(\"FEDummy\");\n return mapWsfeServerStatus(result);\n },\n async getQuotation({ currencyId, representedTaxId, forceAuthRefresh }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FEParamGetCotizacion\",\n {\n representedTaxId,\n forceAuthRefresh,\n },\n {\n MonId: currencyId,\n }\n );\n const raw =\n (result.ResultGet as Record<string, unknown> | undefined) ?? {};\n return mapWsfeQuotation(raw);\n },\n async getVoucherInfo({\n representedTaxId,\n number,\n salesPoint,\n voucherType,\n }) {\n const result = await executeWsfeAuthenticatedOperation(\n \"FECompConsultar\",\n {\n representedTaxId,\n },\n {\n FeCompConsReq: {\n CbteNro: number,\n PtoVta: salesPoint,\n CbteTipo: voucherType,\n },\n }\n );\n const raw = (result.ResultGet as Record<string, unknown> | null) ?? null;\n if (!raw) {\n return null;\n }\n return mapWsfeVoucherInfo(raw);\n },\n };\n}\n\nfunction mapWsfeVoucherInput(\n input: NormalizedWsfeVoucherInput,\n voucherNumber: number\n): Record<string, unknown> {\n const sendsSameForeignCurrencyCancellation =\n input.currencyId !== \"PES\" && input.sameCurrencyForeignCancellation === \"S\";\n\n if (\n input.exchangeRate === undefined &&\n !sendsSameForeignCurrencyCancellation\n ) {\n throw new ArcaInputError(\n \"exchangeRate is required unless sameCurrencyForeignCancellation is S for a foreign-currency voucher.\"\n );\n }\n\n const data: Record<string, unknown> = {\n Concepto: input.concept,\n DocTipo: input.documentType,\n DocNro: input.documentNumber,\n CbteDesde: voucherNumber,\n CbteHasta: voucherNumber,\n CbteFch: input.voucherDate,\n ImpTotal: input.totalAmount,\n ImpTotConc: input.nonTaxableAmount,\n ImpNeto: input.netAmount,\n ImpOpEx: input.exemptAmount,\n ImpTrib: input.taxAmount,\n ImpIVA: input.vatAmount,\n MonId: input.currencyId,\n PtoVta: input.salesPoint,\n CbteTipo: input.voucherType,\n };\n\n if (!sendsSameForeignCurrencyCancellation) {\n data.MonCotiz = input.exchangeRate;\n }\n\n if (input.receiverVatConditionId !== undefined) {\n data.CondicionIVAReceptorId = input.receiverVatConditionId;\n }\n\n if (\n input.currencyId !== \"PES\" &&\n input.sameCurrencyForeignCancellation !== undefined\n ) {\n data.CanMisMonExt = input.sameCurrencyForeignCancellation;\n }\n\n if (input.serviceStartDate !== undefined) {\n data.FchServDesde = input.serviceStartDate;\n }\n if (input.serviceEndDate !== undefined) {\n data.FchServHasta = input.serviceEndDate;\n }\n if (input.paymentDueDate !== undefined) {\n data.FchVtoPago = input.paymentDueDate;\n }\n\n if (input.associatedVouchers) {\n data.CbtesAsoc = {\n CbteAsoc: input.associatedVouchers.map((v) => ({\n Tipo: v.type,\n PtoVta: v.salesPoint,\n Nro: v.number,\n ...(v.taxId === undefined ? {} : { Cuit: v.taxId }),\n ...(v.voucherDate === undefined ? {} : { CbteFch: v.voucherDate }),\n })),\n };\n }\n\n if (input.associatedPeriod) {\n data.PeriodoAsoc = {\n FchDesde: input.associatedPeriod.startDate,\n FchHasta: input.associatedPeriod.endDate,\n };\n }\n\n if (input.taxes) {\n data.Tributos = {\n Tributo: input.taxes.map((t) => ({\n Id: t.id,\n ...(t.description === undefined ? {} : { Desc: t.description }),\n BaseImp: t.baseAmount,\n Alic: t.rate,\n Importe: t.amount,\n })),\n };\n }\n\n if (input.vatRates) {\n data.Iva = {\n AlicIva: input.vatRates.map((v) => ({\n Id: v.id,\n BaseImp: v.baseAmount,\n Importe: v.amount,\n })),\n };\n }\n\n if (input.optionalFields) {\n data.Opcionales = {\n Opcional: input.optionalFields.map((o) => ({\n Id: o.id,\n Valor: o.value,\n })),\n };\n }\n\n if (input.buyers) {\n data.Compradores = {\n Comprador: input.buyers.map((b) => ({\n DocTipo: b.documentType,\n DocNro: b.documentNumber,\n Porcentaje: b.percentage,\n })),\n };\n }\n\n if (input.activities) {\n data.Actividades = {\n Actividad: input.activities.map((a) => ({\n Id: a.id,\n })),\n };\n }\n\n return data;\n}\n\nfunction normalizeWsfeVoucherInput(\n input: WsfeVoucherInput\n): NormalizedWsfeVoucherInput {\n const {\n voucherDate,\n serviceStartDate,\n serviceEndDate,\n paymentDueDate,\n associatedVouchers,\n associatedPeriod,\n ...rest\n } = input;\n\n return {\n ...rest,\n voucherDate: normalizeWsfeDateInput(voucherDate, \"voucherDate\"),\n ...(serviceStartDate === undefined\n ? {}\n : {\n serviceStartDate: normalizeWsfeDateInput(\n serviceStartDate,\n \"serviceStartDate\"\n ),\n }),\n ...(serviceEndDate === undefined\n ? {}\n : {\n serviceEndDate: normalizeWsfeDateInput(\n serviceEndDate,\n \"serviceEndDate\"\n ),\n }),\n ...(paymentDueDate === undefined\n ? {}\n : {\n paymentDueDate: normalizeWsfeDateInput(\n paymentDueDate,\n \"paymentDueDate\"\n ),\n }),\n ...(associatedVouchers === undefined\n ? {}\n : {\n associatedVouchers: associatedVouchers.map((voucher, index) => {\n const { voucherDate: associatedVoucherDate, ...associatedRest } =\n voucher;\n\n return {\n ...associatedRest,\n ...(associatedVoucherDate === undefined\n ? {}\n : {\n voucherDate: normalizeWsfeDateInput(\n associatedVoucherDate,\n `associatedVouchers[${index}].voucherDate`\n ),\n }),\n };\n }),\n }),\n ...(associatedPeriod === undefined\n ? {}\n : {\n associatedPeriod: {\n startDate: normalizeWsfeDateInput(\n associatedPeriod.startDate,\n \"associatedPeriod.startDate\"\n ),\n endDate: normalizeWsfeDateInput(\n associatedPeriod.endDate,\n \"associatedPeriod.endDate\"\n ),\n },\n }),\n };\n}\n\nfunction normalizeWsfeDateInput(\n value: WsfeDateInput,\n fieldName: string\n): string {\n if (typeof value !== \"string\") {\n throw new ArcaInputError(\n `Invalid WSFE ${fieldName}: expected a YYYY-MM-DD or YYYYMMDD string`,\n {\n detail: { field: fieldName, value },\n }\n );\n }\n\n const normalizedValue = value.trim();\n const afipMatch = normalizedValue.match(/^(\\d{4})(\\d{2})(\\d{2})$/);\n if (afipMatch) {\n const [, year, month, day] = afipMatch;\n assertValidCalendarDate(year, month, day, fieldName, normalizedValue);\n return normalizedValue;\n }\n\n const isoMatch = normalizedValue.match(/^(\\d{4})-(\\d{2})-(\\d{2})$/);\n if (isoMatch) {\n const [, year, month, day] = isoMatch;\n assertValidCalendarDate(year, month, day, fieldName, normalizedValue);\n return `${year}${month}${day}`;\n }\n\n throw new ArcaInputError(\n `Invalid WSFE ${fieldName}: expected a YYYY-MM-DD or YYYYMMDD string`,\n {\n detail: { field: fieldName, value: normalizedValue },\n }\n );\n}\n\nfunction assertValidCalendarDate(\n yearInput: string,\n monthInput: string,\n dayInput: string,\n fieldName: string,\n value: string\n) {\n const year = Number(yearInput);\n const month = Number(monthInput);\n const day = Number(dayInput);\n const candidate = new Date(Date.UTC(year, month - 1, day));\n\n if (\n candidate.getUTCFullYear() !== year ||\n candidate.getUTCMonth() !== month - 1 ||\n candidate.getUTCDate() !== day\n ) {\n throw new ArcaInputError(\n `Invalid WSFE ${fieldName}: received a non-existent calendar date`,\n {\n detail: { field: fieldName, value },\n }\n );\n }\n}\n\nfunction mapWsfeSalesPoint(raw: unknown): WsfeSalesPoint {\n const record = raw as Record<string, unknown>;\n return {\n number: Number(record.Nro ?? 0),\n ...(record.EmisionTipo === undefined\n ? {}\n : { emissionType: String(record.EmisionTipo) }),\n ...(record.Bloqueado === undefined\n ? {}\n : { blocked: String(record.Bloqueado) }),\n ...(record.FchBaja === undefined\n ? {}\n : { deletedSince: String(record.FchBaja) }),\n };\n}\n\nfunction mapWsfeCatalogEntry(raw: unknown): WsfeCatalogEntry {\n const record = raw as Record<string, unknown>;\n return {\n id: Number(record.Id ?? 0),\n description: String(record.Desc ?? \"\"),\n };\n}\n\nfunction mapWsfeActivityType(raw: unknown): WsfeActivityType {\n const record = raw as Record<string, unknown>;\n return {\n id: Number(record.Id ?? 0),\n description: String(record.Desc ?? \"\"),\n order: Number(record.Orden ?? 0),\n };\n}\n\nfunction mapWsfeReceiverVatCondition(raw: unknown): WsfeReceiverVatCondition {\n const record = raw as Record<string, unknown>;\n return {\n id: Number(record.Id ?? 0),\n description: String(record.Desc ?? \"\"),\n voucherClass: String(record.Cmp_Clase ?? \"\"),\n };\n}\n\nfunction mapWsfeCurrencyType(raw: unknown): WsfeCurrencyType {\n const record = raw as Record<string, unknown>;\n return {\n id: String(record.Id ?? \"\"),\n description: String(record.Desc ?? \"\"),\n validFrom: String(record.FchDesde ?? \"\"),\n validTo: String(record.FchHasta ?? \"\"),\n };\n}\n\nfunction mapWsfeServerStatus(raw: Record<string, unknown>): WsfeServerStatus {\n return {\n appServer: String(raw.AppServer ?? \"\"),\n dbServer: String(raw.DbServer ?? \"\"),\n authServer: String(raw.AuthServer ?? \"\"),\n };\n}\n\nfunction mapWsfeQuotation(raw: Record<string, unknown>): WsfeQuotation {\n return {\n currencyId: String(raw.MonId ?? \"\"),\n rate: Number(raw.MonCotiz ?? 0),\n date: String(raw.FchCotiz ?? \"\"),\n };\n}\n\nfunction mapWsfeVoucherInfo(raw: Record<string, unknown>): WsfeVoucherInfo {\n return {\n voucherNumber: Number(raw.CbteDesde ?? raw.CbteHasta ?? 0),\n ...(raw.CbteFch === undefined ? {} : { voucherDate: String(raw.CbteFch) }),\n ...(raw.PtoVta === undefined ? {} : { salesPoint: Number(raw.PtoVta) }),\n ...(raw.CbteTipo === undefined\n ? {}\n : { voucherType: Number(raw.CbteTipo) }),\n ...(raw.ImpTotal === undefined\n ? {}\n : { totalAmount: Number(raw.ImpTotal) }),\n ...(raw.Resultado === undefined ? {} : { result: String(raw.Resultado) }),\n ...(raw.CAE === undefined ? {} : { cae: String(raw.CAE) }),\n ...(raw.CAEFchVto === undefined\n ? {}\n : { caeExpiry: String(raw.CAEFchVto) }),\n raw,\n };\n}\n\nfunction createWsfeAuth(\n representedTaxId: number | string,\n token: string,\n sign: string\n) {\n return {\n Token: token,\n Sign: sign,\n Cuit: Number.parseInt(String(representedTaxId), 10),\n };\n}\n\nfunction unwrapWsfeOperationResult(\n operation: string,\n response: Record<string, unknown>\n) {\n const operationResponse = response[`${operation}Response`] as\n | Record<string, unknown>\n | undefined;\n const result = (operationResponse?.[`${operation}Result`] ??\n response[`${operation}Result`] ??\n response) as Record<string, unknown>;\n\n if (operation === \"FECAESolicitar\") {\n const detailResponse = normalizeWsfeDetailResponse(result);\n const resultCode = detailResponse.Resultado;\n if (resultCode && resultCode !== \"A\") {\n const observationsContainer = detailResponse.Observaciones as\n | Record<string, unknown>\n | undefined;\n const observations = normalizeWsfeErrors(observationsContainer?.Obs);\n if (observations.length > 0) {\n const firstObservation = observations[0];\n if (!firstObservation) {\n throw new ArcaServiceError(\n \"WSFE returned an empty observation list\",\n {\n detail: result,\n }\n );\n }\n throw new ArcaServiceError(firstObservation.message, {\n serviceCode: firstObservation.code,\n detail: result,\n });\n }\n }\n }\n\n const errorsContainer = result.Errors as Record<string, unknown> | undefined;\n const errors = normalizeWsfeErrors(errorsContainer?.Err);\n if (errors.length > 0) {\n const firstError = errors[0];\n if (!firstError) {\n throw new ArcaServiceError(\"WSFE returned an empty error list\", {\n detail: result,\n });\n }\n throw new ArcaServiceError(firstError.message, {\n serviceCode: firstError.code,\n detail: result,\n });\n }\n\n return result;\n}\n\nfunction normalizeWsfeDetailResponse(result: Record<string, unknown>) {\n const detailResponse = result.FeDetResp as\n | Record<string, unknown>\n | undefined;\n const rawDetail = detailResponse?.FECAEDetResponse;\n\n if (Array.isArray(rawDetail)) {\n return (rawDetail[0] as Record<string, unknown>) ?? {};\n }\n\n return (rawDetail as Record<string, unknown> | undefined) ?? {};\n}\n\nfunction normalizeWsfeErrors(rawErrors: unknown) {\n const entries = Array.isArray(rawErrors)\n ? rawErrors\n : rawErrors\n ? [rawErrors]\n : [];\n\n return entries\n .map((entry) => entry as Record<string, unknown>)\n .map((entry) => {\n const code = entry.Code ?? entry.code ?? \"N/A\";\n const message = entry.Msg ?? entry.msg ?? \"Unknown WSFE error\";\n return {\n code: String(code),\n message: `(${String(code)}) ${String(message)}`,\n };\n });\n}\n\nfunction getWsfeResultEntries(\n result: Record<string, unknown>,\n key: string\n): Record<string, unknown>[] {\n const rawEntries = (\n result.ResultGet as Record<string, unknown> | undefined\n )?.[key];\n if (!rawEntries) {\n return [];\n }\n\n return (Array.isArray(rawEntries) ? rawEntries : [rawEntries]).map(\n (entry) => entry as Record<string, unknown>\n );\n}\n"],"mappings":";AAGO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACS,OAAe;AAAA,EAEjC,YAAY,SAAiB,OAAO,cAAc,SAAwB;AACxE,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAYO,IAAM,iBAAN,cAA6B,UAAU;AAAA,EAC1B,OAAe;AAAA,EACxB;AAAA,EAET,YACE,SACA,SAGA;AACA,UAAM,SAAS,oBAAoB,OAAO;AAC1C,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;AAiFO,IAAM,mBAAN,cAA+B,UAAU;AAAA,EAC5B,OAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAET,YACE,SACA,SAIA;AACA,UAAM,SAAS,sBAAsB,OAAO;AAC5C,SAAK,cAAc,SAAS;AA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AAEP,SAAO,QACJ,IAAI,CAAC,UAAU,KAAgC,EAC/C,IAAI,CAAC,UAAU;AACd,UAAM,OAAO,MAAM,QAAQ,MAAM,QAAQ;AACzC,UAAM,UAAU,MAAM,OAAO,MAAM,OAAO;AAC1C,WAAO;AAAA,MACL,MAAM,OAAO,IAAI;AAAA,MACjB,SAAS,IAAI,OAAO,IAAI,CAAC,KAAK,OAAO,OAAO,CAAC;AAAA,IAC/C;AAAA,EACF,CAAC;AACL;AAEA,SAAS,qBACP,QACA,KAC2B;AAC3B,QAAM,aACJ,OAAO,YACL,GAAG;AACP,MAAI,CAAC,YAAY;AACf,WAAO,CAAC;AAAA,EACV;AAEA,UAAQ,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU,GAAG;AAAA,IAC7D,CAAC,UAAU;AAAA,EACb;AACF;","names":[]}
|
package/dist/wsmtxca.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { W as WsaaAuthModule, S as SoapTransport } from './index-
|
|
1
|
+
import { l as ArcaRepresentedTaxId, f as ArcaClientConfig } from './types-CKKe1Oo4.js';
|
|
2
|
+
import { W as WsaaAuthModule, S as SoapTransport } from './index-CqXVyU0E.js';
|
|
3
3
|
|
|
4
4
|
/** Result of a successful WSMTXCA voucher authorization. */
|
|
5
5
|
type WsmtxcaAuthorizationResult = {
|
package/dist/wsmtxca.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/services/wsmtxca.ts"],"sourcesContent":["/** Base error class for all ARCA-related errors. */\nexport class ArcaError extends Error {\n readonly code: string;\n override readonly name: string = \"ArcaError\";\n\n constructor(message: string, code = \"ARCA_ERROR\", options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n }\n}\n\n/** Thrown when the ARCA client configuration is missing or invalid. */\nexport class ArcaConfigurationError extends ArcaError {\n override readonly name: string = \"ArcaConfigurationError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_CONFIGURATION_ERROR\", options);\n }\n}\n\n/** Thrown when caller-provided input data is missing or invalid. */\nexport class ArcaInputError extends ArcaError {\n override readonly name: string = \"ArcaInputError\";\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_INPUT_ERROR\", options);\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */\nexport class ArcaTransportError extends ArcaError {\n override readonly name: string = \"ArcaTransportError\";\n readonly statusCode?: number;\n readonly responseBody?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n statusCode?: number;\n responseBody?: string;\n }\n ) {\n super(message, \"ARCA_TRANSPORT_ERROR\", options);\n this.statusCode = options?.statusCode;\n this.responseBody = options?.responseBody;\n }\n}\n\n/** Thrown when the SOAP response contains a Fault element. */\nexport class ArcaSoapFaultError extends ArcaError {\n override readonly name: string = \"ArcaSoapFaultError\";\n readonly faultCode?: string;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n faultCode?: string;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SOAP_FAULT\", options);\n this.faultCode = options?.faultCode;\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */\nexport class ArcaServiceError extends ArcaError {\n override readonly name: string = \"ArcaServiceError\";\n readonly serviceCode?: string | number;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n serviceCode?: string | number;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SERVICE_ERROR\", options);\n this.serviceCode = options?.serviceCode;\n this.detail = options?.detail;\n }\n}\n","import { ArcaServiceError } from \"../errors\";\nimport type { ArcaClientConfig, ArcaRepresentedTaxId } from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\n\n/** Result of a successful WSMTXCA voucher authorization. */\nexport type WsmtxcaAuthorizationResult = {\n cae: string;\n caeExpiry?: string;\n voucherNumber: number;\n messages: string[];\n raw: Record<string, unknown>;\n};\n\n/** Result of querying the last authorized voucher number. */\nexport type WsmtxcaLastAuthorizedVoucherResult = {\n voucherNumber: number;\n raw: Record<string, unknown>;\n};\n\n/** Result of looking up a specific WSMTXCA voucher. */\nexport type WsmtxcaVoucherLookupResult = {\n invoiceDate: string;\n voucher: Record<string, unknown>;\n messages: string[];\n raw: Record<string, unknown>;\n};\n\n/** WSMTXCA electronic invoicing service (Factura de Crédito Electrónica). */\nexport type WsmtxcaService = {\n /** Authorizes a voucher and returns the CAE. */\n authorizeVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n data: Record<string, unknown>;\n }): Promise<WsmtxcaAuthorizationResult>;\n /** Returns the last authorized voucher number for the given sales point and type. */\n getLastAuthorizedVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult>;\n /** Retrieves details for a specific voucher. */\n getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n }): Promise<WsmtxcaVoucherLookupResult>;\n};\n\nexport type CreateWsmtxcaServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\n/** Creates a WSMTXCA service instance wired with authentication and SOAP transport. */\nexport function createWsmtxcaService(\n options: CreateWsmtxcaServiceOptions\n): WsmtxcaService {\n return {\n async authorizeVoucher({ representedTaxId, data }) {\n const auth = await options.auth.login(\"wsmtxca\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation: \"autorizarComprobante\",\n bodyElementName: \"autorizarComprobanteRequest\",\n bodyElementNamespaceMode: \"prefix\",\n body: {\n authRequest: createWsmtxcaAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n ...(data as Record<string, unknown>),\n },\n });\n\n const raw = unwrapWsmtxcaOperationResponse(\n response.result,\n \"autorizarComprobante\"\n );\n const authorizationPayload = extractWsmtxcaAuthorizationPayload(raw);\n const messages = extractWsmtxcaMessages(raw);\n const resultado = raw.resultado ?? authorizationPayload.resultado;\n\n const caeValue =\n authorizationPayload.CAE ??\n authorizationPayload.codigoAutorizacion ??\n raw.codigoAutorizacion;\n\n if (resultado === \"R\" || caeValue == null) {\n throw new ArcaServiceError(\n messages.join(\" | \") || \"WSMTXCA rejected the voucher authorization\",\n { detail: raw }\n );\n }\n\n return {\n cae: String(caeValue),\n caeExpiry: normalizeWsmtxcaResponseDate(\n authorizationPayload.fechaVencimientoCAE ??\n authorizationPayload.fechaVencimiento ??\n raw.fechaVencimiento\n ),\n voucherNumber: parseWsmtxcaVoucherNumber(\n authorizationPayload.numeroComprobante ?? raw.numeroComprobante,\n \"WSMTXCA did not return the authorized voucher number\",\n raw\n ),\n messages,\n raw,\n };\n },\n async getLastAuthorizedVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n }) {\n const auth = await options.auth.login(\"wsmtxca\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation: \"consultarUltimoComprobanteAutorizado\",\n bodyElementName: \"consultarUltimoComprobanteAutorizadoRequest\",\n bodyElementNamespaceMode: \"prefix\",\n body: {\n authRequest: createWsmtxcaAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n consultaUltimoComprobanteAutorizadoRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n },\n },\n });\n\n const raw = unwrapWsmtxcaOperationResponse(\n response.result,\n \"consultarUltimoComprobanteAutorizado\"\n );\n return {\n voucherNumber: parseWsmtxcaVoucherNumber(\n raw.numeroComprobante ?? raw.cbteNro ?? raw.nroComprobante,\n extractWsmtxcaMessages(raw).join(\" | \") ||\n \"WSMTXCA did not return the last authorized voucher number\",\n raw\n ),\n raw,\n };\n },\n async getVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n }) {\n const auth = await options.auth.login(\"wsmtxca\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation: \"consultarComprobante\",\n bodyElementName: \"consultarComprobanteRequest\",\n bodyElementNamespaceMode: \"prefix\",\n body: {\n authRequest: createWsmtxcaAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n consultaComprobanteRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n numeroComprobante: voucherNumber,\n },\n },\n });\n\n const raw = unwrapWsmtxcaOperationResponse(\n response.result,\n \"consultarComprobante\"\n );\n const voucher = extractWsmtxcaVoucherPayload(raw);\n const messages = extractWsmtxcaMessages(raw);\n const invoiceDate = normalizeWsmtxcaResponseDate(\n voucher.fechaEmision ?? voucher.fecha ?? voucher.CbteFch\n );\n\n if (!invoiceDate) {\n throw new ArcaServiceError(\n messages[0] ?? \"WSMTXCA did not return the voucher issue date\",\n { detail: raw }\n );\n }\n\n return {\n invoiceDate,\n voucher,\n messages,\n raw,\n };\n },\n };\n}\n\nfunction createWsmtxcaAuth(\n representedTaxId: number | string,\n token: string,\n sign: string\n) {\n return {\n token,\n sign,\n cuitRepresentada: Number.parseInt(String(representedTaxId), 10),\n };\n}\n\nfunction toRecord(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === \"object\"\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\nfunction unwrapWsmtxcaOperationResponse(\n response: unknown,\n operation:\n | \"autorizarComprobante\"\n | \"consultarUltimoComprobanteAutorizado\"\n | \"consultarComprobante\"\n) {\n const responseRecord = toRecord(response) ?? {};\n\n if (operation === \"autorizarComprobante\") {\n return (\n toRecord(responseRecord.autorizarComprobanteResponse) ??\n toRecord(responseRecord.autorizarComprobanteResult) ??\n toRecord(responseRecord.comprobanteCAEResponse) ??\n toRecord(responseRecord.comprobanteCAEReponse) ??\n responseRecord\n );\n }\n\n if (operation === \"consultarComprobante\") {\n return (\n toRecord(responseRecord.consultarComprobanteResponse) ??\n toRecord(responseRecord.consultaComprobanteResponse) ??\n toRecord(responseRecord.consultarComprobanteResult) ??\n responseRecord\n );\n }\n\n return (\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultaUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResult) ??\n responseRecord\n );\n}\n\nfunction extractWsmtxcaAuthorizationPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobanteCAEResponse) ??\n toRecord(raw.comprobanteCAEReponse) ??\n raw\n );\n}\n\nfunction extractWsmtxcaVoucherPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobante) ??\n toRecord(raw.cmp) ??\n raw\n );\n}\n\nfunction extractWsmtxcaMessages(raw: Record<string, unknown>): string[] {\n const rawErrors = raw.arrayErrores as\n | { codigoDescripcion?: unknown }\n | undefined;\n const rawObservations = raw.arrayObservaciones as\n | { codigoDescripcion?: unknown }\n | undefined;\n\n const toEntries = (\n value: unknown\n ): Array<{ codigo?: unknown; descripcion?: unknown }> => {\n if (!value) {\n return [];\n }\n if (Array.isArray(value)) {\n return value as Array<{ codigo?: unknown; descripcion?: unknown }>;\n }\n if (typeof value === \"object\") {\n return [value as { codigo?: unknown; descripcion?: unknown }];\n }\n return [];\n };\n\n const errors = toEntries(rawErrors?.codigoDescripcion).map((entry) => {\n const code = entry.codigo == null ? \"N/A\" : String(entry.codigo);\n const description =\n entry.descripcion == null\n ? \"Unknown WSMTXCA error\"\n : String(entry.descripcion);\n return `Error ${code}: ${description}`;\n });\n\n const observations = toEntries(rawObservations?.codigoDescripcion).map(\n (entry) => {\n const code = entry.codigo == null ? \"N/A\" : String(entry.codigo);\n const description =\n entry.descripcion == null ? \"\" : String(entry.descripcion);\n return `Obs ${code}: ${description}`.trim();\n }\n );\n\n return [...errors, ...observations];\n}\n\nfunction parseWsmtxcaVoucherNumber(\n value: unknown,\n message: string,\n detail: Record<string, unknown>\n) {\n const parsed = Number.parseInt(String(value ?? \"\"), 10);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new ArcaServiceError(message, { detail });\n }\n return parsed;\n}\n\nfunction normalizeWsmtxcaResponseDate(value: unknown): string | undefined {\n if (typeof value === \"number\" && Number.isInteger(value)) {\n return formatCompactDateToIso(value);\n }\n\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const trimmed = value.trim();\n if (!trimmed) {\n return undefined;\n }\n\n if (/^\\d{8}$/.test(trimmed)) {\n return formatCompactDateToIso(Number.parseInt(trimmed, 10));\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}/.test(trimmed)) {\n return trimmed.slice(0, 10);\n }\n\n return undefined;\n}\n\nfunction formatCompactDateToIso(dateValue?: number | null): string | undefined {\n if (!dateValue) {\n return undefined;\n }\n\n const raw = String(dateValue);\n if (raw.length !== 8) {\n return undefined;\n }\n\n return `${raw.slice(0, 4)}-${raw.slice(4, 6)}-${raw.slice(6, 8)}`;\n}\n"],"mappings":";AACO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACS,OAAe;AAAA,EAEjC,YAAY,SAAiB,OAAO,cAAc,SAAwB;AACxE,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAkEO,IAAM,mBAAN,cAA+B,UAAU;AAAA,EAC5B,OAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAET,YACE,SACA,SAIA;AACA,UAAM,SAAS,sBAAsB,OAAO;AAC5C,SAAK,cAAc,SAAS;AAC5B,SAAK,SAAS,SAAS;AAAA,EACzB;AACF;;;AClCO,SAAS,qBACd,SACgB;AAChB,SAAO;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AAK,OAAO,GAAG;AAC3B,WAAO,uBAAuB,OAAO,SAAS,SAAS,EAAE,CAAC;AAAA,EAC5D;AAEA,MAAI,qBAAqB,KAAK,OAAO,GAAG;AACtC,WAAO,QAAQ,MAAM,GAAG,EAAE;AAAA,EAC5B;AAEA,SAAO;AACT;AAEA,SAAS,uBAAuB,WAA+C;AAC7E,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,QAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,IAAI,WAAW,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC;AACjE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/services/wsmtxca.ts"],"sourcesContent":["import type { ArcaServiceName } from \"./internal/types\";\n\n/** Base error class for all ARCA-related errors. */\nexport class ArcaError extends Error {\n readonly code: string;\n override readonly name: string = \"ArcaError\";\n\n constructor(message: string, code = \"ARCA_ERROR\", options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n }\n}\n\n/** Thrown when the ARCA client configuration is missing or invalid. */\nexport class ArcaConfigurationError extends ArcaError {\n override readonly name: string = \"ArcaConfigurationError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_CONFIGURATION_ERROR\", options);\n }\n}\n\n/** Thrown when caller-provided input data is missing or invalid. */\nexport class ArcaInputError extends ArcaError {\n override readonly name: string = \"ArcaInputError\";\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_INPUT_ERROR\", options);\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */\nexport class ArcaTransportError extends ArcaError {\n override readonly name: string = \"ArcaTransportError\";\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBody?: string;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n statusCode?: number;\n contentType?: string;\n responseBody?: string;\n }\n ) {\n super(message, \"ARCA_TRANSPORT_ERROR\", options);\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBody = options?.responseBody;\n }\n}\n\n/** Thrown when the SOAP response contains a Fault element. */\nexport class ArcaSoapFaultError extends ArcaError {\n override readonly name: string = \"ArcaSoapFaultError\";\n readonly faultCode?: string;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n faultCode?: string;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SOAP_FAULT\", options);\n this.faultCode = options?.faultCode;\n this.detail = options?.detail;\n }\n}\n\n/** Thrown when a response cannot be parsed as a valid SOAP envelope. */\nexport class ArcaInvalidSoapResponseError extends ArcaError {\n override readonly name: string = \"ArcaInvalidSoapResponseError\";\n readonly service?: ArcaServiceName;\n readonly operation?: string;\n readonly endpointUrl?: string;\n readonly statusCode?: number;\n readonly contentType?: string;\n readonly responseBodyLength?: number;\n readonly responseBodyPreview?: string;\n readonly parsedDetail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n service?: ArcaServiceName;\n operation?: string;\n endpointUrl?: string;\n statusCode?: number;\n contentType?: string;\n responseBodyLength?: number;\n responseBodyPreview?: string;\n parsedDetail?: unknown;\n }\n ) {\n super(message, \"ARCA_INVALID_SOAP_RESPONSE\", options);\n this.service = options?.service;\n this.operation = options?.operation;\n this.endpointUrl = options?.endpointUrl;\n this.statusCode = options?.statusCode;\n this.contentType = options?.contentType;\n this.responseBodyLength = options?.responseBodyLength;\n this.responseBodyPreview = options?.responseBodyPreview;\n this.parsedDetail = options?.parsedDetail;\n }\n}\n\n/** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */\nexport class ArcaServiceError extends ArcaError {\n override readonly name: string = \"ArcaServiceError\";\n readonly serviceCode?: string | number;\n readonly detail?: unknown;\n\n constructor(\n message: string,\n options?: ErrorOptions & {\n serviceCode?: string | number;\n detail?: unknown;\n }\n ) {\n super(message, \"ARCA_SERVICE_ERROR\", options);\n this.serviceCode = options?.serviceCode;\n this.detail = options?.detail;\n }\n}\n","import { ArcaServiceError } from \"../errors\";\nimport type { ArcaClientConfig, ArcaRepresentedTaxId } from \"../internal/types\";\nimport type { SoapTransport } from \"../soap\";\nimport type { WsaaAuthModule } from \"../wsaa\";\n\n/** Result of a successful WSMTXCA voucher authorization. */\nexport type WsmtxcaAuthorizationResult = {\n cae: string;\n caeExpiry?: string;\n voucherNumber: number;\n messages: string[];\n raw: Record<string, unknown>;\n};\n\n/** Result of querying the last authorized voucher number. */\nexport type WsmtxcaLastAuthorizedVoucherResult = {\n voucherNumber: number;\n raw: Record<string, unknown>;\n};\n\n/** Result of looking up a specific WSMTXCA voucher. */\nexport type WsmtxcaVoucherLookupResult = {\n invoiceDate: string;\n voucher: Record<string, unknown>;\n messages: string[];\n raw: Record<string, unknown>;\n};\n\n/** WSMTXCA electronic invoicing service (Factura de Crédito Electrónica). */\nexport type WsmtxcaService = {\n /** Authorizes a voucher and returns the CAE. */\n authorizeVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n data: Record<string, unknown>;\n }): Promise<WsmtxcaAuthorizationResult>;\n /** Returns the last authorized voucher number for the given sales point and type. */\n getLastAuthorizedVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n }): Promise<WsmtxcaLastAuthorizedVoucherResult>;\n /** Retrieves details for a specific voucher. */\n getVoucher(input: {\n representedTaxId?: ArcaRepresentedTaxId;\n voucherType: number;\n salesPoint: number;\n voucherNumber: number;\n }): Promise<WsmtxcaVoucherLookupResult>;\n};\n\nexport type CreateWsmtxcaServiceOptions = {\n config: ArcaClientConfig;\n auth: WsaaAuthModule;\n soap: SoapTransport;\n};\n\n/** Creates a WSMTXCA service instance wired with authentication and SOAP transport. */\nexport function createWsmtxcaService(\n options: CreateWsmtxcaServiceOptions\n): WsmtxcaService {\n return {\n async authorizeVoucher({ representedTaxId, data }) {\n const auth = await options.auth.login(\"wsmtxca\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation: \"autorizarComprobante\",\n bodyElementName: \"autorizarComprobanteRequest\",\n bodyElementNamespaceMode: \"prefix\",\n body: {\n authRequest: createWsmtxcaAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n ...(data as Record<string, unknown>),\n },\n });\n\n const raw = unwrapWsmtxcaOperationResponse(\n response.result,\n \"autorizarComprobante\"\n );\n const authorizationPayload = extractWsmtxcaAuthorizationPayload(raw);\n const messages = extractWsmtxcaMessages(raw);\n const resultado = raw.resultado ?? authorizationPayload.resultado;\n\n const caeValue =\n authorizationPayload.CAE ??\n authorizationPayload.codigoAutorizacion ??\n raw.codigoAutorizacion;\n\n if (resultado === \"R\" || caeValue == null) {\n throw new ArcaServiceError(\n messages.join(\" | \") || \"WSMTXCA rejected the voucher authorization\",\n { detail: raw }\n );\n }\n\n return {\n cae: String(caeValue),\n caeExpiry: normalizeWsmtxcaResponseDate(\n authorizationPayload.fechaVencimientoCAE ??\n authorizationPayload.fechaVencimiento ??\n raw.fechaVencimiento\n ),\n voucherNumber: parseWsmtxcaVoucherNumber(\n authorizationPayload.numeroComprobante ?? raw.numeroComprobante,\n \"WSMTXCA did not return the authorized voucher number\",\n raw\n ),\n messages,\n raw,\n };\n },\n async getLastAuthorizedVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n }) {\n const auth = await options.auth.login(\"wsmtxca\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation: \"consultarUltimoComprobanteAutorizado\",\n bodyElementName: \"consultarUltimoComprobanteAutorizadoRequest\",\n bodyElementNamespaceMode: \"prefix\",\n body: {\n authRequest: createWsmtxcaAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n consultaUltimoComprobanteAutorizadoRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n },\n },\n });\n\n const raw = unwrapWsmtxcaOperationResponse(\n response.result,\n \"consultarUltimoComprobanteAutorizado\"\n );\n return {\n voucherNumber: parseWsmtxcaVoucherNumber(\n raw.numeroComprobante ?? raw.cbteNro ?? raw.nroComprobante,\n extractWsmtxcaMessages(raw).join(\" | \") ||\n \"WSMTXCA did not return the last authorized voucher number\",\n raw\n ),\n raw,\n };\n },\n async getVoucher({\n representedTaxId,\n voucherType,\n salesPoint,\n voucherNumber,\n }) {\n const auth = await options.auth.login(\"wsmtxca\", { representedTaxId });\n const response = await options.soap.execute<\n Record<string, unknown>,\n Record<string, unknown>\n >({\n service: \"wsmtxca\",\n operation: \"consultarComprobante\",\n bodyElementName: \"consultarComprobanteRequest\",\n bodyElementNamespaceMode: \"prefix\",\n body: {\n authRequest: createWsmtxcaAuth(\n representedTaxId ?? options.config.taxId,\n auth.token,\n auth.sign\n ),\n consultaComprobanteRequest: {\n codigoTipoComprobante: voucherType,\n numeroPuntoVenta: salesPoint,\n numeroComprobante: voucherNumber,\n },\n },\n });\n\n const raw = unwrapWsmtxcaOperationResponse(\n response.result,\n \"consultarComprobante\"\n );\n const voucher = extractWsmtxcaVoucherPayload(raw);\n const messages = extractWsmtxcaMessages(raw);\n const invoiceDate = normalizeWsmtxcaResponseDate(\n voucher.fechaEmision ?? voucher.fecha ?? voucher.CbteFch\n );\n\n if (!invoiceDate) {\n throw new ArcaServiceError(\n messages[0] ?? \"WSMTXCA did not return the voucher issue date\",\n { detail: raw }\n );\n }\n\n return {\n invoiceDate,\n voucher,\n messages,\n raw,\n };\n },\n };\n}\n\nfunction createWsmtxcaAuth(\n representedTaxId: number | string,\n token: string,\n sign: string\n) {\n return {\n token,\n sign,\n cuitRepresentada: Number.parseInt(String(representedTaxId), 10),\n };\n}\n\nfunction toRecord(value: unknown): Record<string, unknown> | undefined {\n return value && typeof value === \"object\"\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\nfunction unwrapWsmtxcaOperationResponse(\n response: unknown,\n operation:\n | \"autorizarComprobante\"\n | \"consultarUltimoComprobanteAutorizado\"\n | \"consultarComprobante\"\n) {\n const responseRecord = toRecord(response) ?? {};\n\n if (operation === \"autorizarComprobante\") {\n return (\n toRecord(responseRecord.autorizarComprobanteResponse) ??\n toRecord(responseRecord.autorizarComprobanteResult) ??\n toRecord(responseRecord.comprobanteCAEResponse) ??\n toRecord(responseRecord.comprobanteCAEReponse) ??\n responseRecord\n );\n }\n\n if (operation === \"consultarComprobante\") {\n return (\n toRecord(responseRecord.consultarComprobanteResponse) ??\n toRecord(responseRecord.consultaComprobanteResponse) ??\n toRecord(responseRecord.consultarComprobanteResult) ??\n responseRecord\n );\n }\n\n return (\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultaUltimoComprobanteAutorizadoResponse) ??\n toRecord(responseRecord.consultarUltimoComprobanteAutorizadoResult) ??\n responseRecord\n );\n}\n\nfunction extractWsmtxcaAuthorizationPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobanteCAEResponse) ??\n toRecord(raw.comprobanteCAEReponse) ??\n raw\n );\n}\n\nfunction extractWsmtxcaVoucherPayload(raw: Record<string, unknown>) {\n return (\n toRecord(raw.comprobanteResponse) ??\n toRecord(raw.comprobante) ??\n toRecord(raw.cmp) ??\n raw\n );\n}\n\nfunction extractWsmtxcaMessages(raw: Record<string, unknown>): string[] {\n const rawErrors = raw.arrayErrores as\n | { codigoDescripcion?: unknown }\n | undefined;\n const rawObservations = raw.arrayObservaciones as\n | { codigoDescripcion?: unknown }\n | undefined;\n\n const toEntries = (\n value: unknown\n ): Array<{ codigo?: unknown; descripcion?: unknown }> => {\n if (!value) {\n return [];\n }\n if (Array.isArray(value)) {\n return value as Array<{ codigo?: unknown; descripcion?: unknown }>;\n }\n if (typeof value === \"object\") {\n return [value as { codigo?: unknown; descripcion?: unknown }];\n }\n return [];\n };\n\n const errors = toEntries(rawErrors?.codigoDescripcion).map((entry) => {\n const code = entry.codigo == null ? \"N/A\" : String(entry.codigo);\n const description =\n entry.descripcion == null\n ? \"Unknown WSMTXCA error\"\n : String(entry.descripcion);\n return `Error ${code}: ${description}`;\n });\n\n const observations = toEntries(rawObservations?.codigoDescripcion).map(\n (entry) => {\n const code = entry.codigo == null ? \"N/A\" : String(entry.codigo);\n const description =\n entry.descripcion == null ? \"\" : String(entry.descripcion);\n return `Obs ${code}: ${description}`.trim();\n }\n );\n\n return [...errors, ...observations];\n}\n\nfunction parseWsmtxcaVoucherNumber(\n value: unknown,\n message: string,\n detail: Record<string, unknown>\n) {\n const parsed = Number.parseInt(String(value ?? \"\"), 10);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new ArcaServiceError(message, { detail });\n }\n return parsed;\n}\n\nfunction normalizeWsmtxcaResponseDate(value: unknown): string | undefined {\n if (typeof value === \"number\" && Number.isInteger(value)) {\n return formatCompactDateToIso(value);\n }\n\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const trimmed = value.trim();\n if (!trimmed) {\n return undefined;\n }\n\n if (/^\\d{8}$/.test(trimmed)) {\n return formatCompactDateToIso(Number.parseInt(trimmed, 10));\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}/.test(trimmed)) {\n return trimmed.slice(0, 10);\n }\n\n return undefined;\n}\n\nfunction formatCompactDateToIso(dateValue?: number | null): string | undefined {\n if (!dateValue) {\n return undefined;\n }\n\n const raw = String(dateValue);\n if (raw.length !== 8) {\n return undefined;\n }\n\n return `${raw.slice(0, 4)}-${raw.slice(4, 6)}-${raw.slice(6, 8)}`;\n}\n"],"mappings":";AAGO,IAAM,YAAN,cAAwB,MAAM;AAAA,EAC1B;AAAA,EACS,OAAe;AAAA,EAEjC,YAAY,SAAiB,OAAO,cAAc,SAAwB;AACxE,UAAM,SAA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SAAO;AACT;AAEA,SAAS,6BAA6B,OAAoC;AACxE,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,GAAG;AACxD,WAAO,uBAAuB,KAAK;AAAA,EACrC;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,KAAK,OAAO,GAAG;AAC3B,WAAO,uBAAuB,OAAO,SAAS,SAAS,EAAE,CAAC;AAAA,EAC5D;AAEA,MAAI,qBAAqB,KAAK,OAAO,GAAG;AACtC,WAAO,QAAQ,MAAM,GAAG,EAAE;AAAA,EAC5B;AAEA,SAAO;AACT;AAEA,SAAS,uBAAuB,WAA+C;AAC7E,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,QAAM,MAAM,OAAO,SAAS;AAC5B,MAAI,IAAI,WAAW,GAAG;AACpB,WAAO;AAAA,EACT;AAEA,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC;AACjE;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "facturas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Node.js client for ARCA services including WSFE, WSMTXCA, and padron lookups.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": "Lapyme",
|
|
8
|
-
"homepage": "https://github.com/LaPyme/
|
|
8
|
+
"homepage": "https://github.com/LaPyme/facturas#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/LaPyme/
|
|
11
|
+
"url": "git+https://github.com/LaPyme/facturas.git"
|
|
12
12
|
},
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/LaPyme/
|
|
14
|
+
"url": "https://github.com/LaPyme/facturas/issues"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"arca",
|
|
@@ -34,16 +34,6 @@
|
|
|
34
34
|
"README.md",
|
|
35
35
|
"LICENSE"
|
|
36
36
|
],
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "tsup --config tsup.config.ts",
|
|
39
|
-
"pack:check": "npm pack --dry-run",
|
|
40
|
-
"prepack": "pnpm build",
|
|
41
|
-
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
42
|
-
"test": "vitest run --config vitest.config.ts",
|
|
43
|
-
"test:coverage": "vitest run --config vitest.config.ts --coverage",
|
|
44
|
-
"check": "ultracite check",
|
|
45
|
-
"fix": "ultracite fix"
|
|
46
|
-
},
|
|
47
37
|
"exports": {
|
|
48
38
|
".": {
|
|
49
39
|
"types": "./dist/index.d.ts",
|
|
@@ -91,5 +81,14 @@
|
|
|
91
81
|
"typescript": "^5.9.3",
|
|
92
82
|
"ultracite": "7.4.4",
|
|
93
83
|
"vitest": "^4.0.18"
|
|
84
|
+
},
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "tsup --config tsup.config.ts",
|
|
87
|
+
"pack:check": "npm pack --dry-run",
|
|
88
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
89
|
+
"test": "vitest run --config vitest.config.ts",
|
|
90
|
+
"test:coverage": "vitest run --config vitest.config.ts --coverage",
|
|
91
|
+
"check": "ultracite check",
|
|
92
|
+
"fix": "ultracite fix"
|
|
94
93
|
}
|
|
95
|
-
}
|
|
94
|
+
}
|