ruby_native 0.20.0 → 0.21.0

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: e0a826512a814c411dd4edc4e8e6180d00c6b8f8d3c051520d613f5b089dfcf5
4
- data.tar.gz: db4b8cae640abe1b6ac5413d46e7b491de7b944361b948875b1e59bca6ec7c46
3
+ metadata.gz: 308d144022ae260825f489654d98d381884a854c7c254e63dee358fb07b5cb6a
4
+ data.tar.gz: a97d9f02879fd5102fd1587d7c1acd3a98785f77d61cd644462432dcfaaea811
5
5
  SHA512:
6
- metadata.gz: b6ce0830c95718f3a084fd90e7948c22fe18953d2e3364983ffec6bc6c079309d4e4ca8d03bb58827c9568d70dd44194a99881f66391fae3c8c0765eefc78bc6
7
- data.tar.gz: bd5f6dc74e6709ad7736a4602430647d91648ed694f49e75e7612d5cc2cab372677d7214cdb9e5161cd78ab53bf4de453101a4685810aceddb2e0c98980acecd
6
+ metadata.gz: c94e639470044f93aece21cbcc4196a293971df9d44c4d7852f1ce9f42c4c374202b3efd6f5133712f0cf19020feb3f80214e9c13788bccf76c7146fdd5a3fcf
7
+ data.tar.gz: 03a7240dd07185e77f36378d3f00b7b6c4046890645cc382334bead2d4d108052b729f35a9a069be9df1a4a5a2aa14a39007333dff92d97cc0f41787b92baea5
@@ -44,6 +44,7 @@ module RubyNative
44
44
 
45
45
  if signed_transaction.present?
46
46
  transaction = decode_and_verify_jws(signed_transaction)
47
+ verify_bundle_id!(transaction["bundleId"])
47
48
  if transaction["appAccountToken"] != intent.uuid
48
49
  raise VerificationError, "appAccountToken does not match intent UUID"
49
50
  end
@@ -12,7 +12,11 @@ module RubyNative
12
12
  transactions = Array(params[:signed_transactions])
13
13
  return head :bad_request if transactions.empty?
14
14
 
15
- transactions.each { |signed_transaction| restore(decode_and_verify_jws(signed_transaction)) }
15
+ transactions.each do |signed_transaction|
16
+ transaction = decode_and_verify_jws(signed_transaction)
17
+ verify_bundle_id!(transaction["bundleId"])
18
+ restore(transaction)
19
+ end
16
20
 
17
21
  head :ok
18
22
  rescue VerificationError, JWT::DecodeError => e
data/config/signals.yml CHANGED
@@ -52,6 +52,12 @@ signals:
52
52
  since: "0.17.0"
53
53
  data-native-destructive:
54
54
  since: "0.14.0"
55
+ data-native-dismiss-button:
56
+ since: "0.21.0"
57
+ helper: native_presentation_tag
58
+ data-native-dismissible:
59
+ since: "0.21.0"
60
+ helper: native_presentation_tag
55
61
  data-native-fab:
56
62
  since: "0.8.0"
57
63
  helper: native_fab_tag
@@ -101,6 +107,9 @@ signals:
101
107
  helper: native_navbar_tag
102
108
  always: true
103
109
  singleton: true
110
+ data-native-navbar-logo:
111
+ since: "0.21.0"
112
+ helper: native_navbar_tag
104
113
  data-native-overscroll-bottom:
105
114
  since: "0.5.0"
106
115
  helper: native_overscroll_tag
@@ -117,7 +126,6 @@ signals:
117
126
  since: "0.11.2"
118
127
  helper: native_presentation_tag
119
128
  always: true
120
- singleton: true
121
129
  data-native-price:
122
130
  since: "0.5.3"
123
131
  data-native-pull-to-refresh:
@@ -136,6 +144,8 @@ signals:
136
144
  since: "0.9.3"
137
145
  helper: native_review_tag
138
146
  always: true
147
+ data-native-secure-session:
148
+ since: "0.21.0"
139
149
  data-native-segment:
140
150
  since: "0.10.12"
141
151
  data-native-selected:
@@ -20,7 +20,8 @@ appearance:
20
20
  # Accepts a hex string, or { light:, dark: } for dark mode support.
