bidi2pdf 0.1.3 → 0.1.5

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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +19 -1
  3. data/CHANGELOG.md +40 -3
  4. data/README.md +145 -55
  5. data/docker/Dockerfile.chromedriver +5 -0
  6. data/docker/entrypoint.sh +11 -1
  7. data/lib/bidi2pdf/bidi/add_headers_interceptor.rb +18 -21
  8. data/lib/bidi2pdf/bidi/auth_interceptor.rb +31 -38
  9. data/lib/bidi2pdf/bidi/browser_tab.rb +47 -53
  10. data/lib/bidi2pdf/bidi/client.rb +24 -52
  11. data/lib/bidi2pdf/bidi/command_manager.rb +50 -28
  12. data/lib/bidi2pdf/bidi/commands/add_intercept.rb +41 -0
  13. data/lib/bidi2pdf/bidi/commands/base.rb +73 -0
  14. data/lib/bidi2pdf/bidi/commands/browser_close.rb +15 -0
  15. data/lib/bidi2pdf/bidi/commands/browser_create_user_context.rb +15 -0
  16. data/lib/bidi2pdf/bidi/commands/browsing_context_close.rb +25 -0
  17. data/lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb +31 -0
  18. data/lib/bidi2pdf/bidi/commands/browsing_context_print.rb +28 -0
  19. data/lib/bidi2pdf/bidi/commands/cancel_auth.rb +26 -0
  20. data/lib/bidi2pdf/bidi/commands/create_tab.rb +11 -0
  21. data/lib/bidi2pdf/bidi/commands/create_window.rb +32 -0
  22. data/lib/bidi2pdf/bidi/commands/get_user_contexts.rb +15 -0
  23. data/lib/bidi2pdf/bidi/commands/network_continue.rb +29 -0
  24. data/lib/bidi2pdf/bidi/commands/print_parameters_validator.rb +116 -0
  25. data/lib/bidi2pdf/bidi/commands/provide_credentials.rb +33 -0
  26. data/lib/bidi2pdf/bidi/commands/script_evaluate.rb +33 -0
  27. data/lib/bidi2pdf/bidi/commands/session_end.rb +15 -0
  28. data/lib/bidi2pdf/bidi/commands/session_status.rb +15 -0
  29. data/lib/bidi2pdf/bidi/commands/session_subscribe.rb +25 -0
  30. data/lib/bidi2pdf/bidi/commands/set_tab_cookie.rb +71 -0
  31. data/lib/bidi2pdf/bidi/commands/set_usercontext_cookie.rb +67 -0
  32. data/lib/bidi2pdf/bidi/commands.rb +27 -0
  33. data/lib/bidi2pdf/bidi/connection_manager.rb +16 -13
  34. data/lib/bidi2pdf/bidi/event_manager.rb +2 -0
  35. data/lib/bidi2pdf/bidi/interceptor.rb +75 -0
  36. data/lib/bidi2pdf/bidi/network_events.rb +0 -1
  37. data/lib/bidi2pdf/bidi/session.rb +139 -65
  38. data/lib/bidi2pdf/bidi/user_context.rb +25 -31
  39. data/lib/bidi2pdf/bidi/web_socket_dispatcher.rb +2 -0
  40. data/lib/bidi2pdf/chromedriver_manager.rb +2 -1
  41. data/lib/bidi2pdf/cli.rb +12 -7
  42. data/lib/bidi2pdf/dsl.rb +45 -0
  43. data/lib/bidi2pdf/launcher.rb +6 -2
  44. data/lib/bidi2pdf/session_runner.rb +9 -2
  45. data/lib/bidi2pdf/version.rb +1 -1
  46. data/lib/bidi2pdf.rb +16 -1
  47. data/sig/bidi2pdf/bidi/command_manager.rbs +41 -0
  48. data/sig/bidi2pdf/bidi/commands/add_intercept.rbs +21 -0
  49. data/sig/bidi2pdf/bidi/commands/base.rbs +27 -0
  50. data/sig/bidi2pdf/bidi/commands/browser_close.rbs +9 -0
  51. data/sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs +9 -0
  52. data/sig/bidi2pdf/bidi/commands/browsing_context_close.rbs +11 -0
  53. data/sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs +15 -0
  54. data/sig/bidi2pdf/bidi/commands/browsing_context_print.rbs +14 -0
  55. data/sig/bidi2pdf/bidi/commands/cancel_auth.rbs +11 -0
  56. data/sig/bidi2pdf/bidi/commands/create_tab.rbs +9 -0
  57. data/sig/bidi2pdf/bidi/commands/create_window.rbs +19 -0
  58. data/sig/bidi2pdf/bidi/commands/get_user_contexts.rbs +9 -0
  59. data/sig/bidi2pdf/bidi/commands/network_continue.rbs +19 -0
  60. data/sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs +53 -0
  61. data/sig/bidi2pdf/bidi/commands/provide_credentials.rbs +15 -0
  62. data/sig/bidi2pdf/bidi/commands/script_evaluate.rbs +17 -0
  63. data/sig/bidi2pdf/bidi/commands/session_end.rbs +9 -0
  64. data/sig/bidi2pdf/bidi/commands/session_status.rbs +9 -0
  65. data/sig/bidi2pdf/bidi/commands/session_subscribe.rbs +15 -0
  66. data/sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs +31 -0
  67. data/sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs +27 -0
  68. data/sig/bidi2pdf/bidi/commands.rbs +6 -0
  69. data/sig/bidi2pdf/bidi/connection_manager.rbs +17 -0
  70. data/sig/bidi2pdf/bidi/interceptor.rbs +31 -0
  71. data/tasks/coverage.rake +16 -0
  72. metadata +66 -11
  73. data/lib/bidi2pdf/bidi/print_parameters_validator.rb +0 -114
  74. data/sig/bidi2pdf/bidi/print_parameters_validator.rbs +0 -44
  75. data/sig/bidi2pdf/chrome/chromedriver_downloader.rbs +0 -11
  76. data/sig/bidi2pdf/chrome/downloader_helper.rbs +0 -9
  77. data/sig/bidi2pdf/chrome/finder.rbs +0 -27
  78. data/sig/bidi2pdf/chrome/platform.rbs +0 -13
  79. data/sig/bidi2pdf/chrome/version_resolver.rbs +0 -19
