ksef-client-ts 0.6.1 → 0.6.2

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/dist/index.cjs CHANGED
@@ -175,12 +175,14 @@ var init_ksef_unauthorized_error = __esm({
175
175
  detail;
176
176
  traceId;
177
177
  instance;
178
+ timestamp;
178
179
  constructor(problemDetails) {
179
180
  super(problemDetails.detail || "Unauthorized");
180
181
  this.name = "KSeFUnauthorizedError";
181
182
  this.detail = problemDetails.detail;
182
183
  this.traceId = problemDetails.traceId;
183
184
  this.instance = problemDetails.instance;
185
+ this.timestamp = problemDetails.timestamp;
184
186
  }
185
187
  };
186
188
  }
@@ -199,6 +201,7 @@ var init_ksef_forbidden_error = __esm({
199
201
  instance;
200
202
  security;
201
203
  traceId;
204
+ timestamp;
202
205
  constructor(problemDetails) {
203
206
  super(problemDetails.detail || "Forbidden");
204
207
  this.name = "KSeFForbiddenError";
@@ -207,6 +210,31 @@ var init_ksef_forbidden_error = __esm({
207
210
  this.instance = problemDetails.instance;
208
211
  this.security = problemDetails.security;
209
212
  this.traceId = problemDetails.traceId;
213
+ this.timestamp = problemDetails.timestamp;
214
+ }
215
+ };
216
+ }
217
+ });
218
+
219
+ // src/errors/ksef-gone-error.ts
220
+ var KSeFGoneError;
221
+ var init_ksef_gone_error = __esm({
222
+ "src/errors/ksef-gone-error.ts"() {
223
+ "use strict";
224
+ init_ksef_error();
225
+ KSeFGoneError = class extends KSeFError {
226
+ statusCode = 410;
227
+ detail;
228
+ instance;
229
+ traceId;
230
+ timestamp;
231
+ constructor(problemDetails) {
232
+ super(problemDetails.detail || "Operation status no longer available (retention expired)");
233
+ this.name = "KSeFGoneError";
234
+ this.detail = problemDetails.detail;
235
+ this.instance = problemDetails.instance;
236
+ this.traceId = problemDetails.traceId;
237
+ this.timestamp = problemDetails.timestamp;
210
238
  }
211
239
  };
212
240
  }
@@ -274,6 +302,45 @@ var init_ksef_validation_error = __esm({
274
302
  }
275
303
  });
276
304
 
305
+ // src/errors/error-codes.ts
306
+ function hasErrorCode(body, code) {
307
+ return !!body?.exception?.exceptionDetailList?.some((d) => d.exceptionCode === code);
308
+ }
309
+ var KSeFErrorCode;
310
+ var init_error_codes = __esm({
311
+ "src/errors/error-codes.ts"() {
312
+ "use strict";
313
+ KSeFErrorCode = {
314
+ BatchTimeout: 21208,
315
+ DuplicateInvoice: 440
316
+ };
317
+ }
318
+ });
319
+
320
+ // src/errors/ksef-batch-timeout-error.ts
321
+ var KSeFBatchTimeoutError;
322
+ var init_ksef_batch_timeout_error = __esm({
323
+ "src/errors/ksef-batch-timeout-error.ts"() {
324
+ "use strict";
325
+ init_ksef_api_error();
326
+ init_error_codes();
327
+ KSeFBatchTimeoutError = class _KSeFBatchTimeoutError extends KSeFApiError {
328
+ errorCode = KSeFErrorCode.BatchTimeout;
329
+ constructor(message, statusCode, errorResponse) {
330
+ super(message, statusCode, errorResponse);
331
+ this.name = "KSeFBatchTimeoutError";
332
+ }
333
+ static fromResponse(statusCode, body) {
334
+ const detail = body?.exception?.exceptionDetailList?.find(
335
+ (d) => d.exceptionCode === KSeFErrorCode.BatchTimeout
336
+ );
337
+ const message = detail?.exceptionDescription?.trim() || "Batch session timed out before the server completed processing (KSeF 21208).";
338
+ return new _KSeFBatchTimeoutError(message, statusCode, body);
339
+ }
340
+ };
341
+ }
342
+ });
343
+
277
344
  // src/errors/index.ts
278
345
  var init_errors = __esm({
279
346
  "src/errors/index.ts"() {
@@ -283,9 +350,12 @@ var init_errors = __esm({
283
350
  init_ksef_rate_limit_error();
284
351
  init_ksef_unauthorized_error();
285
352
  init_ksef_forbidden_error();
353
+ init_ksef_gone_error();
286
354
  init_ksef_auth_status_error();
287
355
  init_ksef_session_expired_error();
288
356
  init_ksef_validation_error();
357
+ init_ksef_batch_timeout_error();
358
+ init_error_codes();
289
359
  }
290
360
  });
291
361
 
@@ -542,6 +612,9 @@ var init_rest_client = __esm({
542
612
  init_ksef_rate_limit_error();
543
613
  init_ksef_unauthorized_error();
544
614
  init_ksef_forbidden_error();
615
+ init_ksef_gone_error();
616
+ init_ksef_batch_timeout_error();
617
+ init_error_codes();
545
618
  init_route_builder();
546
619
  init_transport();
547
620
  init_retry_policy();
@@ -682,18 +755,33 @@ var init_rest_client = __esm({
682
755
  );
683
756
  }
684
757
  if (response.status === 401) {
685
- const body = parseJson();
686
- if (body?.detail) {
687
- throw new KSeFUnauthorizedError(body);
758
+ const body2 = parseJson();
759
+ if (body2?.detail) {
760
+ throw new KSeFUnauthorizedError(body2);
688
761
  }
689
762
  }
690
763
  if (response.status === 403) {
691
- const body = parseJson();
692
- if (body?.reasonCode) {
693
- throw new KSeFForbiddenError(body);
764
+ const body2 = parseJson();
765
+ if (body2?.reasonCode) {
766
+ throw new KSeFForbiddenError(body2);
694
767
  }
695
768
  }
696
- throw KSeFApiError.fromResponse(response.status, parseJson());
769
+ if (response.status === 410) {
770
+ const body2 = parseJson();
771
+ throw new KSeFGoneError({
772
+ title: body2?.title || "Gone",
773
+ status: body2?.status || 410,
774
+ detail: body2?.detail || "Operation status no longer available (retention expired)",
775
+ instance: body2?.instance,
776
+ traceId: body2?.traceId,
777
+ timestamp: body2?.timestamp
778
+ });
779
+ }
780
+ const body = parseJson();
781
+ if (hasErrorCode(body, KSeFErrorCode.BatchTimeout)) {
782
+ throw KSeFBatchTimeoutError.fromResponse(response.status, body);
783
+ }
784
+ throw KSeFApiError.fromResponse(response.status, body);
697
785
  }
698
786
  };
699
787
  }
@@ -5080,6 +5168,7 @@ var init_client = __esm({
5080
5168
  const tokens = await this.auth.getAccessToken(authToken);
5081
5169
  this.authManager.setAccessToken(tokens.accessToken.token);
5082
5170
  this.authManager.setRefreshToken(tokens.refreshToken.token);
5171
+ return { clientIp: challenge.clientIp };
5083
5172
  }
5084
5173
  async loginWithCertificate(certPem, keyPem, nip, keyPassword) {
5085
5174
  const challenge = await this.auth.getChallenge();
@@ -5092,11 +5181,12 @@ var init_client = __esm({
5092
5181
  const tokens = await this.auth.getAccessToken(authToken);
5093
5182
  this.authManager.setAccessToken(tokens.accessToken.token);
5094
5183
  this.authManager.setRefreshToken(tokens.refreshToken.token);
5184
+ return { clientIp: challenge.clientIp };
5095
5185
  }
5096
5186
  async loginWithPkcs12(p12, password, nip) {
5097
5187
  const { Pkcs12Loader: Pkcs12Loader2 } = await Promise.resolve().then(() => (init_pkcs12_loader(), pkcs12_loader_exports));
5098
5188
  const { certificatePem, privateKeyPem } = Pkcs12Loader2.load(p12, password);
5099
- await this.loginWithCertificate(certificatePem, privateKeyPem, nip);
5189
+ return this.loginWithCertificate(certificatePem, privateKeyPem, nip);
5100
5190
  }
5101
5191
  async awaitAuthReady(referenceNumber, authToken) {
5102
5192
  for (let i = 0; i < 30; i++) {
@@ -5159,9 +5249,12 @@ __export(index_exports, {
5159
5249
  KSEF_FEATURE_HEADER: () => KSEF_FEATURE_HEADER,
5160
5250
  KSeFApiError: () => KSeFApiError,
5161
5251
  KSeFAuthStatusError: () => KSeFAuthStatusError,
5252
+ KSeFBatchTimeoutError: () => KSeFBatchTimeoutError,
5162
5253
  KSeFClient: () => KSeFClient,
5163
5254
  KSeFError: () => KSeFError,
5255
+ KSeFErrorCode: () => KSeFErrorCode,
5164
5256
  KSeFForbiddenError: () => KSeFForbiddenError,
5257
+ KSeFGoneError: () => KSeFGoneError,
5165
5258
  KSeFRateLimitError: () => KSeFRateLimitError,
5166
5259
  KSeFSessionExpiredError: () => KSeFSessionExpiredError,
5167
5260
  KSeFUnauthorizedError: () => KSeFUnauthorizedError,
@@ -6989,9 +7082,12 @@ init_client();
6989
7082
  KSEF_FEATURE_HEADER,
6990
7083
  KSeFApiError,
6991
7084
  KSeFAuthStatusError,
7085
+ KSeFBatchTimeoutError,
6992
7086
  KSeFClient,
6993
7087
  KSeFError,
7088
+ KSeFErrorCode,
6994
7089
  KSeFForbiddenError,
7090
+ KSeFGoneError,
6995
7091
  KSeFRateLimitError,
6996
7092
  KSeFSessionExpiredError,
6997
7093
  KSeFUnauthorizedError,