ksef-client-ts 0.1.1 → 0.3.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 +13 -9
- package/dist/cli.js +40 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +4502 -3714
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +177 -6
- package/dist/index.d.ts +177 -6
- package/dist/index.js +2640 -1868
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,18 +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)**
|
|
5
|
+
**[Documentation](https://flopsstuff.github.io/ksef-client-ts)** · **[NPM](https://www.npmjs.com/package/ksef-client-ts)**
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- **Complete API coverage** —
|
|
9
|
+
- **Complete API coverage** — KSeF API v2.3.0, types aligned with the official OpenAPI spec
|
|
10
10
|
- **Full-featured CLI** — `ksef` with many command groups and subcommands for day-to-day KSeF workflows
|
|
11
11
|
- **Full documentation** — VitePress site: Quick Start, API reference, OpenAPI spec
|
|
12
|
-
- **OpenAPI aligned** — types checked against the official KSeF spec; full spec and domain chunks in `docs/`
|
|
13
12
|
- **Comprehensive test coverage** — Vitest across HTTP, crypto, services, builders; CI on every change
|
|
14
13
|
- **Zero HTTP dependencies** — native `fetch` (Node 18+); dual ESM/CJS via tsup
|
|
15
14
|
- **Built-in cryptography** — AES-256-CBC, RSA-OAEP, ECDH, XAdES-B, self-signed certs (Node crypto)
|
|
16
15
|
- **Automatic token management** — AuthManager: token injection, 401 refresh with dedup, `loginWithToken` / `loginWithCertificate`
|
|
16
|
+
- **High-level workflows** — orchestration functions for auth, online/batch sessions, invoice export with polling and decryption
|
|
17
17
|
- **Typed errors & fluent builders** — `KSeFError` hierarchy (401, 403, 429, validation) and request builders
|
|
18
18
|
|
|
19
19
|
Requires **Node.js 18+**.
|
|
@@ -82,12 +82,16 @@ yarn test # Run all tests (vitest)
|
|
|
82
82
|
- [ksef-client-csharp](https://github.com/CIRFMF/ksef-client-csharp) — official C# reference client
|
|
83
83
|
- [ksef-client-java](https://github.com/CIRFMF/ksef-client-java) — official Java reference client
|
|
84
84
|
|
|
85
|
-
## Status
|
|
86
|
-
|
|
87
|
-
[](https://github.com/Flopsstuff/ksef-client-ts/actions/workflows/test.yml)
|
|
88
|
-
|
|
89
|
-

|
|
90
|
-
|
|
91
85
|
## License
|
|
92
86
|
|
|
93
87
|
[MIT](LICENSE)
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
[](https://github.com/Flopsstuff/ksef-client-ts/actions/workflows/ci.yml)
|
|
92
|
+

|
|
93
|
+

|
|
94
|
+

|
|
95
|
+

|
|
96
|
+

|
|
97
|
+

|
package/dist/cli.js
CHANGED
|
@@ -5179,7 +5179,8 @@ function resolveOptions(options = {}) {
|
|
|
5179
5179
|
lighthouseUrl: options.lighthouseUrl ?? env.lighthouseUrl,
|
|
5180
5180
|
apiVersion: options.apiVersion ?? DEFAULT_API_VERSION,
|
|
5181
5181
|
timeout: options.timeout ?? DEFAULT_TIMEOUT,
|
|
5182
|
-
customHeaders: options.customHeaders ?? {}
|
|
5182
|
+
customHeaders: options.customHeaders ?? {},
|
|
5183
|
+
environmentName: options.environment ?? (options.baseUrl ? void 0 : "TEST")
|
|
5183
5184
|
};
|
|
5184
5185
|
}
|
|
5185
5186
|
|
|
@@ -5590,6 +5591,10 @@ var DefaultAuthManager = class {
|
|
|
5590
5591
|
}
|
|
5591
5592
|
};
|
|
5592
5593
|
|
|
5594
|
+
// src/http/ksef-feature.ts
|
|
5595
|
+
var KSEF_FEATURE_HEADER = "X-KSeF-Feature";
|
|
5596
|
+
var ENFORCE_XADES_COMPLIANCE = "enforce-xades-compliance";
|
|
5597
|
+
|
|
5593
5598
|
// src/http/rest-request.ts
|
|
5594
5599
|
var RestRequest = class _RestRequest {
|
|
5595
5600
|
method;
|
|
@@ -5794,8 +5799,11 @@ var AuthService = class {
|
|
|
5794
5799
|
const response = await this.restClient.execute(request);
|
|
5795
5800
|
return response.body;
|
|
5796
5801
|
}
|
|
5797
|
-
async submitXadesAuthRequest(signedXml, verifyCertificateChain = false) {
|
|
5802
|
+
async submitXadesAuthRequest(signedXml, verifyCertificateChain = false, enforceXadesCompliance = false) {
|
|
5798
5803
|
const request = RestRequest.post(Routes.Authorization.xadesSignature).body(signedXml).header("Content-Type", "application/xml").query("verifyCertificateChain", String(verifyCertificateChain));
|
|
5804
|
+
if (enforceXadesCompliance) {
|
|
5805
|
+
request.header(KSEF_FEATURE_HEADER, ENFORCE_XADES_COMPLIANCE);
|
|
5806
|
+
}
|
|
5799
5807
|
const response = await this.restClient.execute(request);
|
|
5800
5808
|
return response.body;
|
|
5801
5809
|
}
|
|
@@ -5853,7 +5861,7 @@ var OnlineSessionService = class {
|
|
|
5853
5861
|
async openSession(request, upoVersion) {
|
|
5854
5862
|
const req = RestRequest.post(Routes.Sessions.Online.open).body(request);
|
|
5855
5863
|
if (upoVersion) {
|
|
5856
|
-
req.header(
|
|
5864
|
+
req.header(KSEF_FEATURE_HEADER, upoVersion);
|
|
5857
5865
|
}
|
|
5858
5866
|
const response = await this.restClient.execute(req);
|
|
5859
5867
|
return response.body;
|
|
@@ -5878,7 +5886,7 @@ var BatchSessionService = class {
|
|
|
5878
5886
|
async openSession(request, upoVersion) {
|
|
5879
5887
|
const req = RestRequest.post(Routes.Sessions.Batch.open).body(request);
|
|
5880
5888
|
if (upoVersion) {
|
|
5881
|
-
req.header(
|
|
5889
|
+
req.header(KSEF_FEATURE_HEADER, upoVersion);
|
|
5882
5890
|
}
|
|
5883
5891
|
const response = await this.restClient.execute(req);
|
|
5884
5892
|
return response.body;
|
|
@@ -6303,82 +6311,108 @@ var PeppolService = class {
|
|
|
6303
6311
|
// src/services/test-data.ts
|
|
6304
6312
|
var TestDataService = class {
|
|
6305
6313
|
restClient;
|
|
6306
|
-
|
|
6314
|
+
environmentName;
|
|
6315
|
+
constructor(restClient, environmentName) {
|
|
6307
6316
|
this.restClient = restClient;
|
|
6317
|
+
this.environmentName = environmentName;
|
|
6318
|
+
}
|
|
6319
|
+
ensureTestEnvironment() {
|
|
6320
|
+
if (this.environmentName && this.environmentName !== "TEST") {
|
|
6321
|
+
throw new KSeFError(
|
|
6322
|
+
`Test data APIs are only available on the TEST environment (current: ${this.environmentName})`
|
|
6323
|
+
);
|
|
6324
|
+
}
|
|
6308
6325
|
}
|
|
6309
6326
|
// Subject management
|
|
6310
6327
|
async createSubject(request) {
|
|
6328
|
+
this.ensureTestEnvironment();
|
|
6311
6329
|
const req = RestRequest.post(Routes.TestData.createSubject).body(request);
|
|
6312
6330
|
await this.restClient.executeVoid(req);
|
|
6313
6331
|
}
|
|
6314
6332
|
async removeSubject(request) {
|
|
6333
|
+
this.ensureTestEnvironment();
|
|
6315
6334
|
const req = RestRequest.post(Routes.TestData.removeSubject).body(request);
|
|
6316
6335
|
await this.restClient.executeVoid(req);
|
|
6317
6336
|
}
|
|
6318
6337
|
// Person management
|
|
6319
6338
|
async createPerson(request) {
|
|
6339
|
+
this.ensureTestEnvironment();
|
|
6320
6340
|
const req = RestRequest.post(Routes.TestData.createPerson).body(request);
|
|
6321
6341
|
await this.restClient.executeVoid(req);
|
|
6322
6342
|
}
|
|
6323
6343
|
async removePerson(request) {
|
|
6344
|
+
this.ensureTestEnvironment();
|
|
6324
6345
|
const req = RestRequest.post(Routes.TestData.removePerson).body(request);
|
|
6325
6346
|
await this.restClient.executeVoid(req);
|
|
6326
6347
|
}
|
|
6327
6348
|
// Permissions
|
|
6328
6349
|
async grantPermissions(request) {
|
|
6350
|
+
this.ensureTestEnvironment();
|
|
6329
6351
|
const req = RestRequest.post(Routes.TestData.grantPerms).body(request);
|
|
6330
6352
|
await this.restClient.executeVoid(req);
|
|
6331
6353
|
}
|
|
6332
6354
|
async revokePermissions(request) {
|
|
6355
|
+
this.ensureTestEnvironment();
|
|
6333
6356
|
const req = RestRequest.post(Routes.TestData.revokePerms).body(request);
|
|
6334
6357
|
await this.restClient.executeVoid(req);
|
|
6335
6358
|
}
|
|
6336
6359
|
// Attachment permissions
|
|
6337
6360
|
async enableAttachment(request) {
|
|
6361
|
+
this.ensureTestEnvironment();
|
|
6338
6362
|
const req = RestRequest.post(Routes.TestData.enableAttach).body(request);
|
|
6339
6363
|
await this.restClient.executeVoid(req);
|
|
6340
6364
|
}
|
|
6341
6365
|
async disableAttachment(request) {
|
|
6366
|
+
this.ensureTestEnvironment();
|
|
6342
6367
|
const req = RestRequest.post(Routes.TestData.disableAttach).body(request);
|
|
6343
6368
|
await this.restClient.executeVoid(req);
|
|
6344
6369
|
}
|
|
6345
6370
|
// Session limits
|
|
6346
6371
|
async changeSessionLimits(request) {
|
|
6372
|
+
this.ensureTestEnvironment();
|
|
6347
6373
|
const req = RestRequest.post(Routes.TestData.changeSessionLimitsInCurrentContext).body(request);
|
|
6348
6374
|
await this.restClient.executeVoid(req);
|
|
6349
6375
|
}
|
|
6350
6376
|
async restoreDefaultSessionLimits() {
|
|
6377
|
+
this.ensureTestEnvironment();
|
|
6351
6378
|
const req = RestRequest.delete(Routes.TestData.restoreDefaultSessionLimitsInCurrentContext);
|
|
6352
6379
|
await this.restClient.executeVoid(req);
|
|
6353
6380
|
}
|
|
6354
6381
|
// Certificate limits
|
|
6355
6382
|
async changeCertificatesLimit(request) {
|
|
6383
|
+
this.ensureTestEnvironment();
|
|
6356
6384
|
const req = RestRequest.post(Routes.TestData.changeCertificatesLimitInCurrentSubject).body(request);
|
|
6357
6385
|
await this.restClient.executeVoid(req);
|
|
6358
6386
|
}
|
|
6359
6387
|
async restoreDefaultCertificatesLimit() {
|
|
6388
|
+
this.ensureTestEnvironment();
|
|
6360
6389
|
const req = RestRequest.delete(Routes.TestData.restoreDefaultCertificatesLimitInCurrentSubject);
|
|
6361
6390
|
await this.restClient.executeVoid(req);
|
|
6362
6391
|
}
|
|
6363
6392
|
// Rate limits
|
|
6364
6393
|
async setRateLimits(request) {
|
|
6394
|
+
this.ensureTestEnvironment();
|
|
6365
6395
|
const req = RestRequest.post(Routes.TestData.rateLimits).body(request);
|
|
6366
6396
|
await this.restClient.executeVoid(req);
|
|
6367
6397
|
}
|
|
6368
6398
|
async restoreDefaultRateLimits() {
|
|
6399
|
+
this.ensureTestEnvironment();
|
|
6369
6400
|
const req = RestRequest.delete(Routes.TestData.rateLimits);
|
|
6370
6401
|
await this.restClient.executeVoid(req);
|
|
6371
6402
|
}
|
|
6372
6403
|
async setProductionRateLimits() {
|
|
6404
|
+
this.ensureTestEnvironment();
|
|
6373
6405
|
const req = RestRequest.post(Routes.TestData.productionRateLimits);
|
|
6374
6406
|
await this.restClient.executeVoid(req);
|
|
6375
6407
|
}
|
|
6376
6408
|
// Context blocking
|
|
6377
6409
|
async blockContext(request) {
|
|
6410
|
+
this.ensureTestEnvironment();
|
|
6378
6411
|
const req = RestRequest.post(Routes.TestData.blockContext).body(request);
|
|
6379
6412
|
await this.restClient.executeVoid(req);
|
|
6380
6413
|
}
|
|
6381
6414
|
async unblockContext(request) {
|
|
6415
|
+
this.ensureTestEnvironment();
|
|
6382
6416
|
const req = RestRequest.post(Routes.TestData.unblockContext).body(request);
|
|
6383
6417
|
await this.restClient.executeVoid(req);
|
|
6384
6418
|
}
|
|
@@ -6755,7 +6789,7 @@ var KSeFClient = class {
|
|
|
6755
6789
|
this.lighthouse = new LighthouseService(this.options);
|
|
6756
6790
|
this.limits = new LimitsService(restClient);
|
|
6757
6791
|
this.peppol = new PeppolService(restClient);
|
|
6758
|
-
this.testData = new TestDataService(restClient);
|
|
6792
|
+
this.testData = new TestDataService(restClient, this.options.environmentName);
|
|
6759
6793
|
this.qr = new VerificationLinkService(this.options.baseQrUrl);
|
|
6760
6794
|
}
|
|
6761
6795
|
async loginWithToken(token, nip) {
|