@@ -0,0 +1,27 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ module Base
5
+ def method_name: () -> String
6
+
7
+ def params: () -> Hash[Symbol, untyped]
8
+
9
+ def as_payload: (untyped id) -> Hash[Symbol, untyped]
10
+
11
+ def ==: (untyped other) -> bool
12
+
13
+ def eql?: (untyped other) -> bool
14
+
15
+ def hash: () -> Integer
16
+
17
+ def inspect: () -> String
18
+
19
+ private
20
+
21
+ def redact_sensitive_fields: (untyped obj, Array[String] sensitive_keys) -> untyped
22
+
23
+ def raise_timeout_error: (untyped id, String method, Hash[Symbol, untyped] params) -> void
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class BrowserClose
5
+ include Commands::Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class BrowserCreateUserContext
5
+ include Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class BrowsingContextClose
5
+ include Commands::Base
6
+
7
+ def initialize: (context: String) -> void
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class BrowsingContextNavigate
5
+ include Commands::Base
6
+
7
+ def initialize: (
8
+ url: String,
9
+ context: String,
10
+ ?wait: String
11
+ ) -> void
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class BrowsingContextPrint
5
+ include Commands::Base
6
+
7
+ def initialize: (
8
+ context: String,
9
+ print_options: Hash[Symbol, untyped]?
10
+ ) -> void
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class CancelAuth
5
+ include Commands::Base
6
+
7
+ def initialize: (request: String) -> void
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class CreateTab < CreateWindow
5
+ def type: () -> "tab"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class CreateWindow
5
+ @user_context_id: untyped
6
+
7
+ @reference_context: untyped
8
+
9
+ @background: untyped
10
+
11
+ include Base
12
+
13
+ def initialize: (?user_context_id: untyped?, ?reference_context: untyped?, ?background: bool) -> void
14
+
15
+ def type: () -> "window"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class GetUserContexts
5
+ include Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class NetworkContinue
5
+ @headers: untyped
6
+
7
+ @request: untyped
8
+
9
+ include Base
10
+
11
+ attr_reader request: untyped
12
+
13
+ attr_reader headers: untyped
14
+
15
+ def initialize: (request: untyped, headers: untyped) -> void
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,53 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ # Validates parameters for the BiDi method `browsingContext.print`.
5
+ #
6
+ # Allowed structure of the params hash:
7
+ #
8
+ # {
9
+ # background: Boolean (optional, default: false) – print background graphics,
10
+ # margin: {
11
+ # top: Float >= 0.0 (optional, default: 1.0),
12
+ # bottom: Float >= 0.0 (optional, default: 1.0),
13
+ # left: Float >= 0.0 (optional, default: 1.0),
14
+ # right: Float >= 0.0 (optional, default: 1.0)
15
+ # },
16
+ # orientation: "portrait" or "landscape" (optional, default: "portrait"),
17
+ # page: {
18
+ # width: Float >= 0.0352 (optional, default: 21.59),
19
+ # height: Float >= 0.0352 (optional, default: 27.94)
20
+ # },
21
+ # pageRanges: Array of Integers or Strings (optional),
22
+ # scale: Float between 0.1 and 2.0 (optional, default: 1.0),
23
+ # shrinkToFit: Boolean (optional, default: true)
24
+ # }
25
+ #
26
+ # This validator checks presence, types, allowed ranges, and values,
27
+ # and raises ArgumentError with a descriptive message if validation fails.
28
+ class PrintParametersValidator
29
+ @params: untyped
30
+
31
+ def self.validate!: (untyped params) -> untyped
32
+
33
+ def initialize: (untyped params) -> void
34
+
35
+ def validate!: () -> true
36
+
37
+ private
38
+
39
+ def validate_boolean: (untyped key) -> (nil | untyped)
40
+
41
+ def validate_orientation: () -> (nil | untyped)
42
+
43
+ def validate_scale: () -> (nil | untyped)
44
+
45
+ def validate_page_ranges: () -> (nil | untyped)
46
+
47
+ def validate_margin: () -> (nil | untyped)
48
+
49
+ def validate_page_size: () -> (nil | untyped)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class ProvideCredentials
5
+ include Commands::Base
6
+
7
+ def initialize: (
8
+ request: String,
9
+ username: String,
10
+ password: String
11
+ ) -> void
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class ScriptEvaluate
5
+ @expression: untyped
6
+
7
+ @context: untyped
8
+
9
+ @await_promise: untyped
10
+
11
+ include Base
12
+
13
+ def initialize: (expression: untyped, context: untyped, ?await_promise: bool) -> void
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SessionEnd
5
+ include Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SessionStatus
5
+ include Commands::Base
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SessionSubscribe
5
+ @events: untyped
6
+
7
+ include Base
8
+
9
+ attr_reader events: untyped
10
+
11
+ def initialize: (events: untyped) -> void
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SetTabCookie
5
+ include Commands::Base
6
+
7
+ attr_reader name: String
8
+ attr_reader value: String
9
+ attr_reader domain: String
10
+ attr_reader path: String
11
+ attr_reader secure: bool
12
+ attr_reader http_only: bool
13
+ attr_reader same_site: String
14
+ attr_reader ttl: Integer
15
+ attr_reader browsing_context_id: String?
16
+
17
+ def initialize: (
18
+ name: String,
19
+ value: String,
20
+ domain: String,
21
+ browsing_context_id: String?,
22
+ ?path: String,
23
+ ?secure: bool,
24
+ ?http_only: bool,
25
+ ?same_site: String,
26
+ ?ttl: Integer
27
+ ) -> void
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ class SetUsercontextCookie < SetTabCookie
5
+ include Commands::Base
6
+
7
+ attr_reader user_context_id: String
8
+ attr_reader source_origin: String
9
+
10
+ def initialize: (
11
+ name: String,
12
+ value: String,
13
+ domain: String,
14
+ user_context_id: String,
15
+ source_origin: String,
16
+ ?path: String,
17
+ ?secure: bool,
18
+ ?http_only: bool,
19
+ ?same_site: String,
20
+ ?ttl: Integer
21
+ ) -> void
22
+
23
+ def expiry: () -> Integer
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Commands
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ class ConnectionManager
4
+ @logger: untyped
5
+
6
+ @connected: untyped
7
+
8
+ @connection_queue: untyped
9
+
10
+ def initialize: (logger: untyped) -> void
11
+
12
+ def mark_connected: () -> (nil | untyped)
13
+
14
+ def wait_until_open: (timeout: untyped) -> true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ module Interceptor
4
+ @client: untyped
5
+
6
+ def self.included: (untyped base) -> untyped
7
+
8
+ module ClassMethods
9
+ def phases: () -> untyped
10
+
11
+ def events: () -> untyped
12
+ end
13
+
14
+ def url_patterns: () -> untyped
15
+
16
+ def context: () -> untyped
17
+
18
+ def process_interception: (untyped _event_response, untyped _navigation_id, untyped _network_id, untyped _url) -> untyped
19
+
20
+ def register_with_client: (client: untyped) -> untyped
21
+
22
+ def handle_event: (untyped response) -> untyped
23
+
24
+ def interceptor_id: () -> untyped
25
+
26
+ def client: () -> untyped
27
+
28
+ def validate_phases!: () -> untyped
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :coverage do
4
+ desc "Merge simplecov coverage reports"
5
+ task :merge_reports do
6
+ require "simplecov"
7
+
8
+ SimpleCov.collate Dir["coverage/*-resultset.json"] do
9
+ formatter SimpleCov::Formatter::MultiFormatter.new([
10
+ SimpleCov::Formatter::SimpleFormatter,
11
+ SimpleCov::Formatter::HTMLFormatter,
12
+ SimpleCov::Formatter::JSONFormatter
13
+ ])
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidi2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter S.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-06 00:00:00.000000000 Z
11
+ date: 2025-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -240,14 +240,28 @@ dependencies:
240
240
  requirements:
