ksef-rb 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaa5f61dd0f2d3e8f852cb504016268c73b798da5fe1e896a821115ea01fd2a5
4
- data.tar.gz: 23df18df8297859a7fdf10fe0546dc03dc49e43b7617236de86837f7d2dbbe43
3
+ metadata.gz: 540290ac5d524843c717ea5d92bba806eda1e4720926d61d5afd5545265d722b
4
+ data.tar.gz: dbbed4846d2ede6b17eed4813373f2a1d5acce75f49cc54524d9b6131722b9a3
5
5
  SHA512:
6
- metadata.gz: a15c7b19048d06f3328c5e4cb4cbc0a85ce3d7acf4daea6af2c24ec9dc3aee09c83c391071949665fa2a9b81d6f9ac2e9a8285a9e0b582f6e8c45c1d3d764422
7
- data.tar.gz: f2b4956065c21bd7ac5dde726ca129664aa04e30efea9c7ffc746cc32900b0d76d523202f63aa74c1a03105108c58b627e0d96abff8e2c54d208f3d41d90fd5b
6
+ metadata.gz: 669073ea7e384dc08459e1ac3aeb0dbc0c7c3ab3256617e13fe3c5bab9efc3cd3c06ffbfb529edac7fbcaaab87400e99de05c23c4ec3f1a99961f6b217f4a4f0
7
+ data.tar.gz: ee6e786a4d08f53330c4e46fceb4d5e1ff443a5d0555a89c314fdc782cfb6bc2d307a46c0da069a44cd3a77a81e022149b2319207ca7822699f4828c945b8982
data/CHANGELOG.md CHANGED
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.2] - 2026-05-19
11
+
12
+ ### Fixed
13
+ - `/security/public-key-certificates` returns a DER-encoded X.509 certificate,
14
+ not a bare SPKI. The previous `Internal::TokenEncryptor.normalize_public_key`
15
+ fed the DER straight into `OpenSSL::PKey::RSA.new`, which raised
16
+ `OpenSSL::PKey::PKeyError: Neither PUB key nor PRIV key` against the live
17
+ production endpoint. The normaliser now parses the bytes as an X.509
18
+ certificate and extracts the public key, falling back to the bare-key code
19
+ path for backwards compatibility. The spec-helper fixture was updated to
20
+ return a real self-signed X.509 cert (matching the real KSeF response shape)
21
+ so the entire session lifecycle exercises this path.
22
+ - `Ksef::InvoiceHeader` now `require`s `"time"` explicitly. It calls
23
+ `Time.iso8601` to parse `acquisitionDate` / `permanentStorageDate`; the spec
24
+ suite happened to load `time` transitively via `webmock`, but a bare
25
+ consumer that only required `"ksef"` got `NoMethodError: undefined method
26
+ 'iso8601' for class Time` the first time they pulled invoice metadata.
27
+
28
+ ## [0.1.1] - 2026-05-19
29
+
30
+ ### Added
31
+ - `lib/ksef-rb.rb` shim so `gem "ksef-rb"` works in any Gemfile without
32
+ the `require: "ksef"` option. Consumers who already use the explicit
33
+ `require:` form keep working unchanged.
34
+
10
35
  ## [0.1.0] - 2025-05-18
11
36
 
12
37
  ### Added
data/README.md CHANGED
@@ -15,7 +15,7 @@ but additions are expected as more KSeF features land.
15
15
  ## Installation
16
16
 
17
17
  ```ruby
18
- gem "ksef-rb", require: "ksef"
18
+ gem "ksef-rb"
19
19
  ```
20
20
 
21
21
  ## Quick start
@@ -37,7 +37,8 @@ client.sessions.with_interactive do |_session|
37
37
  headers = client.invoices.query(
38
38
  subject_type: :recipient,
39
39
  date_from: Time.now.utc - (7 * 24 * 3600),
40
- date_to: Time.now.utc
40
+ date_to: Time.now.utc,
41
+ date_type: :issue # :permanent_storage (default), :invoicing, or :issue
41
42
  )
42
43
 
43
44
  headers.each do |h|
@@ -49,6 +50,28 @@ client.sessions.with_interactive do |_session|
49
50
  end
50
51
  ```
51
52
 
53
+ `#query` returns at most `page_size` headers per call (default 100, max 250).
54
+ Paginate by bumping `page_offset` until a short page comes back:
55
+
56
+ ```ruby
57
+ all = []
58
+ offset = 0
59
+ loop do
60
+ page = client.invoices.query(
61
+ subject_type: :recipient,
62
+ date_from: Date.new(2026, 4, 1),
63
+ date_to: Date.new(2026, 5, 31),
64
+ date_type: :issue,
65
+ page_size: 250,
66
+ page_offset: offset
67
+ )
68
+ all.concat(page)
69
+ break if page.size < 250
70
+
71
+ offset += 1
72
+ end
73
+ ```
74
+
52
75
  `Ksef::InvoiceHeader` exposes (among others):
53
76
  `ksef_reference_number`, `invoice_number`, `issuer_nip`, `issuer_name`,
54
77
  `recipient_nip`, `recipient_name`, `issued_on`, `gross_amount`, `net_amount`,
@@ -34,13 +34,20 @@ module Ksef
34
34
  Base64.strict_encode64(ciphertext)
35
35
  end
36
36
 
37
- # Convenience wrapper that handles raw DER-encoded (base64) keys returned
38
- # by the public-key endpoint, falling back to PEM if the input already
39
- # contains BEGIN markers.
37
+ # Normalizes whatever `/security/public-key-certificates` hands us into a
38
+ # PEM-encoded RSA public key suitable for {.encrypt}.
39
+ #
40
+ # KSeF returns the `certificate` field as a base64-encoded DER X.509
41
+ # certificate (not a bare public key), so we parse it as a cert first
42
+ # and extract the SPKI. PEM-armored inputs and bare-key DER blobs are
43
+ # also accepted as a courtesy.
40
44
  def normalize_public_key(raw)
41
- return raw if raw.to_s.include?("BEGIN")
45
+ text = raw.to_s
46
+ return text if text.include?("BEGIN")
42
47
 
43
- der = Base64.decode64(raw.to_s)
48
+ der = Base64.decode64(text)
49
+ OpenSSL::X509::Certificate.new(der).public_key.to_pem
50
+ rescue OpenSSL::X509::CertificateError
44
51
  OpenSSL::PKey::RSA.new(der).to_pem
45
52
  end
46
53
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "date"
4
+ require "time"
4
5
 
5
6
  module Ksef
6
7
  # Lightweight value object describing an invoice as returned by
data/lib/ksef/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ksef
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/ksef-rb.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Bundler's default for `gem "ksef-rb"` is `require "ksef-rb"`. This shim
4
+ # makes that resolve to the canonical entry point without forcing every
5
+ # consumer to add `, require: "ksef"`.
6
+ require_relative "ksef"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ksef-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Siwek
@@ -91,6 +91,7 @@ files:
91
91
  - CHANGELOG.md
92
92
  - LICENSE.txt
93
93
  - README.md
94
+ - lib/ksef-rb.rb
94
95
  - lib/ksef.rb
95
96
  - lib/ksef/client.rb
96
97
  - lib/ksef/configuration.rb