21
21
  tint_color: "#007AFF"
22
22
 
23
- # Color shown briefly during launch and as the safe-area fill.
23
+ # Window color behind your pages, shown during transitions and as the
24
+ # safe-area fill. The launch screen color is set in your app's Settings.
24
25
  # Accepts a hex string, or { light:, dark: } for dark mode support.
25
26
  background_color: "#FFFFFF"
26
27
 
@@ -41,7 +42,8 @@ appearance:
41
42
  # # Centered logo, shown instead of the page title. Set this to an image URL.
42
43
  # # For a local asset, point it at image_url wrapped in ERB so the URL is
43
44
  # # fingerprinted (the app re-downloads only when the image changes). The
44
- # # docs page above has the exact snippet to copy.
45
+ # # docs page above has the exact snippet to copy. Accepts { light:, dark: }
46
+ # # for dark mode, and `native_navbar_tag logo: false` hides it on one page.
45
47
  # logo: "https://cdn.example.com/logo.png"
46
48
  #
47
49
  # # Bar background color.
@@ -67,25 +69,31 @@ appearance:
67
69
  # background_color: "#1E293B"
68
70
  # # Title and icon color. Defaults to black or white, picked for contrast.
69
71
  # foreground_color: "#FFFFFF"
72
+ # # Center plain titles like iOS. Defaults to start, Material's convention.
73
+ # title_alignment: center
70
74
  # tab_bar:
71
75
  # background_color: "#1E293B"
72
76
  # # Icon and label color. Defaults to the theme's, with tint_color on the
73
77
  # # selected tab. Set this and unselected tabs dim to 60% of it.
74
78
  # foreground_color: "#FFFFFF"
75
79
 
76
- # Show a launch splash while the first screen loads. It holds your launch icon
77
- # and background_color in frame, with a spinner, until the web content paints.
78
- # Off by default; set enabled: true to turn it on.
80
+ # An X that closes Advanced Mode modals, on both platforms. Leave
81
+ # it out for each platform's default (off on iOS, on on Android).
82
+ # modal_dismiss_button: true
83
+
84
+ # The iOS launch splash holds your launch icon and launch screen color in frame,
85
+ # with a spinner, until the first screen paints. On by default; set
86
+ # enabled: false to turn it off.
79
87
  # https://rubynative.com/docs/appearance#splash-screen
80
88
  # splash:
81
- # enabled: true
89
+ # enabled: false
82
90
  #
83
91
  # # Spinner color. Accepts a hex string, or { light:, dark: } for dark mode.
84
- # # Defaults to a contrast-aware pick from your background_color.
92
+ # # Defaults to a contrast-aware pick from your launch screen color.
85
93
  # spinner_color: "#007AFF"
86
94
  #
87
95
  # # Status bar content over the splash. Options: light (white) or dark.
88
- # # Defaults to a contrast-aware pick from your background_color.
96
+ # # Defaults to a contrast-aware pick from your launch screen color.
89
97
  # status_bar: dark
90
98
 
91
99
  # Configure the native tab bar on the bottom of the screen.
@@ -26,7 +26,7 @@ module RubyNative
26
26
  TOP_LEVEL_KEYS = %w[app appearance tabs auth errors analytics ios android linked_paths ruby_native].freeze
27
27
  APP_KEYS = %w[name mode entry_path].freeze
28
28
  # `android` is the per-platform chrome block, read only by the Android app.
29
- APPEARANCE_KEYS = %w[tint_color background_color theme landscape navbar splash android].freeze
29
+ APPEARANCE_KEYS = %w[tint_color background_color theme landscape navbar splash android modal_dismiss_button].freeze
30
30
  NAVBAR_KEYS = %w[logo background_color foreground_color status_bar].freeze
31
31
  SPLASH_KEYS = %w[enabled spinner_color status_bar].freeze
32
32
  TAB_KEYS = %w[title titles path icon icons key eager search badge auto_route].freeze
@@ -37,6 +37,7 @@ module RubyNative
37
37
  MODES = %w[normal advanced].freeze
38
38
  THEMES = %w[auto light dark].freeze