241
241
  - - "~>"
242
242
  - !ruby/object:Gem::Version
243
- version: 0.2.0
243
+ version: '0.2'
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
- version: 0.2.0
250
+ version: '0.2'
251
+ - !ruby/object:Gem::Dependency
252
+ name: testcontainers-nginx
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: '0.2'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: '0.2'
251
265
  - !ruby/object:Gem::Dependency
252
266
  name: unicode_utils
253
267
  requirement: !ruby/object:Gem::Requirement
@@ -308,16 +322,38 @@ files:
308
322
  - lib/bidi2pdf/bidi/browser_tab.rb
309
323
  - lib/bidi2pdf/bidi/client.rb
310
324
  - lib/bidi2pdf/bidi/command_manager.rb
325
+ - lib/bidi2pdf/bidi/commands.rb
326
+ - lib/bidi2pdf/bidi/commands/add_intercept.rb
327
+ - lib/bidi2pdf/bidi/commands/base.rb
328
+ - lib/bidi2pdf/bidi/commands/browser_close.rb
329
+ - lib/bidi2pdf/bidi/commands/browser_create_user_context.rb
330
+ - lib/bidi2pdf/bidi/commands/browsing_context_close.rb
331
+ - lib/bidi2pdf/bidi/commands/browsing_context_navigate.rb
332
+ - lib/bidi2pdf/bidi/commands/browsing_context_print.rb
333
+ - lib/bidi2pdf/bidi/commands/cancel_auth.rb
334
+ - lib/bidi2pdf/bidi/commands/create_tab.rb
335
+ - lib/bidi2pdf/bidi/commands/create_window.rb
336
+ - lib/bidi2pdf/bidi/commands/get_user_contexts.rb
337
+ - lib/bidi2pdf/bidi/commands/network_continue.rb
338
+ - lib/bidi2pdf/bidi/commands/print_parameters_validator.rb
339
+ - lib/bidi2pdf/bidi/commands/provide_credentials.rb
340
+ - lib/bidi2pdf/bidi/commands/script_evaluate.rb
341
+ - lib/bidi2pdf/bidi/commands/session_end.rb
342
+ - lib/bidi2pdf/bidi/commands/session_status.rb
343
+ - lib/bidi2pdf/bidi/commands/session_subscribe.rb
344
+ - lib/bidi2pdf/bidi/commands/set_tab_cookie.rb
345
+ - lib/bidi2pdf/bidi/commands/set_usercontext_cookie.rb
311
346
  - lib/bidi2pdf/bidi/connection_manager.rb
