shopify_app 18.0.2 → 19.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +4 -5
- data/.gitignore +1 -0
- data/.nvmrc +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +52 -2
- data/CONTRIBUTING.md +6 -1
- data/Gemfile +3 -2
- data/Gemfile.lock +144 -164
- data/README.md +1 -0
- data/Rakefile +4 -3
- data/app/assets/javascripts/shopify_app/app_bridge_2.0.12.js +10 -0
- data/app/assets/javascripts/shopify_app/app_bridge_redirect.js +22 -0
- data/app/assets/javascripts/shopify_app/redirect.js +9 -11
- data/app/assets/javascripts/shopify_app/storage_access.js +4 -10
- data/app/controllers/concerns/shopify_app/authenticated.rb +3 -0
- data/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +16 -3
- data/app/controllers/concerns/shopify_app/require_known_shop.rb +1 -0
- data/app/controllers/concerns/shopify_app/shop_access_scopes_verification.rb +1 -1
- data/app/controllers/shopify_app/authenticated_controller.rb +1 -0
- data/app/controllers/shopify_app/callback_controller.rb +49 -134
- data/app/controllers/shopify_app/sessions_controller.rb +26 -131
- data/app/controllers/shopify_app/webhooks_controller.rb +5 -24
- data/app/views/shopify_app/sessions/enable_cookies.html.erb +1 -1
- data/app/views/shopify_app/sessions/request_storage_access.html.erb +11 -11
- data/app/views/shopify_app/sessions/top_level_interaction.html.erb +1 -1
- data/app/views/shopify_app/shared/redirect.html.erb +2 -2
- data/config/locales/zh-CN.yml +1 -1
- data/config/routes.rb +20 -12
- data/docs/Troubleshooting.md +0 -3
- data/docs/Upgrading.md +116 -14
- data/docs/shopify_app/engine.md +2 -2
- data/docs/shopify_app/handling-access-scopes-changes.md +11 -1
- data/docs/shopify_app/script-tags.md +1 -1
- data/docs/shopify_app/webhooks.md +3 -3
- data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +10 -9
- data/lib/generators/shopify_app/add_after_authenticate_job/templates/after_authenticate_job.rb +1 -0
- data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +4 -3
- data/lib/generators/shopify_app/add_webhook/add_webhook_generator.rb +13 -12
- data/lib/generators/shopify_app/add_webhook/templates/webhook_job.rb.tt +9 -1
- data/lib/generators/shopify_app/app_proxy_controller/app_proxy_controller_generator.rb +7 -6
- data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_controller.rb +2 -1
- data/lib/generators/shopify_app/app_proxy_controller/templates/app_proxy_route.rb +1 -1
- data/lib/generators/shopify_app/authenticated_controller/authenticated_controller_generator.rb +3 -3
- data/lib/generators/shopify_app/controllers/controllers_generator.rb +4 -3
- data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +11 -15
- data/lib/generators/shopify_app/home_controller/templates/home_controller.rb +2 -2
- data/lib/generators/shopify_app/home_controller/templates/index.html.erb +7 -3
- data/lib/generators/shopify_app/install/install_generator.rb +27 -72
- data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +3 -1
- data/lib/generators/shopify_app/install/templates/session_store.rb +2 -1
- data/lib/generators/shopify_app/install/templates/shopify_app.rb.tt +33 -5
- data/lib/generators/shopify_app/install/templates/shopify_app_importmap.js +13 -0
- data/lib/generators/shopify_app/products_controller/products_controller_generator.rb +3 -3
- data/lib/generators/shopify_app/products_controller/templates/products_controller.rb +1 -1
- data/lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb +4 -4
- data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake +1 -0
- data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb +1 -1
- data/lib/generators/shopify_app/routes/routes_generator.rb +6 -5
- data/lib/generators/shopify_app/routes/templates/routes.rb +5 -5
- data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +11 -10
- data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -0
- data/lib/generators/shopify_app/shopify_app_generator.rb +4 -3
- data/lib/generators/shopify_app/user_model/templates/user.rb +1 -0
- data/lib/generators/shopify_app/user_model/user_model_generator.rb +11 -10
- data/lib/generators/shopify_app/views/views_generator.rb +4 -3
- data/lib/shopify_app/access_scopes/shop_strategy.rb +2 -2
- data/lib/shopify_app/access_scopes/user_strategy.rb +4 -4
- data/lib/shopify_app/configuration.rb +33 -14
- data/lib/shopify_app/controller_concerns/app_proxy_verification.rb +4 -3
- data/lib/shopify_app/controller_concerns/csrf_protection.rb +2 -1
- data/lib/shopify_app/controller_concerns/embedded_app.rb +4 -3
- data/lib/shopify_app/controller_concerns/ensure_billing.rb +254 -0
- data/lib/shopify_app/controller_concerns/itp.rb +3 -3
- data/lib/shopify_app/controller_concerns/localization.rb +1 -0
- data/lib/shopify_app/controller_concerns/login_protection.rb +82 -68
- data/lib/shopify_app/controller_concerns/payload_verification.rb +3 -2
- data/lib/shopify_app/controller_concerns/webhook_verification.rb +2 -1
- data/lib/shopify_app/engine.rb +7 -15
- data/lib/shopify_app/jobs/scripttags_manager_job.rb +2 -2
- data/lib/shopify_app/jobs/webhooks_manager_job.rb +4 -5
- data/lib/shopify_app/managers/scripttags_manager.rb +11 -4
- data/lib/shopify_app/managers/webhooks_manager.rb +42 -44
- data/lib/shopify_app/middleware/jwt_middleware.rb +5 -3
- data/lib/shopify_app/session/in_memory_session_store.rb +1 -0
- data/lib/shopify_app/session/in_memory_shop_session_store.rb +2 -1
- data/lib/shopify_app/session/in_memory_user_session_store.rb +1 -0
- data/lib/shopify_app/session/jwt.rb +12 -7
- data/lib/shopify_app/session/null_user_session_store.rb +2 -1
- data/lib/shopify_app/session/session_repository.rb +37 -0
- data/lib/shopify_app/session/session_storage.rb +4 -6
- data/lib/shopify_app/session/shop_session_storage.rb +6 -6
- data/lib/shopify_app/session/shop_session_storage_with_scopes.rb +7 -8
- data/lib/shopify_app/session/user_session_storage.rb +19 -6
- data/lib/shopify_app/session/user_session_storage_with_scopes.rb +22 -9
- data/lib/shopify_app/test_helpers/all.rb +2 -1
- data/lib/shopify_app/test_helpers/webhook_verification_helper.rb +4 -3
- data/lib/shopify_app/utils.rb +4 -10
- data/lib/shopify_app/version.rb +2 -1
- data/lib/shopify_app.rb +44 -40
- data/package.json +1 -1
- data/shopify_app.gemspec +22 -21
- data/translation.yml +1 -1
- data/yarn.lock +103 -88
- metadata +51 -60
- data/config/locales/hi.yml +0 -23
- data/config/locales/ms.yml +0 -22
- data/lib/generators/shopify_app/install/templates/omniauth.rb +0 -4
- data/lib/generators/shopify_app/install/templates/shopify_provider.rb.tt +0 -8
- data/lib/generators/shopify_app/install/templates/user_agent.rb +0 -6
- data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +0 -34
- data/lib/shopify_app/omniauth/omniauth_configuration.rb +0 -64
@@ -1,116 +1,71 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
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(
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
10
|
|
10
|
-
class_option :application_name, type: :array, default: [
|
11
|
-
class_option :scope, type: :array, default: [
|
12
|
-
class_option :embedded, type: :string, default:
|
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[
|
18
|
-
@scope = format_array_argument(options[
|
19
|
-
@api_version = options[
|
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(
|
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(
|
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(
|
46
|
-
copy_file(
|
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(
|
50
|
-
copy_file(
|
51
|
-
copy_file(
|
52
|
-
append_to_file(
|
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")
|
39
|
+
elsif ShopifyApp.use_importmap?
|
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")
|
53
43
|
else
|
54
|
-
copy_file(
|
55
|
-
copy_file(
|
44
|
+
copy_file("shopify_app.js", "app/assets/javascripts/shopify_app.js")
|
45
|
+
copy_file("flash_messages.js", "app/assets/javascripts/flash_messages.js")
|
56
46
|
end
|
57
47
|
end
|
58
48
|
|
59
|
-
def create_user_agent_initializer
|
60
|
-
template('user_agent.rb', 'config/initializers/user_agent.rb')
|
61
|
-
end
|
62
|
-
|
63
49
|
def mount_engine
|
64
50
|
route("mount ShopifyApp::Engine, at: '/'")
|
65
51
|
end
|
66
52
|
|
67
53
|
def insert_hosts_into_development_config
|
68
54
|
inject_into_file(
|
69
|
-
|
70
|
-
" config.hosts = (config.hosts rescue []) <<
|
55
|
+
"config/environments/development.rb",
|
56
|
+
" config.hosts = (config.hosts rescue []) << /\[-\\w]+\\.ngrok\\.io/\n",
|
71
57
|
after: "Rails.application.configure do\n"
|
72
58
|
)
|
73
59
|
end
|
74
60
|
|
75
61
|
private
|
76
62
|
|
77
|
-
def shopify_provider_exists?
|
78
|
-
File.open("config/initializers/omniauth.rb") do |file|
|
79
|
-
file.each_line do |line|
|
80
|
-
if line =~ /provider :shopify/
|
81
|
-
puts "\e[33m#{omniauth_warning}\e[0m"
|
82
|
-
return true
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
false
|
87
|
-
end
|
88
|
-
|
89
|
-
def omniauth_warning
|
90
|
-
<<~OMNIAUTH
|
91
|
-
\n[WARNING] The Shopify App generator attempted to add the following Shopify Omniauth \
|
92
|
-
provider 'config/initializers/omniauth.rb':
|
93
|
-
|
94
|
-
\e[0m#{shopify_provider_template}\e[33m
|
95
|
-
|
96
|
-
Consider updating 'config/initializers/omniauth.rb' to match the configuration above.
|
97
|
-
OMNIAUTH
|
98
|
-
end
|
99
|
-
|
100
|
-
def shopify_provider_template
|
101
|
-
File.read(File.expand_path(find_in_source_paths('shopify_provider.rb.tt')))
|
102
|
-
end
|
103
|
-
|
104
63
|
def embedded_app?
|
105
|
-
options[
|
64
|
+
options["embedded"] == "true"
|
106
65
|
end
|
107
66
|
|
108
67
|
def format_array_argument(array)
|
109
|
-
array.join(
|
110
|
-
end
|
111
|
-
|
112
|
-
def with_cookie_authentication?
|
113
|
-
options['with_cookie_authentication'] || !embedded_app?
|
68
|
+
array.join(" ").tr('"', "")
|
114
69
|
end
|
115
70
|
end
|
116
71
|
end
|
@@ -7,6 +7,8 @@
|
|
7
7
|
<%= stylesheet_link_tag 'application' %>
|
8
8
|
<% if ShopifyApp.use_webpacker? %>
|
9
9
|
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
10
|
+
<% elsif ShopifyApp.use_importmap? %>
|
11
|
+
<%= javascript_importmap_tags %>
|
10
12
|
<% else %>
|
11
13
|
<%= javascript_include_tag 'application', "data-turbolinks-track" => true %>
|
12
14
|
<% end %>
|
@@ -28,7 +30,7 @@
|
|
28
30
|
|
29
31
|
<%= content_tag(:div, nil, id: 'shopify-app-init', data: {
|
30
32
|
api_key: ShopifyApp.configuration.api_key,
|
31
|
-
shop_origin: @shop_origin || (@current_shopify_session.
|
33
|
+
shop_origin: @shop_origin || (@current_shopify_session.shop if @current_shopify_session),
|
32
34
|
host: @host,
|
33
35
|
debug: Rails.env.development?
|
34
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:
|
5
|
+
Rails.application.config.session_store(:cookie_store, key: "_example_session", expire_after: 14.days)
|
@@ -10,16 +10,44 @@ 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
|
+
|
16
|
+
# You may want to charge merchants for using your app. Setting the billing configuration will cause the Authenticated
|
17
|
+
# controller concern to check that the session is for a merchant that has an active one-time payment or subscription.
|
18
|
+
# If no payment is found, it starts off the process and sends the merchant to a confirmation URL so that they can
|
19
|
+
# approve the purchase.
|
20
|
+
#
|
21
|
+
# Learn more about billing in our documentation: https://shopify.dev/apps/billing
|
22
|
+
# config.billing = ShopifyApp::BillingConfiguration.new(
|
23
|
+
# charge_name: "My app billing charge",
|
24
|
+
# amount: 5,
|
25
|
+
# interval: ShopifyApp::BillingConfiguration::INTERVAL_EVERY_30_DAYS,
|
26
|
+
# currency_code: "USD", # Only supports USD for now
|
27
|
+
# )
|
28
|
+
|
18
29
|
if defined? Rails::Server
|
19
30
|
raise('Missing SHOPIFY_API_KEY. See https://github.com/Shopify/shopify_app#requirements') unless config.api_key
|
20
31
|
raise('Missing SHOPIFY_API_SECRET. See https://github.com/Shopify/shopify_app#requirements') unless config.secret
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
24
|
-
|
25
|
-
|
35
|
+
Rails.application.config.after_initialize do
|
36
|
+
if ShopifyApp.configuration.api_key.present? && ShopifyApp.configuration.secret.present?
|
37
|
+
ShopifyAPI::Context.setup(
|
38
|
+
api_key: ShopifyApp.configuration.api_key,
|
39
|
+
api_secret_key: ShopifyApp.configuration.secret,
|
40
|
+
api_version: ShopifyApp.configuration.api_version,
|
41
|
+
host_name: URI(ENV.fetch('HOST', '')).host || '',
|
42
|
+
scope: ShopifyApp.configuration.scope,
|
43
|
+
is_private: !ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', '').empty?,
|
44
|
+
is_embedded: ShopifyApp.configuration.embedded_app,
|
45
|
+
session_storage: ShopifyApp::SessionRepository,
|
46
|
+
logger: Rails.logger,
|
47
|
+
private_shop: ENV.fetch('SHOPIFY_APP_PRIVATE_SHOP', nil),
|
48
|
+
user_agent_prefix: "ShopifyApp/#{ShopifyApp::VERSION}"
|
49
|
+
)
|
50
|
+
|
51
|
+
ShopifyApp::WebhooksManager.add_registrations
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
var data = document.getElementById('shopify-app-init').dataset;
|
2
|
+
var AppBridge = window['app-bridge'];
|
3
|
+
var createApp = AppBridge.default;
|
4
|
+
window.app = createApp({
|
5
|
+
apiKey: data.apiKey,
|
6
|
+
host: data.host,
|
7
|
+
});
|
8
|
+
|
9
|
+
var actions = AppBridge.actions;
|
10
|
+
var TitleBar = actions.TitleBar;
|
11
|
+
TitleBar.create(app, {
|
12
|
+
title: data.page,
|
13
|
+
});
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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(
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
9
|
|
10
10
|
def create_products_controller
|
11
|
-
template(
|
11
|
+
template("products_controller.rb", "app/controllers/products_controller.rb")
|
12
12
|
end
|
13
13
|
|
14
14
|
def add_products_route
|
data/lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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(
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
9
|
|
10
10
|
def add_rotate_shopify_token_job
|
11
|
-
copy_file(
|
12
|
-
copy_file(
|
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
|
data/lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb
CHANGED
@@ -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)[
|
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
|
-
|
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(
|
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
|
-
|
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(
|
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
|
5
|
-
post
|
6
|
-
get
|
7
|
-
get
|
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
|
11
|
+
post ":type" => :receive
|
12
12
|
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
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(
|
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(
|
15
|
+
copy_file("shop.rb", "app/models/shop.rb")
|
15
16
|
end
|
16
17
|
|
17
18
|
def create_shop_migration
|
18
|
-
migration_template(
|
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
|
-
|
37
|
-
|
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(
|
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(
|
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[
|
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
|
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,21 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
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(
|
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(
|
15
|
+
copy_file("user.rb", "app/models/user.rb")
|
15
16
|
end
|
16
17
|
|
17
18
|
def create_user_migration
|
18
|
-
migration_template(
|
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
|
-
|
37
|
-
|
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(
|
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(
|
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[
|
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
|
-
|
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(
|
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,
|
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)&.
|
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::
|
19
|
+
ShopifyAPI::Auth::AuthScopes.new(ShopifyApp.configuration.shop_access_scopes)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -9,7 +9,7 @@ module ShopifyApp
|
|
9
9
|
def update_access_scopes?(user_id: nil, shopify_user_id: nil)
|
10
10
|
return update_access_scopes_for_user_id?(user_id) if user_id
|
11
11
|
return update_access_scopes_for_shopify_user_id?(shopify_user_id) if shopify_user_id
|
12
|
-
raise(InvalidInput,
|
12
|
+
raise(InvalidInput, "#update_access_scopes? requires user_id or shopify_user_id parameter inputs")
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -25,15 +25,15 @@ module ShopifyApp
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def user_access_scopes_by_user_id(user_id)
|
28
|
-
ShopifyApp::SessionRepository.retrieve_user_session(user_id)&.
|
28
|
+
ShopifyApp::SessionRepository.retrieve_user_session(user_id)&.scope
|
29
29
|
end
|
30
30
|
|
31
31
|
def user_access_scopes_by_shopify_user_id(shopify_user_id)
|
32
|
-
ShopifyApp::SessionRepository.retrieve_user_session_by_shopify_user_id(shopify_user_id)&.
|
32
|
+
ShopifyApp::SessionRepository.retrieve_user_session_by_shopify_user_id(shopify_user_id)&.scope
|
33
33
|
end
|
34
34
|
|
35
35
|
def configuration_access_scopes
|
36
|
-
ShopifyAPI::
|
36
|
+
ShopifyAPI::Auth::AuthScopes.new(ShopifyApp.configuration.user_access_scopes)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|