ruby_native 0.19.1 → 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 +4 -4
- data/app/assets/stylesheets/ruby_native.css +19 -5
- data/app/controllers/ruby_native/iap/completions_controller.rb +1 -0
- data/app/controllers/ruby_native/iap/restores_controller.rb +5 -1
- data/config/signals.yml +14 -1
- data/lib/generators/ruby_native/templates/ruby_native.yml +16 -8
- data/lib/ruby_native/cli/mcp/config_validator.rb +25 -1
- data/lib/ruby_native/helper.rb +67 -18
- data/lib/ruby_native/iap/apple_webhook_processor.rb +2 -0
- data/lib/ruby_native/iap/decodable.rb +14 -2
- data/lib/ruby_native/iap/verifiable.rb +67 -12
- data/lib/ruby_native/native_detection.rb +26 -1
- data/lib/ruby_native/version.rb +1 -1
- data/lib/ruby_native.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 308d144022ae260825f489654d98d381884a854c7c254e63dee358fb07b5cb6a
|
|
4
|
+
data.tar.gz: a97d9f02879fd5102fd1587d7c1acd3a98785f77d61cd644462432dcfaaea811
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c94e639470044f93aece21cbcc4196a293971df9d44c4d7852f1ce9f42c4c374202b3efd6f5133712f0cf19020feb3f80214e9c13788bccf76c7146fdd5a3fcf
|
|
7
|
+
data.tar.gz: 03a7240dd07185e77f36378d3f00b7b6c4046890645cc382334bead2d4d108052b729f35a9a069be9df1a4a5a2aa14a39007333dff92d97cc0f41787b92baea5
|
|
@@ -26,20 +26,34 @@
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/* In-app defaults so pages feel native without any setup: no gray tap flash,
|
|
29
|
-
no selecting
|
|
30
|
-
Pair with :active styles for pressed feedback;
|
|
31
|
-
instantly on touch. */
|
|
29
|
+
no selecting text or popping link and image previews on long-press, no
|
|
30
|
+
double-tap zoom on controls. Pair with :active styles for pressed feedback;
|
|
31
|
+
the bridge makes them apply instantly on touch. */
|
|
32
32
|
[data-native-app] * {
|
|
33
33
|
-webkit-tap-highlight-color: transparent;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
[data-native-app]
|
|
37
|
-
[data-native-app] [role="button"] {
|
|
36
|
+
[data-native-app] body {
|
|
38
37
|
-webkit-user-select: none;
|
|
39
38
|
user-select: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[data-native-app] a,
|
|
42
|
+
[data-native-app] img,
|
|
43
|
+
[data-native-app] button,
|
|
44
|
+
[data-native-app] [role="button"] {
|
|
40
45
|
-webkit-touch-callout: none;
|
|
41
46
|
}
|
|
42
47
|
|
|
48
|
+
/* Fields stay editable, and .native-selectable opts copyable text back in. */
|
|
49
|
+
[data-native-app] input,
|
|
50
|
+
[data-native-app] textarea,
|
|
51
|
+
[data-native-app] [contenteditable],
|
|
52
|
+
[data-native-app] .native-selectable {
|
|
53
|
+
-webkit-user-select: text;
|
|
54
|
+
user-select: text;
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
[data-native-app] a,
|
|
44
58
|
[data-native-app] button,
|
|
45
59
|
[data-native-app] input,
|
|
@@ -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
|
|
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
|
@@ -36,6 +36,9 @@ signals:
|
|
|
36
36
|
data-native-badge-tab:
|
|
37
37
|
since: "0.3.2"
|
|
38
38
|
helper: native_badge_tag
|
|
39
|
+
data-native-badge-tabs:
|
|
40
|
+
since: "0.19.2"
|
|
41
|
+
helper: native_badge_tag
|
|
39
42
|
data-native-button:
|
|
40
43
|
since: "0.4.0"
|
|
41
44
|
data-native-click:
|
|
@@ -49,6 +52,12 @@ signals:
|
|
|
49
52
|
since: "0.17.0"
|
|
50
53
|
data-native-destructive:
|
|
51
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
|
|
52
61
|
data-native-fab:
|
|
53
62
|
since: "0.8.0"
|
|
54
63
|
helper: native_fab_tag
|
|
@@ -98,6 +107,9 @@ signals:
|
|
|
98
107
|
helper: native_navbar_tag
|
|
99
108
|
always: true
|
|
100
109
|
singleton: true
|
|
110
|
+
data-native-navbar-logo:
|
|
111
|
+
since: "0.21.0"
|
|
112
|
+
helper: native_navbar_tag
|
|
101
113
|
data-native-overscroll-bottom:
|
|
102
114
|
since: "0.5.0"
|
|
103
115
|
helper: native_overscroll_tag
|
|
@@ -114,7 +126,6 @@ signals:
|
|
|
114
126
|
since: "0.11.2"
|
|
115
127
|
helper: native_presentation_tag
|
|
116
128
|
always: true
|
|
117
|
-
singleton: true
|
|
118
129
|
data-native-price:
|
|
119
130
|
since: "0.5.3"
|
|
120
131
|
data-native-pull-to-refresh:
|
|
@@ -133,6 +144,8 @@ signals:
|
|
|
133
144
|
since: "0.9.3"
|
|
134
145
|
helper: native_review_tag
|
|
135
146
|
always: true
|
|
147
|
+
data-native-secure-session:
|
|
148
|
+
since: "0.21.0"
|
|
136
149
|
data-native-segment:
|
|
137
150
|
since: "0.10.12"
|
|
138
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
|
-
#
|
|
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
|
-
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
data/lib/ruby_native/helper.rb
CHANGED
|
@@ -90,13 +90,16 @@ module RubyNative
|
|
|
90
90
|
tag.button(label, **options)
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
# A tab value is a count, `true` for a dot, or a short string. `tabs:` badges
|
|
94
|
+
# tabs by their config `key`, while `tab:` targets the tab with `badge: true`.
|
|
95
|
+
def native_badge_tag(count = nil, home: nil, tab: nil, tabs: nil)
|
|
94
96
|
home = count if count && home.nil?
|
|
95
97
|
tab = count if count && tab.nil?
|
|
96
98
|
|
|
97
99
|
data = { native_badge: "" }
|
|
98
100
|
data[:native_badge_home] = home unless home.nil?
|
|
99
101
|
data[:native_badge_tab] = tab unless tab.nil?
|
|
102
|
+
data[:native_badge_tabs] = tabs.to_h.transform_keys(&:to_s).to_json unless tabs.nil?
|
|
100
103
|
|
|
101
104
|
tag.div(data: data, hidden: true)
|
|
102
105
|
end
|
|
@@ -119,16 +122,32 @@ module RubyNative
|
|
|
119
122
|
value
|
|
120
123
|
end
|
|
121
124
|
|
|
122
|
-
# The landing intents a page can declare about itself.
|
|
123
|
-
|
|
124
|
-
# rule today that no app can reach), which is why this is a vocabulary
|
|
125
|
-
# rather than a boolean tag.
|
|
126
|
-
PRESENTATION_INTENTS = %w[root].freeze
|
|
125
|
+
# The landing intents a page can declare about itself.
|
|
126
|
+
PRESENTATION_INTENTS = %w[root modal].freeze
|
|
127
127
|
|
|
128
|
-
# Declares
|
|
129
|
-
# back affordance, wherever it lands.
|
|
128
|
+
# Declares how this page lands, wherever it lands.
|
|
130
129
|
#
|
|
131
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" } %>
|
|
132
151
|
#
|
|
133
152
|
# Emits the fact on two channels, because the shells need it at two
|
|
134
153
|
# different moments and neither channel reaches both:
|
|
@@ -146,21 +165,23 @@ module RubyNative
|
|
|
146
165
|
# the only part of that response readable synchronously, since the body
|
|
147
166
|
# arrives as a promise that consuming would take from Turbo.
|
|
148
167
|
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
151
|
-
#
|
|
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.
|
|
152
172
|
#
|
|
153
173
|
# In Advanced Mode this takes effect before the navigation commits when the
|
|
154
174
|
# page arrives from a form submission, because that is the only case where
|
|
155
175
|
# Turbo has already fetched the destination by the time it proposes the
|
|
156
176
|
# visit. A link tap, a deep link and a cold boot are proposed before anything
|
|
157
|
-
# is fetched
|
|
158
|
-
# the page renders.
|
|
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.
|
|
159
180
|
#
|
|
160
181
|
# Do not call this inside a `cache` block. On a cache hit the element comes
|
|
161
182
|
# back from the cache and the header is never set, which silently leaves
|
|
162
183
|
# Advanced Mode with only the slower path.
|
|
163
|
-
def native_presentation_tag(presentation)
|
|
184
|
+
def native_presentation_tag(presentation, dismissible: true, dismiss_button: nil)
|
|
164
185
|
value = presentation.to_s
|
|
165
186
|
unless PRESENTATION_INTENTS.include?(value)
|
|
166
187
|
raise ArgumentError,
|
|
@@ -178,18 +199,43 @@ module RubyNative
|
|
|
178
199
|
"so Advanced Mode will not see it before the navigation commits."
|
|
179
200
|
)
|
|
180
201
|
end
|
|
181
|
-
|
|
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
|
|
182
205
|
end
|
|
183
206
|
|
|
184
|
-
|
|
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"
|
|
218
|
+
end
|
|
219
|
+
|
|
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)
|
|
185
224
|
end
|
|
186
225
|
|
|
187
|
-
|
|
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
|
+
|
|
188
233
|
builder = NavbarBuilder.new(self)
|
|
189
234
|
capture(builder, &block) if block
|
|
190
235
|
|
|
191
236
|
data = { native_navbar: title.to_s }
|
|
192
237
|
data[:native_pull_to_refresh] = "false" unless pull_to_refresh
|
|
238
|
+
data[:native_navbar_logo] = logo.to_s unless logo.nil?
|
|
193
239
|
tag.div(data: data, hidden: true) { builder.to_html }
|
|
194
240
|
end
|
|
195
241
|
|
|
@@ -197,13 +243,16 @@ module RubyNative
|
|
|
197
243
|
# Material FAB on Android. The icon color is derived automatically to
|
|
198
244
|
# stay readable against it. Pass `:tint` instead of a hex to inherit
|
|
199
245
|
# `appearance.tint_color`, keeping the button in sync with the app accent.
|
|
200
|
-
|
|
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)
|
|
201
249
|
resolved = RubyNative::Helper.resolve_icon(icon: icon, icons: icons, platform: try(:native_platform))
|
|
202
250
|
raise ArgumentError, "native_fab_tag requires an icon" if resolved.nil?
|
|
203
251
|
data = { native_fab: true, native_icon: resolved }
|
|
204
252
|
data[:native_href] = href if href
|
|
205
253
|
data[:native_click] = click if click
|
|
206
254
|
data[:native_color] = color if color
|
|
255
|
+
data[:native_title] = title if title.present?
|
|
207
256
|
tag.div(data: data, hidden: true)
|
|
208
257
|
end
|
|
209
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
|
-
|
|
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
|
-
|
|
11
|
-
raise VerificationError, "Missing x5c certificates" if x5c_certs.nil? || x5c_certs.empty?
|
|
23
|
+
private
|
|
12
24
|
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
data/lib/ruby_native/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joe Masilotti
|
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
157
157
|
- !ruby/object:Gem::Version
|
|
158
158
|
version: '0'
|
|
159
159
|
requirements: []
|
|
160
|
-
rubygems_version: 4.0.
|
|
160
|
+
rubygems_version: 4.0.20
|
|
161
161
|
specification_version: 4
|
|
162
162
|
summary: Turn your existing Rails app into a native iOS and Android app.
|
|
163
163
|
test_files: []
|