bidi2pdf 0.1.13 → 0.1.14

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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +53 -0
  3. data/.devcontainer/devcontainer.json +51 -0
  4. data/.devcontainer/docker-compose.yml +33 -0
  5. data/.ruby-gemset +1 -1
  6. data/.ruby-version +1 -1
  7. data/CHANGELOG.md +46 -6
  8. data/README.md +12 -0
  9. data/docker/Dockerfile +1 -1
  10. data/docker/Dockerfile.slim +2 -2
  11. data/docker/chrome-driver/chrome.json +874 -0
  12. data/lib/bidi2pdf/bidi/browser_tab.rb +52 -0
  13. data/lib/bidi2pdf/bidi/commands/capture_screenshot.rb +33 -0
  14. data/lib/bidi2pdf/bidi/commands/set_viewport.rb +32 -0
  15. data/lib/bidi2pdf/bidi/commands.rb +2 -0
  16. data/lib/bidi2pdf/cli.rb +11 -1
  17. data/lib/bidi2pdf/launcher.rb +5 -3
  18. data/lib/bidi2pdf/test_helpers/images.rb +8 -0
  19. data/lib/bidi2pdf/test_helpers/pdf_reader_utils.rb +1 -2
  20. data/lib/bidi2pdf/test_helpers/pdf_text_sanitizer.rb +1 -2
  21. data/lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb +1 -1
  22. data/lib/bidi2pdf/test_helpers/testcontainers/chromedriver_test_helper.rb +18 -0
  23. data/lib/bidi2pdf/test_helpers/testcontainers/container_endpoint.rb +30 -0
  24. data/lib/bidi2pdf/test_helpers/testcontainers/testcontainers_refinement.rb +33 -0
  25. data/lib/bidi2pdf/test_helpers/testcontainers.rb +1 -0
  26. data/lib/bidi2pdf/version.rb +1 -1
  27. data/lib/bidi2pdf.rb +2 -0
  28. data/sig/bidi2pdf/bidi/add_headers_interceptor.rbs +16 -9
  29. data/sig/bidi2pdf/bidi/auth_interceptor.rbs +32 -7
  30. data/sig/bidi2pdf/bidi/browser.rbs +4 -31
  31. data/sig/bidi2pdf/bidi/browser_console_logger.rbs +59 -0
  32. data/sig/bidi2pdf/bidi/browser_tab.rbs +252 -25
  33. data/sig/bidi2pdf/bidi/client.rbs +95 -43
  34. data/sig/bidi2pdf/bidi/command_manager.rbs +5 -17
  35. data/sig/bidi2pdf/bidi/commands/add_intercept.rbs +16 -8
  36. data/sig/bidi2pdf/bidi/commands/base.rbs +49 -9
  37. data/sig/bidi2pdf/bidi/commands/browser_close.rbs +3 -1
  38. data/sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs +2 -0
  39. data/sig/bidi2pdf/bidi/commands/browser_remove_user_context.rbs +19 -0
  40. data/sig/bidi2pdf/bidi/commands/browsing_context_close.rbs +8 -2
  41. data/sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs +12 -6
  42. data/sig/bidi2pdf/bidi/commands/browsing_context_print.rbs +10 -5
  43. data/sig/bidi2pdf/bidi/commands/cancel_auth.rbs +8 -2
  44. data/sig/bidi2pdf/bidi/commands/capture_screenshot.rbs +31 -0
  45. data/sig/bidi2pdf/bidi/commands/cdp_get_session.rbs +17 -0
  46. data/sig/bidi2pdf/bidi/commands/create_window.rbs +4 -0
  47. data/sig/bidi2pdf/bidi/commands/get_user_contexts.rbs +2 -0
  48. data/sig/bidi2pdf/bidi/commands/network_continue.rbs +4 -0
  49. data/sig/bidi2pdf/bidi/commands/page_print.rbs +28 -0
  50. data/sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs +3 -0
  51. data/sig/bidi2pdf/bidi/commands/provide_credentials.rbs +12 -6
  52. data/sig/bidi2pdf/bidi/commands/script_evaluate.rbs +4 -0
  53. data/sig/bidi2pdf/bidi/commands/session_end.rbs +2 -0
  54. data/sig/bidi2pdf/bidi/commands/session_status.rbs +3 -1
  55. data/sig/bidi2pdf/bidi/commands/session_subscribe.rbs +4 -0
  56. data/sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs +51 -23
  57. data/sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs +17 -19
  58. data/sig/bidi2pdf/bidi/commands/set_viewport.rbs +31 -0
  59. data/sig/bidi2pdf/bidi/connection_manager.rbs +2 -1
  60. data/sig/bidi2pdf/bidi/event_manager.rbs +14 -19
  61. data/sig/bidi2pdf/bidi/interceptor.rbs +5 -0
  62. data/sig/bidi2pdf/bidi/js_logger_helper.rbs +9 -0
  63. data/sig/bidi2pdf/bidi/logger_events.rbs +21 -0
  64. data/sig/bidi2pdf/bidi/navigation_failed_events.rbs +17 -0
  65. data/sig/bidi2pdf/bidi/network_event.rbs +54 -46
  66. data/sig/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rbs +63 -0
  67. data/sig/bidi2pdf/bidi/network_event_formatters/network_event_formatter_utils.rbs +15 -0
  68. data/sig/bidi2pdf/bidi/network_event_formatters/network_event_html_formatter.rbs +18 -0
  69. data/sig/bidi2pdf/bidi/network_event_formatters.rbs +6 -0
  70. data/sig/bidi2pdf/bidi/network_events.rbs +14 -39
  71. data/sig/bidi2pdf/bidi/session.rbs +144 -31
  72. data/sig/bidi2pdf/bidi/user_context.rbs +64 -45
  73. data/sig/bidi2pdf/bidi/web_socket_dispatcher.rbs +22 -30
  74. data/sig/bidi2pdf/chromedriver_manager.rbs +57 -22
  75. data/sig/bidi2pdf/cli.rbs +22 -2
  76. data/sig/bidi2pdf/dsl.rbs +34 -0
  77. data/sig/bidi2pdf/launcher.rbs +39 -1
  78. data/sig/bidi2pdf/notifications/event.rbs +40 -0
  79. data/sig/bidi2pdf/notifications/instrumenter.rbs +21 -0
  80. data/sig/bidi2pdf/notifications/logging_subscriber.rbs +41 -0
  81. data/sig/bidi2pdf/notifications.rbs +24 -0
  82. data/sig/bidi2pdf/process_tree.rbs +2 -2
  83. data/sig/bidi2pdf/session_runner.rbs +41 -1
  84. data/sig/bidi2pdf/test_helpers/configuration.rbs +51 -0
  85. data/sig/bidi2pdf/test_helpers/images/extractor.rbs +43 -0
  86. data/sig/bidi2pdf/test_helpers/images/image_similarity_checker.rbs +35 -0
  87. data/sig/bidi2pdf/test_helpers/images/tiff_helper.rbs +70 -0
  88. data/sig/bidi2pdf/test_helpers/images.rbs +0 -0
  89. data/sig/bidi2pdf/test_helpers/matchers/contains_pdf_image.rbs +0 -0
  90. data/sig/bidi2pdf/test_helpers/matchers/contains_pdf_text.rbs +0 -0
  91. data/sig/bidi2pdf/test_helpers/matchers/have_pdf_page_count.rbs +0 -0
  92. data/sig/bidi2pdf/test_helpers/matchers/match_pdf_text.rbs +0 -0
  93. data/sig/bidi2pdf/test_helpers/pdf_file_helper.rbs +23 -0
  94. data/sig/bidi2pdf/test_helpers/pdf_reader_utils.rbs +49 -0
  95. data/sig/bidi2pdf/test_helpers/pdf_text_sanitizer.rbs +38 -0
  96. data/sig/bidi2pdf/test_helpers/spec_paths_helper.rbs +35 -0
  97. data/sig/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rbs +43 -0
  98. data/sig/bidi2pdf/test_helpers/testcontainers/chromedriver_test_helper.rbs +45 -0
  99. data/sig/bidi2pdf/test_helpers/testcontainers/container_endpoint.rbs +25 -0
  100. data/sig/bidi2pdf/test_helpers/testcontainers/shared_docker_network.rbs +3 -0
  101. data/sig/bidi2pdf/test_helpers/testcontainers/testcontainers_refinement.rbs +47 -0
  102. data/sig/bidi2pdf/test_helpers/testcontainers.rbs +6 -0
  103. data/sig/bidi2pdf/test_helpers.rbs +0 -0
  104. data/sig/bidi2pdf/verbose_logger.rbs +37 -0
  105. data/sig/bidi2pdf/version.rbs +3 -0
  106. data/sig/bidi2pdf.rbs +112 -2
  107. data/tasks/generate_rbs.rake +11 -11
  108. metadata +59 -7
  109. data/sig/bidi2pdf/utils.rbs +0 -5
