recapi 0.1.10 → 0.1.11

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -1
  3. data/lib/recapi.rb +12 -3
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9d8c7e28e6929bfef64625ac5ba48ba5bec683d27b3d4c91646b67f189cadeb
4
- data.tar.gz: b17b8ad7945fac43147ce43aca7cd27a1b62105a155fdc5ce15d8eccc7e6fca9
3
+ metadata.gz: ddfbe7da7e2ca36f680b013e06c795a516645d415329f1dc61892024e129d477
4
+ data.tar.gz: dacd7f80f58ecda60c653380d73e63a396315f906339d9940941922a1ed6333e
5
5
  SHA512:
6
- metadata.gz: 01a65170536dc4f5f33596f509fc7102670ba72a566954b1443d7d4dc29f01137206c4a3b3c49822c4bf85bc6b3200751655a49480a2afa46fe0e10ba3fa45e5
7
- data.tar.gz: d6d63d879a0eed194f410983abef9770b3296606184cf822a4824c56c2a0dd5a6350922595af45257c9ddf3bb3905be35de694ba9f230a9cc2d5d7a7b6676e7e
6
+ metadata.gz: f5309158f3114f5d2d314045358364a9467a867aa4324e8650b6dc6269583de306c74e0f5a288f81cbfdf27adc75ca778a0f8d7d12a63710ac1c7c98158d4cfc
7
+ data.tar.gz: 82124ece99593007209d5a4e040c7d1f6768d47ae6ee93a0892f734d83c964b5d10e34d7198badb53453cab39be36ee1bb2bf18d43ac802f62806ae8e525c780
data/README.md CHANGED
@@ -30,7 +30,7 @@ line with your address): save it as `lib/recapi.rb` and
30
30
  `require Rails.root.join("lib/recapi").to_s` instead.
31
31
 
32
32
  ```sh
33
- curl -fLo lib/recapi.rb https://api.<your-domain>/sdk/ruby/recapi-0.1.10.rb
33
+ curl -fLo lib/recapi.rb https://api.<your-domain>/sdk/ruby/recapi-0.1.11.rb
34
34
  ```
35
35
 
36
36
  ## Quick start
@@ -124,6 +124,10 @@ so a visitor who never returns stays on disk (about 8 KB each): run
124
124
 
125
125
  ## Changes
126
126
 
127
+ - 2026-11-07: version 0.1.11. A damaged stored state can't raise into your page
128
+ or stop a visitor's history from saving. A shown entry of the wrong types
129
+ costs that item's click credit, and a history time too big for a number
130
+ discards the state. Same in every library.
127
131
  - 2026-11-05: version 0.1.10. `track` stays queued and in the background in a
128
132
  classic Sinatra app
129
133
  (`ruby app.rb`). The exit hook used to close the client before the server
data/lib/recapi.rb CHANGED
@@ -25,7 +25,7 @@ rescue LoadError
25
25
  end
26
26
 
27
27
  module Recapi
28
- VERSION = "0.1.10"
28
+ VERSION = "0.1.11"
29
29
 
30
30
  # Decayed user history, exactly as docs/history-spec.md (times in unix ms).
31
31
  # A port of sdk/python's history.py, snapshot merging included.
@@ -51,8 +51,10 @@ module Recapi
51
51
  Math.exp(-RATE * (dt_ms / 1000.0))
52
52
  end
53
53
 
54
+ # Compared, not converted: a stored 400-digit integer would become Infinity,
55
+ # which JSON can't save. NaN and Infinity fail the bound.
54
56
  def self.time?(value)
55
- (value.is_a?(Integer) || value.is_a?(Float)) && value.finite?
57
+ (value.is_a?(Integer) || value.is_a?(Float)) && value.abs <= Float::MAX
56
58
  end
57
59
 
58
60
  def self.weight?(value)
@@ -739,13 +741,20 @@ module Recapi
739
741
 
740
742
  shown = {}
741
743
  data["shown"].each do |e|
742
- shown[e[0]] = e[1..] if e.is_a?(Array) && e.size.between?(3, 4) && History.id?(e[0])
744
+ shown[e[0]] = e[1..] if shown_entry?(e)
743
745
  end
744
746
  anon_id = data["anon_id"]
745
747
  new(history, shown, data["restored"] == true, History.id?(anon_id) ? anon_id : nil)
746
748
  rescue JSON::ParserError, TypeError
747
749
  nil
748
750
  end
751
+
752
+ # Bad types here would raise much later, in track on the shop's page, or
753
+ # refuse a whole batch of events at the API.
754
+ def self.shown_entry?(entry)
755
+ entry.is_a?(Array) && entry.size.between?(3, 4) && History.id?(entry[0]) && entry[1].is_a?(String) &&
756
+ entry[2..].all? { |t| t.is_a?(Integer) && t.abs < 2**63 }
757
+ end
749
758
  end
750
759
 
751
760
  def self.attributable?(entry, t)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - recapi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-05 00:00:00.000000000 Z
11
+ date: 2026-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Ruby client for the recapi recommendation API: per-user history, event
14
14
  batching, retries, popular fallback. Standard library only.'