capi_param_builder_ruby 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8525b1ab84c2d04fa5557b0aaba420e7963136503d972a09bdb616f99a18711e
4
- data.tar.gz: 5810250eddcd721a5051e678b23b0165b2b4d84e2683bbf860dd2f9e54751324
3
+ metadata.gz: 8acc5a9893deeb3ac84eb9973c23fe5bf498d86ac00c3afcee5320ffd18a50e9
4
+ data.tar.gz: 5dd4b0017743d2a06b2c8a6c4c8b04d77052a2e642d2d9912895002e220bb62a
5
5
  SHA512:
6
- metadata.gz: 8aaa07d83a623a1f10cd4d34c73c55e6056fc20048006a0c263bd4fe372bb5ae6d2f476a91bd75db02a4a4b103a7d376793c16ae2474b476efb8d670de45166d
7
- data.tar.gz: 9919b3befd095f7bf7cbd88d8ccac7cc6c09ce86a60f8dbcf163beb2af1b22ad876ac5c82b80e03c89d41efdb518de27408ba6cba73d64e1055a9cdc1167c966
6
+ metadata.gz: 2ae3b35cc6ddf7b8cce4a0a1a12ebbe57befeb3cfd3e0f546c78468ec0684253a5ee68c2fbc92eda827fbb1dbb3e0cd829c2327ce9afbd5f8c1f9b15eef8253c
7
+ data.tar.gz: fd12cf81cda06e7b2a72e38e46d68371fff2e0debdc5238fe8bd16ee04b9ca9396af40d0b2f3393370db29565907c76623d6caea369eec9eb29e5eb237ff9798
@@ -7,23 +7,32 @@
7
7
  require_relative 'model/fbc_param_configs'
8
8
  require_relative 'model/cookie_settings'
9
9
  require_relative 'model/etld_plus_one_resolver'
10
+ require_relative 'release_config'
10
11
  require 'set'
11
12
  require 'uri'
12
13
  require 'cgi'
14
+ require 'base64'
13
15
 
14
16
  class ParamBuilder
15
17
  FBC_NAME = "_fbc"
16
18
  FBP_NAME = "_fbp"
17
19
  DEFAULT_1PC_AGE = 90 * 24 * 3600
18
- LANGUAGE_TOKEN = "BQ"
20
+ LANGUAGE_TOKEN = "BQ" # Original Ruby language token
19
21
  SUPPORTED_LANGUAGE_TOKENS = ["AQ", "Ag", "Aw", "BA", "BQ", "Bg"]
20
22
  MIN_PAYLOAD_SPLIT_LENGTH = 4
21
23
  MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH = 5
22
24
  IPV4_REGEX = /\A(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/
23
25
  IPV6_REGEX = /\A(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,7}:\z|\A(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}\z|\A(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}\z|\A(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}\z|\A(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}\z|\A[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}\z|\A:(?::[0-9a-fA-F]{1,4}){1,7}\z|\A::\z|\A(?:[0-9a-fA-F]{1,4}:){6}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/
26
+ # Appendix constants
27
+ DEFAULT_FORMAT = 0x01
28
+ LANGUAGE_TOKEN_INDEX = 0x05 # Ruby language token index
29
+ APPENDIX_LENGTH_V1 = 2
30
+ APPENDIX_LENGTH_V2 = 8
24
31
 
25
32
  def initialize(input = nil)
26
33
  @fbc_params_configs = [FbcParamConfigs.new("fbclid", "", "clickID")]
34
+ @appendix_new = get_appendix(true)
35
+ @appendix_normal = get_appendix(false)
27
36
 
28
37
  if input.nil?
29
38
  return
@@ -39,6 +48,39 @@ class ParamBuilder
39
48
  end
40
49
  end
41
50
 
51
+ private def get_appendix(is_new)
52
+ begin
53
+ version = ReleaseConfig::VERSION
54
+ version_parts = version.split(".")
55
+ major = version_parts[0].to_i
56
+ minor = version_parts[1].to_i
57
+ patch = version_parts[2].to_i
58
+
59
+ is_new_byte = is_new ? 0x01 : 0x00
60
+
61
+ # Create byte array
62
+ bytes_array = [
63
+ DEFAULT_FORMAT, # 0x01 = 1
64
+ LANGUAGE_TOKEN_INDEX, # 0x05 = 5
65
+ is_new_byte, # 0x01 when is_new=true, 0x00 when is_new=false
66
+ major, # Major version number
67
+ minor, # Minor version number
68
+ patch # Patch version number
69
+ ]
70
+
71
+ # Convert to bytes and then to base64url-safe string
72
+ byte_data = bytes_array.pack("C*") # Pack as unsigned chars (bytes)
73
+ base64_encoded = Base64.encode64(byte_data).strip # Remove newlines
74
+ # Make it URL-safe by replacing characters
75
+ base64url_safe = base64_encoded.tr('+/', '-_').gsub(/=+$/, '')
76
+ return base64url_safe
77
+ rescue Exception => e
78
+ puts "Failed to parse version in appendix: #{e}"
79
+ return LANGUAGE_TOKEN # Fall back to original Ruby language token
80
+ end
81
+ end
82
+
83
+
42
84
  private def pre_process_cookies(cookies, cookie_name)
43
85
  # Sanity check
44
86
  if cookies.nil? || cookies[cookie_name].nil?
@@ -50,13 +92,19 @@ class ParamBuilder
50
92
  parts.size > MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH
51
93
  return nil
52
94
  end
53
- if parts.size == MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH && \
54
- !SUPPORTED_LANGUAGE_TOKENS.include?(parts[MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH - 1])
55
- return nil
95
+ if parts.size == MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH
96
+ appendix = parts[MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH - 1]
97
+ if appendix.size == APPENDIX_LENGTH_V1
98
+ if !SUPPORTED_LANGUAGE_TOKENS.include?(appendix)
99
+ return nil
100
+ end
101
+ elsif appendix.size != APPENDIX_LENGTH_V2
102
+ return nil
103
+ end
56
104
  end
57
105
  # Append language token if not present
58
106
  if parts.size == MIN_PAYLOAD_SPLIT_LENGTH
59
- updated_cookie_value = cookie_value + "." + LANGUAGE_TOKEN
107
+ updated_cookie_value = cookie_value + "." + @appendix_normal
60
108
  @cookie_to_set_dict[cookie_name] = CookieSettings.new(
61
109
  cookie_name, updated_cookie_value, @etld_plus_one, DEFAULT_1PC_AGE)
62
110
  return updated_cookie_value
@@ -252,7 +300,7 @@ class ParamBuilder
252
300
  "." +
253
301
  new_fbc_payload +
254
302
  "." +
255
- LANGUAGE_TOKEN
303
+ @appendix_new
256
304
  updated_cookie_setting = CookieSettings.new(
257
305
  FBC_NAME, new_fbc, @etld_plus_one, DEFAULT_1PC_AGE)
258
306
  return updated_cookie_setting
@@ -271,7 +319,7 @@ class ParamBuilder
271
319
  "." +
272
320
  new_fbp_payload +
273
321
  "." +
274
- LANGUAGE_TOKEN
322
+ @appendix_new
275
323
  updated_cookie_setting = CookieSettings.new(
276
324
  FBP_NAME, new_fbp, @etld_plus_one, DEFAULT_1PC_AGE)
277
325
  return updated_cookie_setting
@@ -0,0 +1,3 @@
1
+ module ReleaseConfig
2
+ VERSION = "1.1.0"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capi_param_builder_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Facebook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-07 00:00:00.000000000 Z
11
+ date: 2025-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -20,6 +20,7 @@ files:
20
20
  - lib/model/cookie_settings.rb
21
21
  - lib/model/etld_plus_one_resolver.rb
22
22
  - lib/model/fbc_param_configs.rb
23
+ - lib/release_config.rb
23
24
  homepage:
24
25
  licenses:
25
26
  - Nonstandard