shopify_app 13.0.0 → 13.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -6
  3. data/CHANGELOG.md +10 -0
  4. data/Gemfile +3 -0
  5. data/README.md +32 -1
  6. data/Rakefile +1 -0
  7. data/app/controllers/shopify_app/authenticated_controller.rb +1 -0
  8. data/app/controllers/shopify_app/callback_controller.rb +1 -1
  9. data/app/controllers/shopify_app/sessions_controller.rb +8 -5
  10. data/app/controllers/shopify_app/webhooks_controller.rb +6 -5
  11. data/config/locales/fi.yml +1 -1
  12. data/config/routes.rb +1 -0
  13. data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +5 -3
  14. data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +1 -0
  15. data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +2 -1
  16. data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +4 -4
  17. data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +5 -4
  18. data/lib/generators/shopify_app/add_webhook/templates/webhook_job.rb +5 -0
  19. data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +4 -3
  20. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +3 -3
  21. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +10 -9
  22. data/lib/generators/shopify_app/controllers/controllers_generator.rb +1 -0
  23. data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +4 -3
  24. data/lib/generators/shopify_app/install/install_generator.rb +9 -8
  25. data/lib/generators/shopify_app/install/templates/omniauth.rb +2 -1
  26. data/lib/generators/shopify_app/install/templates/user_agent.rb +2 -1
  27. data/lib/generators/shopify_app/routes/routes_generator.rb +1 -0
  28. data/lib/generators/shopify_app/routes/templates/routes.rb +10 -9
  29. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +5 -4
  30. data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -0
  31. data/lib/generators/shopify_app/shopify_app_generator.rb +4 -3
  32. data/lib/generators/shopify_app/user_model/templates/user.rb +1 -0
  33. data/lib/generators/shopify_app/user_model/user_model_generator.rb +5 -4
  34. data/lib/generators/shopify_app/views/views_generator.rb +1 -0
  35. data/lib/shopify_app.rb +7 -4
  36. data/lib/shopify_app/configuration.rb +15 -8
  37. data/lib/shopify_app/controller_concerns/app_proxy_verification.rb +3 -2
  38. data/lib/shopify_app/controller_concerns/embedded_app.rb +3 -2
  39. data/lib/shopify_app/controller_concerns/localization.rb +1 -0
  40. data/lib/shopify_app/controller_concerns/login_protection.rb +46 -11
  41. data/lib/shopify_app/controller_concerns/webhook_verification.rb +2 -1
  42. data/lib/shopify_app/engine.rb +1 -0
  43. data/lib/shopify_app/jobs/scripttags_manager_job.rb +1 -1
  44. data/lib/shopify_app/jobs/webhooks_manager_job.rb +1 -1
  45. data/lib/shopify_app/managers/scripttags_manager.rb +4 -3
  46. data/lib/shopify_app/managers/webhooks_manager.rb +4 -3
  47. data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +2 -1
  48. data/lib/shopify_app/session/in_memory_session_store.rb +7 -3
  49. data/lib/shopify_app/session/in_memory_shop_session_store.rb +10 -0
  50. data/lib/shopify_app/session/in_memory_user_session_store.rb +10 -0
  51. data/lib/shopify_app/session/jwt.rb +48 -0
  52. data/lib/shopify_app/session/null_user_session_store.rb +22 -0
  53. data/lib/shopify_app/session/session_repository.rb +13 -16
  54. data/lib/shopify_app/session/session_storage.rb +1 -0
  55. data/lib/shopify_app/session/shop_session_storage.rb +21 -9
  56. data/lib/shopify_app/session/user_session_storage.rb +19 -8
  57. data/lib/shopify_app/test_helpers/all.rb +1 -0
  58. data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +16 -0
  59. data/lib/shopify_app/utils.rb +6 -5
  60. data/lib/shopify_app/version.rb +2 -1
  61. data/package-lock.json +4 -4
  62. data/package.json +1 -1
  63. data/shopify_app.gemspec +8 -4
  64. data/yarn.lock +3 -3
  65. metadata +22 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4e2d37f9112725500d1a9f36fe76b743e8981920eea4838024cafd6a71cb5eb
4
- data.tar.gz: 3c52a0ee9a7f40433ad01b82bda3a0c6d30dd9bb45c319f1d457a0bd13c30fc0
3
+ metadata.gz: c32f23c198e7bfcc44d3557857c11194ce71f2dc8a1a42ff0d220569c4eb4599
4
+ data.tar.gz: cf430f7fb26c01592d68d5110a5690f290452ab18c5853dcc4602c5f1d5c0521
5
5
  SHA512:
