bidi2pdf 0.1.3 → 0.1.4

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +19 -1
  3. data/CHANGELOG.md +27 -3
  4. data/docker/Dockerfile.chromedriver +5 -0
  5. data/docker/entrypoint.sh +11 -1
  6. data/lib/bidi2pdf/bidi/add_headers_interceptor.rb +18 -21
  7. data/lib/bidi2pdf/bidi/auth_interceptor.rb +31 -38
  8. data/lib/bidi2pdf/bidi/browser_tab.rb +32 -52
  9. data/lib/bidi2pdf/bidi/client.rb +24 -52
  10. data/lib/bidi2pdf/bidi/command_manager.rb +50 -28
  11. data/lib/bidi2pdf/bidi/commands/add_intercept.rb +41 -0
  12. data/lib/bidi2pdf/bidi/commands/base.rb +73 -0
  13. data/lib/bidi2pdf/bidi/commands/browser_close.rb +15 -0
  14. data/lib/bidi2pdf/bidi/commands/browser_create_user_context.rb +15 -0
  15. data/lib/bidi2pdf/bidi/commands/browsing_context_close.rb +25 -0
  16. data/lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb +31 -0
  17. data/lib/bidi2pdf/bidi/commands/browsing_context_print.rb +28 -0
  18. data/lib/bidi2pdf/bidi/commands/cancel_auth.rb +26 -0
  19. data/lib/bidi2pdf/bidi/commands/create_tab.rb +11 -0
  20. data/lib/bidi2pdf/bidi/commands/create_window.rb +32 -0
  21. data/lib/bidi2pdf/bidi/commands/get_user_contexts.rb +15 -0
  22. data/lib/bidi2pdf/bidi/commands/network_continue.rb +29 -0
  23. data/lib/bidi2pdf/bidi/commands/print_parameters_validator.rb +116 -0
  24. data/lib/bidi2pdf/bidi/commands/provide_credentials.rb +33 -0
  25. data/lib/bidi2pdf/bidi/commands/script_evaluate.rb +33 -0
  26. data/lib/bidi2pdf/bidi/commands/session_end.rb +15 -0
  27. data/lib/bidi2pdf/bidi/commands/session_status.rb +15 -0
  28. data/lib/bidi2pdf/bidi/commands/session_subscribe.rb +25 -0
  29. data/lib/bidi2pdf/bidi/commands/set_tab_cookie.rb +63 -0
  30. data/lib/bidi2pdf/bidi/commands/set_usercontext_cookie.rb +67 -0
  31. data/lib/bidi2pdf/bidi/commands.rb +27 -0
  32. data/lib/bidi2pdf/bidi/connection_manager.rb +16 -13
  33. data/lib/bidi2pdf/bidi/event_manager.rb +2 -0
  34. data/lib/bidi2pdf/bidi/interceptor.rb +75 -0
  35. data/lib/bidi2pdf/bidi/network_events.rb +0 -1
  36. data/lib/bidi2pdf/bidi/session.rb +139 -65
  37. data/lib/bidi2pdf/bidi/user_context.rb +25 -31
  38. data/lib/bidi2pdf/bidi/web_socket_dispatcher.rb +2 -0
  39. data/lib/bidi2pdf/chromedriver_manager.rb +2 -1
  40. data/lib/bidi2pdf/cli.rb +1 -3
  41. data/lib/bidi2pdf/launcher.rb +3 -1
  42. data/lib/bidi2pdf/version.rb +1 -1
  43. data/lib/bidi2pdf.rb +12 -0
  44. data/sig/bidi2pdf/bidi/command_manager.rbs +41 -0
  45. data/sig/bidi2pdf/bidi/commands/add_intercept.rbs +21 -0
  46. data/sig/bidi2pdf/bidi/commands/base.rbs +27 -0
  47. data/sig/bidi2pdf/bidi/commands/browser_close.rbs +9 -0
  48. data/sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs +9 -0
  49. data/sig/bidi2pdf/bidi/commands/browsing_context_close.rbs +11 -0
  50. data/sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs +15 -0
  51. data/sig/bidi2pdf/bidi/commands/browsing_context_print.rbs +14 -0
  52. data/sig/bidi2pdf/bidi/commands/cancel_auth.rbs +11 -0
  53. data/sig/bidi2pdf/bidi/commands/create_tab.rbs +9 -0
  54. data/sig/bidi2pdf/bidi/commands/create_window.rbs +19 -0
  55. data/sig/bidi2pdf/bidi/commands/get_user_contexts.rbs +9 -0
  56. data/sig/bidi2pdf/bidi/commands/network_continue.rbs +19 -0
  57. data/sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs +53 -0
  58. data/sig/bidi2pdf/bidi/commands/provide_credentials.rbs +15 -0
  59. data/sig/bidi2pdf/bidi/commands/script_evaluate.rbs +17 -0
  60. data/sig/bidi2pdf/bidi/commands/session_end.rbs +9 -0
  61. data/sig/bidi2pdf/bidi/commands/session_status.rbs +9 -0
  62. data/sig/bidi2pdf/bidi/commands/session_subscribe.rbs +15 -0
  63. data/sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs +31 -0
  64. data/sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs +27 -0
  65. data/sig/bidi2pdf/bidi/commands.rbs +6 -0
  66. data/sig/bidi2pdf/bidi/connection_manager.rbs +17 -0
  67. data/sig/bidi2pdf/bidi/interceptor.rbs +31 -0
  68. data/tasks/coverage.rake +16 -0
  69. metadata +65 -11
  70. data/lib/bidi2pdf/bidi/print_parameters_validator.rb +0 -114
  71. data/sig/bidi2pdf/bidi/print_parameters_validator.rbs +0 -44
  72. data/sig/bidi2pdf/chrome/chromedriver_downloader.rbs +0 -11
  73. data/sig/bidi2pdf/chrome/downloader_helper.rbs +0 -9
  74. data/sig/bidi2pdf/chrome/finder.rbs +0 -27
  75. data/sig/bidi2pdf/chrome/platform.rbs +0 -13
  76. data/sig/bidi2pdf/chrome/version_resolver.rbs +0 -19
