ksef-client-ts 0.1.0 → 0.2.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 +26 -3
- package/dist/cli.js +155 -86
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +4340 -3588
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +176 -43
- package/dist/index.d.ts +176 -43
- package/dist/index.js +4328 -3589
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -6,17 +6,40 @@ TypeScript client for the Polish National e-Invoice System (KSeF) API v2.
|
|
|
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
|
-
Requires **Node.js 18+**.
|
|
19
|
+
Requires **Node.js 18+**.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
Install CLI globally:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm i -g ksef-client-ts
|
|
27
|
+
ksef --help
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Install in a project:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Choose one package manager:
|
|
34
|
+
# npm
|
|
35
|
+
npm i ksef-client-ts
|
|
36
|
+
# Yarn
|
|
37
|
+
yarn add ksef-client-ts
|
|
38
|
+
# pnpm
|
|
39
|
+
pnpm add ksef-client-ts
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For local development, clone and build:
|
|
20
43
|
|
|
21
44
|
```bash
|
|
22
45
|
git clone https://github.com/Flopsstuff/ksef-client-ts.git
|
package/dist/cli.js
CHANGED
|
@@ -4789,6 +4789,62 @@ var init_signature_service = __esm({
|
|
|
4789
4789
|
}
|
|
4790
4790
|
});
|
|
4791
4791
|
|
|
4792
|
+
// src/crypto/pkcs12-loader.ts
|
|
4793
|
+
var pkcs12_loader_exports = {};
|
|
4794
|
+
__export(pkcs12_loader_exports, {
|
|
4795
|
+
Pkcs12Loader: () => Pkcs12Loader
|
|
4796
|
+
});
|
|
4797
|
+
import forge from "node-forge";
|
|
4798
|
+
var Pkcs12Loader;
|
|
4799
|
+
var init_pkcs12_loader = __esm({
|
|
4800
|
+
"src/crypto/pkcs12-loader.ts"() {
|
|
4801
|
+
"use strict";
|
|
4802
|
+
Pkcs12Loader = class {
|
|
4803
|
+
static load(p12, password) {
|
|
4804
|
+
const { pki, pkcs12, asn1 } = forge;
|
|
4805
|
+
const p12Der = Buffer.from(p12).toString("binary");
|
|
4806
|
+
const p12Asn1 = asn1.fromDer(p12Der);
|
|
4807
|
+
const p12Parsed = pkcs12.pkcs12FromAsn1(p12Asn1, password);
|
|
4808
|
+
const certBagType = pki.oids.certBag;
|
|
4809
|
+
const certBags = p12Parsed.getBags({ bagType: certBagType });
|
|
4810
|
+
const certs = certBags[certBagType];
|
|
4811
|
+
if (!certs || certs.length === 0) {
|
|
4812
|
+
throw new Error("PKCS#12 file does not contain a certificate.");
|
|
4813
|
+
}
|
|
4814
|
+
const shroudedType = pki.oids.pkcs8ShroudedKeyBag;
|
|
4815
|
+
let keyBags = p12Parsed.getBags({ bagType: shroudedType });
|
|
4816
|
+
let keys = keyBags[shroudedType];
|
|
4817
|
+
if (!keys || keys.length === 0) {
|
|
4818
|
+
const plainType = pki.oids.keyBag;
|
|
4819
|
+
keyBags = p12Parsed.getBags({ bagType: plainType });
|
|
4820
|
+
keys = keyBags[plainType];
|
|
4821
|
+
}
|
|
4822
|
+
if (!keys || keys.length === 0) {
|
|
4823
|
+
throw new Error("PKCS#12 file does not contain a private key.");
|
|
4824
|
+
}
|
|
4825
|
+
const cert = certs[0].cert;
|
|
4826
|
+
const key = keys[0].key;
|
|
4827
|
+
if (!cert) {
|
|
4828
|
+
throw new Error("PKCS#12 certificate bag is empty.");
|
|
4829
|
+
}
|
|
4830
|
+
if (!key) {
|
|
4831
|
+
throw new Error("PKCS#12 key bag is empty.");
|
|
4832
|
+
}
|
|
4833
|
+
const certificatePem = pki.certificateToPem(cert);
|
|
4834
|
+
let privateKeyPem;
|
|
4835
|
+
try {
|
|
4836
|
+
privateKeyPem = pki.privateKeyToPem(key);
|
|
4837
|
+
} catch {
|
|
4838
|
+
throw new Error(
|
|
4839
|
+
"Failed to export private key from PKCS#12 to PEM. This can happen with EC keys. Use separate --cert and --key PEM files instead."
|
|
4840
|
+
);
|
|
4841
|
+
}
|
|
4842
|
+
return { certificatePem, privateKeyPem };
|
|
4843
|
+
}
|
|
4844
|
+
};
|
|
4845
|
+
}
|
|
4846
|
+
});
|
|
4847
|
+
|
|
4792
4848
|
// src/cli/index.ts
|
|
4793
4849
|
import { defineCommand as defineCommand15, runMain } from "citty";
|
|
4794
4850
|
|
|
@@ -4804,7 +4860,7 @@ import * as os from "os";
|
|
|
4804
4860
|
var ENV_MAP = {
|
|
4805
4861
|
test: "TEST",
|
|
4806
4862
|
demo: "DEMO",
|
|
4807
|
-
prod: "
|
|
4863
|
+
prod: "PROD"
|
|
4808
4864
|
};
|
|
4809
4865
|
function toEnvironmentName(env) {
|
|
4810
4866
|
return ENV_MAP[env];
|
|
@@ -5105,7 +5161,7 @@ var Environment = {
|
|
|
5105
5161
|
qrUrl: "https://qr-demo.ksef.mf.gov.pl",
|
|
5106
5162
|
lighthouseUrl: ""
|
|
5107
5163
|
},
|
|
5108
|
-
|
|
5164
|
+
PROD: {
|
|
5109
5165
|
apiUrl: "https://api.ksef.mf.gov.pl",
|
|
5110
5166
|
qrUrl: "https://qr.ksef.mf.gov.pl",
|
|
5111
5167
|
lighthouseUrl: "https://api-latarnia.ksef.mf.gov.pl"
|
|
@@ -5313,6 +5369,10 @@ var RestClient = class {
|
|
|
5313
5369
|
const body = await response.json();
|
|
5314
5370
|
return { body, headers: response.headers, statusCode: response.status };
|
|
5315
5371
|
}
|
|
5372
|
+
async executeVoid(request) {
|
|
5373
|
+
const response = await this.sendRequest(request);
|
|
5374
|
+
await this.ensureSuccess(response);
|
|
5375
|
+
}
|
|
5316
5376
|
async executeRaw(request) {
|
|
5317
5377
|
const response = await this.sendRequest(request);
|
|
5318
5378
|
await this.ensureSuccess(response);
|
|
@@ -5530,6 +5590,10 @@ var DefaultAuthManager = class {
|
|
|
5530
5590
|
}
|
|
5531
5591
|
};
|
|
5532
5592
|
|
|
5593
|
+
// src/http/ksef-feature.ts
|
|
5594
|
+
var KSEF_FEATURE_HEADER = "X-KSeF-Feature";
|
|
5595
|
+
var ENFORCE_XADES_COMPLIANCE = "enforce-xades-compliance";
|
|
5596
|
+
|
|
5533
5597
|
// src/http/rest-request.ts
|
|
5534
5598
|
var RestRequest = class _RestRequest {
|
|
5535
5599
|
method;
|
|
@@ -5734,8 +5798,11 @@ var AuthService = class {
|
|
|
5734
5798
|
const response = await this.restClient.execute(request);
|
|
5735
5799
|
return response.body;
|
|
5736
5800
|
}
|
|
5737
|
-
async submitXadesAuthRequest(signedXml, verifyCertificateChain = false) {
|
|
5801
|
+
async submitXadesAuthRequest(signedXml, verifyCertificateChain = false, enforceXadesCompliance = false) {
|
|
5738
5802
|
const request = RestRequest.post(Routes.Authorization.xadesSignature).body(signedXml).header("Content-Type", "application/xml").query("verifyCertificateChain", String(verifyCertificateChain));
|
|
5803
|
+
if (enforceXadesCompliance) {
|
|
5804
|
+
request.header(KSEF_FEATURE_HEADER, ENFORCE_XADES_COMPLIANCE);
|
|
5805
|
+
}
|
|
5739
5806
|
const response = await this.restClient.execute(request);
|
|
5740
5807
|
return response.body;
|
|
5741
5808
|
}
|
|
@@ -5776,11 +5843,11 @@ var ActiveSessionsService = class {
|
|
|
5776
5843
|
}
|
|
5777
5844
|
async revokeCurrentSession() {
|
|
5778
5845
|
const request = RestRequest.delete(Routes.ActiveSessions.currentSession);
|
|
5779
|
-
await this.restClient.
|
|
5846
|
+
await this.restClient.executeVoid(request);
|
|
5780
5847
|
}
|
|
5781
5848
|
async revokeSession(sessionRef) {
|
|
5782
5849
|
const request = RestRequest.delete(Routes.ActiveSessions.delete(sessionRef));
|
|
5783
|
-
await this.restClient.
|
|
5850
|
+
await this.restClient.executeVoid(request);
|
|
5784
5851
|
}
|
|
5785
5852
|
};
|
|
5786
5853
|
|
|
@@ -5793,7 +5860,7 @@ var OnlineSessionService = class {
|
|
|
5793
5860
|
async openSession(request, upoVersion) {
|
|
5794
5861
|
const req = RestRequest.post(Routes.Sessions.Online.open).body(request);
|
|
5795
5862
|
if (upoVersion) {
|
|
5796
|
-
req.header(
|
|
5863
|
+
req.header(KSEF_FEATURE_HEADER, upoVersion);
|
|
5797
5864
|
}
|
|
5798
5865
|
const response = await this.restClient.execute(req);
|
|
5799
5866
|
return response.body;
|
|
@@ -5805,7 +5872,7 @@ var OnlineSessionService = class {
|
|
|
5805
5872
|
}
|
|
5806
5873
|
async closeSession(sessionRef) {
|
|
5807
5874
|
const req = RestRequest.post(Routes.Sessions.Online.close(sessionRef));
|
|
5808
|
-
await this.restClient.
|
|
5875
|
+
await this.restClient.executeVoid(req);
|
|
5809
5876
|
}
|
|
5810
5877
|
};
|
|
5811
5878
|
|
|
@@ -5818,7 +5885,7 @@ var BatchSessionService = class {
|
|
|
5818
5885
|
async openSession(request, upoVersion) {
|
|
5819
5886
|
const req = RestRequest.post(Routes.Sessions.Batch.open).body(request);
|
|
5820
5887
|
if (upoVersion) {
|
|
5821
|
-
req.header(
|
|
5888
|
+
req.header(KSEF_FEATURE_HEADER, upoVersion);
|
|
5822
5889
|
}
|
|
5823
5890
|
const response = await this.restClient.execute(req);
|
|
5824
5891
|
return response.body;
|
|
@@ -5846,7 +5913,7 @@ var BatchSessionService = class {
|
|
|
5846
5913
|
}
|
|
5847
5914
|
async closeSession(batchRef) {
|
|
5848
5915
|
const req = RestRequest.post(Routes.Sessions.Batch.close(batchRef));
|
|
5849
|
-
await this.restClient.
|
|
5916
|
+
await this.restClient.executeVoid(req);
|
|
5850
5917
|
}
|
|
5851
5918
|
};
|
|
5852
5919
|
|
|
@@ -6119,7 +6186,7 @@ var TokenService = class {
|
|
|
6119
6186
|
}
|
|
6120
6187
|
async revokeToken(ref) {
|
|
6121
6188
|
const req = RestRequest.delete(Routes.Tokens.byReference(ref));
|
|
6122
|
-
await this.restClient.
|
|
6189
|
+
await this.restClient.executeVoid(req);
|
|
6123
6190
|
}
|
|
6124
6191
|
};
|
|
6125
6192
|
|
|
@@ -6156,7 +6223,7 @@ var CertificateApiService = class {
|
|
|
6156
6223
|
}
|
|
6157
6224
|
async revoke(serialNumber, request) {
|
|
6158
6225
|
const req = RestRequest.post(Routes.Certificates.revoke(serialNumber)).body(request);
|
|
6159
|
-
await this.restClient.
|
|
6226
|
+
await this.restClient.executeVoid(req);
|
|
6160
6227
|
}
|
|
6161
6228
|
async query(request, pageSize, pageOffset) {
|
|
6162
6229
|
const req = RestRequest.post(Routes.Certificates.query).body(request);
|
|
@@ -6249,95 +6316,78 @@ var TestDataService = class {
|
|
|
6249
6316
|
// Subject management
|
|
6250
6317
|
async createSubject(request) {
|
|
6251
6318
|
const req = RestRequest.post(Routes.TestData.createSubject).body(request);
|
|
6252
|
-
|
|
6253
|
-
return response.body;
|
|
6319
|
+
await this.restClient.executeVoid(req);
|
|
6254
6320
|
}
|
|
6255
6321
|
async removeSubject(request) {
|
|
6256
6322
|
const req = RestRequest.post(Routes.TestData.removeSubject).body(request);
|
|
6257
|
-
|
|
6258
|
-
return response.body;
|
|
6323
|
+
await this.restClient.executeVoid(req);
|
|
6259
6324
|
}
|
|
6260
6325
|
// Person management
|
|
6261
6326
|
async createPerson(request) {
|
|
6262
6327
|
const req = RestRequest.post(Routes.TestData.createPerson).body(request);
|
|
6263
|
-
|
|
6264
|
-
return response.body;
|
|
6328
|
+
await this.restClient.executeVoid(req);
|
|
6265
6329
|
}
|
|
6266
6330
|
async removePerson(request) {
|
|
6267
6331
|
const req = RestRequest.post(Routes.TestData.removePerson).body(request);
|
|
6268
|
-
|
|
6269
|
-
return response.body;
|
|
6332
|
+
await this.restClient.executeVoid(req);
|
|
6270
6333
|
}
|
|
6271
6334
|
// Permissions
|
|
6272
6335
|
async grantPermissions(request) {
|
|
6273
6336
|
const req = RestRequest.post(Routes.TestData.grantPerms).body(request);
|
|
6274
|
-
|
|
6275
|
-
return response.body;
|
|
6337
|
+
await this.restClient.executeVoid(req);
|
|
6276
6338
|
}
|
|
6277
6339
|
async revokePermissions(request) {
|
|
6278
6340
|
const req = RestRequest.post(Routes.TestData.revokePerms).body(request);
|
|
6279
|
-
|
|
6280
|
-
return response.body;
|
|
6341
|
+
await this.restClient.executeVoid(req);
|
|
6281
6342
|
}
|
|
6282
6343
|
// Attachment permissions
|
|
6283
6344
|
async enableAttachment(request) {
|
|
6284
6345
|
const req = RestRequest.post(Routes.TestData.enableAttach).body(request);
|
|
6285
|
-
|
|
6286
|
-
return response.body;
|
|
6346
|
+
await this.restClient.executeVoid(req);
|
|
6287
6347
|
}
|
|
6288
6348
|
async disableAttachment(request) {
|
|
6289
6349
|
const req = RestRequest.post(Routes.TestData.disableAttach).body(request);
|
|
6290
|
-
|
|
6291
|
-
return response.body;
|
|
6350
|
+
await this.restClient.executeVoid(req);
|
|
6292
6351
|
}
|
|
6293
6352
|
// Session limits
|
|
6294
6353
|
async changeSessionLimits(request) {
|
|
6295
6354
|
const req = RestRequest.post(Routes.TestData.changeSessionLimitsInCurrentContext).body(request);
|
|
6296
|
-
|
|
6297
|
-
return response.body;
|
|
6355
|
+
await this.restClient.executeVoid(req);
|
|
6298
6356
|
}
|
|
6299
6357
|
async restoreDefaultSessionLimits() {
|
|
6300
6358
|
const req = RestRequest.delete(Routes.TestData.restoreDefaultSessionLimitsInCurrentContext);
|
|
6301
|
-
|
|
6302
|
-
return response.body;
|
|
6359
|
+
await this.restClient.executeVoid(req);
|
|
6303
6360
|
}
|
|
6304
6361
|
// Certificate limits
|
|
6305
6362
|
async changeCertificatesLimit(request) {
|
|
6306
6363
|
const req = RestRequest.post(Routes.TestData.changeCertificatesLimitInCurrentSubject).body(request);
|
|
6307
|
-
|
|
6308
|
-
return response.body;
|
|
6364
|
+
await this.restClient.executeVoid(req);
|
|
6309
6365
|
}
|
|
6310
6366
|
async restoreDefaultCertificatesLimit() {
|
|
6311
6367
|
const req = RestRequest.delete(Routes.TestData.restoreDefaultCertificatesLimitInCurrentSubject);
|
|
6312
|
-
|
|
6313
|
-
return response.body;
|
|
6368
|
+
await this.restClient.executeVoid(req);
|
|
6314
6369
|
}
|
|
6315
6370
|
// Rate limits
|
|
6316
6371
|
async setRateLimits(request) {
|
|
6317
6372
|
const req = RestRequest.post(Routes.TestData.rateLimits).body(request);
|
|
6318
|
-
|
|
6319
|
-
return response.body;
|
|
6373
|
+
await this.restClient.executeVoid(req);
|
|
6320
6374
|
}
|
|
6321
6375
|
async restoreDefaultRateLimits() {
|
|
6322
6376
|
const req = RestRequest.delete(Routes.TestData.rateLimits);
|
|
6323
|
-
|
|
6324
|
-
return response.body;
|
|
6377
|
+
await this.restClient.executeVoid(req);
|
|
6325
6378
|
}
|
|
6326
6379
|
async setProductionRateLimits() {
|
|
6327
6380
|
const req = RestRequest.post(Routes.TestData.productionRateLimits);
|
|
6328
|
-
|
|
6329
|
-
return response.body;
|
|
6381
|
+
await this.restClient.executeVoid(req);
|
|
6330
6382
|
}
|
|
6331
6383
|
// Context blocking
|
|
6332
6384
|
async blockContext(request) {
|
|
6333
6385
|
const req = RestRequest.post(Routes.TestData.blockContext).body(request);
|
|
6334
|
-
|
|
6335
|
-
return response.body;
|
|
6386
|
+
await this.restClient.executeVoid(req);
|
|
6336
6387
|
}
|
|
6337
6388
|
async unblockContext(request) {
|
|
6338
6389
|
const req = RestRequest.post(Routes.TestData.unblockContext).body(request);
|
|
6339
|
-
|
|
6340
|
-
return response.body;
|
|
6390
|
+
await this.restClient.executeVoid(req);
|
|
6341
6391
|
}
|
|
6342
6392
|
};
|
|
6343
6393
|
|
|
@@ -6725,6 +6775,7 @@ var KSeFClient = class {
|
|
|
6725
6775
|
encryptedToken: Buffer.from(encryptedToken).toString("base64")
|
|
6726
6776
|
});
|
|
6727
6777
|
const authToken = submitResult.authenticationToken.token;
|
|
6778
|
+
await this.awaitAuthReady(submitResult.referenceNumber, authToken);
|
|
6728
6779
|
const tokens = await this.auth.getAccessToken(authToken);
|
|
6729
6780
|
this.authManager.setAccessToken(tokens.accessToken.token);
|
|
6730
6781
|
this.authManager.setRefreshToken(tokens.refreshToken.token);
|
|
@@ -6736,10 +6787,26 @@ var KSeFClient = class {
|
|
|
6736
6787
|
const signedXml = SignatureService2.sign(authRequestXml, certPem, keyPem);
|
|
6737
6788
|
const submitResult = await this.auth.submitXadesAuthRequest(signedXml);
|
|
6738
6789
|
const authToken = submitResult.authenticationToken.token;
|
|
6790
|
+
await this.awaitAuthReady(submitResult.referenceNumber, authToken);
|
|
6739
6791
|
const tokens = await this.auth.getAccessToken(authToken);
|
|
6740
6792
|
this.authManager.setAccessToken(tokens.accessToken.token);
|
|
6741
6793
|
this.authManager.setRefreshToken(tokens.refreshToken.token);
|
|
6742
6794
|
}
|
|
6795
|
+
async loginWithPkcs12(p12, password, nip) {
|
|
6796
|
+
const { Pkcs12Loader: Pkcs12Loader2 } = await Promise.resolve().then(() => (init_pkcs12_loader(), pkcs12_loader_exports));
|
|
6797
|
+
const { certificatePem, privateKeyPem } = Pkcs12Loader2.load(p12, password);
|
|
6798
|
+
await this.loginWithCertificate(certificatePem, privateKeyPem, nip);
|
|
6799
|
+
}
|
|
6800
|
+
async awaitAuthReady(referenceNumber, authToken) {
|
|
6801
|
+
for (let i = 0; i < 30; i++) {
|
|
6802
|
+
const status6 = await this.auth.getAuthStatus(referenceNumber, authToken);
|
|
6803
|
+
if (status6.status.code === 200) return;
|
|
6804
|
+
if (status6.status.code !== 100) {
|
|
6805
|
+
throw new Error(`Authentication failed with status ${status6.status.code}: ${status6.status.description}`);
|
|
6806
|
+
}
|
|
6807
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
6808
|
+
}
|
|
6809
|
+
}
|
|
6743
6810
|
async logout() {
|
|
6744
6811
|
this.authManager.setAccessToken(void 0);
|
|
6745
6812
|
this.authManager.setRefreshToken(void 0);
|
|
@@ -6901,6 +6968,8 @@ var login = defineCommand2({
|
|
|
6901
6968
|
token: { type: "string", description: "KSeF authorization token" },
|
|
6902
6969
|
cert: { type: "string", description: "Path to PEM certificate file (XAdES auth)" },
|
|
6903
6970
|
key: { type: "string", description: "Path to PEM private key file (XAdES auth)" },
|
|
6971
|
+
p12: { type: "string", description: "Path to PKCS#12 (.p12/.pfx) certificate file" },
|
|
6972
|
+
"p12-password": { type: "string", description: "Password for the PKCS#12 file (default: empty)" },
|
|
6904
6973
|
env: { type: "string", description: "Environment (test/demo/prod)" },
|
|
6905
6974
|
json: { type: "boolean", description: "Output as JSON" },
|
|
6906
6975
|
verbose: { type: "boolean", description: "Show HTTP request/response details" },
|
|
@@ -6918,13 +6987,17 @@ var login = defineCommand2({
|
|
|
6918
6987
|
}
|
|
6919
6988
|
if (args.token) {
|
|
6920
6989
|
await client.loginWithToken(args.token, nip);
|
|
6990
|
+
} else if (args.p12) {
|
|
6991
|
+
const fs7 = await import("fs");
|
|
6992
|
+
const p12Buffer = fs7.readFileSync(args.p12);
|
|
6993
|
+
await client.loginWithPkcs12(p12Buffer, args["p12-password"] ?? "", nip);
|
|
6921
6994
|
} else if (args.cert && args.key) {
|
|
6922
6995
|
const fs7 = await import("fs");
|
|
6923
6996
|
const certPem = fs7.readFileSync(args.cert, "utf-8");
|
|
6924
6997
|
const keyPem = fs7.readFileSync(args.key, "utf-8");
|
|
6925
6998
|
await client.loginWithCertificate(certPem, keyPem, nip);
|
|
6926
6999
|
} else {
|
|
6927
|
-
throw new Error("Provide --token or both --cert and --key for authentication.");
|
|
7000
|
+
throw new Error("Provide --token, --p12, or both --cert and --key for authentication.");
|
|
6928
7001
|
}
|
|
6929
7002
|
const session = {
|
|
6930
7003
|
accessToken: client.authManager.getAccessToken(),
|
|
@@ -9221,15 +9294,11 @@ function requireNonProd(globalOpts) {
|
|
|
9221
9294
|
throw new Error("Test data commands are only available in test/demo environments.");
|
|
9222
9295
|
}
|
|
9223
9296
|
}
|
|
9224
|
-
function
|
|
9297
|
+
function outputDone(json) {
|
|
9225
9298
|
if (json) {
|
|
9226
|
-
outputResult(
|
|
9299
|
+
outputResult({ status: "ok" }, { json: true });
|
|
9227
9300
|
} else {
|
|
9228
9301
|
outputSuccess("Done.");
|
|
9229
|
-
outputKeyValue({
|
|
9230
|
-
"Code": result.code,
|
|
9231
|
-
"Description": result.description
|
|
9232
|
-
}, { json: false });
|
|
9233
9302
|
}
|
|
9234
9303
|
}
|
|
9235
9304
|
var createSubject = defineCommand10({
|
|
@@ -9254,8 +9323,8 @@ var createSubject = defineCommand10({
|
|
|
9254
9323
|
description: args.description,
|
|
9255
9324
|
createdDate: args["created-date"]
|
|
9256
9325
|
};
|
|
9257
|
-
|
|
9258
|
-
|
|
9326
|
+
await createClient(globalOpts).testData.createSubject(request);
|
|
9327
|
+
outputDone(args.json);
|
|
9259
9328
|
});
|
|
9260
9329
|
}
|
|
9261
9330
|
});
|
|
@@ -9273,8 +9342,8 @@ var removeSubject = defineCommand10({
|
|
|
9273
9342
|
const globalOpts = getGlobalOpts9(args);
|
|
9274
9343
|
requireNonProd(globalOpts);
|
|
9275
9344
|
const request = { subjectNip: args.nip };
|
|
9276
|
-
|
|
9277
|
-
|
|
9345
|
+
await createClient(globalOpts).testData.removeSubject(request);
|
|
9346
|
+
outputDone(args.json);
|
|
9278
9347
|
});
|
|
9279
9348
|
}
|
|
9280
9349
|
});
|
|
@@ -9304,8 +9373,8 @@ var createPerson = defineCommand10({
|
|
|
9304
9373
|
isDeceased: args.deceased,
|
|
9305
9374
|
createdDate: args["created-date"]
|
|
9306
9375
|
};
|
|
9307
|
-
|
|
9308
|
-
|
|
9376
|
+
await createClient(globalOpts).testData.createPerson(request);
|
|
9377
|
+
outputDone(args.json);
|
|
9309
9378
|
});
|
|
9310
9379
|
}
|
|
9311
9380
|
});
|
|
@@ -9323,8 +9392,8 @@ var removePerson = defineCommand10({
|
|
|
9323
9392
|
const globalOpts = getGlobalOpts9(args);
|
|
9324
9393
|
requireNonProd(globalOpts);
|
|
9325
9394
|
const request = { nip: args.nip };
|
|
9326
|
-
|
|
9327
|
-
|
|
9395
|
+
await createClient(globalOpts).testData.removePerson(request);
|
|
9396
|
+
outputDone(args.json);
|
|
9328
9397
|
});
|
|
9329
9398
|
}
|
|
9330
9399
|
});
|
|
@@ -9354,8 +9423,8 @@ var grantPermissions = defineCommand10({
|
|
|
9354
9423
|
},
|
|
9355
9424
|
permissions
|
|
9356
9425
|
};
|
|
9357
|
-
|
|
9358
|
-
|
|
9426
|
+
await createClient(globalOpts).testData.grantPermissions(request);
|
|
9427
|
+
outputDone(args.json);
|
|
9359
9428
|
});
|
|
9360
9429
|
}
|
|
9361
9430
|
});
|
|
@@ -9382,8 +9451,8 @@ var revokePermissions = defineCommand10({
|
|
|
9382
9451
|
value: args.identifier
|
|
9383
9452
|
}
|
|
9384
9453
|
};
|
|
9385
|
-
|
|
9386
|
-
|
|
9454
|
+
await createClient(globalOpts).testData.revokePermissions(request);
|
|
9455
|
+
outputDone(args.json);
|
|
9387
9456
|
});
|
|
9388
9457
|
}
|
|
9389
9458
|
});
|
|
@@ -9401,8 +9470,8 @@ var enableAttachment = defineCommand10({
|
|
|
9401
9470
|
const globalOpts = getGlobalOpts9(args);
|
|
9402
9471
|
requireNonProd(globalOpts);
|
|
9403
9472
|
const request = { nip: args.nip };
|
|
9404
|
-
|
|
9405
|
-
|
|
9473
|
+
await createClient(globalOpts).testData.enableAttachment(request);
|
|
9474
|
+
outputDone(args.json);
|
|
9406
9475
|
});
|
|
9407
9476
|
}
|
|
9408
9477
|
});
|
|
@@ -9424,8 +9493,8 @@ var disableAttachment = defineCommand10({
|
|
|
9424
9493
|
nip: args.nip,
|
|
9425
9494
|
expectedEndDate: args["end-date"]
|
|
9426
9495
|
};
|
|
9427
|
-
|
|
9428
|
-
|
|
9496
|
+
await createClient(globalOpts).testData.disableAttachment(request);
|
|
9497
|
+
outputDone(args.json);
|
|
9429
9498
|
});
|
|
9430
9499
|
}
|
|
9431
9500
|
});
|
|
@@ -9461,8 +9530,8 @@ var changeSessionLimits = defineCommand10({
|
|
|
9461
9530
|
maxInvoices: parseInt(args["batch-max-invoices"], 10)
|
|
9462
9531
|
}
|
|
9463
9532
|
};
|
|
9464
|
-
|
|
9465
|
-
|
|
9533
|
+
await client.testData.changeSessionLimits(request);
|
|
9534
|
+
outputDone(args.json);
|
|
9466
9535
|
});
|
|
9467
9536
|
}
|
|
9468
9537
|
});
|
|
@@ -9480,8 +9549,8 @@ var restoreSessionLimits = defineCommand10({
|
|
|
9480
9549
|
const globalOpts = getGlobalOpts9(args);
|
|
9481
9550
|
requireNonProd(globalOpts);
|
|
9482
9551
|
const { client } = requireSession(globalOpts);
|
|
9483
|
-
|
|
9484
|
-
|
|
9552
|
+
await client.testData.restoreDefaultSessionLimits();
|
|
9553
|
+
outputDone(args.json);
|
|
9485
9554
|
});
|
|
9486
9555
|
}
|
|
9487
9556
|
});
|
|
@@ -9507,8 +9576,8 @@ var changeCertLimits = defineCommand10({
|
|
|
9507
9576
|
enrollment: args["max-enrollments"] !== void 0 ? { maxEnrollments: parseInt(args["max-enrollments"], 10) } : void 0,
|
|
9508
9577
|
certificate: args["max-certificates"] !== void 0 ? { maxCertificates: parseInt(args["max-certificates"], 10) } : void 0
|
|
9509
9578
|
};
|
|
9510
|
-
|
|
9511
|
-
|
|
9579
|
+
await client.testData.changeCertificatesLimit(request);
|
|
9580
|
+
outputDone(args.json);
|
|
9512
9581
|
});
|
|
9513
9582
|
}
|
|
9514
9583
|
});
|
|
@@ -9526,8 +9595,8 @@ var restoreCertLimits = defineCommand10({
|
|
|
9526
9595
|
const globalOpts = getGlobalOpts9(args);
|
|
9527
9596
|
requireNonProd(globalOpts);
|
|
9528
9597
|
const { client } = requireSession(globalOpts);
|
|
9529
|
-
|
|
9530
|
-
|
|
9598
|
+
await client.testData.restoreDefaultCertificatesLimit();
|
|
9599
|
+
outputDone(args.json);
|
|
9531
9600
|
});
|
|
9532
9601
|
}
|
|
9533
9602
|
});
|
|
@@ -9549,8 +9618,8 @@ var setRateLimits = defineCommand10({
|
|
|
9549
9618
|
const request = {
|
|
9550
9619
|
rateLimits: JSON.parse(args.limits)
|
|
9551
9620
|
};
|
|
9552
|
-
|
|
9553
|
-
|
|
9621
|
+
await client.testData.setRateLimits(request);
|
|
9622
|
+
outputDone(args.json);
|
|
9554
9623
|
});
|
|
9555
9624
|
}
|
|
9556
9625
|
});
|
|
@@ -9568,8 +9637,8 @@ var restoreRateLimits = defineCommand10({
|
|
|
9568
9637
|
const globalOpts = getGlobalOpts9(args);
|
|
9569
9638
|
requireNonProd(globalOpts);
|
|
9570
9639
|
const { client } = requireSession(globalOpts);
|
|
9571
|
-
|
|
9572
|
-
|
|
9640
|
+
await client.testData.restoreDefaultRateLimits();
|
|
9641
|
+
outputDone(args.json);
|
|
9573
9642
|
});
|
|
9574
9643
|
}
|
|
9575
9644
|
});
|
|
@@ -9587,8 +9656,8 @@ var setProductionRateLimits = defineCommand10({
|
|
|
9587
9656
|
const globalOpts = getGlobalOpts9(args);
|
|
9588
9657
|
requireNonProd(globalOpts);
|
|
9589
9658
|
const { client } = requireSession(globalOpts);
|
|
9590
|
-
|
|
9591
|
-
|
|
9659
|
+
await client.testData.setProductionRateLimits();
|
|
9660
|
+
outputDone(args.json);
|
|
9592
9661
|
});
|
|
9593
9662
|
}
|
|
9594
9663
|
});
|
|
@@ -9614,8 +9683,8 @@ var blockContext = defineCommand10({
|
|
|
9614
9683
|
value: args["context-value"]
|
|
9615
9684
|
}
|
|
9616
9685
|
};
|
|
9617
|
-
|
|
9618
|
-
|
|
9686
|
+
await client.testData.blockContext(request);
|
|
9687
|
+
outputDone(args.json);
|
|
9619
9688
|
});
|
|
9620
9689
|
}
|
|
9621
9690
|
});
|
|
@@ -9641,8 +9710,8 @@ var unblockContext = defineCommand10({
|
|
|
9641
9710
|
value: args["context-value"]
|
|
9642
9711
|
}
|
|
9643
9712
|
};
|
|
9644
|
-
|
|
9645
|
-
|
|
9713
|
+
await client.testData.unblockContext(request);
|
|
9714
|
+
outputDone(args.json);
|
|
9646
9715
|
});
|
|
9647
9716
|
}
|
|
9648
9717
|
});
|