6
- metadata.gz: 19a445a22b25b01f860a84128551234313bc44e7acd1583ec90bc96f59d65a8fac208feb1d5a6899453935dd19458196c5253605d85e3ac346be2fa405a50b4c
7
- data.tar.gz: 526354098526753ade6d30a346ffa75b2280707638b66dba61c89b34a771e72dd4c23cfae8bda319de58a7a373e7c05d233a13a4f2f8325c7754cda1ed58d835
6
+ metadata.gz: 4af6eb8ff59c68d9bc1089c577d90d40cfa2997550331314e90f620580da62898000e2b7568616b077fa15080878d0e8ddc9a09160490dea3a4ce719f4e814cd
7
+ data.tar.gz: b3cf9731363e7df4b3cc78f057bd96204f25f9ab2832662e2cc7e98a3e52ad98ef68d142bcca6d9c96d232eac2cc1dbc2518a41d364f1470247100c2eddd92fc
@@ -1,10 +1,17 @@
1
- inherit_from:
2
- - https://shopify.github.io/ruby-style-guide/rubocop.yml
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
3
 
4
- LineLength:
4
+ AllCops:
5
+ TargetRubyVersion: 2.4
5
6
  Exclude:
6
- - test/**/*
7
+ - 'lib/generators/**/*'
8
+ - 'test/tmp/**/*'
7
9
 
8
- Metrics/ClassLength:
10
+ Style/MethodCallWithArgsParentheses:
9
11
  Exclude:
10
- - test/**/*
12
+ - '**/Gemfile'
13
+
14
+ Style/ClassAndModuleChildren:
15
+ Exclude:
16
+ - 'test/**/*'
17
+
@@ -1,3 +1,13 @@
1
+ 13.0.1
2
+ ------
3
+ * Small addition to WebhookJob to return if the shop is nil #952
4
+ * Added Rubocop to the Repo #948
5
+ * Added a WebhookVerification test helper #950
6
+
7
+ 13.0.1
8
+ ------
9
+ * fix for deprecation warning while loading session storage at startup
10
+
1
11
  13.0.0
2
12
  ------
3
13
  + #887 Added concurrent user and shop session support (online/offline)
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in shopify_app.gemspec
4
5
  gemspec
5
6
 
6
7
  gem 'rails-controller-testing', group: :test
