ksef-client-ts 0.9.1 → 0.10.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 CHANGED
@@ -2,58 +2,18 @@
2
2
 
3
3
  TypeScript client for the Polish National e-Invoice System (KSeF) API v2.
4
4
 
5
- **[Documentation](https://flopsstuff.github.io/ksef-client-ts)** · **[NPM](https://www.npmjs.com/package/ksef-client-ts)**
6
-
7
- ## Features
8
-
9
- - **Complete API coverage** — KSeF API v2.6.1, types aligned with the official OpenAPI spec
10
- - **Offline invoice mode** — full lifecycle for all 4 KSeF offline modes with QR KOD I + KOD II signing, deadline tracking, local storage, and technical correction
11
- - **Full-featured CLI** — `ksef` with 15 command groups for auth, sessions, invoices, offline, batch upload, export, and more
12
- - **High-level workflows** — auth, online/batch sessions, invoice export — full lifecycle in a single call
13
- - **Built-in cryptography** — AES-256-CBC, RSA-OAEP, ECDH, XAdES-B signatures, self-signed certs (Node crypto)
14
- - **External signing** — HSM, EPUAP, and smart card authentication via callback-based signing
15
- - **Automatic token management** — AuthManager: token injection, 401 refresh with dedup
16
- - **Opt-in circuit breaker** — pauses outgoing requests for a short cooldown window after consecutive upstream failures
17
- - **Streaming batch uploads** — constant-memory batch upload via Web Streams API with ZIP bomb protection
18
- - **Incremental export** — HWM-based paginated export with file-based state persistence
19
- - **Multiple document structures** — FA, PEF, PEF_KOR, FA_RR with typed FormCode constants and UPO parsing
20
- - **Invoice XML serialization (FA2/FA3/PEF/PEF_KOR)** — build XSD-compliant invoice XML from typed TypeScript objects with correct element ordering (including the FA3 per-VAT-rate interleave) and namespace injection; `ksef invoice build` exposes the same pipeline to shell workflows with JSON/YAML input and optional XSD validation
21
- - **Invoice XML validation** — three-level client-side validation (well-formedness, XSD schema via Zod, NIP/PESEL checksums, future date rejection) with auto-detection for all 6 invoice types
22
- - **Typed errors with RFC 7807 Problem Details** — `KSeFError` hierarchy with dedicated classes for 400/401/403/410/429 carrying structured diagnostic context; exhaustive dispatch via the `KSeFApiProblem` union and `assertNever`; fluent request builders
23
- - **Comprehensive test coverage** — unit + E2E tests across HTTP, crypto, services, workflows; CI on every change
24
- - **Interactive setup wizard** — `ksef setup` guides through environment selection, authentication, and token generation in one flow
25
- - **Zero HTTP dependencies** — native `fetch` (Node 18+); dual ESM/CJS via tsup
26
-
27
- Requires **Node.js 18+**.
5
+ **[Documentation](https://flopsstuff.github.io/ksef-client-ts)** · **[GitHub](https://github.com/Flopsstuff/ksef-client-ts)**
28
6
 
29
7
  ## Install
30
8
 
31
- Install CLI globally:
32
-
33
- ```bash
34
- npm i -g ksef-client-ts
35
- ksef --help
36
- ```
37
-
38
- Install in a project:
39
-
40
9
  ```bash
41
- # Choose one package manager:
42
- # npm
43
- npm i ksef-client-ts
44
- # Yarn
45
- yarn add ksef-client-ts
46
- # pnpm
47
- pnpm add ksef-client-ts
10
+ npm i ksef-client-ts # library
11
+ npm i -g ksef-client-ts # ksef CLI
48
12
  ```
49
13
 
50
- For local development, clone and build:
14
+ Requires **Node.js 18+**. Dual ESM/CJS output via tsup.
51
15
 
52
- ```bash
53
- git clone https://github.com/Flopsstuff/ksef-client-ts.git
54
- cd ksef-client-ts
55
- yarn install && yarn build
56
- ```
16
+ ## Quick start
57
17
 
58
18
  ```ts
59
19
  import { KSeFClient } from 'ksef-client-ts';
@@ -62,7 +22,7 @@ const client = new KSeFClient({ environment: 'TEST' });
62
22
  await client.crypto.init();
63
23
 
64
24
  const challenge = await client.auth.getChallenge();
65
- // ... authenticate, open session, send invoices
25
+ // ... authenticate, open a session, send invoices
66
26
  ```
67
27
 
68
28
  ```bash
@@ -70,38 +30,19 @@ ksef auth login --token "$KSEF_TOKEN" --nip "$KSEF_NIP"
70
30
  ksef session open # 1. Open online session (required)
71
31
  ksef invoice send invoice.xml # 2. Send invoice
72
32
  ksef session invoices # 3. Verify invoice status
73
- ksef session close # 4. Close session (optional)
74
33
  ```
75
34
 
76
- See the [documentation](https://flopsstuff.github.io/ksef-client-ts) for full usage, [API reference](https://flopsstuff.github.io/ksef-client-ts/api-reference), and [CLI reference](https://flopsstuff.github.io/ksef-client-ts/cli).
77
-
78
- ## Development
35
+ Node-only helpers (filesystem storage, native XSD validation) are available from the `ksef-client-ts/node` entry point.
79
36
 
80
- ```bash
81
- yarn install # Install dependencies (yarn 4.x via Corepack)
82
- yarn build # Build ESM + CJS + DTS via tsup
83
- yarn lint # Type-check (tsc --noEmit)
84
- yarn test # Run all tests (vitest)
85
- ```
37
+ ## Documentation
86
38
 
87
- ## Related
39
+ The full feature list, guides, API and CLI reference, and the v0.10 migration guide live in the **[documentation](https://flopsstuff.github.io/ksef-client-ts)** and the **[GitHub README](https://github.com/Flopsstuff/ksef-client-ts)**:
88
40
 
89
- - [KSeF Web Portal](https://ap.ksef.mf.gov.pl/web/) — official KSeF web application (token management, permissions, invoices)
90
- - [KSeF official docs](https://github.com/CIRFMF/ksef-docs) — official documentation (Polish)
91
- - [KSeF docs translated](https://flopsstuff.github.io/ksef-docs/) — translated documentation (EN/RU/UK), [source on GitHub](https://github.com/Flopsstuff/ksef-docs)
92
- - [ksef-client-csharp](https://github.com/CIRFMF/ksef-client-csharp) — official C# reference client
93
- - [ksef-client-java](https://github.com/CIRFMF/ksef-client-java) — official Java reference client
41
+ - [Quick start](https://flopsstuff.github.io/ksef-client-ts/quick-start)
42
+ - [API reference](https://flopsstuff.github.io/ksef-client-ts/api-reference)
43
+ - [CLI reference](https://flopsstuff.github.io/ksef-client-ts/cli)
44
+ - [Migration guide (v0.10)](https://flopsstuff.github.io/ksef-client-ts/migration-v0.10)
94
45
 
95
46
  ## License
96
47
 
97
48
  [MIT](LICENSE)
98
-
99
- ---
100
-
101
- [![Tests](https://github.com/Flopsstuff/ksef-client-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/Flopsstuff/ksef-client-ts/actions/workflows/ci.yml)
102
- ![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Fl0p/1558034ac67a11548c7f8f0c05e8d4c0/raw/ksef-client-ts-coverage.json&cacheSeconds=300)
103
- ![NPM Version](https://img.shields.io/npm/v/ksef-client-ts?color=green)
104
- ![NPM Downloads](https://img.shields.io/npm/dm/ksef-client-ts)
105
- ![GitHub Stars](https://img.shields.io/github/stars/Flopsstuff/ksef-client-ts)
106
- ![GitHub Forks](https://img.shields.io/github/forks/Flopsstuff/ksef-client-ts)
107
- ![GitHub License](https://img.shields.io/github/license/Flopsstuff/ksef-client-ts)
package/dist/cli.js CHANGED
@@ -256,14 +256,6 @@ var init_ksef_auth_status_error = __esm({
256
256
  }
257
257
  });
258
258
 
259
- // src/errors/ksef-session-expired-error.ts
260
- var init_ksef_session_expired_error = __esm({
261
- "src/errors/ksef-session-expired-error.ts"() {
262
- "use strict";
263
- init_ksef_error();
264
- }
265
- });
266
-
267
259
  // src/errors/ksef-validation-error.ts
268
260
  var ksef_validation_error_exports = {};
269
261
  __export(ksef_validation_error_exports, {
@@ -292,14 +284,6 @@ var init_ksef_validation_error = __esm({
292
284
  }
293
285
  });
294
286
 
295
- // src/errors/ksef-metadata-pagination-error.ts
296
- var init_ksef_metadata_pagination_error = __esm({
297
- "src/errors/ksef-metadata-pagination-error.ts"() {
298
- "use strict";
299
- init_ksef_error();
300
- }
301
- });
302
-
303
287
  // src/errors/error-codes.ts
304
288
  function hasErrorCode(body, code) {
305
289
  return !!body?.exception?.exceptionDetailList?.some((d) => d.exceptionCode === code);
@@ -416,13 +400,6 @@ var init_ksef_xsd_validation_error = __esm({
416
400
  }
417
401
  });
418
402
 
419
- // src/errors/assert-never.ts
420
- var init_assert_never = __esm({
421
- "src/errors/assert-never.ts"() {
422
- "use strict";
423
- }
424
- });
425
-
426
403
  // src/errors/index.ts
427
404
  var init_errors = __esm({
428
405
  "src/errors/index.ts"() {
@@ -434,16 +411,7 @@ var init_errors = __esm({
434
411
  init_ksef_forbidden_error();
435
412
  init_ksef_gone_error();
436
413
  init_ksef_bad_request_error();
437
- init_ksef_auth_status_error();
438
- init_ksef_session_expired_error();
439
414
  init_ksef_validation_error();
440
- init_ksef_metadata_pagination_error();
441
- init_ksef_batch_timeout_error();
442
- init_ksef_unknown_public_key_error();
443
- init_ksef_circuit_open_error();
444
- init_ksef_xsd_validation_error();
445
- init_error_codes();
446
- init_assert_never();
447
415
  }
448
416
  });
449
417
 
@@ -500,7 +468,6 @@ var init_options = __esm({
500
468
  var init_config = __esm({
501
469
  "src/config/index.ts"() {
502
470
  "use strict";
503
- init_environments();
504
471
  init_options();
505
472
  }
506
473
  });
@@ -2861,6 +2828,7 @@ var init_verification_link_service = __esm({
2861
2828
  constructor(baseQrUrl) {
2862
2829
  this.baseQrUrl = baseQrUrl;
2863
2830
  }
2831
+ baseQrUrl;
2864
2832
  /**
2865
2833
  * Build invoice verification URL (Code I).
2866
2834
  * Format: {baseQrUrl}/invoice/{NIP}/{DD-MM-YYYY}/{hash_base64url}
@@ -3171,6 +3139,7 @@ var init_offline_invoice_workflow = __esm({
3171
3139
  constructor(qrService) {
3172
3140
  this.qrService = qrService;
3173
3141
  }
3142
+ qrService;
3174
3143
  async generate(input, options) {
3175
3144
  if (!input.invoiceXml || input.invoiceXml.trim().length === 0) {
3176
3145
  throw new Error("invoiceXml must not be empty");
@@ -4718,11 +4687,6 @@ var init_xml = __esm({
4718
4687
  "src/xml/index.ts"() {
4719
4688
  "use strict";
4720
4689
  init_upo_parser();
4721
- init_invoice_field_extractor();
4722
- init_xml_engine();
4723
- init_order_map();
4724
- init_faktura_builder();
4725
- init_pef_builder();
4726
4690
  init_invoice_serializer();
4727
4691
  }
4728
4692
  });
@@ -6200,11 +6164,6 @@ var SCHEMA_TYPES, NAMESPACE_MAP;
6200
6164
  var init_schemas = __esm({
6201
6165
  "src/validation/schemas/index.ts"() {
6202
6166
  "use strict";
6203
- init_fa3();
6204
- init_fa2();
6205
- init_fa_rr1();
6206
- init_pef3();
6207
- init_pef_kor3();
6208
6167
  SCHEMA_TYPES = ["FA3", "FA2", "FA_RR1", "PEF3", "PEF_KOR3"];
6209
6168
  NAMESPACE_MAP = {
6210
6169
  "http://crd.gov.pl/wzor/2025/06/25/13775/": "FA3",
@@ -7320,7 +7279,6 @@ function clearCredentials() {
7320
7279
 
7321
7280
  // src/workflows/auth-workflow.ts
7322
7281
  init_polling();
7323
- init_auth_xml_builder();
7324
7282
  init_with_key_rotation_retry();
7325
7283
  init_ksef_auth_status_error();
7326
7284
  var AUTH_STATUS_SUCCESS = 200;
@@ -8369,6 +8327,7 @@ var FileHwmStore = class {
8369
8327
  constructor(filePath) {
8370
8328
  this.filePath = filePath;
8371
8329
  }
8330
+ filePath;
8372
8331
  async load() {
8373
8332
  try {
8374
8333
  const data = await fs7.readFile(this.filePath, "utf-8");
@@ -8386,8 +8345,6 @@ var FileHwmStore = class {
8386
8345
  };
8387
8346
 
8388
8347
  // src/workflows/invoice-export-workflow.ts
8389
- init_zip();
8390
- init_targz();
8391
8348
  init_polling();
8392
8349
  init_with_key_rotation_retry();
8393
8350