@lapyme/arca 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lapyme
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # arca.ts
2
+
3
+ `@lapyme/arca` is a Node.js client for ARCA web services. It currently covers WSAA authentication plus the first production-oriented service modules we use most often: `wsfe`, `wsmtxca`, and padron lookups.
4
+
5
+ The package is ESM-first, supports Node.js `>=20`, and defaults to a safe configuration for open-source use:
6
+
7
+ - WSAA credentials stay in memory by default.
8
+ - Disk-backed WSAA caching is opt-in and requires an explicit directory.
9
+ - The documented public surface is intentionally narrow.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pnpm add @lapyme/arca
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```ts
20
+ import {
21
+ createArcaClient,
22
+ createArcaClientConfigFromEnv,
23
+ } from "@lapyme/arca";
24
+
25
+ const client = createArcaClient(
26
+ createArcaClientConfigFromEnv({
27
+ defaultEnvironment: "test",
28
+ })
29
+ );
30
+
31
+ const nextVoucher = await client.wsfe.getLastVoucher({
32
+ salesPoint: 1,
33
+ voucherType: 6,
34
+ });
35
+
36
+ console.log(nextVoucher);
37
+ ```
38
+
39
+ Expected environment variables:
40
+
41
+ - `ARCA_TAX_ID`
42
+ - `ARCA_CERTIFICATE_PEM`
43
+ - `ARCA_PRIVATE_KEY_PEM`
44
+ - `ARCA_ENVIRONMENT` with `test` or `production`
45
+
46
+ The helper defaults `ARCA_ENVIRONMENT` to `test` when it is omitted.
47
+
48
+ ## Configuration
49
+
50
+ You can pass configuration directly instead of loading it from environment variables:
51
+
52
+ ```ts
53
+ import { createArcaClient } from "@lapyme/arca";
54
+
55
+ const client = createArcaClient({
56
+ taxId: "20123456789",
57
+ certificatePem: process.env.ARCA_CERTIFICATE_PEM!,
58
+ privateKeyPem: process.env.ARCA_PRIVATE_KEY_PEM!,
59
+ environment: "test",
60
+ });
61
+ ```
62
+
63
+ ### Opt-in disk cache for WSAA credentials
64
+
65
+ By default, WSAA login tickets are cached in memory only. To persist them across process restarts, enable disk cache explicitly:
66
+
67
+ ```ts
68
+ import { createArcaClient } from "@lapyme/arca";
69
+
70
+ const client = createArcaClient({
71
+ taxId: "20123456789",
72
+ certificatePem: process.env.ARCA_CERTIFICATE_PEM!,
73
+ privateKeyPem: process.env.ARCA_PRIVATE_KEY_PEM!,
74
+ environment: "production",
75
+ wsaa: {
76
+ cache: {
77
+ mode: "disk",
78
+ directory: ".arca-wsaa-cache",
79
+ },
80
+ },
81
+ });
82
+ ```
83
+
84
+ Environment-based configuration also supports:
85
+
86
+ - `ARCA_WSAA_CACHE_MODE` with `memory` or `disk`
87
+ - `ARCA_WSAA_CACHE_DIRECTORY` when `ARCA_WSAA_CACHE_MODE=disk`
88
+
89
+ ## Supported Modules
90
+
91
+ ### `client.wsfe`
92
+
93
+ WSFE electronic invoicing. All inputs and outputs use JS-convention names; the library maps them to AFIP's SOAP schema internally.
94
+
95
+ - `createNextVoucher({ data })` — Authorizes a new voucher. Takes a typed `WsfeVoucherInput` and returns `WsfeAuthorizationResult` with `cae`, `caeExpiry`, `voucherNumber`, and `raw`.
96
+ - `getLastVoucher({ salesPoint, voucherType })` — Returns the next available voucher number.
97
+ - `getSalesPoints({})` — Lists configured points of sale as `WsfeSalesPoint[]`.
98
+ - `getVoucherInfo({ number, salesPoint, voucherType })` — Retrieves voucher details as `WsfeVoucherInfo | null`.
99
+
100
+ ```ts
101
+ const result = await client.wsfe.createNextVoucher({
102
+ data: {
103
+ salesPoint: 1,
104
+ voucherType: 6,
105
+ concept: 1,
106
+ documentType: 80,
107
+ documentNumber: 30717329654,
108
+ voucherDate: "20260501",
109
+ totalAmount: 121,
110
+ nonTaxableAmount: 0,
111
+ netAmount: 100,
112
+ exemptAmount: 0,
113
+ taxAmount: 0,
114
+ vatAmount: 21,
115
+ currencyId: "PES",
116
+ exchangeRate: 1,
117
+ vatRates: [{ id: 5, baseAmount: 100, amount: 21 }],
118
+ },
119
+ });
120
+
121
+ console.log(result.cae, result.caeExpiry, result.voucherNumber);
122
+ ```
123
+
124
+ ### `client.wsmtxca`
125
+
126
+ WSMTXCA electronic invoicing (Factura de Crédito Electrónica).
127
+
128
+ - `authorizeVoucher({ data })` — Returns `WsmtxcaAuthorizationResult`.
129
+ - `getLastAuthorizedVoucher({ voucherType, salesPoint })` — Returns `WsmtxcaLastAuthorizedVoucherResult`.
130
+ - `getVoucher({ voucherType, salesPoint, voucherNumber })` — Returns `WsmtxcaVoucherLookupResult`.
131
+
132
+ ### `client.padron`
133
+
134
+ Padron taxpayer registry lookups.
135
+
136
+ - `getTaxpayerDetails(taxId)` — Returns `PadronTaxpayerResult | null` with `taxId`, `name`, `personType`, and `raw`.
137
+ - `getTaxIdByDocument(documentNumber)` — Returns `PadronTaxIdLookupResult | null` with `taxIds` and `raw`.
138
+
139
+ You can also import the service factories directly from documented subpaths:
140
+
141
+ ```ts
142
+ import { createWsfeService } from "@lapyme/arca/wsfe";
143
+ import { ArcaServiceError } from "@lapyme/arca/errors";
144
+ import type { WsfeVoucherInput } from "@lapyme/arca/wsfe";
145
+ ```
146
+
147
+ ## Public API
148
+
149
+ Documented, semver-governed entrypoints:
150
+
151
+ - `@lapyme/arca`
152
+ - `@lapyme/arca/wsfe`
153
+ - `@lapyme/arca/wsmtxca`
154
+ - `@lapyme/arca/padron`
155
+ - `@lapyme/arca/errors`
156
+ - `@lapyme/arca/types`
157
+
158
+ Low-level SOAP, HTTP, and WSAA internals are intentionally not part of the public contract.
159
+
160
+ ## Development
161
+
162
+ ```bash
163
+ pnpm install
164
+ pnpm typecheck
165
+ pnpm test
166
+ pnpm test:coverage
167
+ pnpm pack:check
168
+ ```
169
+
170
+ ## Security Notes
171
+
172
+ - Treat your certificate and private key as secrets.
173
+ - Default in-memory WSAA caching avoids silent disk writes.
174
+ - If you enable disk cache, point it at a directory with appropriate filesystem permissions for your runtime.
175
+
176
+ ## License
177
+
178
+ MIT
@@ -0,0 +1,43 @@
1
+ /** Base error class for all ARCA-related errors. */
2
+ declare class ArcaError extends Error {
3
+ readonly code: string;
4
+ readonly name: string;
5
+ constructor(message: string, code?: string, options?: ErrorOptions);
6
+ }
7
+ /** Thrown when the ARCA client configuration is missing or invalid. */
8
+ declare class ArcaConfigurationError extends ArcaError {
9
+ readonly name: string;
10
+ constructor(message: string, options?: ErrorOptions);
11
+ }
12
+ /** Thrown when an HTTP request to an ARCA endpoint fails at the transport level. */
13
+ declare class ArcaTransportError extends ArcaError {
14
+ readonly name: string;
15
+ readonly statusCode?: number;
16
+ readonly responseBody?: string;
17
+ constructor(message: string, options?: ErrorOptions & {
18
+ statusCode?: number;
19
+ responseBody?: string;
20
+ });
21
+ }
22
+ /** Thrown when the SOAP response contains a Fault element. */
23
+ declare class ArcaSoapFaultError extends ArcaError {
24
+ readonly name: string;
25
+ readonly faultCode?: string;
26
+ readonly detail?: unknown;
27
+ constructor(message: string, options?: ErrorOptions & {
28
+ faultCode?: string;
29
+ detail?: unknown;
30
+ });
31
+ }
32
+ /** Thrown when an ARCA service (WSFE, WSMTXCA, Padron) returns a domain-level error. */
33
+ declare class ArcaServiceError extends ArcaError {
34
+ readonly name: string;
35
+ readonly serviceCode?: string | number;
36
+ readonly detail?: unknown;
37
+ constructor(message: string, options?: ErrorOptions & {
38
+ serviceCode?: string | number;
39
+ detail?: unknown;
40
+ });
41
+ }
42
+
43
+ export { ArcaConfigurationError, ArcaError, ArcaServiceError, ArcaSoapFaultError, ArcaTransportError };
package/dist/errors.js ADDED
@@ -0,0 +1,53 @@
1
+ // src/errors.ts
2
+ var ArcaError = class extends Error {
3
+ code;
4
+ name = "ArcaError";
5
+ constructor(message, code = "ARCA_ERROR", options) {
6
+ super(message, options);
7
+ this.code = code;
8
+ }
9
+ };
10
+ var ArcaConfigurationError = class extends ArcaError {
11
+ name = "ArcaConfigurationError";
12
+ constructor(message, options) {
13
+ super(message, "ARCA_CONFIGURATION_ERROR", options);
14
+ }
15
+ };
16
+ var ArcaTransportError = class extends ArcaError {
17
+ name = "ArcaTransportError";
18
+ statusCode;
19
+ responseBody;
20
+ constructor(message, options) {
21
+ super(message, "ARCA_TRANSPORT_ERROR", options);
22
+ this.statusCode = options?.statusCode;
23
+ this.responseBody = options?.responseBody;
24
+ }
25
+ };
26
+ var ArcaSoapFaultError = class extends ArcaError {
27
+ name = "ArcaSoapFaultError";
28
+ faultCode;
29
+ detail;
30
+ constructor(message, options) {
31
+ super(message, "ARCA_SOAP_FAULT", options);
32
+ this.faultCode = options?.faultCode;
33
+ this.detail = options?.detail;
34
+ }
35
+ };
36
+ var ArcaServiceError = class extends ArcaError {
37
+ name = "ArcaServiceError";
38
+ serviceCode;
39
+ detail;
40
+ constructor(message, options) {
41
+ super(message, "ARCA_SERVICE_ERROR", options);
42
+ this.serviceCode = options?.serviceCode;
43
+ this.detail = options?.detail;
44
+ }
45
+ };
46
+ export {
47
+ ArcaConfigurationError,
48
+ ArcaError,
49
+ ArcaServiceError,
50
+ ArcaSoapFaultError,
51
+ ArcaTransportError
52
+ };
53
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.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\nclass ArcaNotImplementedError extends ArcaError {\n override readonly name: string = \"ArcaNotImplementedError\";\n\n constructor(message: string, options?: ErrorOptions) {\n super(message, \"ARCA_NOT_IMPLEMENTED\", options);\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"],"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;AAGO,IAAM,yBAAN,cAAqC,UAAU;AAAA,EAClC,OAAe;AAAA,EAEjC,YAAY,SAAiB,SAAwB;AACnD,UAAM,SAAS,4BAA4B,OAAO;AAAA,EACpD;AACF;AAWO,IAAM,qBAAN,cAAiC,UAAU;AAAA,EAC9B,OAAe;AAAA,EACxB;AAAA,EACA;AAAA,EAET,YACE,SACA,SAIA;AACA,UAAM,SAAS,wBAAwB,OAAO;AAC9C,SAAK,aAAa,SAAS;AAC3B,SAAK,eAAe,SAAS;AAAA,EAC/B;AACF;AAGO,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;AAGO,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;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { j as ArcaSoapExecutionOptions, k as ArcaSoapResponse, i as ArcaWsaaServiceId, c as ArcaAuthOptions, b as ArcaAuthCredentials } from './types-DWsYue4B.js';
2
+
3
+ type SoapTransport = {
4
+ execute<TBody, TResult>(request: ArcaSoapExecutionOptions<TBody>): Promise<ArcaSoapResponse<TResult>>;
5
+ };
6
+
7
+ type WsaaAuthModule = {
8
+ login(service: ArcaWsaaServiceId, options?: ArcaAuthOptions): Promise<ArcaAuthCredentials>;
9
+ };
10
+
11
+ export type { SoapTransport as S, WsaaAuthModule as W };
@@ -0,0 +1,62 @@
1
+ import { A as ArcaClientConfig, a as ArcaEnvironment } from './types-DWsYue4B.js';
2
+ export { b as ArcaAuthCredentials, c as ArcaAuthOptions, d as ArcaPadronServiceName, e as ArcaRepresentedTaxId, f as ArcaServiceName, g as ArcaServiceTarget, h as ArcaWsaaCacheConfig, i as ArcaWsaaServiceId } from './types-DWsYue4B.js';
3
+ import { PadronService } from './padron.js';
4
+ export { CreatePadronServiceOptions, PadronTaxIdLookupResult, PadronTaxpayerResult, createPadronService } from './padron.js';
5
+ import { WsfeService } from './wsfe.js';
6
+ export { CreateWsfeServiceOptions, WsfeAssociatedVoucher, WsfeAuthorizationResult, WsfeBuyer, WsfeOptionalField, WsfeSalesPoint, WsfeTax, WsfeVatRate, WsfeVoucherInfo, WsfeVoucherInput, createWsfeService } from './wsfe.js';
7
+ import { WsmtxcaService } from './wsmtxca.js';
8
+ export { CreateWsmtxcaServiceOptions, WsmtxcaAuthorizationResult, WsmtxcaLastAuthorizedVoucherResult, WsmtxcaVoucherLookupResult, createWsmtxcaService } from './wsmtxca.js';
9
+ export { ArcaConfigurationError, ArcaError, ArcaServiceError, ArcaSoapFaultError, ArcaTransportError } from './errors.js';
10
+ import './index-vWZOjFDO.js';
11
+
12
+ /** Fully wired ARCA client with access to all service modules. */
13
+ type ArcaClient = {
14
+ config: ArcaClientConfig;
15
+ wsfe: WsfeService;
16
+ wsmtxca: WsmtxcaService;
17
+ padron: PadronService;
18
+ };
19
+ /**
20
+ * Creates an ARCA client from the given configuration.
21
+ * Validates the config, wires WSAA authentication and SOAP transport,
22
+ * and returns an object with `.wsfe`, `.wsmtxca`, and `.padron` service modules.
23
+ *
24
+ * @throws {ArcaConfigurationError} When the config is missing or invalid.
25
+ */
26
+ declare function createArcaClient(config: ArcaClientConfig): ArcaClient;
27
+
28
+ /** Valid ARCA environment names. */
29
+ declare const ARCA_ENVIRONMENTS: readonly ["production", "test"];
30
+ /** Default environment variable names read by {@link createArcaClientConfigFromEnv}. */
31
+ declare const ARCA_ENV_VARIABLES: {
32
+ readonly taxId: "ARCA_TAX_ID";
33
+ readonly certificatePem: "ARCA_CERTIFICATE_PEM";
34
+ readonly privateKeyPem: "ARCA_PRIVATE_KEY_PEM";
35
+ readonly environment: "ARCA_ENVIRONMENT";
36
+ readonly wsaaCacheMode: "ARCA_WSAA_CACHE_MODE";
37
+ readonly wsaaCacheDirectory: "ARCA_WSAA_CACHE_DIRECTORY";
38
+ };
39
+ type ArcaClientConfigEnvironment = Record<string, string | undefined>;
40
+ /** Options for {@link createArcaClientConfigFromEnv}. */
41
+ type CreateArcaClientConfigFromEnvOptions = {
42
+ env?: ArcaClientConfigEnvironment;
43
+ defaultEnvironment?: ArcaEnvironment;
44
+ variableNames?: Partial<typeof ARCA_ENV_VARIABLES>;
45
+ };
46
+ /** Returns `"production"` or `"test"` based on the boolean flag. */
47
+ declare function resolveArcaEnvironment(production: boolean): ArcaEnvironment;
48
+ /**
49
+ * Builds an {@link ArcaClientConfig} from environment variables.
50
+ * Reads `process.env` by default; override with `options.env`.
51
+ *
52
+ * @throws {ArcaConfigurationError} When required variables are missing or invalid.
53
+ */
54
+ declare function createArcaClientConfigFromEnv(options?: CreateArcaClientConfigFromEnvOptions): ArcaClientConfig;
55
+ /**
56
+ * Validates an {@link ArcaClientConfig} and throws if any field is invalid.
57
+ *
58
+ * @throws {ArcaConfigurationError} With a list of invalid field names.
59
+ */
60
+ declare function assertArcaClientConfig(config: ArcaClientConfig): void;
61
+
62
+ export { ARCA_ENVIRONMENTS, ARCA_ENV_VARIABLES, type ArcaClient, ArcaClientConfig, ArcaEnvironment, type CreateArcaClientConfigFromEnvOptions, PadronService, WsfeService, WsmtxcaService, assertArcaClientConfig, createArcaClient, createArcaClientConfigFromEnv, resolveArcaEnvironment };