8
+
9
+ gem 'rubocop-shopify', require: false
data/README.md CHANGED
@@ -25,7 +25,7 @@ Table of Contents
25
25
  - [AppProxyVerification](#appproxyverification)
26
26
  - [Troubleshooting](#troubleshooting)
27
27
  - [Testing an embedded app outside the Shopify admin](#testing-an-embedded-app-outside-the-shopify-admin)
28
- - [Migration to 13.0.0](#migrating-to-13)
28
+ - [Migration to 13.0.0](#migrating-to-1300)
29
29
  - [Questions or problems?](#questions-or-problems-)
30
30
  - [Rails 6 Compatibility](#rails-6-compatibility)
31
31
  - [Upgrading from 8.6 to 9.0.0](#upgrading-from-86-to-900)
@@ -472,6 +472,31 @@ Troubleshooting
472
472
 
473
473
  see [TROUBLESHOOTING.md](https://github.com/Shopify/shopify_app/blob/master/docs/Troubleshooting.md)
474
474
 
475
+ Using Test Helpers inside your Application
476
+ -----------------------------------------
477
+
478
+ A test helper that will allow you to test `ShopifyApp::WebhookVerification` in the controller from your app, to use this test, you need to `require` it directly in side you app `test/controllers/webhook_verification_test.rb`.
479
+
480
+ ```ruby
481
+ require 'test_helper'
482
+ require 'action_controller'
483
+ require 'action_controller/base'
484
+ require 'shopify_app/test_helpers/webhook_verification_helper'
485
+ ```
486
+
487
+ or you can require in your `test/test_helper.rb`
488
+
489
+ ```ruby
490
+ ENV['RAILS_ENV'] ||= 'test'
491
+ require_relative '../config/environment'
492
+ require 'rails/test_help'
493
+ require 'byebug'
494
+ require 'shopify_app/test_helpers/all'
495
+ ```
496
+
497
+ With `lib/shopify_app/test_helpers/all'` more tests can be added and will only need to be required in once in your library.
498
+
499
+
475
500
  Testing an embedded app outside the Shopify admin
476
501
  -------------------------------------------------
477
502
 
@@ -495,6 +520,12 @@ change to how session stores work. Here are the steps to migrate to 13.x
495
520
  ### Shop Model Changes (normally `app/models/shop.rb`)
496
521
  - *CHANGE* `include ShopifyApp::SessionStorage` to `include ShopifyApp::ShopSessionStorage`
497
522
 
523
+ ### Changes to the @shop_session instance variable (normally in `app/controllers/*.rb`)
524
+ - *CHANGE* if you are using shop sessions, `@shop_session` will need to be changed to `@current_shopify_session`
525
+
526
+ ### Changes to Rails `session`
527
+ - *CHANGE* `session[:shopify]` is no longer set. Use `session[:user_id]` if your app uses user based tokens, or `session[:shop_id]` if your app uses shop based tokens.
528
+
498
529
  ### Changes to `ShopifyApp::LoginProtection`
499
530
  `ShopifyApp::LoginProtection`
500
531
 
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rake/testtask'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyApp
2
3
  class AuthenticatedController < ActionController::Base
3
4
  include ShopifyApp::Authenticated
@@ -17,7 +17,7 @@ module ShopifyApp
17
17
  install_scripttags
18
18
  perform_after_authenticate_job
19
19
 
20
- redirect_to return_address
20
+ redirect_to(return_address)
21
21
  else
22
22
  flash[:error] = I18n.t('could_not_log_in')
23
23
  redirect_to(login_url_with_optional_shop)
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyApp
2
- class SessionsController < ActionController::Base # rubocop:disable Metrics/ClassLength
3
+ class SessionsController < ActionController::Base
3
4
  include ShopifyApp::LoginProtection
4
5
 
5
6
  layout false, only: :new
@@ -29,7 +30,7 @@ module ShopifyApp
29
30
  shop: sanitized_shop_name,
30
31
  return_to: params[:return_to]
31
32
  ),
32
- current_shopify_domain: current_shopify_domain
33
+ current_shopify_domain: current_shopify_domain,
33
34
  })
34
35
  end
35
36
 
@@ -91,6 +92,7 @@ module ShopifyApp
91
92
  end
92
93
  end
93
94
 
95
+ # rubocop:disable Lint/SuppressedException
94
96
  def set_user_tokens_option
95
97
  if shop_session.blank?
96
98
  session[:user_tokens] = false
@@ -110,6 +112,7 @@ module ShopifyApp
110
112
  session[:user_tokens] = false
111
113
  rescue StandardError
112
114
  end
115
+ # rubocop:enable Lint/SuppressedException
113
116
 
114
117
  def validate_shop_presence
115
118
  @shop = sanitized_shop_name
@@ -127,7 +130,7 @@ module ShopifyApp
127
130
 
128
131
  def render_invalid_shop_error
129
132
  flash[:error] = I18n.t('invalid_shop_url')
130
- redirect_to return_address
133
+ redirect_to(return_address)
131
134
  end
132
135
 
133
136
  def enable_cookie_access
@@ -138,7 +141,7 @@ module ShopifyApp
138
141
  end
139
142
 
140
143
  def authenticate_in_context
141
- redirect_to "#{main_app.root_path}auth/shopify"
144
+ redirect_to("#{main_app.root_path}auth/shopify")
142
145
  end
143
146
 
144
147
  def authenticate_at_top_level
@@ -173,7 +176,7 @@ module ShopifyApp
173
176
  shop: sanitized_shop_name,
174
177
  return_to: session[:return_to]
175
178
  ),
176
- current_shopify_domain: current_shopify_domain
179
+ current_shopify_domain: current_shopify_domain,
177
180
  }
178
181
  )
179
182
  end
@@ -1,14 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyApp
3
+ class MissingWebhookJobError < StandardError; end
4
+
2
5
  class WebhooksController < ActionController::Base
3
6
  include ShopifyApp::WebhookVerification
4
7
 
5
- class ShopifyApp::MissingWebhookJobError < StandardError; end
6
-
7
8
  def receive
8
9
  params.permit!
9
- job_args = {shop_domain: shop_domain, webhook: webhook_params.to_h}
10
+ job_args = { shop_domain: shop_domain, webhook: webhook_params.to_h }
10
11
  webhook_job_klass.perform_later(job_args)
11
- head :no_content
12
+ head(:no_content)
12
13
  end
13
14
 
14
15
  private
@@ -18,7 +19,7 @@ module ShopifyApp
18
19
  end
19
20
 
20
21
  def webhook_job_klass
21
- webhook_job_klass_name.safe_constantize or raise ShopifyApp::MissingWebhookJobError
22
+ webhook_job_klass_name.safe_constantize || raise(ShopifyApp::MissingWebhookJobError)
22
23
  end
23
24
 
24
25
  def webhook_job_klass_name(type = webhook_type)
@@ -15,6 +15,6 @@ fi:
15
15
  top_level_interaction_action: Jatka
16
16
  request_storage_access_heading: "%{app} edellyttää evästeiden käyttöä"
17
17
  request_storage_access_body: Näin sovellus voi todentaa sinut tallentamalla henkilötietosi
18
- tilapäisesti. Napsauta Jatka ja salli evästeet sovelluksen käyttämiseksi.
18
+ tilapäisesti. Klikkaa Jatka ja salli evästeet sovelluksen käyttämiseksi.
19
19
  request_storage_access_footer: Evästeet vanhenevat 30 päivän kuluttua.
20
20
  request_storage_access_action: Jatka
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ShopifyApp::Engine.routes.draw do
2
3
  controller :sessions do
3
4
  get 'login' => :new, :as => :login
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators/base'
2
3
 
3
4
  module ShopifyApp
@@ -6,7 +7,7 @@ module ShopifyApp
6
7
  source_root File.expand_path('../templates', __FILE__)
7
8
 
8
9
  hook_for :test_framework, as: :job, in: :rails do |instance, generator|
9
- instance.invoke generator, [ instance.send(:job_file_name) ]
10
+ instance.invoke(generator, [instance.send(:job_file_name)])
10
11
  end
11
12
 
12
13
  def init_after_authenticate_config
@@ -23,12 +24,13 @@ module ShopifyApp
23
24
  )
24
25
 
25
26
  unless initializer.include?(after_authenticate_job_config)
26
- shell.say("Error adding after_authenticate_job to config. Add this line manually: #{after_authenticate_job_config}", :red)
27
+ shell.say("Error adding after_authenticate_job to config. Add this line manually: "\
28
+ "#{after_authenticate_job_config}", :red)
27
29
  end
28
30
  end
29
31
 
30
32
  def add_after_authenticate_job
31
- template 'after_authenticate_job.rb', "app/jobs/#{job_file_name}_job.rb"
33
+ template('after_authenticate_job.rb', "app/jobs/#{job_file_name}_job.rb")
32
34
  end
33
35
 
34
36
  private
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Shopify
2
3
  class AfterAuthenticateJob < ActiveJob::Base
3
4
  def perform(shop_domain:)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators/base'
2
3
 
3
4
  module ShopifyApp
@@ -6,7 +7,7 @@ module ShopifyApp
6
7
  source_root File.expand_path('../templates', __FILE__)
7
8
 
8
9
  def generate_app_extension
9
- template "marketing_activities_controller.rb", "app/controllers/marketing_activities_controller.rb"
10
+ template("marketing_activities_controller.rb", "app/controllers/marketing_activities_controller.rb")
10
11
  generate_routes
11
12
  end
12
13
 
@@ -3,7 +3,7 @@
3
3
  class MarketingActivitiesController < ShopifyApp::ExtensionVerificationController
4
4
  def preload_form_data
5
5
  preload_data = {
6
- "form_data": {}
6
+ "form_data": {},
7
7
  }
8
8
  render(json: preload_data, status: :ok)
9
9
  end
@@ -31,14 +31,14 @@ class MarketingActivitiesController < ShopifyApp::ExtensionVerificationControlle
31
31
  "preview_url": placeholder_img,
32
32
  "content_type": "text/html",
33
33
  "width": 360,
34
- "height": 200
34
+ "height": 200,
35
35
  },
36
36
  "mobile": {
37
37
  "preview_url": placeholder_img,
38
38
  "content_type": "text/html",
39
39
  "width": 360,
40
- "height": 200
41
- }
40
+ "height": 200,
41
+ },
42
42
  }