39
39
  STATUS_BARS = %w[light dark].freeze
40
+ TITLE_ALIGNMENTS = %w[start center].freeze
40
41
 
41
42
  # UIColor(hex:) takes exactly six hex digits and an optional `#`. A
42
43
  # three-digit shorthand parses as nil, which reads on device as the
@@ -177,8 +178,20 @@ module RubyNative
177
178
  check_color(appearance["background_color"], "appearance.background_color")
178
179
  check_enum(appearance["theme"], "appearance.theme", THEMES)
179
180
  check_boolean(appearance["landscape"], "appearance.landscape")
181
+ check_boolean(appearance["modal_dismiss_button"], "appearance.modal_dismiss_button")
180
182
  check_navbar(appearance["navbar"])
181
183
  check_splash(appearance["splash"])
184
+ check_android_title_alignment(appearance.dig("android", "navbar")) if appearance["android"].is_a?(Hash)
185
+ end
186
+
187
+ # Android decodes this as a string, so a typo leaves the title start-aligned instead of failing.
188
+ def check_android_title_alignment(navbar)
189
+ return unless navbar.is_a?(Hash)
190
+
191
+ value = navbar["title_alignment"]
192
+ return if value.nil? || sentinel?(value) || TITLE_ALIGNMENTS.include?(value.to_s)
193
+
194
+ warning("appearance.android.navbar.title_alignment", "`appearance.android.navbar.title_alignment` is #{value.inspect}. It takes #{TITLE_ALIGNMENTS.join(" or ")}, so the title stays start-aligned.")
182
195
  end
183
196
 
184
197
  def check_navbar(navbar)
@@ -186,6 +199,7 @@ module RubyNative
186
199
  return error("appearance.navbar", "`appearance.navbar` has to be a mapping.") unless navbar.is_a?(Hash)
187
200
 
188
201
  unknown_keys(navbar, NAVBAR_KEYS, "appearance.navbar")
202
+ check_logo(navbar["logo"], "appearance.navbar.logo")
189
203
  check_color(navbar["background_color"], "appearance.navbar.background_color")
190
204
  check_color(navbar["foreground_color"], "appearance.navbar.foreground_color")
191
205
  check_enum(navbar["status_bar"], "appearance.navbar.status_bar", STATUS_BARS)
@@ -394,6 +408,16 @@ module RubyNative
394
408
 
395
409
  # --- Value checks ---
396
410
 
411
+ def check_logo(value, key)
412
+ return if value.nil? || value.is_a?(String)
413
+ return error(key, "`#{key}` has to be an image URL, or a mapping with `light` and `dark` URLs.") unless value.is_a?(Hash)
414
+
415
+ missing = %w[light dark] - value.keys.map(&:to_s)
416
+ return if missing.empty?
417
+
418
+ error(key, "`#{key}` is a mapping without #{missing.map { |field| "`#{field}`" }.join(" and ")}. A per-theme logo needs both, or the config fails to decode and the app shows its error screen.")
419
+ end
420
+
397
421
  def check_color(value, key)
398
422
  return if value.nil?
399
423
 
@@ -122,16 +122,32 @@ module RubyNative
122
122
  value
123
123
  end
124
124
 
125
- # The landing intents a page can declare about itself. Only :root so far.
126
- # :modal is the obvious second member (both shells hardcode a /new + /edit
127
- # rule today that no app can reach), which is why this is a vocabulary
128
- # rather than a boolean tag.
129
- PRESENTATION_INTENTS = %w[root].freeze
130
-
131
- # Declares that this page is a root: it lands with nothing behind it, and no
132
- # back affordance, wherever it lands.
125
+ # The landing intents a page can declare about itself.
126
+ PRESENTATION_INTENTS = %w[root modal].freeze
127
+
128
+ # Declares how this page lands, wherever it lands.
133
129
  #
134
130
  # <%= native_presentation_tag :root %>
