shopify_app 18.1.3 → 19.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +2 -2
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +3 -2
  5. data/Gemfile +3 -2
  6. data/Gemfile.lock +122 -136
  7. data/Rakefile +4 -3
  8. data/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +1 -1
  9. data/app/controllers/shopify_app/authenticated_controller.rb +1 -0
  10. data/app/controllers/shopify_app/callback_controller.rb +35 -147
  11. data/app/controllers/shopify_app/sessions_controller.rb +25 -137
  12. data/app/controllers/shopify_app/webhooks_controller.rb +5 -23
  13. data/config/routes.rb +6 -12
  14. data/docs/Troubleshooting.md +0 -3
  15. data/docs/Upgrading.md +85 -2
  16. data/docs/shopify_app/webhooks.md +1 -1
  17. data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +10 -9
  18. data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +1 -0
  19. data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +4 -3
  20. data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +13 -12
  21. data/lib/generators/shopify_app/add_webhook/templates/webhook_job.rb.tt +9 -1
  22. data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +7 -6
  23. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +2 -1
  24. data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +1 -1
  25. data/lib/generators/shopify_app/authenticated_controller/authenticated_controller_generator.rb +3 -3
  26. data/lib/generators/shopify_app/controllers/controllers_generator.rb +4 -3
  27. data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +11 -15
  28. data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +2 -2
  29. data/lib/generators/shopify_app/home_controller/templates/index.html.erb +3 -3
  30. data/lib/generators/shopify_app/install/install_generator.rb +25 -74
  31. data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +1 -1
  32. data/lib/generators/shopify_app/install/templates/session_store.rb +2 -1
  33. data/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +20 -5
  34. data/lib/generators/shopify_app/products_controller/products_controller_generator.rb +3 -3
  35. data/lib/generators/shopify_app/products_controller/templates/products_controller.rb +1 -1
  36. data/lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb +4 -4
  37. data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake +1 -0
  38. data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb +1 -1
  39. data/lib/generators/shopify_app/routes/routes_generator.rb +6 -5
  40. data/lib/generators/shopify_app/routes/templates/routes.rb +5 -5
  41. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +11 -10
  42. data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -0
  43. data/lib/generators/shopify_app/shopify_app_generator.rb +4 -3
  44. data/lib/generators/shopify_app/user_model/templates/user.rb +1 -0
  45. data/lib/generators/shopify_app/user_model/user_model_generator.rb +11 -10
  46. data/lib/generators/shopify_app/views/views_generator.rb +4 -3
  47. data/lib/shopify_app/access_scopes/shop_strategy.rb +2 -2
  48. data/lib/shopify_app/access_scopes/user_strategy.rb +4 -4
  49. data/lib/shopify_app/configuration.rb +5 -17
  50. data/lib/shopify_app/controller_concerns/app_proxy_verification.rb +4 -3
  51. data/lib/shopify_app/controller_concerns/csrf_protection.rb +2 -1
  52. data/lib/shopify_app/controller_concerns/embedded_app.rb +4 -3
  53. data/lib/shopify_app/controller_concerns/itp.rb +3 -3
  54. data/lib/shopify_app/controller_concerns/localization.rb +1 -0
  55. data/lib/shopify_app/controller_concerns/login_protection.rb +50 -70
  56. data/lib/shopify_app/controller_concerns/payload_verification.rb +3 -2
  57. data/lib/shopify_app/controller_concerns/webhook_verification.rb +2 -1
  58. data/lib/shopify_app/engine.rb +7 -15
  59. data/lib/shopify_app/jobs/scripttags_manager_job.rb +2 -2
  60. data/lib/shopify_app/jobs/webhooks_manager_job.rb +4 -5
  61. data/lib/shopify_app/managers/scripttags_manager.rb +11 -4
  62. data/lib/shopify_app/managers/webhooks_manager.rb +42 -44
  63. data/lib/shopify_app/middleware/jwt_middleware.rb +5 -4
  64. data/lib/shopify_app/session/in_memory_session_store.rb +1 -0
  65. data/lib/shopify_app/session/in_memory_shop_session_store.rb +2 -1
  66. data/lib/shopify_app/session/in_memory_user_session_store.rb +1 -0
  67. data/lib/shopify_app/session/jwt.rb +9 -8
  68. data/lib/shopify_app/session/null_user_session_store.rb +2 -1
  69. data/lib/shopify_app/session/session_repository.rb +37 -0
  70. data/lib/shopify_app/session/session_storage.rb +4 -6
  71. data/lib/shopify_app/session/shop_session_storage.rb +6 -6
  72. data/lib/shopify_app/session/shop_session_storage_with_scopes.rb +7 -8
  73. data/lib/shopify_app/session/user_session_storage.rb +19 -6
  74. data/lib/shopify_app/session/user_session_storage_with_scopes.rb +21 -8
  75. data/lib/shopify_app/test_helpers/all.rb +2 -1
  76. data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +4 -3
  77. data/lib/shopify_app/utils.rb +2 -9
  78. data/lib/shopify_app/version.rb +2 -1
  79. data/lib/shopify_app.rb +35 -40
  80. data/package.json +1 -1
  81. data/shopify_app.gemspec +21 -20
  82. data/yarn.lock +6 -6
  83. metadata +45 -50
  84. data/lib/generators/shopify_app/install/templates/omniauth.rb +0 -4
  85. data/lib/generators/shopify_app/install/templates/shopify_provider.rb.tt +0 -8
  86. data/lib/generators/shopify_app/install/templates/user_agent.rb +0 -6
  87. data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +0 -34
  88. data/lib/shopify_app/omniauth/omniauth_configuration.rb +0 -64
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'rails/generators/base'
2
+
3
+ require "rails/generators/base"
3
4
 
