shopify_app 9.0.0 → 13.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/CHANGELOG.md +159 -0
- data/README.md +221 -130
- data/app/assets/javascripts/shopify_app/itp_helper.js +6 -6
- data/app/assets/javascripts/shopify_app/storage_access.js +36 -7
- data/app/controllers/concerns/shopify_app/authenticated.rb +2 -2
- data/app/controllers/shopify_app/callback_controller.rb +20 -7
- data/app/controllers/shopify_app/extension_verification_controller.rb +20 -0
- data/app/controllers/shopify_app/sessions_controller.rb +71 -22
- data/app/views/shopify_app/sessions/enable_cookies.html.erb +3 -1
- data/app/views/shopify_app/sessions/request_storage_access.html.erb +2 -1
- data/app/views/shopify_app/sessions/top_level_interaction.html.erb +1 -0
- data/app/views/shopify_app/shared/redirect.html.erb +1 -0
- data/config/locales/cs.yml +23 -0
- data/config/locales/da.yml +20 -0
- data/config/locales/de.yml +5 -5
- data/config/locales/en.yml +1 -1
- data/config/locales/es.yml +3 -3
- data/config/locales/fi.yml +20 -0
- data/config/locales/fr.yml +3 -3
- data/config/locales/hi.yml +23 -0
- data/config/locales/it.yml +2 -3
- data/config/locales/ja.yml +1 -1
- data/config/locales/ko.yml +19 -0
- data/config/locales/ms.yml +22 -0
- data/config/locales/nb.yml +21 -0
- data/config/locales/nl.yml +3 -3
- data/config/locales/pl.yml +21 -0
- data/config/locales/pt-BR.yml +9 -10
- data/config/locales/pt-PT.yml +22 -0
- data/config/locales/sv.yml +21 -0
- data/config/locales/th.yml +20 -0
- data/config/locales/tr.yml +22 -0
- data/config/locales/zh-CN.yml +3 -3
- data/config/locales/zh-TW.yml +1 -2
- data/docs/Quickstart.md +44 -16
- data/docs/Releasing.md +0 -1
- data/docs/install-on-dev-shop.png +0 -0
- data/docs/test-your-app.png +0 -0
- data/karma.conf.js +1 -0
- data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +2 -2
- data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +39 -0
- data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +62 -0
- data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +0 -6
- data/lib/generators/shopify_app/home_controller/templates/index.html.erb +1 -1
- data/lib/generators/shopify_app/install/install_generator.rb +27 -11
- data/lib/generators/shopify_app/install/templates/_flash_messages.html.erb +1 -17
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +11 -10
- data/lib/generators/shopify_app/install/templates/flash_messages.js +26 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.js +15 -0
- data/lib/generators/shopify_app/install/templates/shopify_app.rb +6 -3
- data/lib/generators/shopify_app/install/templates/shopify_app_index.js +2 -0
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb +1 -0
- data/lib/generators/shopify_app/install/templates/user_agent.rb +5 -0
- data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +1 -1
- data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -1
- data/lib/generators/shopify_app/user_model/templates/db/migrate/create_users.erb +16 -0
- data/lib/generators/shopify_app/user_model/templates/user.rb +7 -0
- data/lib/generators/shopify_app/user_model/templates/users.yml +4 -0
- data/lib/generators/shopify_app/user_model/user_model_generator.rb +38 -0
- data/lib/shopify_app/configuration.rb +22 -10
- data/lib/shopify_app/controller_concerns/login_protection.rb +66 -15
- data/lib/shopify_app/engine.rb +4 -0
- data/lib/shopify_app/managers/webhooks_manager.rb +1 -1
- data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +33 -0
- data/lib/shopify_app/session/in_memory_session_store.rb +1 -1
- data/lib/shopify_app/session/in_memory_shop_session_store.rb +4 -0
- data/lib/shopify_app/session/in_memory_user_session_store.rb +4 -0
- data/lib/shopify_app/session/session_repository.rb +38 -13
- data/lib/shopify_app/session/session_storage.rb +0 -22
- data/lib/shopify_app/session/shop_session_storage.rb +30 -0
- data/lib/shopify_app/session/user_session_storage.rb +31 -0
- data/lib/shopify_app/utils.rb +7 -0
- data/lib/shopify_app/version.rb +1 -1
- data/lib/shopify_app.rb +48 -29
- data/package-lock.json +7227 -5
- data/package.json +9 -9
- data/service.yml +1 -1
- data/shopify_app.gemspec +10 -5
- data/translation.yml +1 -1
- data/yarn.lock +2555 -1886
- metadata +117 -19
- data/lib/generators/shopify_app/home_controller/templates/shopify_app_ready_script.html.erb +0 -7
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration[<%= rails_migration_version %>]
|
2
|
+
def self.up
|
3
|
+
create_table :users do |t|
|
4
|
+
t.bigint :shopify_user_id, null: false
|
5
|
+
t.string :shopify_domain, null: false
|
6
|
+
t.string :shopify_token, null: false
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :users, :shopify_user_id, unique: true
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :users
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module ShopifyApp
|
5
|
+
module Generators
|
6
|
+
class UserModelGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
def create_user_model
|
11
|
+
copy_file 'user.rb', 'app/models/user.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_user_migration
|
15
|
+
migration_template 'db/migrate/create_users.erb', 'db/migrate/create_users.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_shopify_app_initializer
|
19
|
+
gsub_file 'config/initializers/shopify_app.rb', 'ShopifyApp::InMemoryUserSessionStore', 'User'
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_user_fixtures
|
23
|
+
copy_file 'users.yml', 'test/fixtures/users.yml'
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def rails_migration_version
|
29
|
+
Rails.version.match(/\d\.\d/)[0]
|
30
|
+
end
|
31
|
+
|
32
|
+
# for generating a timestamp when using `create_migration`
|
33
|
+
def self.next_migration_number(dir)
|
34
|
+
ActiveRecord::Generators::Base.next_migration_number(dir)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -5,7 +5,7 @@ module ShopifyApp
|
|
5
5
|
# for the app in your Shopify Partners page. Change your settings in
|
6
6
|
# `config/initializers/shopify_app.rb`
|
7
7
|
attr_accessor :application_name
|
8
|
-
attr_accessor
|
8
|
+
attr_accessor :api_key
|
9
9
|
attr_accessor :secret
|
10
10
|
attr_accessor :old_secret
|
11
11
|
attr_accessor :scope
|
@@ -14,7 +14,8 @@ module ShopifyApp
|
|
14
14
|
attr_accessor :webhooks
|
15
15
|
attr_accessor :scripttags
|
16
16
|
attr_accessor :after_authenticate_job
|
17
|
-
|
17
|
+
attr_reader :shop_session_repository
|
18
|
+
attr_reader :user_session_repository
|
18
19
|
attr_accessor :api_version
|
19
20
|
|
20
21
|
# customise urls
|
@@ -28,28 +29,35 @@ module ShopifyApp
|
|
28
29
|
# configure myshopify domain for local shopify development
|
29
30
|
attr_accessor :myshopify_domain
|
30
31
|
|
32
|
+
# ability to have webpacker installed but not used in this gem and the generators
|
33
|
+
attr_accessor :disable_webpacker
|
34
|
+
|
31
35
|
# allow namespacing webhook jobs
|
32
36
|
attr_accessor :webhook_jobs_namespace
|
33
37
|
|
38
|
+
# allow enabling of same site none on cookies
|
39
|
+
attr_accessor :enable_same_site_none
|
40
|
+
|
34
41
|
def initialize
|
35
42
|
@root_url = '/'
|
36
43
|
@myshopify_domain = 'myshopify.com'
|
37
44
|
@scripttags_manager_queue_name = Rails.application.config.active_job.queue_name
|
38
45
|
@webhooks_manager_queue_name = Rails.application.config.active_job.queue_name
|
46
|
+
@disable_webpacker = ENV['SHOPIFY_APP_DISABLE_WEBPACKER'].present?
|
39
47
|
end
|
40
48
|
|
41
49
|
def login_url
|
42
50
|
@login_url || File.join(@root_url, 'login')
|
43
51
|
end
|
44
52
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
def user_session_repository=(klass)
|
54
|
+
@user_session_repository = klass
|
55
|
+
ShopifyApp::SessionRepository.user_storage = klass
|
56
|
+
end
|
57
|
+
|
58
|
+
def shop_session_repository=(klass)
|
59
|
+
@shop_session_repository = klass
|
60
|
+
ShopifyApp::SessionRepository.shop_storage = klass
|
53
61
|
end
|
54
62
|
|
55
63
|
def has_webhooks?
|
@@ -59,6 +67,10 @@ module ShopifyApp
|
|
59
67
|
def has_scripttags?
|
60
68
|
scripttags.present?
|
61
69
|
end
|
70
|
+
|
71
|
+
def enable_same_site_none
|
72
|
+
!Rails.env.test? && (@enable_same_site_none.nil? ? embedded_app? : @enable_same_site_none)
|
73
|
+
end
|
62
74
|
end
|
63
75
|
|
64
76
|
def self.configuration
|
@@ -14,26 +14,48 @@ module ShopifyApp
|
|
14
14
|
rescue_from ActiveResource::UnauthorizedAccess, :with => :close_session
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
return redirect_to_login
|
17
|
+
def activate_shopify_session
|
18
|
+
return redirect_to_login if current_shopify_session.blank?
|
19
19
|
clear_top_level_oauth_cookie
|
20
20
|
|
21
21
|
begin
|
22
|
-
ShopifyAPI::Base.activate_session(
|
22
|
+
ShopifyAPI::Base.activate_session(current_shopify_session)
|
23
23
|
yield
|
24
24
|
ensure
|
25
25
|
ShopifyAPI::Base.clear_session
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def current_shopify_session
|
30
|
+
if session[:user_id].present?
|
31
|
+
@current_shopify_session ||= user_session
|
32
|
+
else
|
33
|
+
@current_shopify_session ||= shop_session
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def user_session
|
38
|
+
return if session[:user_id].blank?
|
39
|
+
ShopifyApp::SessionRepository.retrieve_user_session(session[:user_id])
|
40
|
+
end
|
41
|
+
|
29
42
|
def shop_session
|
30
|
-
return
|
31
|
-
|
43
|
+
return if session[:shop_id].blank?
|
44
|
+
ShopifyApp::SessionRepository.retrieve_shop_session(session[:shop_id])
|
32
45
|
end
|
33
46
|
|
34
|
-
def
|
35
|
-
if
|
36
|
-
|
47
|
+
def login_again_if_different_user_or_shop
|
48
|
+
if session[:user_session].present? && params[:session].present? # session data was sent/stored correctly
|
49
|
+
clear_session = session[:user_session] != params[:session] # current user is different from stored user
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
if current_shopify_session && params[:shop] && params[:shop].is_a?(String) && (current_shopify_session.domain != params[:shop])
|
54
|
+
clear_session = true
|
55
|
+
end
|
56
|
+
|
57
|
+
if clear_session
|
58
|
+
clear_shopify_session
|
37
59
|
redirect_to_login
|
38
60
|
end
|
39
61
|
end
|
@@ -45,24 +67,32 @@ module ShopifyApp
|
|
45
67
|
head :unauthorized
|
46
68
|
else
|
47
69
|
if request.get?
|
48
|
-
|
70
|
+
path = request.path
|
71
|
+
query = sanitized_params.to_query
|
72
|
+
else
|
73
|
+
referer = URI(request.referer || "/")
|
74
|
+
path = referer.path
|
75
|
+
query = "#{referer.query}&#{sanitized_params.to_query}"
|
49
76
|
end
|
50
|
-
|
77
|
+
session[:return_to] = "#{path}?#{query}"
|
78
|
+
redirect_to(login_url_with_optional_shop)
|
51
79
|
end
|
52
80
|
end
|
53
81
|
|
54
82
|
def close_session
|
55
|
-
|
56
|
-
redirect_to
|
83
|
+
clear_shopify_session
|
84
|
+
redirect_to(login_url_with_optional_shop)
|
57
85
|
end
|
58
86
|
|
59
|
-
def
|
60
|
-
session[:
|
87
|
+
def clear_shopify_session
|
88
|
+
session[:shop_id] = nil
|
89
|
+
session[:user_id] = nil
|
61
90
|
session[:shopify_domain] = nil
|
62
91
|
session[:shopify_user] = nil
|
92
|
+
session[:user_session] = nil
|
63
93
|
end
|
64
94
|
|
65
|
-
def
|
95
|
+
def login_url_with_optional_shop(top_level: false)
|
66
96
|
url = ShopifyApp.configuration.login_url
|
67
97
|
|
68
98
|
query_params = login_url_params(top_level: top_level)
|
@@ -75,6 +105,12 @@ module ShopifyApp
|
|
75
105
|
query_params = {}
|
76
106
|
query_params[:shop] = sanitized_params[:shop] if params[:shop].present?
|
77
107
|
|
108
|
+
return_to = session[:return_to] || params[:return_to]
|
109
|
+
|
110
|
+
if return_to.present? && return_to_param_required?
|
111
|
+
query_params[:return_to] = return_to
|
112
|
+
end
|
113
|
+
|
78
114
|
has_referer_shop_name = referer_sanitized_shop_name.present?
|
79
115
|
|
80
116
|
if has_referer_shop_name
|
@@ -85,6 +121,11 @@ module ShopifyApp
|
|
85
121
|
query_params
|
86
122
|
end
|
87
123
|
|
124
|
+
def return_to_param_required?
|
125
|
+
native_params = %i[shop hmac timestamp locale protocol return_to]
|
126
|
+
request.path != '/' || sanitized_params.except(*native_params).any?
|
127
|
+
end
|
128
|
+
|
88
129
|
def fullpage_redirect_to(url)
|
89
130
|
if ShopifyApp.configuration.embedded_app?
|
90
131
|
render 'shopify_app/shared/redirect', layout: false, locals: { url: url, current_shopify_domain: current_shopify_domain }
|
@@ -131,5 +172,15 @@ module ShopifyApp
|
|
131
172
|
def return_address
|
132
173
|
session.delete(:return_to) || ShopifyApp.configuration.root_url
|
133
174
|
end
|
175
|
+
|
176
|
+
def return_address_with_params(params)
|
177
|
+
uri = URI(return_address)
|
178
|
+
uri.query = CGI.parse(uri.query.to_s)
|
179
|
+
.symbolize_keys
|
180
|
+
.transform_values { |v| v.one? ? v.first : v }
|
181
|
+
.merge(params)
|
182
|
+
.to_query
|
183
|
+
uri.to_s
|
184
|
+
end
|
134
185
|
end
|
135
186
|
end
|
data/lib/shopify_app/engine.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module ShopifyApp
|
2
|
+
class SameSiteCookieMiddleware
|
3
|
+
COOKIE_SEPARATOR = "\n"
|
4
|
+
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
status, headers, body = @app.call(env)
|
11
|
+
user_agent = env['HTTP_USER_AGENT']
|
12
|
+
|
13
|
+
if headers && headers['Set-Cookie'] &&
|
14
|
+
BrowserSniffer.new(user_agent).same_site_none_compatible? &&
|
15
|
+
ShopifyApp.configuration.enable_same_site_none &&
|
16
|
+
Rack::Request.new(env).ssl?
|
17
|
+
|
18
|
+
set_cookies = headers['Set-Cookie']
|
19
|
+
.split(COOKIE_SEPARATOR)
|
20
|
+
.compact
|
21
|
+
.map do |cookie|
|
22
|
+
cookie << '; Secure' if not cookie =~ /;\s*secure/i
|
23
|
+
cookie << '; SameSite=None' unless cookie =~ /;\s*samesite=/i
|
24
|
+
cookie
|
25
|
+
end
|
26
|
+
|
27
|
+
headers['Set-Cookie'] = set_cookies.join(COOKIE_SEPARATOR)
|
28
|
+
end
|
29
|
+
|
30
|
+
[status, headers, body]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -3,31 +3,56 @@ module ShopifyApp
|
|
3
3
|
class ConfigurationError < StandardError; end
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def shop_storage=(storage)
|
7
|
+
@shop_storage = storage
|
8
8
|
|
9
|
-
unless storage.nil? || self.
|
10
|
-
raise ArgumentError, "storage must respond to :store and :retrieve"
|
9
|
+
unless storage.nil? || self.shop_storage.respond_to?(:store) && self.shop_storage.respond_to?(:retrieve)
|
10
|
+
raise ArgumentError, "shop storage must respond to :store and :retrieve"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
storage
|
14
|
+
def user_storage=(storage)
|
15
|
+
@user_storage = storage
|
16
|
+
|
17
|
+
unless storage.nil? || self.user_storage.respond_to?(:store) && self.user_storage.respond_to?(:retrieve)
|
18
|
+
raise ArgumentError, "user storage must respond to :store and :retrieve"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def retrieve_shop_session(id)
|
23
|
+
shop_storage.retrieve(id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def retrieve_user_session(id)
|
27
|
+
user_storage.retrieve(id)
|
16
28
|
end
|
17
29
|
|
18
|
-
def
|
19
|
-
|
30
|
+
def store_shop_session(session)
|
31
|
+
shop_storage.store(session)
|
20
32
|
end
|
21
33
|
|
22
|
-
def
|
23
|
-
|
34
|
+
def store_user_session(session, user)
|
35
|
+
user_storage.store(session, user)
|
36
|
+
end
|
37
|
+
|
38
|
+
def shop_storage
|
39
|
+
load_shop_storage || raise(ConfigurationError.new("ShopifySessionRepository.shop_storage is not configured!"))
|
40
|
+
end
|
41
|
+
|
42
|
+
def user_storage
|
43
|
+
load_user_storage
|
24
44
|
end
|
25
45
|
|
26
46
|
private
|
27
47
|
|
28
|
-
def
|
29
|
-
return unless @
|
30
|
-
@
|
48
|
+
def load_shop_storage
|
49
|
+
return unless @shop_storage
|
50
|
+
@shop_storage.respond_to?(:safe_constantize) ? @shop_storage.safe_constantize : @shop_storage
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_user_storage
|
54
|
+
return unless @user_storage
|
55
|
+
@user_storage.respond_to?(:safe_constantize) ? @user_storage.safe_constantize : @user_storage
|
31
56
|
end
|
32
57
|
end
|
33
58
|
end
|
@@ -3,7 +3,6 @@ module ShopifyApp
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
validates :shopify_domain, presence: true, uniqueness: { case_sensitive: false }
|
7
6
|
validates :shopify_token, presence: true
|
8
7
|
validates :api_version, presence: true
|
9
8
|
end
|
@@ -16,26 +15,5 @@ module ShopifyApp
|
|
16
15
|
&block
|
17
16
|
)
|
18
17
|
end
|
19
|
-
|
20
|
-
class_methods do
|
21
|
-
def store(session)
|
22
|
-
shop = find_or_initialize_by(shopify_domain: session.domain)
|
23
|
-
shop.shopify_token = session.token
|
24
|
-
shop.save!
|
25
|
-
shop.id
|
26
|
-
end
|
27
|
-
|
28
|
-
def retrieve(id)
|
29
|
-
return unless id
|
30
|
-
|
31
|
-
if shop = self.find_by(id: id)
|
32
|
-
ShopifyAPI::Session.new(
|
33
|
-
domain: shop.shopify_domain,
|
34
|
-
token: shop.shopify_token,
|
35
|
-
api_version: shop.api_version
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
18
|
end
|
41
19
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ShopifyApp
|
2
|
+
module ShopSessionStorage
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ::ShopifyApp::SessionStorage
|
5
|
+
|
6
|
+
included do
|
7
|
+
validates :shopify_domain, presence: true, uniqueness: { case_sensitive: false }
|
8
|
+
end
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def store(auth_session, *args)
|
12
|
+
shop = find_or_initialize_by(shopify_domain: auth_session.domain)
|
13
|
+
shop.shopify_token = auth_session.token
|
14
|
+
shop.save!
|
15
|
+
shop.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def retrieve(id)
|
19
|
+
return unless id
|
20
|
+
if shop = self.find_by(id: id)
|
21
|
+
ShopifyAPI::Session.new(
|
22
|
+
domain: shop.shopify_domain,
|
23
|
+
token: shop.shopify_token,
|
24
|
+
api_version: shop.api_version
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ShopifyApp
|
2
|
+
module UserSessionStorage
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include ::ShopifyApp::SessionStorage
|
5
|
+
|
6
|
+
included do
|
7
|
+
validates :shopify_domain, presence: true
|
8
|
+
end
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def store(auth_session, user)
|
12
|
+
user = find_or_initialize_by(shopify_user_id: user[:id])
|
13
|
+
user.shopify_token = auth_session.token
|
14
|
+
user.shopify_domain = auth_session.domain
|
15
|
+
user.save!
|
16
|
+
user.id
|
17
|
+
end
|
18
|
+
|
19
|
+
def retrieve(id)
|
20
|
+
return unless id
|
21
|
+
if user = find_by(id: id)
|
22
|
+
ShopifyAPI::Session.new(
|
23
|
+
domain: user.shopify_domain,
|
24
|
+
token: user.shopify_token,
|
25
|
+
api_version: user.api_version
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/shopify_app/utils.rb
CHANGED
@@ -12,5 +12,12 @@ module ShopifyApp
|
|
12
12
|
nil
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.fetch_known_api_versions
|
16
|
+
Rails.logger.info("[ShopifyAPI::ApiVersion] Fetching known Admin API Versions from Shopify...")
|
17
|
+
ShopifyAPI::ApiVersion.fetch_known_versions
|
18
|
+
Rails.logger.info("[ShopifyAPI::ApiVersion] Known API Versions: #{ShopifyAPI::ApiVersion.versions.keys}")
|
19
|
+
rescue ActiveResource::ConnectionError
|
20
|
+
logger.error( "[ShopifyAPI::ApiVersion] Unable to fetch api_versions from Shopify")
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
data/lib/shopify_app/version.rb
CHANGED
data/lib/shopify_app.rb
CHANGED
@@ -4,32 +4,51 @@ require 'shopify_app/version'
|
|
4
4
|
require 'shopify_api'
|
5
5
|
require 'omniauth-shopify-oauth2'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
require 'shopify_app/
|
20
|
-
|
21
|
-
|
22
|
-
require 'shopify_app/
|
23
|
-
|
24
|
-
#
|
25
|
-
require 'shopify_app/
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
require 'shopify_app/
|
30
|
-
require 'shopify_app/
|
31
|
-
|
32
|
-
|
33
|
-
require 'shopify_app/
|
34
|
-
|
35
|
-
|
7
|
+
module ShopifyApp
|
8
|
+
def self.rails6?
|
9
|
+
Rails::VERSION::MAJOR >= 6
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.use_webpacker?
|
13
|
+
rails6? &&
|
14
|
+
defined?(Webpacker) == 'constant' &&
|
15
|
+
!configuration.disable_webpacker
|
16
|
+
end
|
17
|
+
|
18
|
+
# config
|
19
|
+
require 'shopify_app/configuration'
|
20
|
+
|
21
|
+
# engine
|
22
|
+
require 'shopify_app/engine'
|
23
|
+
|
24
|
+
# utils
|
25
|
+
require 'shopify_app/utils'
|
26
|
+
|
27
|
+
# controller concerns
|
28
|
+
require 'shopify_app/controller_concerns/localization'
|
29
|
+
require 'shopify_app/controller_concerns/itp'
|
30
|
+
require 'shopify_app/controller_concerns/login_protection'
|
31
|
+
require 'shopify_app/controller_concerns/embedded_app'
|
32
|
+
require 'shopify_app/controller_concerns/webhook_verification'
|
33
|
+
require 'shopify_app/controller_concerns/app_proxy_verification'
|
34
|
+
|
35
|
+
# jobs
|
36
|
+
require 'shopify_app/jobs/webhooks_manager_job'
|
37
|
+
require 'shopify_app/jobs/scripttags_manager_job'
|
38
|
+
|
39
|
+
# managers
|
40
|
+
require 'shopify_app/managers/webhooks_manager'
|
41
|
+
require 'shopify_app/managers/scripttags_manager'
|
42
|
+
|
43
|
+
# middleware
|
44
|
+
require 'shopify_app/middleware/same_site_cookie_middleware'
|
45
|
+
|
46
|
+
# session
|
47
|
+
require 'shopify_app/session/session_storage'
|
48
|
+
require 'shopify_app/session/shop_session_storage'
|
49
|
+
require 'shopify_app/session/user_session_storage'
|
50
|
+
require 'shopify_app/session/session_repository'
|
51
|
+
require 'shopify_app/session/in_memory_session_store'
|
52
|
+
require 'shopify_app/session/in_memory_shop_session_store'
|
53
|
+
require 'shopify_app/session/in_memory_user_session_store'
|
54
|
+
end
|