@@ -1,114 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bidi2pdf
4
- module Bidi
5
- # Validates parameters for the BiDi method `browsingContext.print`.
6
- #
7
- # Allowed structure of the params hash:
8
- #
9
- # {
10
- # background: Boolean (optional, default: false) – print background graphics,
11
- # margin: {
12
- # top: Float >= 0.0 (optional, default: 1.0),
13
- # bottom: Float >= 0.0 (optional, default: 1.0),
14
- # left: Float >= 0.0 (optional, default: 1.0),
15
- # right: Float >= 0.0 (optional, default: 1.0)
16
- # },
17
- # orientation: "portrait" or "landscape" (optional, default: "portrait"),
18
- # page: {
19
- # width: Float >= 0.0352 (optional, default: 21.59),
20
- # height: Float >= 0.0352 (optional, default: 27.94)
21
- # },
22
- # pageRanges: Array of Integers or Strings (optional),
23
- # scale: Float between 0.1 and 2.0 (optional, default: 1.0),
24
- # shrinkToFit: Boolean (optional, default: true)
25
- # }
26
- #
27
- # This validator checks presence, types, allowed ranges, and values,
28
- # and raises ArgumentError with a descriptive message if validation fails.
29
- class PrintParametersValidator
30
- def self.validate!(params)
31
- new(params).validate!
32
- end
33
-
34
- def initialize(params)
35
- @params = params
36
- end
37
-
38
- def validate!
39
- raise ArgumentError, "params must be a Hash" unless @params.is_a?(Hash)
40
-
41
- validate_boolean(:background)
42
- validate_boolean(:shrinkToFit)
43
- validate_orientation
44
- validate_scale
45
- validate_page_ranges
46
- validate_margin
47
- validate_page_size
48
-
49
- true
50
- end
51
-
52
- private
53
-
54
- def validate_boolean(key)
55
- return unless @params.key?(key)
56
- return if [true, false].include?(@params[key])
57
-
58
- raise ArgumentError, ":#{key} must be a boolean"
59
- end
60
-
61
- def validate_orientation
62
- return unless @params.key?(:orientation)
63
- return if %w[portrait landscape].include?(@params[:orientation])
64
-
65
- raise ArgumentError, ":orientation must be 'portrait' or 'landscape'"
66
- end
67
-
68
- def validate_scale
69
- return unless @params.key?(:scale)
70
-
71
- scale = @params[:scale]
72
- return if scale.is_a?(Numeric) && scale >= 0.1 && scale <= 2.0
73
-
74
- raise ArgumentError, ":scale must be a number between 0.1 and 2.0"
75
- end
76
-
77
- def validate_page_ranges
78
- return unless @params.key?(:pageRanges)
79
- unless @params[:pageRanges].is_a?(Array) &&
80
- @params[:pageRanges].all? { |v| v.is_a?(Integer) || v.is_a?(String) }
81
- raise ArgumentError, ":pageRanges must be an array of integers or strings"
82
- end
83
- end
84
-
85
- def validate_margin
86
- return unless @params.key?(:margin)
87
-
88
- margin = @params[:margin]
89
- raise ArgumentError, ":margin must be a Hash" unless margin.is_a?(Hash)
90
-
91
- %i[top bottom left right].each do |side|
92
- next unless margin.key?(side)
93
-
94
- val = margin[side]
95
- raise ArgumentError, "margin[:#{side}] must be a float >= 0.0" unless val.is_a?(Numeric) && val >= 0.0
96
- end
97
- end
98
-
99
- def validate_page_size
100
- return unless @params.key?(:page)
101
-
102
- page = @params[:page]
103
- raise ArgumentError, ":page must be a Hash" unless page.is_a?(Hash)
104
-
105
- %i[width height].each do |dim|
106
- next unless page.key?(dim)
107
-
108
- val = page[dim]
109
- raise ArgumentError, "page[:#{dim}] must be a float >= 0.0352" unless val.is_a?(Numeric) && val >= 0.0352
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,44 +0,0 @@
1
- module Bidi2pdf
2
- module Bidi
3
- class PrintParametersValidator
4
- # Valid print parameter configurations
5
- DEFAULT_PARAMETERS: Hash[Symbol, untyped]
6
- ALLOWED_PAGE_RANGES_FORMATS: Array[String]
7
- ALLOWED_MARGIN_UNITS: Array[String]
8
- ALLOWED_PAPER_FORMATS: Array[String]
9
- ALLOWED_ORIENTATIONS: Array[String]
10
-
11
- @parameters: Hash[Symbol, untyped]
12
- @errors: Array[String]
13
-
14
- attr_reader errors: Array[String]
15
- attr_reader parameters: Hash[Symbol, untyped]
16
-
17
- def initialize: (Hash[Symbol, untyped] parameters) -> void
18
-
19
- def validate: () -> bool
20
-
21
- def valid?: () -> bool
22
-
23
- private
24
-
25
- def validate_boolean: (Symbol key) -> void
26
-
27
- def validate_number: (Symbol key, ?min: Numeric?, ?max: Numeric?) -> void
28
-
29
- def validate_string: (Symbol key) -> void
30
-
31
- def validate_enum: (Symbol key, Array[String] allowed_values) -> void
32
-
33
- def validate_margins: () -> void
34
-
35
- def validate_page_ranges: () -> void
36
-
37
- def validate_paper_size: () -> void
38
-
39
- def normalize_parameters: () -> void
40
-
41
- def add_error: (String message) -> void
42
- end
43
- end
44
- end
@@ -1,11 +0,0 @@
1
- module Bidi2pdf
2
- module Chrome
3
- class ChromedriverDownloader
4
- def self.install_dir: -> String
5
-
6
- def self.target: -> String
7
-
8
- def self.update: -> String
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module Bidi2pdf
2
- module Chrome
3
- module DownloaderHelper
4
- def download_file: (String url, String destination) -> nil
5
-
6
- def extract_zip: (String zip_file, String destination) -> nil
7
- end
8
- end
9
- end
@@ -1,27 +0,0 @@
1
- module Bidi2pdf
2
- module Chrome
3
- class Finder
4
- def self.location: -> String
5
-
6
- def self.version: -> String
7
-
8
- def self.win_location: -> String
9
-
10
- def self.mac_location: -> String
11
-
12
- def self.linux_location: -> String
13
-
14
- def self.win_version: (String location) -> String
15
-
16
- def self.linux_version: (String location) -> String
17
-
18
- def self.mac_version: (String location) -> String
19
-
20
- def self.call: (String process, Array[String] arg) -> String
21
-
22
- private
23
-
24
- def self.find_in_paths: -> String
25
- end
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- module Bidi2pdf
2
- module Chrome
3
- module Platform
4
- def platform: -> String
5
-
6
- def platform_id: -> String
7
-
8
- def driver_filename: -> String
9
-
10
- def file_name: -> String
11
- end
12
- end
13
- end
@@ -1,19 +0,0 @@
1
- module Bidi2pdf
2
- module Chrome
3
- module VersionResolver
4
- def browser_build_version: -> Gem::Version
5
-
6
- def browser_version: -> Gem::Version
7
-
8
- def direct_url_from_api: (_ToS driver_version, String driver_filename) -> String
9
-
10
- def latest_patch_version_for_build: -> String
11
-
12
- def normalize_version: (_ToS version) -> Gem::Version
13
-
14
- private
15
-
16
- def fetch_data: (String json_file) -> String
17
- end
18
- end
19
- end