43
43
  render(json: preview_response, status: :ok)
44
44
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators/base'
2
3
 
3
4
  module ShopifyApp
@@ -8,7 +9,7 @@ module ShopifyApp
8
9
  class_option :address, type: :string, aliases: "-a", required: true
9
10
 
10
11
  hook_for :test_framework, as: :job, in: :rails do |instance, generator|
11
- instance.invoke generator, [ instance.send(:job_file_name) ]
12
+ instance.invoke(generator, [instance.send(:job_file_name)])
12
13
  end
13
14
 
14
15
  def init_webhook_config
@@ -32,14 +33,14 @@ module ShopifyApp
32
33
  initializer = load_initializer
33
34
 
34
35
  unless initializer.include?(webhook_config)
35
- shell.say "Error adding webhook to config. Add this line manually: #{webhook_config}", :red
36
+ shell.say("Error adding webhook to config. Add this line manually: #{webhook_config}", :red)
36
37
  end
37
38
  end
38
39
 
39
40
  def add_webhook_job
40
41
  @job_file_name = job_file_name + '_job'
41
- @job_class_name = @job_file_name.classify
42
- template 'webhook_job.rb', "app/jobs/#{@job_file_name}.rb"
42
+ @job_class_name = @job_file_name.classify
43
+ template('webhook_job.rb', "app/jobs/#{@job_file_name}.rb")
43
44
  end
