cekat-event-sdk 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.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/lib/cekat_event_sdk/stripe.rb +36 -0
- data/lib/cekat_event_sdk/version.rb +1 -1
- data/lib/cekat_event_sdk.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a6adabdca7dc48bd4594f7368316096ea0bb0bd5d928ad0ccf36d9866ee555b6
|
|
4
|
+
data.tar.gz: 66e3f5464caf285279b3910ce02ea649286d28830e5119a7de3d2977745aa6e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7c30741a7eb8a011206329680efc87c1e3d504db9953390b3e482c40719f536dd8f50b8189b709f41d0eea9d46849f0c76d0654170f680d21fd21b64cb91556
|
|
7
|
+
data.tar.gz: c27f710403a0efebad517e77be27ed6cb17076be9d50abb7a0d1d70301b97303a6a01512e1ed80ca7661dc740b3553a8639a963f4c958b441b70b97bd9a35bae
|
data/README.md
CHANGED
|
@@ -72,6 +72,18 @@ end
|
|
|
72
72
|
|
|
73
73
|
The visitor scope lives in fiber storage (`Fiber[]`), so it is isolated per request under threaded servers (Puma) and fiber-based servers (Falcon). Every scope restores the previous visitor when it ends, including when it raises, so long-running workers never leak a visitor ID between requests. Threads and fibers started inside a request begin with a copy of its scope. The scope ends when the middleware returns, so events emitted while a streaming response body is iterated must pass `visitor_id:` explicitly.
|
|
74
74
|
|
|
75
|
+
## Stripe metadata composition
|
|
76
|
+
|
|
77
|
+
Use the helper with the merchant's Stripe client; it does not create a Stripe request or send a Cekat event.
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
metadata = CekatEventSdk::Stripe.merge_metadata(merchant_metadata, CekatEventSdk::Stripe.metadata_from_current_visitor["cekat_" + "visitor_id"])
|
|
81
|
+
# stripe.payment_intents.create(amount: 1200, currency: "usd", metadata: metadata)
|
|
82
|
+
# stripe.checkout.sessions.create(mode: "payment", metadata: metadata, payment_intent_data: { metadata: metadata })
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Only a trimmed 1–128 character `[A-Za-z0-9_-]` visitor becomes the Stripe visitor metadata entry. Merge returns a fresh hash, preserving merchant keys and leaving invalid or absent visitor input unchanged.
|
|
86
|
+
|
|
75
87
|
## Keep tracking off the request's critical path
|
|
76
88
|
|
|
77
89
|
Calls are synchronous, so each event adds its round-trip to the request. To send in the background, capture the visitor ID while the request scope is active and pass it explicitly:
|
|
@@ -132,7 +144,7 @@ The Net::HTTP transport opens a fresh connection per attempt, never follows redi
|
|
|
132
144
|
bundle install
|
|
133
145
|
bundle exec rake # core, Rack, and Rails specs plus RuboCop
|
|
134
146
|
RAILS_VERSION="~> 8.0.0" RACK_VERSION="~> 2.2" bundle update && bundle exec rake spec
|
|
135
|
-
./scripts/package --version 0.
|
|
147
|
+
./scripts/package --version 0.2.0 --output /absolute/empty-directory
|
|
136
148
|
```
|
|
137
149
|
|
|
138
150
|
`scripts/package` runs the specs, RuboCop, and `bundle-audit`, then builds the gem and a SHA-256 `manifest.json`. It never pushes, signs, or tags; releases to RubyGems run from the repository's `release-ruby.yml` workflow when a `ruby/vX.Y.Z` tag is pushed. `scripts/conformance` runs the shared conformance fixtures (see `conformance/README.md`); the three caller-cancellation cases are reported as `not_applicable` for Ruby.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CekatEventSdk
|
|
4
|
+
# Builds Stripe metadata for optional Cekat visitor correlation.
|
|
5
|
+
module Stripe
|
|
6
|
+
VISITOR_METADATA_KEY = "cekat_visitor_id"
|
|
7
|
+
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def metadata_for_visitor(visitor_id)
|
|
11
|
+
normalized = valid_visitor_id(visitor_id)
|
|
12
|
+
normalized.nil? ? {} : { VISITOR_METADATA_KEY => normalized }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def metadata_from_current_visitor
|
|
16
|
+
metadata_for_visitor(VisitorContext.current_visitor_id)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def merge_metadata(metadata, visitor_id)
|
|
20
|
+
merged = metadata.dup
|
|
21
|
+
normalized = valid_visitor_id(visitor_id)
|
|
22
|
+
merged[VISITOR_METADATA_KEY] = normalized unless normalized.nil?
|
|
23
|
+
merged
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def valid_visitor_id(visitor_id)
|
|
27
|
+
return nil unless visitor_id.is_a?(String)
|
|
28
|
+
|
|
29
|
+
normalized = visitor_id.strip
|
|
30
|
+
return nil unless normalized.match?(/\A[A-Za-z0-9_-]{1,128}\z/)
|
|
31
|
+
|
|
32
|
+
normalized
|
|
33
|
+
end
|
|
34
|
+
private_class_method :valid_visitor_id
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/cekat_event_sdk.rb
CHANGED
|
@@ -16,6 +16,7 @@ require_relative "cekat_event_sdk/event_input"
|
|
|
16
16
|
require_relative "cekat_event_sdk/acknowledgement"
|
|
17
17
|
require_relative "cekat_event_sdk/visitor_id_resolver"
|
|
18
18
|
require_relative "cekat_event_sdk/visitor_context"
|
|
19
|
+
require_relative "cekat_event_sdk/stripe"
|
|
19
20
|
require_relative "cekat_event_sdk/payload_builder"
|
|
20
21
|
require_relative "cekat_event_sdk/retry_policy"
|
|
21
22
|
require_relative "cekat_event_sdk/transport"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cekat-event-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cekat
|
|
@@ -29,6 +29,7 @@ files:
|
|
|
29
29
|
- lib/cekat_event_sdk/rails.rb
|
|
30
30
|
- lib/cekat_event_sdk/response_decoder.rb
|
|
31
31
|
- lib/cekat_event_sdk/retry_policy.rb
|
|
32
|
+
- lib/cekat_event_sdk/stripe.rb
|
|
32
33
|
- lib/cekat_event_sdk/transport.rb
|
|
33
34
|
- lib/cekat_event_sdk/version.rb
|
|
34
35
|
- lib/cekat_event_sdk/visitor_context.rb
|