4
5
  module ShopifyApp
5
6
  module Generators
@@ -15,14 +16,14 @@ module ShopifyApp
15
16
  private
16
17
 
17
18
  def controllers
18
- files_within_root('.', 'app/controllers/shopify_app/*.*')
19
+ files_within_root(".", "app/controllers/shopify_app/*.*")
19
20
  end
20
21
 
21
22
  def files_within_root(prefix, glob)
22
23
  root = "#{self.class.source_root}/#{prefix}"
23
24
 
24
25
  Dir["#{root}/#{glob}"].sort.map do |full_path|
25
- full_path.sub(root, '.').gsub('/./', '/')
26
+ full_path.sub(root, ".").gsub("/./", "/")
26
27
  end
27
28
  end
28
29
  end
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
- require 'rails/generators/base'
2
+
3
+ require "rails/generators/base"
3
4
 
4
5
  module ShopifyApp
5
6
  module Generators
6
7
  class HomeControllerGenerator < Rails::Generators::Base
7
- source_root File.expand_path('../templates', __FILE__)
8
+ source_root File.expand_path("../templates", __FILE__)
8
9
 
9
- class_option :with_cookie_authentication, type: :boolean, default: false
10
- class_option :embedded, type: :string, default: 'true'
10
+ class_option :embedded, type: :string, default: "true"
11
11
 
12
12
  def create_home_controller
13
- template(home_controller_template, 'app/controllers/home_controller.rb')
13
+ template(home_controller_template, "app/controllers/home_controller.rb")
14
14
  end
15
15
 
16
16
  def create_products_controller
17
- generate("shopify_app:products_controller") unless with_cookie_authentication?
17
+ generate("shopify_app:products_controller") if embedded? || embedded_app?
18
18
  end
19
19
 
20
20
  def create_home_index_view
21
- template('index.html.erb', 'app/views/home/index.html.erb')
21
+ template("index.html.erb", "app/views/home/index.html.erb")
22
22
  end
23
23
 
24
24
  def add_home_index_route
@@ -28,25 +28,21 @@ module ShopifyApp
28
28
  private
29
29
 
30
30
  def embedded?
31
- options['embedded'] == 'true'
31
+ options["embedded"] == "true"
32
32
  end
33
33
 