131
+ # <%= native_presentation_tag :modal %>
132
+ # <%= native_presentation_tag :modal, dismissible: false %>
133
+ #
134
+ # `dismissible: false` makes a modal the user can't close: no close button,
135
+ # no swipe down, no back. Only the server moves them on, by redirecting to a
136
+ # page without it. Use it for paywalls and sign-in.
137
+ #
138
+ # `dismiss_button:` shows (true) or hides (false) the modal's dismiss button
139
+ # on this page, overriding `appearance.modal_dismiss_button`. A modal that
140
+ # isn't dismissible never shows one.
141
+ #
142
+ # :root lands with nothing behind it and no back affordance. :modal lands in
143
+ # Advanced Mode's modal: it presents one, or pushes inside the one already
144
+ # up, so a multi-step flow reached by redirects stays in a single modal.
145
+ # Normal Mode has no modals and ignores it.
146
+ #
147
+ # A link tap is proposed before anything is fetched, so neither channel
148
+ # below reaches the shell in time for it. Mark the link instead:
149
+ #
150
+ # <%= link_to "Add player", new_player_path, data: { native_presentation: "modal" } %>
135
151
  #
136
152
  # Emits the fact on two channels, because the shells need it at two
137
153
  # different moments and neither channel reaches both:
@@ -149,21 +165,23 @@ module RubyNative
149
165
  # the only part of that response readable synchronously, since the body
150
166
  # arrives as a promise that consuming would take from Turbo.
151
167
  #
152
- # Nothing is declared at the origin. Both channels ride the response for the
153
- # page itself, so a redirect chain carries the intent to wherever it actually
154
- # lands rather than to wherever the link pointed.
168
+ # Both channels ride the response for the page itself, so a redirect chain
169
+ # carries the intent to wherever it actually lands rather than to wherever
170
+ # the form pointed. That is also why a conditional redirect needs nothing
171
+ # extra: the page it picks declares itself or doesn't.
155
172
  #
156
173
  # In Advanced Mode this takes effect before the navigation commits when the
157
174
  # page arrives from a form submission, because that is the only case where
158
175
  # Turbo has already fetched the destination by the time it proposes the
159
176
  # visit. A link tap, a deep link and a cold boot are proposed before anything
160
- # is fetched, so those fall back to the element and the shell corrects after
161
- # the page renders. Normal Mode always uses the element.
177
+ # is fetched. For :root those fall back to the element and the shell corrects
178
+ # after the page renders. :modal has no late correction, which is why links
179
+ # carry the attribute themselves. Normal Mode always uses the element.
162
180
  #
163
181
  # Do not call this inside a `cache` block. On a cache hit the element comes
164
182
  # back from the cache and the header is never set, which silently leaves
165
183
  # Advanced Mode with only the slower path.
166
- def native_presentation_tag(presentation)
184
+ def native_presentation_tag(presentation, dismissible: true, dismiss_button: nil)
167
185
  value = presentation.to_s
168
186
  unless PRESENTATION_INTENTS.include?(value)
169
187
  raise ArgumentError,
@@ -181,18 +199,43 @@ module RubyNative
181
199
  "so Advanced Mode will not see it before the navigation commits."
182
200
  )
183
201
  end
184
- response.headers["Native-Presentation"] = value
202
+ # A 422 re-render answers the POST, so its URL is the collection
203
+ # (/players), and a :modal header there would mark that page modal.
204
+ response.headers["Native-Presentation"] = value unless response.status.to_i >= 400
205
+ end
206
+
207
+ unless [ true, false ].include?(dismissible)
208
+ raise ArgumentError, "native_presentation_tag dismissible: must be true or false, got #{dismissible.inspect}"
209
+ end
210
+ if !dismissible && value != "modal"
211
+ raise ArgumentError, "native_presentation_tag dismissible: false only applies to :modal"
212
+ end
213
+ unless [ nil, true, false ].include?(dismiss_button)
214
+ raise ArgumentError, "native_presentation_tag dismiss_button: must be true or false, got #{dismiss_button.inspect}"
215
+ end
216
+ if !dismiss_button.nil? && value != "modal"
217
+ raise ArgumentError, "native_presentation_tag dismiss_button: only applies to :modal"
185
218
  end
186
219
 
187
- tag.div(data: { native_presentation: value }, hidden: true)
220
+ data = { native_presentation: value }
221
+ data[:native_dismissible] = "false" unless dismissible
222
+ data[:native_dismiss_button] = dismiss_button.to_s unless dismiss_button.nil?
223
+ tag.div(data: data, hidden: true)
188
224
  end
