capi_param_builder_ruby 1.0.1 → 1.1.1

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: 4a33297523bdd07b142d4a946e4b3134675aec7d95d3479dad27647e566e36e4
4
+ data.tar.gz: e62d98b35b46fd27adb878d736f8640c8cb589d437f94a7a19ab9d986eb2d38c
5
5
  SHA512:
6
- metadata.gz: 8aaa07d83a623a1f10cd4d34c73c55e6056fc20048006a0c263bd4fe372bb5ae6d2f476a91bd75db02a4a4b103a7d376793c16ae2474b476efb8d670de45166d
7
- data.tar.gz: 9919b3befd095f7bf7cbd88d8ccac7cc6c09ce86a60f8dbcf163beb2af1b22ad876ac5c82b80e03c89d41efdb518de27408ba6cba73d64e1055a9cdc1167c966
6
+ metadata.gz: 0c0a171eb5f541ca08f7a08c23f7505bdc5a00818668126698b440ea2268670f17bedefeadf10f2b6b89a9c504111a55b1050a2988180a12165c28e5e3cd5498
7
+ data.tar.gz: a44149e6a88bddb67c82239b9f680668fc54f73e4ed6fcc16c6748b541110c1086e9f639cfca24aca7ac701ec11568e45cb2a5e8dae92f5fd3c0c1fd5dc071ea
@@ -7,23 +7,39 @@
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
31
+
32
+ # Appendix type constants
33
+ APPENDIX_NO_CHANGE = 0x00
34
+ APPENDIX_GENERAL_NEW = 0x01
35
+ APPENDIX_NET_NEW = 0x02
36
+ APPENDIX_MODIFIED_NEW = 0x03
24
37
 
25
38
  def initialize(input = nil)
26
39
  @fbc_params_configs = [FbcParamConfigs.new("fbclid", "", "clickID")]
40
+ @appendix_net_new = get_appendix(APPENDIX_NET_NEW)
41
+ @appendix_modified_new = get_appendix(APPENDIX_MODIFIED_NEW)
42
+ @appendix_no_change = get_appendix(APPENDIX_NO_CHANGE)
27
43
 
28
44
  if input.nil?
29
45
  return
@@ -39,6 +55,45 @@ class ParamBuilder
39
55
  end
40
56
  end
41
57
 
58
+ private def get_appendix(appendix_type)
59
+ begin
60
+ version = ReleaseConfig::VERSION
61
+ version_parts = version.split(".")
62
+ major = version_parts[0].to_i
63
+ minor = version_parts[1].to_i
64
+ patch = version_parts[2].to_i
65
+
66
+ # Validate appendix type
67
+ valid_types = [APPENDIX_NET_NEW, APPENDIX_GENERAL_NEW, APPENDIX_MODIFIED_NEW]
68
+ if valid_types.include?(appendix_type)
69
+ type_byte = appendix_type
70
+ else
71
+ type_byte = APPENDIX_NO_CHANGE
72
+ end
73
+
74
+ # Create byte array
75
+ bytes_array = [
76
+ DEFAULT_FORMAT, # 0x01 = 1
77
+ LANGUAGE_TOKEN_INDEX, # 0x05 = 5
78
+ type_byte, # appendix type
79
+ major, # Major version number
80
+ minor, # Minor version number
81
+ patch # Patch version number
82
+ ]
83
+
84
+ # Convert to bytes and then to base64url-safe string
85
+ byte_data = bytes_array.pack("C*") # Pack as unsigned chars (bytes)
86
+ base64_encoded = Base64.encode64(byte_data).strip # Remove newlines
87
+ # Make it URL-safe by replacing characters
88
+ base64url_safe = base64_encoded.tr('+/', '-_').gsub(/=+$/, '')
89
+ return base64url_safe
90
+ rescue Exception => e
91
+ puts "Failed to parse version in appendix: #{e}"
92
+ return LANGUAGE_TOKEN # Fall back to original Ruby language token
93
+ end
94
+ end
95
+
96
+
42
97
  private def pre_process_cookies(cookies, cookie_name)
43
98
  # Sanity check
44
99
  if cookies.nil? || cookies[cookie_name].nil?
@@ -50,13 +105,19 @@ class ParamBuilder
50
105
  parts.size > MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH
51
106
  return nil
52
107
  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
108
+ if parts.size == MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH
109
+ appendix = parts[MAX_PAYLOAD_WITH_LANGUAGE_TOKEN_LENGTH - 1]
110
+ if appendix.size == APPENDIX_LENGTH_V1
111
+ if !SUPPORTED_LANGUAGE_TOKENS.include?(appendix)
112
+ return nil
113
+ end
114
+ elsif appendix.size != APPENDIX_LENGTH_V2
115
+ return nil
116
+ end
56
117
  end
57
118
  # Append language token if not present
58
119
  if parts.size == MIN_PAYLOAD_SPLIT_LENGTH
59
- updated_cookie_value = cookie_value + "." + LANGUAGE_TOKEN
120
+ updated_cookie_value = cookie_value + "." + @appendix_no_change
60
121
  @cookie_to_set_dict[cookie_name] = CookieSettings.new(
61
122
  cookie_name, updated_cookie_value, @etld_plus_one, DEFAULT_1PC_AGE)
62
123
  return updated_cookie_value
@@ -234,17 +295,26 @@ class ParamBuilder
234
295
  return nil
235
296
  end
236
297
 
298
+ cookie_update = false
299
+ is_net_new = false
237
300
  if existing_fbc.nil?
238
301
  cookie_update = true
302
+ is_net_new = true
239
303
  else
240
304
  parts = existing_fbc.split(/\./)
241
- cookie_update = new_fbc_payload != parts[3]
305
+ if parts.size < MIN_PAYLOAD_SPLIT_LENGTH
306
+ cookie_update = true
307
+ is_net_new = true
308
+ else
309
+ cookie_update = new_fbc_payload != parts[3]
310
+ end
242
311
  end
243
312
  if cookie_update == false
244
313
  return nil
245
314
  end
246
315
 
247
316
  current_ms = (Time.now.to_f * 1000).to_i.to_s
317
+ appendix = is_net_new ? @appendix_net_new : @appendix_modified_new
248
318
  new_fbc = "fb." +
249
319
  @sub_domain_index.to_s +
250
320
  "." +
@@ -252,7 +322,7 @@ class ParamBuilder
252
322
  "." +
253
323
  new_fbc_payload +
254
324
  "." +
255
- LANGUAGE_TOKEN
325
+ appendix
256
326
  updated_cookie_setting = CookieSettings.new(
257
327
  FBC_NAME, new_fbc, @etld_plus_one, DEFAULT_1PC_AGE)
258
328
  return updated_cookie_setting
@@ -271,7 +341,7 @@ class ParamBuilder
271
341
  "." +
272
342
  new_fbp_payload +
273
343
  "." +
274
- LANGUAGE_TOKEN
344
+ @appendix_net_new
275
345
  updated_cookie_setting = CookieSettings.new(
276
346
  FBP_NAME, new_fbp, @etld_plus_one, DEFAULT_1PC_AGE)
277
347
  return updated_cookie_setting
@@ -0,0 +1,8 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+ module ReleaseConfig
7
+ VERSION = "1.1.1"
8
+ 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.1
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: 2026-01-30 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