34
34
  def embedded_app?
35
35
  ShopifyApp.configuration.embedded_app?
36
36
  end
37
37
 
38
- def with_cookie_authentication?
39
- options['with_cookie_authentication']
40
- end
41
-
42
38
  def home_controller_template
43
- return 'unauthenticated_home_controller.rb' unless authenticated_home_controller_required?
39
+ return "unauthenticated_home_controller.rb" unless authenticated_home_controller_required?
44
40
 
45
- 'home_controller.rb'
41
+ "home_controller.rb"
46
42
  end
47
43
 
48
44
  def authenticated_home_controller_required?
49
- with_cookie_authentication? || !embedded? || !embedded_app?
45
+ !embedded? || !embedded_app?
50
46
  end
51
47
  end
52
48
  end
@@ -6,8 +6,8 @@ class HomeController < AuthenticatedController
6
6
  before_action :set_host
7
7
 
8
8
  def index
9
- @products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
10
- @webhooks = ShopifyAPI::Webhook.find(:all)
9
+ @products = ShopifyAPI::Product.all(limit: 10)
10
+ @webhooks = ShopifyAPI::Webhook.all
11
11
  end
12
12
 
13
13
  private
@@ -7,7 +7,7 @@
7
7
  rel="stylesheet"
8
8
  href="https://unpkg.com/@shopify/polaris@4.25.0/styles.min.css"
9
9
  />