189
225
 
190
- def native_navbar_tag(title = nil, pull_to_refresh: true, &block)
226
+ # `logo: false` hides `appearance.navbar.logo` on this page and shows the
227
+ # title instead. The logo shows everywhere else, as it does without the option.
228
+ def native_navbar_tag(title = nil, pull_to_refresh: true, logo: nil, &block)
229
+ unless [ nil, true, false ].include?(logo)
230
+ raise ArgumentError, "native_navbar_tag logo: must be true or false, got #{logo.inspect}"
231
+ end
232
+
191
233
  builder = NavbarBuilder.new(self)
192
234
  capture(builder, &block) if block
193
235
 
194
236
  data = { native_navbar: title.to_s }
195
237
  data[:native_pull_to_refresh] = "false" unless pull_to_refresh
238
+ data[:native_navbar_logo] = logo.to_s unless logo.nil?
196
239
  tag.div(data: data, hidden: true) { builder.to_html }
197
240
  end
198
241
 
@@ -200,13 +243,16 @@ module RubyNative
200
243
  # Material FAB on Android. The icon color is derived automatically to
201
244
  # stay readable against it. Pass `:tint` instead of a hex to inherit
202
245
  # `appearance.tint_color`, keeping the button in sync with the app accent.
203
- def native_fab_tag(icon: nil, icons: nil, href: nil, click: nil, color: nil)
246
+ # `title:` shows text next to the icon (an extended FAB). The icon stays
247
+ # required so builds that predate titles still show a usable button.
248
+ def native_fab_tag(icon: nil, icons: nil, href: nil, title: nil, click: nil, color: nil)
204
249
  resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: try(:native_platform))
205
250
  raise ArgumentError, "native_fab_tag requires an icon" if resolved.nil?
206
251
  data = { native_fab: true, native_icon: resolved }
207
252
  data[:native_href] = href if href
208
253
  data[:native_click] = click if click
209
254
  data[:native_color] = color if color
255
+ data[:native_title] = title if title.present?
210
256
  tag.div(data: data, hidden: true)
211
257
  end
212
258
 
@@ -7,6 +7,8 @@ module RubyNative
7
7
 
8
8
  def process(signed_payload)
9
9
  notification = parse_notification(signed_payload)
10
+ verify_bundle_id!(notification.bundle_id)
11
+ verify_bundle_id!(notification.transaction_bundle_id)
10
12
  intent = PurchaseIntent.find_by(uuid: notification.app_account_token)
11
13
 
12
14
  event = build_event(notification, intent)
@@ -8,6 +8,7 @@ module RubyNative
8
8
  :subtype,
9
9
  :notification_uuid,
10
10
  :bundle_id,
11
+ :transaction_bundle_id,
11
12
  :app_account_token,
12
13
  :product_id,
13
14
  :original_transaction_id,
@@ -29,6 +30,7 @@ module RubyNative
29
30
  subtype: payload["subtype"],
30
31
  notification_uuid: payload["notificationUUID"],
31
32
  bundle_id: payload["data"]["bundleId"],
33
+ transaction_bundle_id: transaction_info["bundleId"],
32
34
  app_account_token: transaction_info["appAccountToken"],
33
35
  product_id: transaction_info["productId"],
34
36
  original_transaction_id: transaction_info["originalTransactionId"],
@@ -41,11 +43,21 @@ module RubyNative
41
43
  end
42
44
 
43
45
  def decode_and_verify_jws(jws)
