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.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -1
- data/CHANGELOG.md +27 -3
- data/docker/Dockerfile.chromedriver +5 -0
- data/docker/entrypoint.sh +11 -1
- data/lib/bidi2pdf/bidi/add_headers_interceptor.rb +18 -21
- data/lib/bidi2pdf/bidi/auth_interceptor.rb +31 -38
- data/lib/bidi2pdf/bidi/browser_tab.rb +32 -52
- data/lib/bidi2pdf/bidi/client.rb +24 -52
- data/lib/bidi2pdf/bidi/command_manager.rb +50 -28
- data/lib/bidi2pdf/bidi/commands/add_intercept.rb +41 -0
- data/lib/bidi2pdf/bidi/commands/base.rb +73 -0
- data/lib/bidi2pdf/bidi/commands/browser_close.rb +15 -0
- data/lib/bidi2pdf/bidi/commands/browser_create_user_context.rb +15 -0
- data/lib/bidi2pdf/bidi/commands/browsing_context_close.rb +25 -0
- data/lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb +31 -0
- data/lib/bidi2pdf/bidi/commands/browsing_context_print.rb +28 -0
- data/lib/bidi2pdf/bidi/commands/cancel_auth.rb +26 -0
- data/lib/bidi2pdf/bidi/commands/create_tab.rb +11 -0
- data/lib/bidi2pdf/bidi/commands/create_window.rb +32 -0
- data/lib/bidi2pdf/bidi/commands/get_user_contexts.rb +15 -0
- data/lib/bidi2pdf/bidi/commands/network_continue.rb +29 -0
- data/lib/bidi2pdf/bidi/commands/print_parameters_validator.rb +116 -0
- data/lib/bidi2pdf/bidi/commands/provide_credentials.rb +33 -0
- data/lib/bidi2pdf/bidi/commands/script_evaluate.rb +33 -0
- data/lib/bidi2pdf/bidi/commands/session_end.rb +15 -0
- data/lib/bidi2pdf/bidi/commands/session_status.rb +15 -0
- data/lib/bidi2pdf/bidi/commands/session_subscribe.rb +25 -0
- data/lib/bidi2pdf/bidi/commands/set_tab_cookie.rb +63 -0
- data/lib/bidi2pdf/bidi/commands/set_usercontext_cookie.rb +67 -0
- data/lib/bidi2pdf/bidi/commands.rb +27 -0
- data/lib/bidi2pdf/bidi/connection_manager.rb +16 -13
- data/lib/bidi2pdf/bidi/event_manager.rb +2 -0
- data/lib/bidi2pdf/bidi/interceptor.rb +75 -0
- data/lib/bidi2pdf/bidi/network_events.rb +0 -1
- data/lib/bidi2pdf/bidi/session.rb +139 -65
- data/lib/bidi2pdf/bidi/user_context.rb +25 -31
- data/lib/bidi2pdf/bidi/web_socket_dispatcher.rb +2 -0
- data/lib/bidi2pdf/chromedriver_manager.rb +2 -1
- data/lib/bidi2pdf/cli.rb +1 -3
- data/lib/bidi2pdf/launcher.rb +3 -1
- data/lib/bidi2pdf/version.rb +1 -1
- data/lib/bidi2pdf.rb +12 -0
- data/sig/bidi2pdf/bidi/command_manager.rbs +41 -0
- data/sig/bidi2pdf/bidi/commands/add_intercept.rbs +21 -0
- data/sig/bidi2pdf/bidi/commands/base.rbs +27 -0
- data/sig/bidi2pdf/bidi/commands/browser_close.rbs +9 -0
- data/sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs +9 -0
- data/sig/bidi2pdf/bidi/commands/browsing_context_close.rbs +11 -0
- data/sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs +15 -0
- data/sig/bidi2pdf/bidi/commands/browsing_context_print.rbs +14 -0
- data/sig/bidi2pdf/bidi/commands/cancel_auth.rbs +11 -0
- data/sig/bidi2pdf/bidi/commands/create_tab.rbs +9 -0
- data/sig/bidi2pdf/bidi/commands/create_window.rbs +19 -0
- data/sig/bidi2pdf/bidi/commands/get_user_contexts.rbs +9 -0
- data/sig/bidi2pdf/bidi/commands/network_continue.rbs +19 -0
- data/sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs +53 -0
- data/sig/bidi2pdf/bidi/commands/provide_credentials.rbs +15 -0
- data/sig/bidi2pdf/bidi/commands/script_evaluate.rbs +17 -0
- data/sig/bidi2pdf/bidi/commands/session_end.rbs +9 -0
- data/sig/bidi2pdf/bidi/commands/session_status.rbs +9 -0
- data/sig/bidi2pdf/bidi/commands/session_subscribe.rbs +15 -0
- data/sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs +31 -0
- data/sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs +27 -0
- data/sig/bidi2pdf/bidi/commands.rbs +6 -0
- data/sig/bidi2pdf/bidi/connection_manager.rbs +17 -0
- data/sig/bidi2pdf/bidi/interceptor.rbs +31 -0
- data/tasks/coverage.rake +16 -0
- metadata +65 -11
- data/lib/bidi2pdf/bidi/print_parameters_validator.rb +0 -114
- data/sig/bidi2pdf/bidi/print_parameters_validator.rbs +0 -44
- data/sig/bidi2pdf/chrome/chromedriver_downloader.rbs +0 -11
- data/sig/bidi2pdf/chrome/downloader_helper.rbs +0 -9
- data/sig/bidi2pdf/chrome/finder.rbs +0 -27
- data/sig/bidi2pdf/chrome/platform.rbs +0 -13
- 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,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,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
|