10
- <% unless with_cookie_authentication? %> <script>
10
+ <% if embedded_app? %> <script>
11
11
  document.addEventListener("DOMContentLoaded", async function() {
12
12
  <% if ShopifyApp.use_importmap? %>
13
13
  await import("lib/shopify_app")
@@ -51,10 +51,10 @@
51
51
  <% end %> </head>
52
52
  <body>
53
53
  <h2>Products</h2>
54
- <% unless with_cookie_authentication? %> <div id="products"><br>Loading...</div><% else %>
54
+ <% if embedded_app? %> <div id="products"><br>Loading...</div><% else %>
55
55
  <ul>
56
56
  <%% @products.each do |product| %>
57
- <li><%%= link_to product.title, "https://#{@current_shopify_session.domain}/admin/products/#{product.id}", target: "_top" %></li>
57
+ <li><%%= link_to product.title, "https://#{@current_shopify_session.shop}/admin/products/#{product.id}", target: "_top" %></li>
58
58
  <%% end %>
59
59
  </ul>
60
60
 
@@ -1,76 +1,58 @@
1
1
  # frozen_string_literal: true
2
- require 'rails/generators/base'
2
+
3
+ require "rails/generators/base"
3
4
 
4
5
  module ShopifyApp
5
6
  module Generators
6
7
  class InstallGenerator < Rails::Generators::Base
7
8
  include Rails::Generators::Migration
8
- source_root File.expand_path('../templates', __FILE__)
9
+ source_root File.expand_path("../templates", __FILE__)
9
10
 
10
- class_option :application_name, type: :array, default: ['My', 'Shopify', 'App']
11
- class_option :scope, type: :array, default: ['read_products']
12
- class_option :embedded, type: :string, default: 'true'
11
+ class_option :application_name, type: :array, default: ["My", "Shopify", "App"]
12
+ class_option :scope, type: :array, default: ["read_products"]
13
+ class_option :embedded, type: :string, default: "true"
13
14
  class_option :api_version, type: :string, default: nil
14
- class_option :with_cookie_authentication, type: :boolean, default: false
15
15
 
16
16
  def create_shopify_app_initializer
17
- @application_name = format_array_argument(options['application_name'])
18
- @scope = format_array_argument(options['scope'])
19
- @api_version = options['api_version'] || ShopifyAPI::Meta.admin_versions.find(&:latest_supported).handle
17
+ @application_name = format_array_argument(options["application_name"])
18
+ @scope = format_array_argument(options["scope"])
19
+ @api_version = options["api_version"] || ShopifyAPI::LATEST_SUPPORTED_ADMIN_VERSION
20
20
 
21
- template('shopify_app.rb', 'config/initializers/shopify_app.rb')
21
+ template("shopify_app.rb", "config/initializers/shopify_app.rb")
22
22
  end
23
23
 
24
24
  def create_session_store_initializer
25
- copy_file('session_store.rb', 'config/initializers/session_store.rb')
26
- end
27
-
28
- def create_and_inject_into_omniauth_initializer
29
- unless File.exist?("config/initializers/omniauth.rb")
30
- copy_file('omniauth.rb', 'config/initializers/omniauth.rb')
31
- end
32
-
33
- return if !Rails.env.test? && shopify_provider_exists?
34
-
35
- inject_into_file(
36
- 'config/initializers/omniauth.rb',
37
- shopify_provider_template,
38
- after: "Rails.application.config.middleware.use(OmniAuth::Builder) do\n"
39
- )
25
+ copy_file("session_store.rb", "config/initializers/session_store.rb")
40
26
  end
41
27
 
42
28
  def create_embedded_app_layout
43
29
  return unless embedded_app?
44
30
 
45
- copy_file('embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb')
46
- copy_file('_flash_messages.html.erb', 'app/views/layouts/_flash_messages.html.erb')
31
+ copy_file("embedded_app.html.erb", "app/views/layouts/embedded_app.html.erb")
32
+ copy_file("_flash_messages.html.erb", "app/views/layouts/_flash_messages.html.erb")
47
33
 
48
34
  if ShopifyApp.use_webpacker?
49
- copy_file('shopify_app.js', 'app/javascript/shopify_app/shopify_app.js')
50
- copy_file('flash_messages.js', 'app/javascript/shopify_app/flash_messages.js')
51
- copy_file('shopify_app_index.js', 'app/javascript/shopify_app/index.js')
52
- append_to_file('app/javascript/packs/application.js', "require(\"shopify_app\")\n")
35
+ copy_file("shopify_app.js", "app/javascript/shopify_app/shopify_app.js")
36
+ copy_file("flash_messages.js", "app/javascript/shopify_app/flash_messages.js")
37
+ copy_file("shopify_app_index.js", "app/javascript/shopify_app/index.js")
38
+ append_to_file("app/javascript/packs/application.js", "require(\"shopify_app\")\n")
53
39
  elsif ShopifyApp.use_importmap?
54
- copy_file('shopify_app_importmap.js', 'app/javascript/lib/shopify_app.js')
55
- copy_file('flash_messages.js', 'app/javascript/lib/flash_messages.js')
56
- append_to_file('config/importmap.rb', "pin_all_from \"app/javascript/lib\", under: \"lib\"\n")
40
+ copy_file("shopify_app_importmap.js", "app/javascript/lib/shopify_app.js")
41
+ copy_file("flash_messages.js", "app/javascript/lib/flash_messages.js")
42
+ append_to_file("config/importmap.rb", "pin_all_from \"app/javascript/lib\", under: \"lib\"\n")
57
43
  else
58
- copy_file('shopify_app.js', 'app/assets/javascripts/shopify_app.js')
59
- copy_file('flash_messages.js', 'app/assets/javascripts/flash_messages.js')
44
+ copy_file("shopify_app.js", "app/assets/javascripts/shopify_app.js")
45
+ copy_file("flash_messages.js", "app/assets/javascripts/flash_messages.js")
60
46
  end
61
47
  end
62
48
 
63
- def create_user_agent_initializer
64
- template('user_agent.rb', 'config/initializers/user_agent.rb')
65
- end
66
-
67
49
  def mount_engine
68
50
  route("mount ShopifyApp::Engine, at: '/'")
69
51
  end
70
52
 
71
53
  def insert_hosts_into_development_config
72
54
  inject_into_file(
73
- 'config/environments/development.rb',
55
+ "config/environments/development.rb",
74
56
  " config.hosts = (config.hosts rescue []) << /\[-\\w]+\\.ngrok\\.io/\n",
75
57
  after: "Rails.application.configure do\n"
76
58
  )
@@ -78,43 +60,12 @@ module ShopifyApp
78
60
 
79
61
  private
80
62
 
81
- def shopify_provider_exists?
82
- File.open("config/initializers/omniauth.rb") do |file|
83
- file.each_line do |line|
84
- if line =~ /provider :shopify/
85
- puts "\e[33m#{omniauth_warning}\e[0m"
86
- return true
87
- end
88
- end
89
- end
90
- false
91
- end
92
-
93
- def omniauth_warning
94
- <<~OMNIAUTH
95
- \n[WARNING] The Shopify App generator attempted to add the following Shopify Omniauth \
96
- provider 'config/initializers/omniauth.rb':
97
-
98
- \e[0m#{shopify_provider_template}\e[33m
99
-
100
- Consider updating 'config/initializers/omniauth.rb' to match the configuration above.
101
- OMNIAUTH
102
- end
103
-
104
- def shopify_provider_template
105
- File.read(File.expand_path(find_in_source_paths('shopify_provider.rb.tt')))
106
- end
107
-
108
63
  def embedded_app?
109
- options['embedded'] == 'true'
64
+ options["embedded"] == "true"
110
65
  end
111
66
 
112
67
  def format_array_argument(array)
113
- array.join(' ').tr('"', '')
114
- end
115
-
116
- def with_cookie_authentication?
117
- options['with_cookie_authentication'] || !embedded_app?
68
+ array.join(" ").tr('"', "")
118
69
  end
119
70
  end
120
71
  end
@@ -30,7 +30,7 @@
30
30
 
31
31
  <%= content_tag(:div, nil, id: 'shopify-app-init', data: {
32
32
  api_key: ShopifyApp.configuration.api_key,
33
- shop_origin: @shop_origin || (@current_shopify_session.domain if @current_shopify_session),
33
+ shop_origin: @shop_origin || (@current_shopify_session.shop if @current_shopify_session),
34
34
  host: @host,
35
35
  debug: Rails.env.development?
36
36
  } ) %>
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # Be sure to restart your server when you modify this file.
3
4
 
4
- Rails.application.config.session_store(:cookie_store, key: '_example_session', expire_after: 14.days)
5
+ Rails.application.config.session_store(:cookie_store, key: "_example_session", expire_after: 14.days)
@@ -10,16 +10,31 @@ ShopifyApp.configure do |config|
10
10
 
11
11
  config.reauth_on_access_scope_changes = true
12
12
 
13
- config.allow_jwt_authentication = <%= !with_cookie_authentication? %>
14
- config.allow_cookie_authentication = <%= with_cookie_authentication? %>
15
-
16
13
  config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence
17
14
  config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence
15
+
18
16
  if defined? Rails::Server
19
17
  raise('Missing SHOPIFY_API_KEY. See https://github.com/Shopify/shopify_app#requirements') unless config.api_key
20
18
  raise('Missing SHOPIFY_API_SECRET. See https://github.com/Shopify/shopify_app#requirements') unless config.secret
21
19
  end
22
20
  end
23
21
 
24
- # ShopifyApp::Utils.fetch_known_api_versions # Uncomment to fetch known api versions from shopify servers on boot
25
- # ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown # Uncomment to raise an error if attempting to use an api version that was not previously known
22
+ Rails.application.config.after_initialize do
23
+ if ShopifyApp.configuration.api_key.present? && ShopifyApp.configuration.secret.present?
24
+ ShopifyAPI::Context.setup(
25
+ api_key: ShopifyApp.configuration.api_key,
26
+ api_secret_key: ShopifyApp.configuration.secret,
27
+ api_version: ShopifyApp.configuration.api_version,
28
+ host_name: URI(ENV.fetch('HOST', '')).host || '',
29
+ scope: ShopifyApp.configuration.scope,
30
+ is_private: !ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', '').empty?,
31
+ is_embedded: ShopifyApp.configuration.embedded_app,
32
+ session_storage: ShopifyApp::SessionRepository,
33
+ logger: Rails.logger,
34
+ private_shop: ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', nil),
35
+ user_agent_prefix: "ShopifyApp/#{ShopifyApp::VERSION}"
36
+ )
37
+
38
+ ShopifyApp::WebhooksManager.add_registrations
39
+ end
40
+ end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators/base'
3
+ require "rails/generators/base"
4
4
 
5
5
  module ShopifyApp
6
6
  module Generators
7
7
  class ProductsControllerGenerator < Rails::Generators::Base
8
- source_root File.expand_path('../templates', __FILE__)
8
+ source_root File.expand_path("../templates", __FILE__)
9
9
 
10
10
  def create_products_controller
11
- template('products_controller.rb', 'app/controllers/products_controller.rb')
11
+ template("products_controller.rb", "app/controllers/products_controller.rb")
12
12
  end
13
13
 
14
14
  def add_products_route
@@ -2,7 +2,7 @@
2
2
 
3
3
  class ProductsController < AuthenticatedController
4
4
  def index
5
- @products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
5
+ @products = ShopifyAPI::Product.all(limit: 10)
6
6
  render(json: { products: @products })
7
7
  end
8
8
  end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators/base'
3
+ require "rails/generators/base"
4
4
 
5
5
  module ShopifyApp
6
6
  module Generators
7
7
  class RotateShopifyTokenJobGenerator < Rails::Generators::Base
8
- source_root File.expand_path('../templates', __FILE__)
8
+ source_root File.expand_path("../templates", __FILE__)
9
9
 
10
10
  def add_rotate_shopify_token_job
11
- copy_file('rotate_shopify_token_job.rb', "app/jobs/shopify/rotate_shopify_token_job.rb")
12
- copy_file('rotate_shopify_token.rake', "lib/tasks/shopify/rotate_shopify_token.rake")
11
+ copy_file("rotate_shopify_token_job.rb", "app/jobs/shopify/rotate_shopify_token_job.rb")
12
+ copy_file("rotate_shopify_token.rake", "lib/tasks/shopify/rotate_shopify_token.rake")
13
13
  end
14
14
  end
15
15
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  namespace :shopify do
3
4
  desc "Rotate shopify tokens for all active shops"
4
5
  task :rotate_shopify_tokens, [:refresh_token] => :environment do |_t, args|
@@ -18,7 +18,7 @@ module Shopify
18
18
  @response = Net::HTTP.post_form(uri, post_data)
19
19
  return log_error(response_exception_error_message) unless @response.is_a?(Net::HTTPSuccess)
20
20
 
21
- access_token = JSON.parse(@response.body)['access_token']
21
+ access_token = JSON.parse(@response.body)["access_token"]
22
22
  return log_error(no_access_token_error_message) unless access_token
23
23
 
24
24
  @shop.update(shopify_token: access_token)
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
- require 'rails/generators/base'
2
+
3
+ require "rails/generators/base"
3
4
 
4
5
  module ShopifyApp
5
6
  module Generators
6
7
  class RoutesGenerator < Rails::Generators::Base
7
- source_root File.expand_path('../templates', __FILE__)
8
+ source_root File.expand_path("../templates", __FILE__)
8
9
 
9
10
  def inject_shopify_app_routes_into_application_routes
10
11
  route(session_routes)
@@ -12,9 +13,9 @@ module ShopifyApp
12
13
 
13
14
  def disable_engine_routes
14
15
  gsub_file(
15
- 'config/routes.rb',
16
+ "config/routes.rb",
16
17
  "mount ShopifyApp::Engine, at: '/'",
17
- ''
18
+ ""
18
19
  )
19
20
  end
20
21
 
@@ -25,7 +26,7 @@ module ShopifyApp
25
26
  end
26
27
 
27
28
  def routes_file_path
28
- File.expand_path(find_in_source_paths('routes.rb'))
29
+ File.expand_path(find_in_source_paths("routes.rb"))
29
30
  end
30
31
  end
31
32
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  controller :sessions do
4
- get 'login' => :new, :as => :login
5
- post 'login' => :create, :as => :authenticate
6
- get 'auth/shopify/callback' => :callback
7
- get 'logout' => :destroy, :as => :logout
4
+ get "login" => :new, :as => :login
5
+ post "login" => :create, :as => :authenticate
6
+ get "auth/shopify/callback" => :callback
7
+ get "logout" => :destroy, :as => :logout
8
8
  end
9
9
 
10
10
  namespace :webhooks do
11
- post ':type' => :receive
11
+ post ":type" => :receive
12
12
  end
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
- require 'rails/generators/base'
3
- require 'rails/generators/active_record'
2
+
3
+ require "rails/generators/base"
4
+ require "rails/generators/active_record"
4
5
 
5
6
  module ShopifyApp
6
7
  module Generators
7
8
  class ShopModelGenerator < Rails::Generators::Base
8
9
  include Rails::Generators::Migration
9
- source_root File.expand_path('../templates', __FILE__)
10
+ source_root File.expand_path("../templates", __FILE__)
10
11
 
11
12
  class_option :new_shopify_cli_app, type: :boolean, default: false
12
13
 
13
14
  def create_shop_model
14
- copy_file('shop.rb', 'app/models/shop.rb')
15
+ copy_file("shop.rb", "app/models/shop.rb")
15
16
  end
16
17
 
17
18
  def create_shop_migration
18
- migration_template('db/migrate/create_shops.erb', 'db/migrate/create_shops.rb')
19
+ migration_template("db/migrate/create_shops.erb", "db/migrate/create_shops.rb")
19
20
  end
20
21
 
21
22
  def create_shop_with_access_scopes_migration
@@ -33,24 +34,24 @@ module ShopifyApp
33
34
 
34
35
  if new_shopify_cli_app? || Rails.env.test? || yes?(scopes_column_prompt)
35
36
  migration_template(
36
- 'db/migrate/add_shop_access_scopes_column.erb',
37
- 'db/migrate/add_shop_access_scopes_column.rb'
37
+ "db/migrate/add_shop_access_scopes_column.erb",
38
+ "db/migrate/add_shop_access_scopes_column.rb"
38
39
  )
39
40
  end
40
41
  end
41
42
 
42
43
  def update_shopify_app_initializer
43
- gsub_file('config/initializers/shopify_app.rb', 'ShopifyApp::InMemoryShopSessionStore', 'Shop')
44
+ gsub_file("config/initializers/shopify_app.rb", "ShopifyApp::InMemoryShopSessionStore", "Shop")
44
45
  end
45
46
 
46
47
  def create_shop_fixtures
47
- copy_file('shops.yml', 'test/fixtures/shops.yml')
48
+ copy_file("shops.yml", "test/fixtures/shops.yml")
48
49
  end
49
50
 
50
51
  private
51
52
 
52
53
  def new_shopify_cli_app?
53
- options['new_shopify_cli_app']
54
+ options["new_shopify_cli_app"]
54
55
  end
55
56
 
56
57
  def rails_migration_version
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class Shop < ActiveRecord::Base
3
4
  include ShopifyApp::ShopSessionStorageWithScopes
4
5
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module ShopifyApp
3
4
  module Generators
4
5
  class ShopifyAppGenerator < Rails::Generators::Base
@@ -8,10 +9,10 @@ module ShopifyApp
8
9
  end
9
10
 
10
11
  def run_all_generators
11
- generate("shopify_app:install #{@opts.join(' ')}")
12
- generate("shopify_app:shop_model #{@opts.join(' ')}")
12
+ generate("shopify_app:install #{@opts.join(" ")}")
13
+ generate("shopify_app:shop_model #{@opts.join(" ")}")
13
14
  generate("shopify_app:authenticated_controller")
14
- generate("shopify_app:home_controller #{@opts.join(' ')}")
15
+ generate("shopify_app:home_controller #{@opts.join(" ")}")
15
16
  end
16
17
  end
17
18
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  class User < ActiveRecord::Base
3
4
  include ShopifyApp::UserSessionStorageWithScopes
4
5
 
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
- require 'rails/generators/base'
3
- require 'rails/generators/active_record'
2
+
3
+ require "rails/generators/base"
4
+ require "rails/generators/active_record"
4
5
 
5
6
  module ShopifyApp
6
7
  module Generators
7
8
  class UserModelGenerator < Rails::Generators::Base
8
9
  include Rails::Generators::Migration
9
- source_root File.expand_path('../templates', __FILE__)
10
+ source_root File.expand_path("../templates", __FILE__)
10
11
 
11
12
  class_option :new_shopify_cli_app, type: :boolean, default: false
12
13
 
13
14
  def create_user_model
14
- copy_file('user.rb', 'app/models/user.rb')
15
+ copy_file("user.rb", "app/models/user.rb")
15
16
  end
16
17
 
17
18
  def create_user_migration
18
- migration_template('db/migrate/create_users.erb', 'db/migrate/create_users.rb')
19
+ migration_template("db/migrate/create_users.erb", "db/migrate/create_users.rb")
19
20
  end
20
21
 
21
22
  def create_scopes_storage_in_user_model
@@ -33,24 +34,24 @@ module ShopifyApp
33
34
 
34
35
  if new_shopify_cli_app? || Rails.env.test? || yes?(scopes_column_prompt)
35
36
  migration_template(
36
- 'db/migrate/add_user_access_scopes_column.erb',
37
- 'db/migrate/add_user_access_scopes_column.rb'
37
+ "db/migrate/add_user_access_scopes_column.erb",
38
+ "db/migrate/add_user_access_scopes_column.rb"
38
39
  )
39
40
  end
40
41
  end
41
42
 
42
43
  def update_shopify_app_initializer
43
- gsub_file('config/initializers/shopify_app.rb', 'ShopifyApp::InMemoryUserSessionStore', 'User')
44
+ gsub_file("config/initializers/shopify_app.rb", "ShopifyApp::InMemoryUserSessionStore", "User")
44
45
  end
45
46
 
46
47
  def create_user_fixtures
47
- copy_file('users.yml', 'test/fixtures/users.yml')
48
+ copy_file("users.yml", "test/fixtures/users.yml")
48
49
  end
49
50
 
50
51
  private
51
52
 
52
53
  def new_shopify_cli_app?
53
- options['new_shopify_cli_app']
54
+ options["new_shopify_cli_app"]
54
55
  end
55
56
 
56
57
  def rails_migration_version
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'rails/generators/base'
2
+
3
+ require "rails/generators/base"
3
4
 
4
5
  module ShopifyApp
5
6
  module Generators
@@ -15,14 +16,14 @@ module ShopifyApp
15
16
  private
16
17
 
17
18
  def views
18
- files_within_root('.', 'app/views/**/*.*')
19
+ files_within_root(".", "app/views/**/*.*")
19
20
  end
20
21
 
21
22
  def files_within_root(prefix, glob)
22
23
  root = "#{self.class.source_root}/#{prefix}"
23
24
 
24
25
  Dir["#{root}/#{glob}"].sort.map do |full_path|
25
- full_path.sub(root, '.').gsub('/./', '/')
26
+ full_path.sub(root, ".").gsub("/./", "/")
26
27
  end
27
28
  end
28
29
  end
@@ -12,11 +12,11 @@ module ShopifyApp
12
12
  private
13
13
 
14
14
  def shop_access_scopes(shop_domain)
15
- ShopifyApp::SessionRepository.retrieve_shop_session_by_shopify_domain(shop_domain)&.access_scopes
15
+ ShopifyApp::SessionRepository.retrieve_shop_session_by_shopify_domain(shop_domain)&.scope
16
16
  end
17
17
 
18
18
  def configuration_access_scopes
19
- ShopifyAPI::ApiAccess.new(ShopifyApp.configuration.shop_access_scopes)
19
+ ShopifyAPI::Auth::AuthScopes.new(ShopifyApp.configuration.shop_access_scopes)
20
20
  end
21
21
  end
22
22
  end