44
- JWT.decode(jws, nil, true, algorithms: ["ES256"]) { |header|
45
- verify_certificate_chain(header["x5c"])
46
+ JWT.decode(jws, nil, true, algorithms: ["ES256"]) { |header, payload|
47
+ verify_certificate_chain(header["x5c"], at: signed_at(payload))
46
48
  }.first
47
49
  end
48
50
 
51
+ # Apple stamps every payload with `signedDate`, in milliseconds.
52
+ def signed_at(payload)
53
+ signed_date = payload["signedDate"] if payload.is_a?(Hash)
54
+ return Time.now unless signed_date.is_a?(Numeric)
55
+
56
+ Time.at(signed_date / 1000.0)
57
+ rescue RangeError
58
+ raise VerificationError, "signedDate is out of range"
59
+ end
60
+
49
61
  def parse_timestamp(milliseconds)
50
62
  return nil if milliseconds.nil?
51
63
  Time.at(milliseconds / 1000.0).utc
@@ -5,26 +5,81 @@ module RubyNative
5
5
  module Verifiable
6
6
  APPLE_ROOT_CERT_PATH = File.join(__dir__, "..", "certs", "AppleRootCA-G3.pem")
7
7
 
8
- private
8
+ # Extensions Apple puts on the certificates that sign App Store payloads.
9
+ RECEIPT_SIGNING_LEAF_OID = "1.2.840.113635.100.6.11.1"
10
+ WWDR_INTERMEDIATE_OID = "1.2.840.113635.100.6.2.1"
11
+
12
+ CHAIN_LENGTH = 3
13
+
14
+ def self.warn_missing_bundle_id
15
+ return if @warned_missing_bundle_id
16
+
17
+ @warned_missing_bundle_id = true
18
+ Rails.logger.warn(
19
+ "[RubyNative] Set ios.bundle_id in config/ruby_native.yml so in-app purchases are checked against your app."
20
+ )
21
+ end
9
22
 
10
- def verify_certificate_chain(x5c_certs)
11
- raise VerificationError, "Missing x5c certificates" if x5c_certs.nil? || x5c_certs.empty?
23
+ private
12
24
 
13
- certs = x5c_certs.map do |cert_base64|
14
- OpenSSL::X509::Certificate.new(Base64.decode64(cert_base64))
25
+ # `at` is the time the chain has to be valid at, so a payload signed
26
+ # before its certificate expired still verifies.
27
+ def verify_certificate_chain(x5c_certs, at: Time.now)
28
+ raise VerificationError, "Missing x5c certificates" unless x5c_certs.is_a?(Array) && !x5c_certs.empty?
29
+ unless x5c_certs.size == CHAIN_LENGTH
30
+ raise VerificationError, "Expected #{CHAIN_LENGTH} x5c certificates, got #{x5c_certs.size}"
15
31
  end
16
32
 
17
- unless certs.last.to_der == apple_root_certificate.to_der
33
+ leaf, intermediate, root = x5c_certs.map { |cert_base64| parse_certificate(cert_base64) }
34
+
35
+ unless root.to_der == apple_root_certificate.to_der
18
36
  raise VerificationError, "Root certificate does not match Apple's known root"
19
37
  end
20
-
21
- certs.each_cons(2) do |child, parent|
22
- unless child.verify(parent.public_key)
23
- raise VerificationError, "Certificate chain verification failed"
24
- end
38
+ unless extension?(leaf, RECEIPT_SIGNING_LEAF_OID)
39
+ raise VerificationError, "Leaf certificate is not an App Store signing certificate"
25
40
  end
41
+ unless extension?(intermediate, WWDR_INTERMEDIATE_OID)
42
+ raise VerificationError, "Intermediate certificate is not an Apple WWDR certificate"
43
+ end
44
+
45
+ verify_certificate_path(leaf, intermediate, at)
46
+
47
+ leaf.public_key
48
+ end
49
+
50
+ def parse_certificate(cert_base64)
51
+ raise VerificationError, "x5c certificate is not a string" unless cert_base64.is_a?(String)
52
+
53
+ OpenSSL::X509::Certificate.new(Base64.decode64(cert_base64))
54
+ rescue OpenSSL::X509::CertificateError => error
55
+ raise VerificationError, "x5c certificate could not be parsed: #{error.message}"
56
+ end
57
+
58
+ def extension?(certificate, oid)
59
+ certificate.extensions.any? { |extension| extension.oid == oid }
60
+ end
26
61
 
27
- certs.first.public_key
62
+ # Only the bundled root is trusted. The root the payload presents is never added to the store.
63
+ def verify_certificate_path(leaf, intermediate, at)
64
+ store = OpenSSL::X509::Store.new
65
+ store.add_cert(apple_root_certificate)
66
+ store.time = at
67
+
68
+ return if store.verify(leaf, [intermediate])
69
+
70
+ raise VerificationError, "Certificate chain verification failed: #{store.error_string}"
71
+ rescue RangeError
72
+ raise VerificationError, "Certificate chain cannot be verified at #{at}"
73
+ end
74
+
75
+ def verify_bundle_id!(bundle_id)
76
+ expected = RubyNative.config&.dig(:ios, :bundle_id)
77
+
78
+ if expected.blank?
79
+ Verifiable.warn_missing_bundle_id
80
+ elsif bundle_id != expected.to_s
81
+ raise VerificationError, "bundleId does not match ios.bundle_id in config/ruby_native.yml"
82
+ end
28
83
  end
29
84
 
30
85
  def apple_root_certificate
@@ -12,7 +12,8 @@ module RubyNative
12
12
  included do
13
13
  if respond_to?(:helper_method)
14
14
  helper_method :native_app?, :native_version, :native_platform,
15
- :native_app_version, :native_app_build, :native_os_version, :native_os_build
15
+ :native_app_version, :native_app_build, :native_os_version, :native_os_build,
16
+ :native_secure_session_completion_url
16
17
  end
17
18
  end
18
19
 
@@ -56,5 +57,29 @@ module RubyNative
56
57
  def native_os_build
57
58
  request.user_agent.to_s[SIGNATURE, 4]
58
59
  end
60
+
61
+ SECURE_SESSION_COOKIE = "_ruby_native_callback_scheme".freeze
62
+
63
+ # Where a provider like Plaid Hosted Link or Stripe Connect onboarding sends
64
+ # the user when they finish. Pass it as the provider's completion URI, then
65
+ # link to the provider with `data: { native_secure_session: true }`. The app
66
+ # opens the link in a secure browser and, on completion, loads `return_to`
67
+ # in the web view, still signed in.
68
+ #
69
+ # completion_redirect_uri: native_secure_session_completion_url(return_to: bank_done_path)
70
+ #
71
+ # Returns nil outside the app (or in a build without secure sessions), so
72
+ # fall back to a regular web URL there.
73
+ def native_secure_session_completion_url(return_to:)
74
+ path = return_to.to_s
75
+ unless path.start_with?("/") && !path.start_with?("//")
76
+ raise ArgumentError, "return_to must be a path on your site, like /bank/done"
77
+ end
78
+
79
+ scheme = request.cookies[SECURE_SESSION_COOKIE].to_s
80
+ return unless scheme.match?(OAuthMiddleware::CALLBACK_SCHEME)
81
+
82
+ "#{scheme}://secure-session?#{{ return_to: path }.to_query}"
83
+ end
59
84
  end
60
85
  end
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.20.0"
2
+ VERSION = "0.21.0"
3
3
  end
data/lib/ruby_native.rb CHANGED
@@ -173,6 +173,7 @@ module RubyNative
173
173
  # emitting it so they still boot when the YAML omits the block.
174
174
  payload[:appearance] ||= {}
175
175
  localize_tab_titles(payload[:tabs])
176
+ split_navbar_logo(payload.dig(:appearance, :navbar))
176
177
  errors = error_screen_config(payload[:errors])
177
178
  if errors.empty?
178
179
  payload.delete(:errors)
@@ -182,6 +183,16 @@ module RubyNative
182
183
  payload
183
184
  end
184
185
 
186
+ # A `{ light:, dark: }` logo goes out as `logo` plus `logo_dark`. Builds before
187
+ # 0.21 decode `logo` as a plain String and fail the whole config on a mapping.
188
+ def self.split_navbar_logo(navbar)
189
+ return unless navbar.is_a?(Hash) && navbar[:logo].is_a?(Hash)
190
+
191
+ logo = navbar[:logo]
192
+ navbar[:logo] = logo[:light]
193
+ navbar[:logo_dark] = logo[:dark]
194
+ end
195
+
185
196
  # Fills each tab's `titles` from `ruby_native.tabs.<key>.title` in the host
186
197
  # app's locale files, mirroring the `ruby_native.errors.*` namespace. The map
187
198
  # is emitted beside the flat `title` rather than replacing it, the same
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti