shopify_app 7.2.0 → 17.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +5 -5
  2. data/.babelrc +5 -0
  3. data/.github/CODEOWNERS +1 -0
  4. data/.github/ISSUE_TEMPLATE/bug-report.md +63 -0
  5. data/.github/ISSUE_TEMPLATE/config.yml +1 -0
  6. data/.github/ISSUE_TEMPLATE/feature-request.md +33 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
  8. data/.github/probots.yml +2 -0
  9. data/.github/workflows/build.yml +38 -0
  10. data/.github/workflows/release.yml +24 -0
  11. data/.github/workflows/rubocop.yml +22 -0
  12. data/.gitignore +4 -1
  13. data/.nvmrc +1 -0
  14. data/.rubocop.yml +18 -0
  15. data/.ruby-version +1 -0
  16. data/CHANGELOG.md +465 -0
  17. data/CONTRIBUTING.md +76 -0
  18. data/Gemfile +7 -0
  19. data/Gemfile.lock +256 -0
  20. data/README.md +73 -288
  21. data/Rakefile +1 -0
  22. data/SECURITY.md +59 -0
  23. data/app/assets/images/storage_access.svg +1 -0
  24. data/app/assets/javascripts/shopify_app/enable_cookies.js +3 -0
  25. data/app/assets/javascripts/shopify_app/itp_helper.js +40 -0
  26. data/app/assets/javascripts/shopify_app/partition_cookies.js +8 -0
  27. data/app/assets/javascripts/shopify_app/redirect.js +33 -0
  28. data/app/assets/javascripts/shopify_app/request_storage_access.js +3 -0
  29. data/app/assets/javascripts/shopify_app/storage_access.js +154 -0
  30. data/app/assets/javascripts/shopify_app/storage_access_redirect.js +17 -0
  31. data/app/assets/javascripts/shopify_app/top_level.js +2 -0
  32. data/app/assets/javascripts/shopify_app/top_level_interaction.js +11 -0
  33. data/app/controllers/concerns/shopify_app/authenticated.rb +16 -0
  34. data/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +26 -0
  35. data/app/controllers/concerns/shopify_app/require_known_shop.rb +39 -0
  36. data/app/controllers/concerns/shopify_app/shop_access_scopes_verification.rb +32 -0
  37. data/app/controllers/shopify_app/authenticated_controller.rb +5 -5
  38. data/app/controllers/shopify_app/callback_controller.rb +196 -0
  39. data/app/controllers/shopify_app/extension_verification_controller.rb +15 -0
  40. data/app/controllers/shopify_app/sessions_controller.rb +190 -2
  41. data/app/controllers/shopify_app/webhooks_controller.rb +16 -7
  42. data/app/views/shopify_app/partials/_button_styles.html.erb +109 -0
  43. data/app/views/shopify_app/partials/_card_styles.html.erb +33 -0
  44. data/app/views/shopify_app/partials/_empty_state_styles.html.erb +98 -0
  45. data/app/views/shopify_app/partials/_form_styles.html.erb +56 -0
  46. data/app/views/shopify_app/partials/_layout_styles.html.erb +182 -0
  47. data/app/views/shopify_app/partials/_typography_styles.html.erb +35 -0
  48. data/app/views/shopify_app/sessions/enable_cookies.html.erb +70 -0
  49. data/app/views/shopify_app/sessions/new.html.erb +39 -83
  50. data/app/views/shopify_app/sessions/request_storage_access.html.erb +68 -0
  51. data/app/views/shopify_app/sessions/top_level_interaction.html.erb +63 -0
  52. data/app/views/shopify_app/shared/redirect.html.erb +23 -0
  53. data/config/locales/cs.yml +23 -0
  54. data/config/locales/da.yml +20 -0
  55. data/config/locales/de.yml +22 -0
  56. data/config/locales/en.yml +12 -1
  57. data/config/locales/es.yml +21 -3
  58. data/config/locales/fi.yml +20 -0
  59. data/config/locales/fr.yml +23 -0
  60. data/config/locales/hi.yml +23 -0
  61. data/config/locales/it.yml +21 -0
  62. data/config/locales/ja.yml +17 -0
  63. data/config/locales/ko.yml +19 -0
  64. data/config/locales/ms.yml +22 -0
  65. data/config/locales/nb.yml +21 -0
  66. data/config/locales/nl.yml +21 -0
  67. data/config/locales/pl.yml +21 -0
  68. data/config/locales/pt-BR.yml +21 -0
  69. data/config/locales/pt-PT.yml +22 -0
  70. data/config/locales/sv.yml +21 -0
  71. data/config/locales/th.yml +20 -0
  72. data/config/locales/tr.yml +22 -0
  73. data/config/locales/vi.yml +22 -0
  74. data/config/locales/zh-CN.yml +16 -0
  75. data/config/locales/zh-TW.yml +16 -0
  76. data/config/routes.rb +12 -1
  77. data/docs/Quickstart.md +31 -0
  78. data/docs/Releasing.md +21 -0
  79. data/docs/Troubleshooting.md +16 -0
  80. data/docs/Upgrading.md +110 -0
  81. data/docs/shopify_app/authentication.md +124 -0
  82. data/docs/shopify_app/engine.md +82 -0
  83. data/docs/shopify_app/generators.md +127 -0
  84. data/docs/shopify_app/handling-access-scopes-changes.md +8 -0
  85. data/docs/shopify_app/script-tags.md +28 -0
  86. data/docs/shopify_app/session-repository.md +88 -0
  87. data/docs/shopify_app/testing.md +38 -0
  88. data/docs/shopify_app/webhooks.md +72 -0
  89. data/karma.conf.js +44 -0
  90. data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +47 -0
  91. data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +11 -0
  92. data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +40 -0
  93. data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +62 -0
  94. data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +5 -4
  95. data/lib/generators/shopify_app/add_webhook/templates/{webhook_job.rb → webhook_job.rb.tt} +5 -0
  96. data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +4 -3
  97. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +3 -3
  98. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +10 -9
  99. data/lib/generators/shopify_app/app_proxy_controller/templates/index.html.erb +2 -2
  100. data/lib/generators/shopify_app/authenticated_controller/authenticated_controller_generator.rb +15 -0
  101. data/lib/generators/shopify_app/authenticated_controller/templates/authenticated_controller.rb +5 -0
  102. data/lib/generators/shopify_app/controllers/controllers_generator.rb +2 -1
  103. data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +31 -9
  104. data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +6 -1
  105. data/lib/generators/shopify_app/home_controller/templates/index.html.erb +70 -6
  106. data/lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb +11 -0
  107. data/lib/generators/shopify_app/install/install_generator.rb +78 -27
  108. data/lib/generators/shopify_app/install/templates/_flash_messages.html.erb +1 -13
  109. data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +12 -11
  110. data/lib/generators/shopify_app/install/templates/flash_messages.js +24 -0
  111. data/lib/generators/shopify_app/install/templates/omniauth.rb +3 -1
  112. data/lib/generators/shopify_app/install/templates/session_store.rb +4 -0
  113. data/lib/generators/shopify_app/install/templates/shopify_app.js +15 -0
  114. data/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +25 -0
  115. data/lib/generators/shopify_app/install/templates/shopify_app_index.js +2 -0
  116. data/lib/generators/shopify_app/install/templates/shopify_provider.rb.tt +8 -0
  117. data/lib/generators/shopify_app/install/templates/user_agent.rb +6 -0
  118. data/lib/generators/shopify_app/products_controller/products_controller_generator.rb +19 -0
  119. data/lib/generators/shopify_app/products_controller/templates/products_controller.rb +8 -0
  120. data/lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb +16 -0
  121. data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake +17 -0
  122. data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb +42 -0
  123. data/lib/generators/shopify_app/routes/routes_generator.rb +1 -0
  124. data/lib/generators/shopify_app/routes/templates/routes.rb +10 -9
  125. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +42 -14
  126. data/lib/generators/shopify_app/shop_model/templates/db/migrate/add_shop_access_scopes_column.erb +5 -0
  127. data/lib/generators/shopify_app/shop_model/templates/db/migrate/{create_shops.rb → create_shops.erb} +1 -1
  128. data/lib/generators/shopify_app/shop_model/templates/shop.rb +6 -2
  129. data/lib/generators/shopify_app/shopify_app_generator.rb +5 -3
  130. data/lib/generators/shopify_app/user_model/templates/db/migrate/add_user_access_scopes_column.erb +5 -0
  131. data/lib/generators/shopify_app/user_model/templates/db/migrate/create_users.erb +16 -0
  132. data/lib/generators/shopify_app/user_model/templates/user.rb +8 -0
  133. data/lib/generators/shopify_app/user_model/templates/users.yml +4 -0
  134. data/lib/generators/shopify_app/user_model/user_model_generator.rb +70 -0
  135. data/lib/generators/shopify_app/views/views_generator.rb +2 -1
  136. data/lib/shopify_app/access_scopes/noop_strategy.rb +13 -0
  137. data/lib/shopify_app/access_scopes/shop_strategy.rb +24 -0
  138. data/lib/shopify_app/access_scopes/user_strategy.rb +41 -0
  139. data/lib/shopify_app/configuration.rb +69 -5
  140. data/lib/shopify_app/{app_proxy_verification.rb → controller_concerns/app_proxy_verification.rb} +4 -9
  141. data/lib/shopify_app/controller_concerns/csrf_protection.rb +15 -0
  142. data/lib/shopify_app/controller_concerns/embedded_app.rb +20 -0
  143. data/lib/shopify_app/controller_concerns/itp.rb +45 -0
  144. data/lib/shopify_app/controller_concerns/localization.rb +23 -0
  145. data/lib/shopify_app/controller_concerns/login_protection.rb +244 -0
  146. data/lib/shopify_app/controller_concerns/payload_verification.rb +24 -0
  147. data/lib/shopify_app/controller_concerns/webhook_verification.rb +23 -0
  148. data/lib/shopify_app/engine.rb +40 -0
  149. data/lib/shopify_app/jobs/scripttags_manager_job.rb +16 -0
  150. data/lib/shopify_app/{webhooks_manager_job.rb → jobs/webhooks_manager_job.rb} +3 -2
  151. data/lib/shopify_app/{scripttags_manager.rb → managers/scripttags_manager.rb} +25 -8
  152. data/lib/shopify_app/{webhooks_manager.rb → managers/webhooks_manager.rb} +6 -5
  153. data/lib/shopify_app/middleware/jwt_middleware.rb +42 -0
  154. data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +34 -0
  155. data/lib/shopify_app/omniauth/omniauth_configuration.rb +64 -0
  156. data/lib/shopify_app/session/in_memory_session_store.rb +31 -0
  157. data/lib/shopify_app/session/in_memory_shop_session_store.rb +16 -0
  158. data/lib/shopify_app/session/in_memory_user_session_store.rb +16 -0
  159. data/lib/shopify_app/session/jwt.rb +63 -0
  160. data/lib/shopify_app/session/null_user_session_store.rb +22 -0
  161. data/lib/shopify_app/session/session_repository.rb +56 -0
  162. data/lib/shopify_app/session/session_storage.rb +20 -0
  163. data/lib/shopify_app/session/shop_session_storage.rb +42 -0
  164. data/lib/shopify_app/session/shop_session_storage_with_scopes.rb +58 -0
  165. data/lib/shopify_app/session/user_session_storage.rb +42 -0
  166. data/lib/shopify_app/session/user_session_storage_with_scopes.rb +58 -0
  167. data/lib/shopify_app/test_helpers/all.rb +2 -0
  168. data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +17 -0
  169. data/lib/shopify_app/utils.rb +24 -4
  170. data/lib/shopify_app/version.rb +2 -1
  171. data/lib/shopify_app.rb +65 -24
  172. data/package.json +27 -0
  173. data/service.yml +7 -0
  174. data/shipit.rubygems.yml +3 -0
  175. data/shopify_app.gemspec +20 -9
  176. data/translation.yml +7 -0
  177. data/webpack.config.js +24 -0
  178. data/yarn.lock +5215 -0
  179. metadata +274 -43
  180. data/.travis.yml +0 -17
  181. data/Gemfile.rails50 +0 -5
  182. data/Gemfile.ruby22 +0 -6
  183. data/Gemfile.ruby22.rails50 +0 -9
  184. data/ISSUE_TEMPLATE.md +0 -14
  185. data/QUICKSTART.md +0 -72
  186. data/RELEASING +0 -13
  187. data/lib/generators/shopify_app/home_controller/templates/shopify_app_ready_script.html.erb +0 -11
  188. data/lib/generators/shopify_app/install/templates/shopify_app.rb +0 -9
  189. data/lib/generators/shopify_app/install/templates/shopify_provider.rb +0 -4
  190. data/lib/generators/shopify_app/install/templates/shopify_session_repository.rb +0 -23
  191. data/lib/generators/shopify_app/shop_model/templates/shopify_session_repository.rb +0 -7
  192. data/lib/shopify_app/in_memory_session_store.rb +0 -25
  193. data/lib/shopify_app/login_protection.rb +0 -103
  194. data/lib/shopify_app/scripttags_manager_job.rb +0 -15
  195. data/lib/shopify_app/session_storage.rb +0 -23
  196. data/lib/shopify_app/sessions_concern.rb +0 -101
  197. data/lib/shopify_app/shop.rb +0 -15
  198. data/lib/shopify_app/shopify_session_repository.rb +0 -34
  199. data/lib/shopify_app/webhook_verification.rb +0 -39