312
347
  - lib/bidi2pdf/bidi/event_manager.rb
348
+ - lib/bidi2pdf/bidi/interceptor.rb
313
349
  - lib/bidi2pdf/bidi/network_event.rb
314
350
  - lib/bidi2pdf/bidi/network_events.rb
315
- - lib/bidi2pdf/bidi/print_parameters_validator.rb
316
351
  - lib/bidi2pdf/bidi/session.rb
317
352
  - lib/bidi2pdf/bidi/user_context.rb
318
353
  - lib/bidi2pdf/bidi/web_socket_dispatcher.rb
319
354
  - lib/bidi2pdf/chromedriver_manager.rb
320
355
  - lib/bidi2pdf/cli.rb
356
+ - lib/bidi2pdf/dsl.rb
321
357
  - lib/bidi2pdf/launcher.rb
322
358
  - lib/bidi2pdf/process_tree.rb
323
359
  - lib/bidi2pdf/session_runner.rb
@@ -329,18 +365,36 @@ files:
329
365
  - sig/bidi2pdf/bidi/browser.rbs
330
366
  - sig/bidi2pdf/bidi/browser_tab.rbs
331
367
  - sig/bidi2pdf/bidi/client.rbs
368
+ - sig/bidi2pdf/bidi/command_manager.rbs
369
+ - sig/bidi2pdf/bidi/commands.rbs
370
+ - sig/bidi2pdf/bidi/commands/add_intercept.rbs
371
+ - sig/bidi2pdf/bidi/commands/base.rbs
372
+ - sig/bidi2pdf/bidi/commands/browser_close.rbs
373
+ - sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs
374
+ - sig/bidi2pdf/bidi/commands/browsing_context_close.rbs
375
+ - sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs
376
+ - sig/bidi2pdf/bidi/commands/browsing_context_print.rbs
377
+ - sig/bidi2pdf/bidi/commands/cancel_auth.rbs
378
+ - sig/bidi2pdf/bidi/commands/create_tab.rbs
379
+ - sig/bidi2pdf/bidi/commands/create_window.rbs
380
+ - sig/bidi2pdf/bidi/commands/get_user_contexts.rbs
381
+ - sig/bidi2pdf/bidi/commands/network_continue.rbs
382
+ - sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs
383
+ - sig/bidi2pdf/bidi/commands/provide_credentials.rbs
384
+ - sig/bidi2pdf/bidi/commands/script_evaluate.rbs
385
+ - sig/bidi2pdf/bidi/commands/session_end.rbs
386
+ - sig/bidi2pdf/bidi/commands/session_status.rbs
387
+ - sig/bidi2pdf/bidi/commands/session_subscribe.rbs
388
+ - sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs
389
+ - sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs
390
+ - sig/bidi2pdf/bidi/connection_manager.rbs
332
391
  - sig/bidi2pdf/bidi/event_manager.rbs