@@ -1,53 +1,45 @@
1
1
  module Bidi2pdf
2
2
  module Bidi
3
3
  class WebSocketDispatcher
4
- @url: String
5
- @socket: WebSocket::Driver
6
- @connection: TCPSocket
7
- @pending_requests: Hash[Integer, Concurrent::Promises::ResolvableFuture]
8
- @message_id: Integer
9
- @listeners: Hash[String, Array[Proc]]
10
- @thread: Thread?
11
- @mutex: Mutex
12
- @connected: bool
13
- @logger: Logger?
4
+ @socket: untyped
14
5
 
15
- attr_reader url: String
16
- attr_reader connected: bool
6
+ @socket_events: untyped
17
7
 
18
- def initialize: (String url, ?logger: Logger?) -> void
8
+ @session_events: untyped
19
9
 
20
- def connect: () -> bool
10
+ attr_reader socket_events: untyped
21
11
 
22
- def disconnect: () -> void
12
+ attr_reader session_events: untyped
23
13
 
24
- def send_command: [T] (String method, ?Hash[Symbol, untyped] params) -> T
14
+ def initialize: (untyped socket) -> void
25
15
 
26
- def send_message: (Hash[Symbol, untyped] message) -> Integer
16
+ def start_listening: () -> untyped
27
17
 
28
- def add_event_listener: (String event_name) { (Hash[String, untyped]) -> void } -> void
18
+ def on_message: () { (?) -> untyped } -> untyped
29
19
 
30
- def remove_event_listener: (String event_name, ?Proc? callback) -> void
20
+ def on_event: (*untyped event_names) { (?) -> untyped } -> untyped
31
21
 
32
- def connected?: () -> bool
22
+ def on_open: () { (?) -> untyped } -> untyped
33
23
 
34
- private
24
+ def on_close: () { (?) -> untyped } -> untyped
25
+
26
+ def on_error: () { (?) -> untyped } -> untyped
35
27
 
36
- def generate_message_id: () -> Integer
28
+ def remove_message_listener: (untyped block) -> untyped
37
29
 
38
- def create_socket: () -> WebSocket::Driver
30
+ def remove_event_listener: (untyped name, untyped listener) -> untyped
39
31
 
40
- def handle_open: () -> void
32
+ def remove_open_listener: (untyped listener) -> untyped
41
33
 
42
- def handle_message: (String data) -> void
34
+ def remove_close_listener: (untyped listener) -> untyped
43
35
 
44
- def handle_close: () -> void
36
+ def remove_error_listener: (untyped listener) -> untyped
45
37
 
46
- def handle_error: (Exception error) -> void
38
+ private
47
39
 
48
- def dispatch_event: (String event_name, Hash[String, untyped] params) -> void
40
+ def setup_message_handler: () -> untyped
49
41
 
50
- def listen_for_messages: () -> void
42
+ def setup_connection_lifecycle_handlers: () -> untyped
51
43
  end
52
44
  end
53
- end
45
+ end
@@ -1,42 +1,77 @@
1
1
  module Bidi2pdf
2
2
  class ChromedriverManager
3
- @port: Integer
4
- @headless: bool
3
+ @port: untyped
4
+
5
+ @headless: untyped
6
+
5
7
  @session: untyped
6
- @pid: Integer?
7
8
 
8
- attr_reader port: Integer
9
- attr_reader pid: Integer?
10
- attr_reader session: untyped
9
+ @started: untyped
10
+
11
+ @chrome_args: untyped
12
+
13
+ @shutdown_mutex: untyped
14
+
15
+ @pid: untyped
16
+
17
+ include Chromedriver::Binary::Platform
18
+
19
+ attr_reader port: untyped
20
+
21
+ attr_reader pid: untyped
22
+
23
+ attr_reader started: untyped
24
+
25
+ attr_reader headless: untyped
11
26
 
12
- def initialize: (?port: Integer, ?headless: bool) -> void
27
+ attr_reader chrome_args: untyped
13
28
 
14
- def start: () -> self
29
+ attr_reader shutdown_mutex: untyped
15
30
 