44
45
 
45
46
  private
@@ -2,6 +2,11 @@ class <%= @job_class_name %> < ActiveJob::Base
2
2
  def perform(shop_domain:, webhook:)
3
3
  shop = Shop.find_by(shopify_domain: shop_domain)
4
4
 
5
+ if shop.nil?
6
+ logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'")
7
+ return
8
+ end
9
+
5
10
  shop.with_shopify_session do
6
11
  end
7
12
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators/base'
2
3
 
3
4
  module ShopifyApp
@@ -6,11 +7,11 @@ module ShopifyApp
6
7
  source_root File.expand_path('../templates', __FILE__)
7
8
 
8
9
  def create_app_proxy_controller
9
- template 'app_proxy_controller.rb', 'app/controllers/app_proxy_controller.rb'
10
+ template('app_proxy_controller.rb', 'app/controllers/app_proxy_controller.rb')
10
11
  end
11
12
 
12
13
  def create_app_proxy_index_view
13
- copy_file 'index.html.erb', 'app/views/app_proxy/index.html.erb'
14
+ copy_file('index.html.erb', 'app/views/app_proxy/index.html.erb')
14
15
  end
15
16
 
16
17
  def add_app_proxy_route
@@ -18,7 +19,7 @@ module ShopifyApp
18
19
  'config/routes.rb',
19
20
  File.read(File.expand_path(find_in_source_paths('app_proxy_route.rb'))),
20
21
  after: "mount ShopifyApp::Engine, at: '/'\n"
21
- )
22
+ )
22
23
  end
23
24
  end
24
25
  end
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  class AppProxyController < ApplicationController
2
- include ShopifyApp::AppProxyVerification
3
+ include ShopifyApp::AppProxyVerification
3
4
 
4
5
  def index
5
- render layout: false, content_type: 'application/liquid'
6
+ render(layout: false, content_type: 'application/liquid')
6
7
  end
7
-
8
8
  end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
 
2
- namespace :app_proxy do
3
- root action: 'index'
4
- # simple routes without a specified controller will go to AppProxyController
5
-
6
- # more complex routes will go to controllers in the AppProxy namespace
7
- # resources :reviews
8
- # GET /app_proxy/reviews will now be routed to
9
- # AppProxy::ReviewsController#index, for example
10
- end
3
+ namespace :app_proxy do
4
+ root action: 'index'
5
+ # simple routes without a specified controller will go to AppProxyController
6
+
7
+ # more complex routes will go to controllers in the AppProxy namespace
8
+ # resources :reviews
9
+ # GET /app_proxy/reviews will now be routed to
10
+ # AppProxy::ReviewsController#index, for example
11
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators/base'
2
3
 
3
4
  module ShopifyApp
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rails/generators/base'
2
3
 
3
4
  module ShopifyApp
@@ -6,15 +7,15 @@ module ShopifyApp
6
7
  source_root File.expand_path('../templates', __FILE__)
7
8
 
8
9
  def create_home_controller
9
- template 'home_controller.rb', 'app/controllers/home_controller.rb'
10
+ template('home_controller.rb', 'app/controllers/home_controller.rb')
10
11
  end
11
12
 
12
13
  def create_home_index_view
13
- copy_file 'index.html.erb', 'app/views/home/index.html.erb'
14
+ copy_file('index.html.erb', 'app/views/home/index.html.erb')
14
15
  end
15
16
 
16
17
  def add_home_index_route
17
- route "root :to => 'home#index'"
18
+ route("root :to => 'home#index'")
18
19
  end
19
20
 
20
21
  def embedded_app?