data/Gemfile.lock ADDED
@@ -0,0 +1,256 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shopify_app (17.1.0)
5
+ browser_sniffer (~> 1.2.2)
6
+ jwt (~> 2.2.1)
7
+ omniauth-shopify-oauth2 (~> 2.2.2)
8
+ rails (> 5.2.1, < 6.1)
9
+ redirect_safely (~> 1.0)
10
+ shopify_api (~> 9.4)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ actioncable (6.0.3.5)
16
+ actionpack (= 6.0.3.5)
17
+ nio4r (~> 2.0)
18
+ websocket-driver (>= 0.6.1)
19
+ actionmailbox (6.0.3.5)
20
+ actionpack (= 6.0.3.5)
21
+ activejob (= 6.0.3.5)
22
+ activerecord (= 6.0.3.5)
23
+ activestorage (= 6.0.3.5)
24
+ activesupport (= 6.0.3.5)
25
+ mail (>= 2.7.1)
26
+ actionmailer (6.0.3.5)
27
+ actionpack (= 6.0.3.5)
28
+ actionview (= 6.0.3.5)
29
+ activejob (= 6.0.3.5)
30
+ mail (~> 2.5, >= 2.5.4)
31
+ rails-dom-testing (~> 2.0)
32
+ actionpack (6.0.3.5)
33
+ actionview (= 6.0.3.5)
34
+ activesupport (= 6.0.3.5)
35
+ rack (~> 2.0, >= 2.0.8)
36
+ rack-test (>= 0.6.3)
37
+ rails-dom-testing (~> 2.0)
38
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
39
+ actiontext (6.0.3.5)
40
+ actionpack (= 6.0.3.5)
41
+ activerecord (= 6.0.3.5)
42
+ activestorage (= 6.0.3.5)
43
+ activesupport (= 6.0.3.5)
44
+ nokogiri (>= 1.8.5)
45
+ actionview (6.0.3.5)
46
+ activesupport (= 6.0.3.5)
47
+ builder (~> 3.1)
48
+ erubi (~> 1.4)
49
+ rails-dom-testing (~> 2.0)
50
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
51
+ activejob (6.0.3.5)
52
+ activesupport (= 6.0.3.5)
53
+ globalid (>= 0.3.6)
54
+ activemodel (6.0.3.5)
55
+ activesupport (= 6.0.3.5)
56
+ activemodel-serializers-xml (1.0.2)
57
+ activemodel (> 5.x)
58
+ activesupport (> 5.x)
59
+ builder (~> 3.1)
60
+ activerecord (6.0.3.5)
61
+ activemodel (= 6.0.3.5)
62
+ activesupport (= 6.0.3.5)
63
+ activeresource (5.1.1)
64
+ activemodel (>= 5.0, < 7)
65
+ activemodel-serializers-xml (~> 1.0)
66
+ activesupport (>= 5.0, < 7)
67
+ activestorage (6.0.3.5)
68
+ actionpack (= 6.0.3.5)
69
+ activejob (= 6.0.3.5)
70
+ activerecord (= 6.0.3.5)
71
+ marcel (~> 0.3.1)
72
+ activesupport (6.0.3.5)
73
+ concurrent-ruby (~> 1.0, >= 1.0.2)
74
+ i18n (>= 0.7, < 2)
75
+ minitest (~> 5.1)
76
+ tzinfo (~> 1.1)
77
+ zeitwerk (~> 2.2, >= 2.2.2)
78
+ addressable (2.7.0)
79
+ public_suffix (>= 2.0.2, < 5.0)
80
+ ast (2.4.1)
81
+ binding_of_caller (0.8.0)
82
+ debug_inspector (>= 0.0.1)
83
+ browser_sniffer (1.2.2)
84
+ builder (3.2.4)
85
+ byebug (11.1.3)
86
+ coderay (1.1.3)
87
+ concurrent-ruby (1.1.8)
88
+ crack (0.4.4)
89
+ crass (1.0.6)
90
+ debug_inspector (0.0.3)
91
+ erubi (1.9.0)
92
+ faraday (1.3.0)
93
+ faraday-net_http (~> 1.0)
94
+ multipart-post (>= 1.2, < 3)
95
+ ruby2_keywords
96
+ faraday-net_http (1.0.1)
97
+ globalid (0.4.2)
98
+ activesupport (>= 4.2.0)
99
+ graphql (1.12.5)
100
+ graphql-client (0.16.0)
101
+ activesupport (>= 3.0)
102
+ graphql (~> 1.8)
103
+ hashdiff (1.0.1)
104
+ hashie (4.1.0)
105
+ i18n (1.8.9)
106
+ concurrent-ruby (~> 1.0)
107
+ jwt (2.2.2)
108
+ loofah (2.7.0)
109
+ crass (~> 1.0.2)
110
+ nokogiri (>= 1.5.9)
111
+ mail (2.7.1)
112
+ mini_mime (>= 0.1.1)
113
+ marcel (0.3.3)
114
+ mimemagic (~> 0.3.2)
115
+ method_source (0.9.2)
116
+ mimemagic (0.3.5)
117
+ mini_mime (1.0.2)
118
+ mini_portile2 (2.5.0)
119
+ minitest (5.14.4)
120
+ mocha (1.11.2)
121
+ multi_json (1.15.0)
122
+ multi_xml (0.6.0)
123
+ multipart-post (2.1.1)
124
+ nio4r (2.5.7)
125
+ nokogiri (1.11.1)
126
+ mini_portile2 (~> 2.5.0)
127
+ racc (~> 1.4)
128
+ oauth2 (1.4.4)
129
+ faraday (>= 0.8, < 2.0)
130
+ jwt (>= 1.0, < 3.0)
131
+ multi_json (~> 1.3)
132
+ multi_xml (~> 0.5)
133
+ rack (>= 1.2, < 3)
134
+ omniauth (1.9.1)
135
+ hashie (>= 3.4.6)
136
+ rack (>= 1.6.2, < 3)
137
+ omniauth-oauth2 (1.5.0)
138
+ oauth2 (~> 1.1)
139
+ omniauth (~> 1.2)
140
+ omniauth-shopify-oauth2 (2.2.3)
141
+ activesupport
142
+ omniauth-oauth2 (~> 1.5.0)
143
+ parallel (1.20.1)
144
+ parser (2.7.2.0)
145
+ ast (~> 2.4.1)
146
+ pry (0.12.2)
147
+ coderay (~> 1.1.0)
148
+ method_source (~> 0.9.0)
149
+ pry-nav (0.3.0)
150
+ pry (>= 0.9.10, < 0.13.0)
151
+ pry-stack_explorer (0.4.9.3)
152
+ binding_of_caller (>= 0.7)
153
+ pry (>= 0.9.11)
154
+ public_suffix (4.0.6)
155
+ racc (1.5.2)
156
+ rack (2.2.3)
157
+ rack-test (1.1.0)
158
+ rack (>= 1.0, < 3)
159
+ rails (6.0.3.5)
160
+ actioncable (= 6.0.3.5)
161
+ actionmailbox (= 6.0.3.5)
162
+ actionmailer (= 6.0.3.5)
163
+ actionpack (= 6.0.3.5)
164
+ actiontext (= 6.0.3.5)
165
+ actionview (= 6.0.3.5)
166
+ activejob (= 6.0.3.5)
167
+ activemodel (= 6.0.3.5)
168
+ activerecord (= 6.0.3.5)
169
+ activestorage (= 6.0.3.5)
170
+ activesupport (= 6.0.3.5)
171
+ bundler (>= 1.3.0)
172
+ railties (= 6.0.3.5)
173
+ sprockets-rails (>= 2.0.0)
174
+ rails-controller-testing (1.0.5)
175
+ actionpack (>= 5.0.1.rc1)
176
+ actionview (>= 5.0.1.rc1)
177
+ activesupport (>= 5.0.1.rc1)
178
+ rails-dom-testing (2.0.3)
179
+ activesupport (>= 4.2.0)
180
+ nokogiri (>= 1.6)
181
+ rails-html-sanitizer (1.3.0)
182
+ loofah (~> 2.3)
183
+ railties (6.0.3.5)
184
+ actionpack (= 6.0.3.5)
185
+ activesupport (= 6.0.3.5)
186
+ method_source
187
+ rake (>= 0.8.7)
188
+ thor (>= 0.20.3, < 2.0)
189
+ rainbow (3.0.0)
190
+ rake (13.0.3)
191
+ rb-readline (0.5.5)
192
+ redirect_safely (1.0.0)
193
+ activemodel
194
+ regexp_parser (2.0.0)
195
+ rexml (3.2.4)
196
+ rubocop (1.5.2)
197
+ parallel (~> 1.10)
198
+ parser (>= 2.7.1.5)
199
+ rainbow (>= 2.2.2, < 4.0)
200
+ regexp_parser (>= 1.8, < 3.0)
201
+ rexml
202
+ rubocop-ast (>= 1.2.0, < 2.0)
203
+ ruby-progressbar (~> 1.7)
204
+ unicode-display_width (>= 1.4.0, < 2.0)
205
+ rubocop-ast (1.3.0)
206
+ parser (>= 2.7.1.5)
207
+ rubocop-shopify (1.0.7)
208
+ rubocop (~> 1.4)
209
+ ruby-progressbar (1.10.1)
210
+ ruby2_keywords (0.0.4)
211
+ shopify_api (9.4.0)
212
+ activeresource (>= 4.1.0, < 6.0.0)
213
+ graphql-client
214
+ rack
215
+ sprockets (4.0.2)
216
+ concurrent-ruby (~> 1.0)
217
+ rack (> 1, < 3)
218
+ sprockets-rails (3.2.2)
219
+ actionpack (>= 4.0)
220
+ activesupport (>= 4.0)
221
+ sprockets (>= 3.0.0)
222
+ sqlite3 (1.4.2)
223
+ thor (1.1.0)
224
+ thread_safe (0.3.6)
225
+ tzinfo (1.2.9)
226
+ thread_safe (~> 0.1)
227
+ unicode-display_width (1.7.0)
228
+ webmock (3.9.1)
229
+ addressable (>= 2.3.6)
230
+ crack (>= 0.3.2)
231
+ hashdiff (>= 0.4.0, < 2.0.0)
232
+ websocket-driver (0.7.3)
233
+ websocket-extensions (>= 0.1.0)
234
+ websocket-extensions (0.1.5)
235
+ zeitwerk (2.4.2)
236
+
237
+ PLATFORMS
238
+ ruby
239
+
240
+ DEPENDENCIES
241
+ byebug
242
+ minitest
243
+ mocha
244
+ pry
245
+ pry-nav
246
+ pry-stack_explorer
247
+ rails-controller-testing
248
+ rake
249
+ rb-readline
250
+ rubocop-shopify
251
+ shopify_app!
252
+ sqlite3 (~> 1.4)
253
+ webmock
254
+
255
+ BUNDLED WITH
256
+ 2.1.4
data/README.md CHANGED
@@ -1,345 +1,130 @@
1
- Shopify App
2
- ===========
3
- [![Version][gem]][gem_url] [![Build Status](https://travis-ci.org/Shopify/shopify_app.png)](https://travis-ci.org/Shopify/shopify_app)
1
+ # Shopify App
2
+
3
+ [![Version][gem]][gem_url] [![Build Status](https://github.com/Shopify/shopify_app/workflows/CI/badge.svg)](https://github.com/Shopify/shopify_app/actions?query=workflow%3ACI) ![Supported Rails version][supported_rails_version]
4
4
 
5
5
  [gem]: https://img.shields.io/gem/v/shopify_app.svg
6
6
  [gem_url]: https://rubygems.org/gems/shopify_app
7
+ [supported_rails_version]: https://img.shields.io/badge/rails-%3C6.1.0-orange
7
8
 
9
+ This gem builds Rails applications that can be embedded in the Shopify Admin.
8
10
 
9
- Shopify Application Rails engine and generator
10
-
11
-
12
- Table of Contents
13
- -----------------
14
- * [**Description**](#description)
15
- * [**Quickstart**](#quickstart)
16
- * [**Becoming a Shopify App Developer**](#becoming-a-shopify-app-developer)
17
- * [**Installation**](#installation)
18
- * [Rails 5](#rails-5)
19
- * [**Generators**](#generators)
20
- * [Default Generator](#default-generator)
21
- * [Install Generator](#install-generator)
22
- * [Shop Model Generator](#shop-model-generator)
23
- * [Home Controller Generator](#home-controller-generator)
24
- * [App Proxy Controller Generator](#app-proxy-controller-generator)
25
- * [Controllers, Routes and Views](#controllers-routes-and-views)
26
- * [**Mounting the Engine**](#mounting-the-engine)
27
- * [**Managing Api Keys**](#managing-api-keys)
28
- * [**WebhooksManager**](#webhooksmanager)
29
- * [**ScripttagsManager**](#scripttagsmanager)
30
- * [**ShopifyApp::SessionRepository**](#shopifyappsessionrepository)
31
- * [**AuthenticatedController**](#authenticatedcontroller)
32
- * [**AppProxyVerification**](#appproxyverification)
33
- * [Recommended Usage](#recommended-usage)
34
- * [**Troubleshooting**](#troubleshooting)
35
- * [Generator shopify_app:install hangs](#generator-shopify_appinstall-hangs)
36
- * [**Testing an embedded app outside the Shopify admin**](#testing-an-embedded-app-outside-the-shopify-admin)
37
- * [**App Tunneling**](#app-tunneling)
38
- * [**Questions or problems?**](#questions-or-problems)
39
-
40
-
41
- Description
42
- -----------
43
- This gem includes a Rails Engine and generators for writing Rails applications using the Shopify API. The Engine provides a SessionsController and all the required code for authenticating with a shop via Oauth (other authentication methods are not supported).
44
-
45
- The [example](https://github.com/Shopify/shopify_app/tree/master/example) directory contains an app that was generated with this gem. It also contains sample code demonstrating the usage of the embedded app sdk.
46
-
47
- *Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete some of your files.*
48
-
49
-
50
- Quickstart
51
- ----------
52
-
53
- Check out this screencast on how to create and deploy a new Shopify App to Heroku in 5 minutes:
54
-
55
- [https://vimeo.com/130247240](https://vimeo.com/130247240)
56
-
57
- Or if you prefer text instructions the steps in the video are written out [here](https://github.com/Shopify/shopify_app/blob/master/QUICKSTART.md)
11
+ [Introduction](#introduction) |
12
+ [Requirements](#requirements) |
13
+ [Usage](#usage) |
14
+ [Documentation](#documentation) |
15
+ [Contributing](/CONTRIBUTING.md) |
16
+ [License](/LICENSE)
58
17
 
59
- Becoming a Shopify App Developer
60
- --------------------------------
61
- If you don't have a Shopify Partner account yet head over to http://shopify.com/partners to create one, you'll need it before you can start developing apps.
18
+ ## Introduction
62
19
 
63
- Once you have a Partner account create a new application to get an Api key and other Api credentials. To create a development application set the Application Callback URL to
20
+ This gem includes a Rails engine, generators, modules, and mixins that help create Rails applications that work with Shopify APIs. The [Shopify App Rails engine](/docs/shopify_app/engine.md) provides all the code required to implement OAuth with Shopify. The [default Shopify App generator](/docs/shopify_app/generators.md#-environment-rails-generate-shopify_app) builds an app that can be embedded in the Shopify Admin and secures it with [session tokens](https://shopify.dev/concepts/apps/building-embedded-apps-using-session-tokens).
64
21
 
65
- ```
66
- http://localhost:3000/
67
- ```
22
+ <!-- This section is linked to in `templates/shopify_app.rb.tt`. Be careful renaming this heading. -->
23
+ ## Requirements
68
24
 
69
- and the `redirect_uri` to
25
+ > **Rails compatibility**
26
+ > * Rails 6.1 or above is not yet supported due to the new `cookies_same_site_protection` setting.
27
+ > * Use Shopify App `<= v7.2.8` if you need to work with Rails 4.
70
28
 
71
- ```
72
- http://localhost:3000/auth/shopify/callback
73
- ```
29
+ To become a Shopify app developer, you will need a [Shopify Partners](https://www.shopify.com/partners) account. Explore the [Shopify dev docs](https://shopify.dev/concepts/shopify-introduction) to learn more about [building Shopify apps](https://shopify.dev/concepts/apps).
74
30
 
75
- This way you'll be able to run the app on your local machine.
31
+ This gem requires that you have the following credentials:
76
32
 
77
- Also note, ShopifyApp creates embedded apps by default, so remember to check `enabled` for the embedded settings.
33
+ - **Shopify API key:** The API key app credential specified in your [Shopify Partners dashboard](https://partners.shopify.com/organizations).
34
+ - **Shopify API secret:** The API secret key app credential specified in your [Shopify Partners dashboard](https://partners.shopify.com/organizations).
78
35
 
36
+ ## Usage
79
37
 
80
- Installation
81
- ------------
82
- To get started add shopify_app to your Gemfile and bundle install
38
+ 1. To get started, create a new Rails app:
83
39
 
84
40
  ``` sh
85
- # Create a new rails app
86
41
  $ rails new my_shopify_app
87
- $ cd my_shopify_app
88
-
89
- # Add the gem shopify_app to your Gemfile
90
- $ echo "gem 'shopify_app'" >> Gemfile
91
- $ bundle install
92
- ```
93
-
94
- Now we are ready to run any of the shopify_app generators. The following section explains the generators and what they can do.
95
-
96
-
97
- #### Rails 5
98
-
99
- shopify_app is compatible with Rails 5 but since the latest ActiveResource release (4.1) is locked on Rails 4.x, you'll need to use the unreleased master version:
100
-
101
- ```ruby
102
- gem 'shopify_app'
103
- gem 'activeresource', github: 'rails/activeresource'
104
42
  ```
105
43
 
106
-
107
- Generators
108
- ----------
109
-
110
- ### Default Generator
111
-
112
- The default generator will run the `install`, `shop`, and `home_controller` generators. This is the recommended way to start your app.
44
+ 2. Add the Shopify App gem to `my_shopify_app`'s Gemfile.
113
45
 
114
46
  ```sh
115
- $ rails generate shopify_app --api_key <your_api_key> --secret <your_app_secret>
47
+ $ bundle add shopify_app
116
48
  ```
117
49
 
50
+ 3. Create a `.env` file in the root of `my_shopify_app` to specify your Shopify API credentials:
118
51
 
119
- ### Install Generator
120
-
121
- ```sh
122
- $ rails generate shopify_app:install
123
-
124
- # or optionally with arguments:
125
-
126
- $ rails generate shopify_app:install --api_key <your_api_key> --secret <your_app_secret>
127
52
  ```
128
-
129
- Other options include:
130
- * `application_name` - the name of your app
131
- * `scope` - the Oauth access scope required for your app, eg 'read_products, write_orders'. For more information read the [docs](http://docs.shopify.com/api/tutorials/oauth)
132
- * `embedded` - the default is to generate an [embedded app](http://docs.shopify.com/embedded-app-sdk), if you want a legacy non-embedded app then set this to false, `--embedded false`
133
-
134
- You can update any of these settings later on easily, the arguments are simply for convenience.
135
-
136
- The generator adds ShopifyApp and the required initializers to the host Rails application.
137
-
138
- After running the `install` generator, you can start your app with `bundle exec rails server` and install your app by visiting localhost.
139
-
140
-
141
- ### Shop Model Generator
142
-
143
- ```sh
144
- $ rails generate shopify_app:shop_model
53
+ SHOPIFY_API_KEY=<Your Shopify API key>
54
+ SHOPIFY_API_SECRET=<Your Shopify API secret>
145
55
  ```
146
56
 
147
- The install generator doesn't create any database models for you and if you are starting a new app its quite likely that you will want one (most of our internally developed apps do!). This generator creates a simple shop model and a migration. It also creates a model called `SessionStorage` which interacts with `ShopifyApp::SessionRepository`. Check out the later section to learn more about `ShopifyApp::SessionRepository`
148
-
149
- *Note that you will need to run rake db:migrate after this generator*
57
+ > In a development environment, you can use a gem like `dotenv-rails` to manage environment variables.
150
58
 
151
-
152
- ### Home Controller Generator
59
+ 4. Run the default Shopify App generator to create an app that can be embedded in the Shopify Admin:
153
60
 
154
61
  ```sh
155
- $ rails generate shopify_app:home_controller
62
+ $ rails generate shopify_app
156
63
  ```
157
64
 
158
- This generator creates an example home controller and view which fetches and displays products using the ShopifyAPI
159
-
160
-
161
- ### App Proxy Controller Generator
65
+ 5. Run a migration to create the necessary tables in your database:
162
66
 
163
67
  ```sh
164
- $ rails generate shopify_app:app_proxy_controller
68
+ $ rails db:migrate
165
69
  ```
166
70
 
167
- This optional generator, not included with the default generator, creates the app proxy controller to handle proxy requests to the app from your shop storefront, modifies 'config/routes.rb' with a namespace route, and an example view which displays current shop information using the LiquidAPI
168
-
169
-
170
- ### Controllers, Routes and Views
171
-
172
- The last group of generators are for your convenience if you want to start overriding code included as part of the Rails engine. For example by default the engine provides a simple SessionController, if you run the `rails generate shopify_app:controllers` generator then this code gets copied out into your app so you can start adding to it. Routes and views follow the exact same pattern.
173
-
174
- Mounting the Engine
175
- -------------------
176
-
177
- Mounting the Engine will provide the basic routes to authenticating a shop with your custom application. It will provide:
71
+ 6. Run the app:
178
72
 
179
- | Verb | Route | Action |
180
- |--------|-------------------------------|------------------------------|
181
- |GET |'/login' |Login |
182
- |POST |'/login' |Login |
183
- |GET |'/auth/shopify/callback' |Authenticate Callback |
184
- |GET |'/logout' |Logout |
185
- |POST |'/webhooks/:type' |Webhook Callback |
186
-
187
-
188
- The default routes of the Shopify rails engine, which is mounted to the root, can be altered to mount on a different route. The `config/routes.rb` can be modified to put these under a nested route (say `/app-name`) as:
189
-
190
- ```ruby
191
- mount ShopifyApp::Engine, at: '/app-name'
192
- ```
193
-
194
- This will create the Shopify engine routes under the specified Subdirectory, as a result it will redirect new consumers to `/app-name/login` and following a similar format for the other engine routes.
195
-
196
- To use named routes with the engine so that it can route between the application and the engine's routes it should be prefixed with `main_app` or `shopify_app`.
197
-
198
- ```ruby
199
- main_app.login_path # For a named login route on the rails app.
200
-
201
- shopify_app.login_path # For the shopify app store login route.
202
- ```
203
-
204
- Managing Api Keys
205
- -----------------
206
-
207
- The `install` generator places your Api credentials directly into the shopify_app initializer which is convenient and fine for development but once your app goes into production **your api credentials should not be in source control**. When we develop apps we keep our keys in environment variables so a production shopify_app initializer would look like this:
208
-
209
- ```ruby
210
- ShopifyApp.configure do |config|
211
- config.application_name = 'Your app name' # Optional
212
- config.api_key = ENV['SHOPIFY_CLIENT_API_KEY']
213
- config.secret = ENV['SHOPIFY_CLIENT_API_SECRET']
214
- config.scope = 'read_customers, read_orders, write_products'
215
- config.embedded_app = true
216
- end
217
- ```
218
-
219
-
220
- WebhooksManager
221
- ---------------
222
-
223
- ShopifyApp can manage your app's webhooks for you by setting which webhooks you require in the initializer:
224
-
225
- ```ruby
226
- ShopifyApp.configure do |config|
227
- config.webhooks = [
228
- {topic: 'carts/update', address: 'example-app.com/webhooks/carts_update'}
229
- ]
230
- end
231
- ```
232
-
233
- When the oauth callback is completed successfully ShopifyApp will queue a background job which will ensure all the specified webhooks exist for that shop. Because this runs on every oauth callback it means your app will always have the webhooks it needs even if the user uninstalls and re-installs the app.
234
-
235
- ShopifyApp also provides a WebhooksController that receives webhooks and queues a job based on the webhook url. For example if you register the webhook from above then all you need to do is create a job called `CartsUpdateJob`. The job will be queued with 2 params `shop_domain` and `webhook` which is the webhook body.
236
-
237
- If you'd rather implement your own controller then you'll want to use the WebhookVerfication module to verify your webhooks:
238
-
239
- ```ruby
240
- class CustomWebhooksController < ApplicationController
241
- include ShopifyApp::WebhookVerification
242
-
243
- def carts_update
244
- SomeJob.perform_later(shopify_domain: shop_domain, webhook: params)
245
- head :ok
246
- end
247
- end
248
- ```
249
-
250
- The module skips the `verify_authenticity_token` before_action and adds an action to verify that the webhook came from Shopify.
251
-
252
- The WebhooksManager uses ActiveJob, if ActiveJob is not configured then by default Rails will run the jobs inline. However it is highly recommended to configure a proper background processing queue like sidekiq or resque in production.
253
-
254
- ShopifyApp can create webhooks for you using the `add_webhook` generator. This will add the new webhook to your config and create the required job class for you.
255
-
256
- ```
257
- rails g shopify_app:add_webhook -t carts/update -a https://example.com/webhooks/carts_update
73
+ ```sh
74
+ $ rails server
258
75
  ```
259
76
 
260
- where `-t` is the topic and `-a` is the address the webhook should be sent to.
261
-
262
- ScripttagsManager
263
- -----------------
264
-
265
- As with webhooks, ShopifyApp can manage your app's scripttags for you by setting which scripttags you require in the initializer:
77
+ See [*Quickstart*](/docs/Quickstart.md) to learn how to install your app on a shop.
266
78
 
267
- ```ruby
268
- ShopifyApp.configure do |config|
269
- config.scripttags = [
270
- {event:'onload', src: 'https://my-shopifyapp.herokuapp.com/fancy.js'}
271
- ]
272
- end
273
- ```
274
-
275
- Scripttags are created in the same way as the Webhooks, with a background job which will create the required scripttags.
79
+ This app implements [OAuth 2.0](https://shopify.dev/tutorials/authenticate-with-oauth) with Shopify to authenticate requests made to Shopify APIs. By default, this app is configured to use [session tokens](https://shopify.dev/concepts/apps/building-embedded-apps-using-session-tokens) to authenticate merchants when embedded in the Shopify Admin.
276
80
 
277
- ShopifyApp::SessionRepository
278
- -----------------------------
81
+ See [*Generators*](/docs/shopify_app/generators.md) for a complete list of generators available to Shopify App.
279
82
 
280
- `ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are retrieved and stored for a shop. The `SessionRepository` is configured using the `config/initializers/shopify_session_repository.rb` file and can be set to any object that implements `self.store(shopify_session)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id. See either the `InMemorySessionStore` or the `SessionStorage` module for examples.
83
+ ## Documentation
281
84
 
282
- If you only run the install generator then by default you will have an in memory store but it **won't work** on multi-server environments including Heroku. If you ran all the generators including the shop_model generator then the Shop model itself will be the `SessionRepository`. If you look at the implementation of the generated shop model you'll see that this gem provides an activerecord mixin for the `SessionRepository`. You can use this mixin on any model that responds to `shopify_domain` and `shopify_token`.
85
+ You can find documentation on gem usage, concepts, mixins, installation, and more in [`/docs`](/docs).
283
86
 
284
- AuthenticatedController
285
- -----------------------
87
+ * Start with the [*Generators*](/docs/shopify_app/generators.md) document to learn more about the generators this gem offers.
88
+ * Check out the [*Changelog*](/CHANGELOG.md) for notes on the latest gem releases.
89
+ * See [*Troubleshooting*](/docs/Troubleshooting.md) for tips on common issues.
90
+ * If you are looking to upgrade your Shopify App version to a new major release, see [*Upgrading*](/docs/Upgrading.md) for important notes on breaking changes.
286
91
 
287
- The engine includes a controller called `ShopifyApp::AuthenticatedController` which inherits from `ApplicationController`. It adds some before_filters which ensure the user is authenticated and will redirect to the login page if not. It is best practice to have all controllers that belong to the Shopify part of your app inherit from this controller. The HomeController that is generated already inherits from AuthenticatedController.
92
+ ### Overview
288
93
 
289
- AppProxyVerification
290
- --------------------
94
+ [Quickstart](/docs/Quickstart.md)
291
95
 
292
- The engine provides a mixin for verifying incoming HTTP requests sent via an App Proxy. Any controller that `include`s `ShopifyApp::AppProxyVerification` will verify that each request has a valid `signature` query parameter that is calculated using the other query parameters and the app's shared secret.
96
+ [Troubleshooting](/docs/Troubleshooting.md)
293
97
 
294
- ### Recommended Usage
98
+ [Upgrading](/docs/Upgrading.md)
295
99
 
296
- The App Proxy Controller Generator automatically adds the mixin to the generated app_proxy_controller.rb
297
- Additional controllers for resources within the App_Proxy namespace, will need to include the mixin like so:
100
+ [Shopify App](/docs/shopify_app)
101
+ * [Authentication](/docs/shopify_app/authentication.md)
102
+ * [Engine](/docs/shopify_app/engine.md)
103
+ * [Generators](/docs/shopify_app/generators.md)
104
+ * [ScriptTags](/docs/shopify_app/script-tags.md)
105
+ * [Session repository](/docs/shopify_app/session-repository.md)
106
+ * [Handling changes in access scopes](/docs/shopify_app/handling-access-scopes-changes.md)
107
+ * [Testing](/docs/shopify_app/testing.md)
108
+ * [Webhooks](/docs/shopify_app/webhooks.md)
298
109
 
299
- ```ruby
300
- # app/controllers/app_proxy/reviews_controller.rb
301
- class ReviewsController < ApplicationController
302
- include ShopifyApp::AppProxyVerification
303
- # ...
304
- end
305
- ```
110
+ ### Engine
306
111
 
307
- Create your app proxy url in the [Shopify Partners' Dashboard](https://app.shopify.com/services/partners/api_clients), making sure to point it to `https://your_app_website.com/app_proxy`.
308
- ![Creating an App Proxy](/images/app-proxy-screenshot.png)
309
-
310
- Troubleshooting
311
- ---------------
312
-
313
- ### Generator shopify_app:install hangs
314
-
315
- Rails uses spring by default to speed up development. To run the generator, spring has to be stopped:
316
-
317
- ```sh
318
- $ bundle exec spring stop
319
- ```
320
-
321
- Run shopify_app generator again.
322
-
323
- Testing an embedded app outside the Shopify admin
324
- -------------------------------------------------
325
-
326
- By default, loading your embedded app will redirect to the Shopify admin, with the app view loaded in an `iframe`. If you need to load your app outside of the Shopify admin (e.g., for performance testing), you can change `forceRedirect: false` to `true` in `ShopifyApp.init` block in the `embedded_app` view. To keep the redirect on in production but off in your `development` and `test` environments, you can use:
327
-
328
- ```javascript
329
- forceRedirect: <%= Rails.env.development? || Rails.env.test? ? 'false' : 'true' %>
330
- ```
112
+ Mounting the Shopify App Rails Engine provides the following routes. These routes are configured to help install your application on shops and implement OAuth.
331
113
 
332
- App Tunneling
333
- -------------
114
+ | Verb | Route | Action |
115
+ | ---: | :--- | :--- |
116
+ | `GET` | `/login` | Login |
117
+ | `POST` | `/login` | Login |
118
+ | `GET` | `/auth/shopify/callback` | OAuth redirect URI |
119
+ | `GET` | `/logout` | Logout |
120
+ | `POST` | `/webhooks/:type` | Webhook callback |
334
121
 
335
- For certain features like Application Proxy or Webhooks to receive requests from Shopify, your app needs to be on a publicly visible URL. This can be a hurdle during development or testing on a local machine. Fortunately, this can be overcome by employing a tunneling service like [Forward](https://forwardhq.com/), [RequestBin](requestb.in/), [ngrok](https://ngrok.com/) etc. These tools allow you to create a secure tunnel from the public Internet to your local machine.
122
+ These routes are configurable. See the more detailed [*Engine*](/docs/shopify_app/engine.md) documentation to learn how you can customize the login URL or mount the Shopify App Rails engine at nested routes.
336
123
 
337
- Tunneling is also useful for working the the embedded app sdk to solve mixed content issues since most tunnles provide ssl.
124
+ To learn more about how this gem authenticates with Shopify, see [*Authentication*](/docs/shopify_app/authentication.md).
338
125
 
339
- Questions or problems?
340
- ----------------------
341
- http://api.shopify.com <= Read up on the possible API calls!
126
+ ### API Versioning
342
127
 
343
- http://ecommerce.shopify.com/c/shopify-apis-and-technology <= Ask questions!
128
+ [Shopify's API is versioned](https://shopify.dev/concepts/about-apis/versioning). With Shopify App `v1.11.0`, the included Shopify API gem allows developers to specify and update the Shopify API version they want their app or service to use. The Shopify API gem also surfaces warnings to Rails apps about [deprecated endpoints, GraphQL fields and more](https://shopify.dev/concepts/about-apis/versioning#deprecation-practices).
344
129
 
345
- http://docs.shopify.com/api/the-basics/getting-started <= Read the docs!
130
+ See the [Shopify API gem README](https://github.com/Shopify/shopify_api/) for more information.