16
- def stop: (?timeout: Integer) -> bool
31
+ attr_accessor reader_thread: untyped
32
+
33
+ def initialize: (?port: ::Integer, ?headless: bool, ?chrome_args: untyped) -> void
34
+
35
+ def start: () -> untyped
36
+
37
+ def session: () -> (nil | untyped)
38
+
39
+ def session_url: () -> (nil | ::String)
40
+
41
+ # rubocop: disable Metrics/AbcSize
42
+ def stop: (?timeout: ::Integer) -> untyped
17
43
 
18
44
  private
19
45
 
20
- # rubocop:disable Metrics/AbcSize
21
- def detect_zombie_processes: () -> Array[Integer]?
46
+ def spawn_process: (untyped cmd) -> untyped
47
+
48
+ def detect_zombie_processes: (untyped old_childprocesses) -> (nil | untyped)
49
+
50
+ def term_zombie_processes: (untyped zombie_processes) -> untyped
51
+
52
+ def debug_show_all_children: () -> untyped
53
+
54
+ def close_session: () -> untyped
55
+
56
+ def term_chromedriver: () -> untyped
22
57
 
23
- def debug_show_all_children: () -> void
58
+ def kill_chromedriver: (?timeout: ::Integer) -> untyped
24
59
 
25
- def close_session: () -> void
60
+ def build_cmd: () -> untyped
26
61
 
27
- def term_chromedriver: () -> bool
62
+ def chromedriver_log_level: () -> untyped
28
63
 
29
- def kill_chromedriver: (?timeout: Integer) -> bool
64
+ def user_data_dir_arg: () -> (untyped | ::String)
30
65
 
31
- def build_cmd: () -> Array[String]
66
+ def process_chrome_args: () -> (::Array[untyped] | untyped)
32
67
 
33
- def update_chromedriver: () -> void
68
+ def update_chromedriver: () -> untyped
34
69
 
35
- # rubocop:disable Metrics/AbcSize
36
- def parse_port_from_output: (IO io, ?timeout: Integer) -> Integer?
70
+ # rubocop: disable Metrics/AbcSize
71
+ def parse_port_from_output: (untyped io, ?timeout: ::Integer) -> (nil | untyped)
37
72
 
38
- def process_alive?: (?pid: Integer?) -> bool
73
+ def process_alive?: (?untyped pid) -> (false | untyped)
39
74
 
40
- def wait_until_chromedriver_ready: (?timeout: Integer) -> bool
75
+ def wait_until_chromedriver_ready: (?timeout: ::Integer) -> (true | untyped)
41
76
  end
42
- end
77
+ end
data/sig/bidi2pdf/cli.rbs CHANGED
@@ -1,13 +1,31 @@
1
1
  module Bidi2pdf
2
+ # rubocop:disable Metrics/AbcSize
2
3
  class CLI < Thor
3
- # rubocop:disable Layout/BeginEndAlignment
4
4
  @launcher: untyped
5
5
 
6
+ def self.exit_on_failure?: () -> true
7
+
6
8
  def render: () -> untyped
7
9
 
10
+ def version: () -> untyped
11
+
12
+ def template: () -> untyped
13
+
8
14
  private
9
15
 
10
- # rubocop:disable Metrics/AbcSize
16
+ def load_config: () -> (nil | untyped)
17
+
18
+ def validate_required_options!: () -> (untyped | untyped | nil)
19
+
20
+ def validate_print_options: (untyped opts) -> untyped
21
+
22
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
23
+ def print_options: () -> untyped
24
+
25
+ def option_provided?: (untyped key) -> untyped
26
+
27
+ def assign_if_provided: (untyped hash, untyped key, ?untyped option_key) -> (untyped | nil)
28
+
11
29
  def launcher: () -> untyped
12
30
 
13
31
  def configure: () -> untyped
@@ -17,5 +35,7 @@ module Bidi2pdf
17
35
  def parse_key_values: (untyped pairs) -> untyped
18
36
 
19
37
  def parse_auth: (untyped auth_string) -> ::Array[untyped]
38
+
39
+ def merged_options: () -> untyped
20
40
  end
21
41
  end
@@ -0,0 +1,34 @@
1
+ module Bidi2pdf
2
+ module DSL
3
+ # rubocop: disable Metrics/AbcSize
4
+ #
5
+ # Executes a block of code within the context of a browser tab.
6
+ #
7
+ # This method handles the setup and teardown of a browser session, user context,
8
+ # browser window, and tab. It ensures that resources are properly cleaned up
9
+ # after the block is executed.
10
+ #
11
+ # @param [String, nil] remote_browser_url The URL of a remote browser to connect to.
12
+ # If provided, the session will connect to this browser in headless mode.
13
+ # @param [Integer] port The port to use for the local browser session. Defaults to 0 (chooses a random port).
14
+ # @param [Boolean] headless Whether to run the browser in headless mode. Defaults to true.
15
+ # @param [Array<String>] chrome_args Additional arguments to pass to the Chrome browser.
16
+ # Defaults to the `DEFAULT_CHROME_ARGS` from the `Bidi2pdf::Bidi::Session` class.
17
+ #
18
+ # @yield [tab] The browser tab created within the session.
19
+ # @yieldparam [Object] tab The browser tab object.
20
+ #
21
+ # @example Using a local browser session
22
+ # Bidi2pdf::DSL.with_tab(port: 9222, headless: false) do |tab|
23
+ # # Perform actions with the tab
24
+ # end
25
+ #
26
+ # @example Using a remote browser session
27
+ # Bidi2pdf::DSL.with_tab(remote_browser_url: "http://remote-browser:9222/session") do |tab|
28
+ # # Perform actions with the tab
29
+ # end
30
+ #
31
+ # @return [void]
32
+ def self.with_tab: (?remote_browser_url: untyped?, ?port: ::Integer, ?headless: bool, ?chrome_args: untyped) { (untyped) -> untyped } -> untyped
33
+ end
34
+ end
@@ -1,7 +1,39 @@
1
1
  module Bidi2pdf
2
+ # Represents a launcher for managing browser sessions and executing tasks
3
+ # using the Bidi2pdf library. This class handles the setup and teardown
4
+ # of browser sessions, as well as the execution of tasks within those sessions.
5
+ #
6
+ # @example Launching a session
7
+ # launcher = Bidi2pdf::Launcher.new(
8
+ # url: "http://example.com",
9
+ # inputfile: "input.pdf",
10
+ # output: "output.pdf",
11
+ # cookies: [],
12
+ # headers: {},
13
+ # auth: nil,
14
+ # headless: true
15
+ # )
16
+ # launcher.launch
17
+ # launcher.stop
18
+ #
19
+ # @param [String] url The URL to navigate to in the browser session.
20
+ # @param [String] inputfile The path to the input file to be processed.
21
+ # @param [String] output The path to the output file to be generated.
22
+ # @param [Array<Hash>] cookies An array of cookies to set in the browser session.
23
+ # @param [Hash] headers A hash of HTTP headers to include in the browser session.
24
+ # @param [Hash, nil] auth Authentication credentials (e.g., username and password).
25
+ # @param [Boolean] headless Whether to run the browser in headless mode. Defaults to true.
26
+ # @param [Integer] port The port to use for the browser session. Defaults to 0.
27
+ # @param [Boolean] wait_window_loaded Whether to wait for the window to fully load. Defaults to false.
28
+ # @param [Boolean] wait_network_idle Whether to wait for the network to become idle. Defaults to false.
29
+ # @param [Hash] print_options Options for printing the page. Defaults to an empty hash.
30
+ # @param [String, nil] remote_browser_url The URL of a remote browser to connect to. Defaults to nil.
31
+ # @param [Symbol] network_log_format The format for network logs. Defaults to :console.
2
32
  class Launcher
3
33
  @url: untyped
4
34
 
35
+ @inputfile: untyped
36
+
5
37
  @port: untyped
6
38
 
7
39
  @headless: untyped
@@ -24,8 +56,14 @@ module Bidi2pdf
24
56
 
25
57
  @remote_browser_url: untyped
26
58
 
59
+ @custom_session: untyped
60
+
61
+ @network_log_format: untyped
62
+
63
+ @chrome_args: untyped
64
+
27
65
  # rubocop:disable Metrics/ParameterLists
28
- def initialize: (url: untyped, output: untyped, cookies: untyped, headers: untyped, auth: untyped, ?headless: bool, ?port: ::Integer, ?wait_window_loaded: bool, ?wait_network_idle: bool, ?print_options: ::Hash[untyped, untyped], ?remote_browser_url: untyped?) -> void
66
+ def initialize: (url: untyped, inputfile: untyped, output: untyped, cookies: untyped, headers: untyped, auth: untyped, ?headless: bool, ?port: ::Integer, ?wait_window_loaded: bool, ?wait_network_idle: bool, ?print_options: ::Hash[untyped, untyped], ?remote_browser_url: untyped?, ?network_log_format: ::Symbol, ?chrome_args: untyped) -> void
29
67
 
30
68
  def launch: () -> untyped
31
69
 
@@ -0,0 +1,40 @@
1
+ module Bidi2pdf
2
+ # rubocop: disable Lint/RescueException
3
+ module Notifications
4
+ class Event
5
+ @name: untyped
6
+
7
+ @payload: untyped
8
+
9
+ @time: untyped
10
+
11
+ @transaction_id: untyped
12
+
13
+ @end: untyped
14
+
15
+ attr_reader name: untyped
16
+
17
+ attr_reader transaction_id: untyped
18
+
19
+ attr_accessor payload: untyped
20
+
21
+ def initialize: (untyped name, untyped start, untyped ending, untyped transaction_id, untyped payload) -> void
22
+
23
+ def record: () ?{ (untyped) -> untyped } -> untyped
24
+
25
+ def start!: () -> untyped
26
+
27
+ def finish!: () -> untyped
28
+
29
+ def duration: () -> untyped
30
+
31
+ def time: () -> (untyped | nil)
32
+
33
+ def end: () -> (untyped | nil)
34
+
35
+ private
36
+
37
+ def now: () -> untyped
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ module Bidi2pdf
2
+ # rubocop: disable Lint/RescueException, Lint/SuppressedException
3
+ module Notifications
4
+ class Instrumenter
5
+ @id: untyped
6
+
7
+ attr_reader id: untyped
8
+
9
+ def initialize: () -> void
10
+
11
+ def notify: (untyped name, untyped payload) { (?) -> untyped } -> untyped
12
+
13
+ private
14
+
15
+ def create_event: (untyped name, untyped payload) -> untyped
16
+
17
+ # rubocop:disable Style/CaseEquality
18
+ def notify_subscribers: (untyped name, untyped event) -> untyped
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ module Bidi2pdf
2
+ module Notifications
3
+ # for reuse within ActiveSupport::LogSubscriber
4
+ module LoggingSubscriberActions
5
+ def handle_response: (untyped event) -> untyped
6
+
7
+ def send_cmd: (untyped event) -> untyped
8
+
9
+ def send_cmd_and_wait: (untyped event) -> (nil | untyped)
10
+
11
+ def session_close: (untyped event) -> (nil | untyped)
12
+
13
+ # rubocop: disable Metrics/AbcSize
14
+ def network_event_received: (untyped event) -> (nil | untyped)
15
+
16
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
17
+ def network_idle: (untyped event) -> (nil | untyped)
18
+
19
+ def page_loaded: (untyped event) -> untyped
20
+
21
+ def print: (untyped event) -> untyped
22
+
23
+ private
24
+
25
+ def redact_sensitive_fields: (untyped obj, ?::Array[untyped] sensitive_keys) -> untyped
26
+ end
27
+
28
+ class LoggingSubscriber
29
+ @logger: untyped
30
+
31
+ include LoggingSubscriberActions
32
+
33
+ attr_accessor logger: untyped
34
+
35
+ # rubocop: disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
36
+ def initialize: (?logger: untyped) -> void
37
+
38
+ def unsubscribe: () -> untyped
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module Bidi2pdf
2
+ module Notifications
3
+ self.@subscribers: untyped
4
+
5
+ attr_reader self.subscribers: untyped
6
+
7
+ def self.instrument: (untyped name, ?::Hash[untyped, untyped] payload) ?{ (untyped) -> untyped } -> untyped
8
+
9
+ def self.subscribe: (untyped event_pattern) { (?) -> untyped } -> untyped
10
+
11
+ def self.unsubscribe: (untyped event_pattern, ?untyped? block) -> untyped
12
+
13
+ # rubocop: disable Style/CaseEquality
14
+ def self.listening?: (untyped name) -> untyped
15
+
16
+ private
17
+
18
+ def self.bidi2pdf_notification_instrumenter: () -> untyped
19
+
20
+ def self.notify: (untyped name, untyped payload) { (?) -> untyped } -> untyped
21
+
22
+ def self.normalize_pattern: (untyped pat) -> untyped
23
+ end
24
+ end
@@ -10,7 +10,7 @@ module Bidi2pdf
10
10
 
11
11
  def children: (untyped of_pid) -> (::Array[untyped] | untyped)
12
12
 
13
- def traverse: () { () -> untyped } -> untyped
13
+ def traverse: () { (?) -> untyped } -> untyped
14
14
 
15
15
  private
16
16
 
@@ -22,6 +22,6 @@ module Bidi2pdf
22
22
 
23
23
  def root_pids: () -> (::Array[untyped] | untyped)
24
24
 
25
- def traverse_branch: (untyped pid, ?::Integer level) { () -> untyped } -> (nil | untyped)
25
+ def traverse_branch: (untyped pid, ?::Integer level) { (?) -> untyped } -> (nil | untyped)
26
26
  end
27
27
  end
@@ -1,9 +1,43 @@
1
1
  module Bidi2pdf
2
+ # Represents a runner for managing browser sessions and executing tasks
3
+ # using the Bidi2pdf library. This class handles the setup, configuration,
4
+ # and execution of browser-related workflows, including navigation, cookie
5
+ # management, and printing.
6
+ #
7
+ # @example Running a session
8
+ # session_runner = Bidi2pdf::SessionRunner.new(
9
+ # session: session,
10
+ # url: "http://example.com",
11
+ # inputfile: "input.html",
12
+ # output: "output.pdf",
13
+ # cookies: { "key" => "value" },
14
+ # headers: { "Authorization" => "Bearer token" },
15
+ # auth: { username: "user", password: "pass" },
16
+ # wait_window_loaded: true,
17
+ # wait_network_idle: true,
18
+ # print_options: { landscape: true },
19
+ # network_log_format: :json
20
+ # )
21
+ # session_runner.run
22
+ #
23
+ # @param [Object] session The browser session object to use.
24
+ # @param [String, nil] url The URL to navigate to in the browser session.
25
+ # @param [String, nil] inputfile The path to the input file to be processed if no URL is provided.
26
+ # @param [String, nil] output The path to the output file to be generated.
27
+ # @param [Hash] cookies A hash of cookies to set in the browser session. Defaults to an empty hash.
28
+ # @param [Hash] headers A hash of HTTP headers to include in the browser session. Defaults to an empty hash.
29
+ # @param [Hash, nil] auth Authentication credentials (e.g., username and password). Defaults to an empty hash.
30
+ # @param [Boolean] wait_window_loaded Whether to wait for the window to fully load. Defaults to false.
31
+ # @param [Boolean] wait_network_idle Whether to wait for the network to become idle. Defaults to false.
32
+ # @param [Hash] print_options Options for printing the page. Defaults to an empty hash.
33
+ # @param [Symbol] network_log_format The format for network logs. Defaults to :console.
2
34
  class SessionRunner
3
35
  @session: untyped
4
36
 
5
37
  @url: untyped
6
38
 
39
+ @inputfile: untyped
40
+
7
41
  @output: untyped
8
42
 
9
43
  @cookies: untyped
@@ -18,13 +52,18 @@ module Bidi2pdf
18
52
 
19
53
  @print_options: untyped
20
54
 
55
+ @network_log_format: untyped
56
+
21
57
  @window: untyped
22
58
 
23
59
  @tab: untyped
24
60
 
61
+ @user_context: untyped
62
+
25
63
  @uri: untyped
26
64
 
27
- def initialize: (session: untyped, url: untyped, output: untyped, ?cookies: ::Hash[untyped, untyped], ?headers: ::Hash[untyped, untyped], ?auth: ::Hash[untyped, untyped], ?wait_window_loaded: bool, ?wait_network_idle: bool, ?print_options: ::Hash[untyped, untyped]) -> void
65
+ # rubocop: disable Metrics/ParameterLists
66
+ def initialize: (session: untyped, url: untyped, inputfile: untyped, output: untyped, ?cookies: ::Hash[untyped, untyped], ?headers: ::Hash[untyped, untyped], ?auth: ::Hash[untyped, untyped], ?wait_window_loaded: bool, ?wait_network_idle: bool, ?print_options: ::Hash[untyped, untyped], ?network_log_format: ::Symbol) -> void
28
67
 
29
68
  def run: () -> untyped
30
69
 
@@ -38,6 +77,7 @@ module Bidi2pdf
38
77
 
39
78
  def add_basic_auth: () -> (nil | untyped)
40
79
 
80
+ # rubocop: disable Metrics/AbcSize
41
81
  def run_flow: () -> untyped
42
82
 
43
83
  def uri: () -> untyped
@@ -0,0 +1,51 @@
1
+ module Bidi2pdf
2
+ module TestHelpers
3
+ self.@configuration: untyped
4
+
5
+ class Configuration
6
+ @spec_dir: untyped
7
+
8
+ @docker_dir: untyped
9
+
10
+ @fixture_dir: untyped
11
+
12
+ @tmp_dir: untyped
13
+
14
+ @prefix: untyped
15
+
16
+ # @!attribute [rw] spec_dir
17
+ # @return [Pathname] the directory where specs are located
18
+ attr_accessor spec_dir: untyped
19
+
20
+ # @!attribute [rw] tmp_dir
21
+ # @return [String] the directory for temporary files
22
+ attr_accessor tmp_dir: untyped
23
+
24
+ # @!attribute [rw] prefix
25
+ # @return [String] the prefix for temporary files
26
+ attr_accessor prefix: untyped
27
+
28
+ # @!attribute [rw] docker_dir
29
+ # @return [String] the directory for Docker files
30
+ attr_accessor docker_dir: untyped
31
+
32
+ # @!attribute [rw] fixture_dir
33
+ # @return [String] the directory for fixture files
34
+ attr_accessor fixture_dir: untyped
35
+
36
+ def initialize: () -> void
37
+ end
38
+
39
+ # Retrieves the current configuration object for TestHelpers.
40
+ # @return [Configuration] the configuration object
41
+ def self.configuration: () -> untyped
42
+
43
+ # Sets the configuration object for TestHelpers.
44
+ # @param [Configuration] config the configuration object to set
45
+ attr_writer self.configuration: untyped
46
+
47
+ # Allows configuration of TestHelpers by yielding the configuration object.
48
+ # @yieldparam [Configuration] configuration the configuration object to modify
49
+ def self.configure: () { (untyped) -> untyped } -> untyped
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ module Bidi2pdf
2
+ module TestHelpers
3
+ module Images
4
+ class Extractor
5
+ @pages: untyped
6
+
7
+ @logger: untyped
8
+
9
+ @extracted_images: untyped
10
+
11
+ include PDFReaderUtils
12
+
13
+ include TIFFHelper
14
+
15
+ attr_reader pages: untyped
16
+
17
+ attr_reader logger: untyped
18
+
19
+ def initialize: (untyped pdf_data, ?logger: untyped) -> void
20
+
21
+ def all_images: () -> untyped
22
+
23
+ def image_on_page: (untyped page_number, untyped image_number) -> (nil | untyped)
24
+
25
+ def images_on_page: (untyped page_number) -> untyped
26
+
27
+ private
28
+
29
+ def extracted_images: () -> untyped
30
+
31
+ def extract_images: (untyped page) -> (nil | untyped)
32
+
33
+ def process_image_stream: (untyped stream) -> (nil | untyped)
34
+
35
+ def extract_raw_image_data: (untyped stream, untyped filter) -> untyped
36
+
37
+ def handle_compressed_image: (untyped stream) -> untyped
38
+
39
+ def create_vips_image: (untyped raw, untyped filter) -> untyped
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ module Bidi2pdf
2
+ module TestHelpers
3
+ module Images
4
+ class ImageSimilarityChecker
5
+ @expected_image: untyped
6
+
7
+ @image_to_check: untyped
8
+
9
+ @expected_fingerprint: untyped
10
+
11
+ @actual_fingerprint: untyped
12
+
13
+ @distance: untyped
14
+
15
+ def initialize: (untyped expected_image, untyped image_to_check) -> void
16
+
17
+ def similar?: (?tolerance: ::Integer) -> untyped
18
+
19
+ def very_similar?: () -> untyped
20
+
21
+ def slightly_similar?: () -> untyped
22
+
23
+ def different?: () -> untyped
24
+
25
+ def expected_fingerprint: () -> untyped
26
+
27
+ def actual_fingerprint: () -> untyped
28
+
29
+ def distance: () -> untyped
30
+
31
+ def fingerprint: (untyped image) -> untyped
32
+ end
33
+ end
34
+ end
35
+ end