392
+ - sig/bidi2pdf/bidi/interceptor.rbs
333
393
  - sig/bidi2pdf/bidi/network_event.rbs
334
394
  - sig/bidi2pdf/bidi/network_events.rbs
335
- - sig/bidi2pdf/bidi/print_parameters_validator.rbs
336
395
  - sig/bidi2pdf/bidi/session.rbs
337
396
  - sig/bidi2pdf/bidi/user_context.rbs
338
397
  - sig/bidi2pdf/bidi/web_socket_dispatcher.rbs
339
- - sig/bidi2pdf/chrome/chromedriver_downloader.rbs
340
- - sig/bidi2pdf/chrome/downloader_helper.rbs
341
- - sig/bidi2pdf/chrome/finder.rbs
342
- - sig/bidi2pdf/chrome/platform.rbs
343
- - sig/bidi2pdf/chrome/version_resolver.rbs
344
398
  - sig/bidi2pdf/chromedriver_manager.rbs
345
399
  - sig/bidi2pdf/cli.rbs
346
400
  - sig/bidi2pdf/launcher.rbs
@@ -349,6 +403,7 @@ files:
349
403
  - sig/bidi2pdf/utils.rbs
350
404
  - sig/vendor/thor.rbs
351
405
  - tasks/changelog.rake
406
+ - tasks/coverage.rake
352
407
  - tasks/generate_rbs.rake
353
408
  - tmp/.keep
354
409
  homepage: https://github.com/dieter-medium/bidi2pdf
@@ -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