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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -2
  3. data/CHANGELOG.md +159 -0
  4. data/README.md +221 -130
  5. data/app/assets/javascripts/shopify_app/itp_helper.js +6 -6
  6. data/app/assets/javascripts/shopify_app/storage_access.js +36 -7
  7. data/app/controllers/concerns/shopify_app/authenticated.rb +2 -2
  8. data/app/controllers/shopify_app/callback_controller.rb +20 -7
  9. data/app/controllers/shopify_app/extension_verification_controller.rb +20 -0
  10. data/app/controllers/shopify_app/sessions_controller.rb +71 -22
  11. data/app/views/shopify_app/sessions/enable_cookies.html.erb +3 -1
  12. data/app/views/shopify_app/sessions/request_storage_access.html.erb +2 -1
  13. data/app/views/shopify_app/sessions/top_level_interaction.html.erb +1 -0
  14. data/app/views/shopify_app/shared/redirect.html.erb +1 -0
  15. data/config/locales/cs.yml +23 -0
  16. data/config/locales/da.yml +20 -0
  17. data/config/locales/de.yml +5 -5
  18. data/config/locales/en.yml +1 -1
  19. data/config/locales/es.yml +3 -3
  20. data/config/locales/fi.yml +20 -0
  21. data/config/locales/fr.yml +3 -3
  22. data/config/locales/hi.yml +23 -0
  23. data/config/locales/it.yml +2 -3
  24. data/config/locales/ja.yml +1 -1
  25. data/config/locales/ko.yml +19 -0
  26. data/config/locales/ms.yml +22 -0
  27. data/config/locales/nb.yml +21 -0
  28. data/config/locales/nl.yml +3 -3
  29. data/config/locales/pl.yml +21 -0
  30. data/config/locales/pt-BR.yml +9 -10
  31. data/config/locales/pt-PT.yml +22 -0
  32. data/config/locales/sv.yml +21 -0
  33. data/config/locales/th.yml +20 -0
  34. data/config/locales/tr.yml +22 -0
  35. data/config/locales/zh-CN.yml +3 -3
  36. data/config/locales/zh-TW.yml +1 -2
  37. data/docs/Quickstart.md +44 -16
  38. data/docs/Releasing.md +0 -1
  39. data/docs/install-on-dev-shop.png +0 -0
  40. data/docs/test-your-app.png +0 -0
  41. data/karma.conf.js +1 -0
  42. data/lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb +2 -2
  43. data/lib/generators/shopify_app/add_marketing_activity_extension/add_marketing_activity_extension_generator.rb +39 -0
  44. data/lib/generators/shopify_app/add_marketing_activity_extension/templates/marketing_activities_controller.rb +62 -0
  45. data/lib/generators/shopify_app/home_controller/home_controller_generator.rb +0 -6
  46. data/lib/generators/shopify_app/home_controller/templates/index.html.erb +1 -1
  47. data/lib/generators/shopify_app/install/install_generator.rb +27 -11
  48. data/lib/generators/shopify_app/install/templates/_flash_messages.html.erb +1 -17
  49. data/lib/generators/shopify_app/install/templates/embedded_app.html.erb +11 -10
  50. data/lib/generators/shopify_app/install/templates/flash_messages.js +26 -0
  51. data/lib/generators/shopify_app/install/templates/shopify_app.js +15 -0
  52. data/lib/generators/shopify_app/install/templates/shopify_app.rb +6 -3
  53. data/lib/generators/shopify_app/install/templates/shopify_app_index.js +2 -0
  54. data/lib/generators/shopify_app/install/templates/shopify_provider.rb +1 -0
  55. data/lib/generators/shopify_app/install/templates/user_agent.rb +5 -0
  56. data/lib/generators/shopify_app/shop_model/shop_model_generator.rb +1 -1
  57. data/lib/generators/shopify_app/shop_model/templates/shop.rb +1 -1
  58. data/lib/generators/shopify_app/user_model/templates/db/migrate/create_users.erb +16 -0
  59. data/lib/generators/shopify_app/user_model/templates/user.rb +7 -0
  60. data/lib/generators/shopify_app/user_model/templates/users.yml +4 -0
  61. data/lib/generators/shopify_app/user_model/user_model_generator.rb +38 -0
  62. data/lib/shopify_app/configuration.rb +22 -10
  63. data/lib/shopify_app/controller_concerns/login_protection.rb +66 -15
  64. data/lib/shopify_app/engine.rb +4 -0
  65. data/lib/shopify_app/managers/webhooks_manager.rb +1 -1
  66. data/lib/shopify_app/middleware/same_site_cookie_middleware.rb +33 -0
  67. data/lib/shopify_app/session/in_memory_session_store.rb +1 -1
  68. data/lib/shopify_app/session/in_memory_shop_session_store.rb +4 -0
  69. data/lib/shopify_app/session/in_memory_user_session_store.rb +4 -0
  70. data/lib/shopify_app/session/session_repository.rb +38 -13
  71. data/lib/shopify_app/session/session_storage.rb +0 -22
  72. data/lib/shopify_app/session/shop_session_storage.rb +30 -0
  73. data/lib/shopify_app/session/user_session_storage.rb +31 -0
  74. data/lib/shopify_app/utils.rb +7 -0
  75. data/lib/shopify_app/version.rb +1 -1
  76. data/lib/shopify_app.rb +48 -29
  77. data/package-lock.json +7227 -5
  78. data/package.json +9 -9
  79. data/service.yml +1 -1
  80. data/shopify_app.gemspec +10 -5
  81. data/translation.yml +1 -1
  82. data/yarn.lock +2555 -1886
  83. metadata +117 -19
  84. data/lib/generators/shopify_app/home_controller/templates/shopify_app_ready_script.html.erb +0 -7
@@ -0,0 +1,22 @@
1
+ ---
2
+ pt-PT:
3
+ logged_out: Terminou a sessão com sucesso
4
+ could_not_log_in: Não foi possível iniciar sessão na loja da Shopify
5
+ invalid_shop_url: Domínio de loja inválido
6
+ enable_cookies_heading: Ativar cookies de %{app}
7
+ enable_cookies_body: Tem de ativar manualmente os cookies neste navegador para utilizar
8
+ %{app} dentro da Shopify.
9
+ enable_cookies_footer: Os cookies permitem que a aplicação o autentique armazenando
10
+ temporariamente as suas preferências e informações pessoais. Expiram ao fim de
11
+ 30 dias.
12
+ enable_cookies_action: Ativar cookies
13
+ top_level_interaction_heading: O seu navegador tem de autenticar %{app}
14
+ top_level_interaction_body: O seu navegador exige que aplicações como %{app} lhe
15
+ solicitem o acesso de cookies, antes que a Shopify as possa abrir.
16
+ top_level_interaction_action: Continuar
17
+ request_storage_access_heading: "%{app} tem de aceder a cookies"
18
+ request_storage_access_body: Isto permite que a aplicação o autentique armazenando
19
+ temporariamente as suas informações pessoais. Clique em continuar e permita os
20
+ cookies para utilizar a aplicação.
21
+ request_storage_access_footer: Os cookies expiram ao fim de 30 dias.
22
+ request_storage_access_action: Continuar
@@ -0,0 +1,21 @@
1
+ ---
2
+ sv:
3
+ logged_out: Har loggats ut
4
+ could_not_log_in: Det gick inte att logga in i Shopify-butiken
5
+ invalid_shop_url: Ogiltig butiksdomän
6
+ enable_cookies_heading: Aktivera cookies från %{app}
7
+ enable_cookies_body: Du måste aktivera cookies manuellt i den här webbläsaren för
8
+ att kunna använda %{app} inom Shopify.
9
+ enable_cookies_footer: Cookies låter appen autentisera dig genom att tillfälligt
10
+ lagra dina inställningar och personuppgifter. De upphör efter 30 dagar.
11
+ enable_cookies_action: Aktivera cookies
12
+ top_level_interaction_heading: Din webbläsare måste verifiera %{app}
13
+ top_level_interaction_body: Din webbläsare kräver att appar som %{app} frågar dig
14
+ om tillgång till cookies innan Shopify kan öppna den för dig.
15
+ top_level_interaction_action: Fortsätt
16
+ request_storage_access_heading: "%{app} behöver tillgång till cookies"
17
+ request_storage_access_body: Detta gör det möjligt för appen att autentisera dig
18
+ genom att tillfälligt lagra din personliga information. Klicka på fortsätt och
19
+ tillåta cookies att använda appen.
20
+ request_storage_access_footer: Cookies upphör efter 30 dagar.
21
+ request_storage_access_action: Fortsätt
@@ -0,0 +1,20 @@
1
+ ---
2
+ th:
3
+ logged_out: ออกจากระบบสำเร็จ
4
+ could_not_log_in: ไม่สามารถเข้าสู่ระบบร้านค้า Shopify ได้
5
+ invalid_shop_url: โดเมนร้านค้าไม่ถูกต้อง
6
+ enable_cookies_heading: เปิดใช้งานคุกกี้จาก %{app}
7
+ enable_cookies_body: คุณต้องเปิดใช้งานคุกกี้ด้วยตนเองในเบราว์เซอร์นี้เพื่อใช้งาน
8
+ %{app} ภายใน Shopify
9
+ enable_cookies_footer: คุกกี้ช่วยให้แอปตรวจสอบความถูกต้องของคุณด้วยการจัดเก็บความชื่นชอบและข้อมูลส่วนตัวของคุณชั่วคราว
10
+ คุกกี้จะหมดอายุหลังจาก 30 วัน
11
+ enable_cookies_action: เปิดใช้งานคุกกี้
12
+ top_level_interaction_heading: เบราว์เซอร์ของคุณต้องรับรองความถูกต้องของ %{app}
13
+ top_level_interaction_body: เบราว์เซอร์ของคุณต้องการแอปอย่าง %{app} เพื่อขอให้คุณเข้าถึงคุกกี้ก่อนที่
14
+ Shopify จะสามารถเปิดมันให้คุณได้
15
+ top_level_interaction_action: ดำเนินการต่อ
16
+ request_storage_access_heading: "%{app} ต้องการสิทธิ์การเข้าถึงคุกกี้"
17
+ request_storage_access_body: สิ่งนี้ช่วยให้แอปตรวจสอบความถูกต้องของคุณด้วยการจัดเก็บข้อมูลส่วนตัวของคุณชั่วคราว
18
+ คลิกดำเนินการต่อและอนุญาตให้คุกกี้ใช้แอป
19
+ request_storage_access_footer: คุกกี้จะหมดอายุหลังจาก 30 วัน
20
+ request_storage_access_action: ดำเนินการต่อ
@@ -0,0 +1,22 @@
1
+ ---
2
+ tr:
3
+ logged_out: Oturum başarıyla kapatıldı
4
+ could_not_log_in: Shopify mağazasında oturum açılamadı
5
+ invalid_shop_url: Geçersiz mağaza alan adı
6
+ enable_cookies_heading: "%{app} uygulamasından çerezleri etkinleştir"
7
+ enable_cookies_body: "%{app} uygulamasını Shopify içinde kullanabilmek için bu tarayıcıda
8
+ çerezleri manuel olarak etkinleştirmelisiniz."
9
+ enable_cookies_footer: Çerezler, tercihlerinizi ve kişisel bilgilerinizi geçici
10
+ olarak saklayıp uygulamanın kimliğinizi doğrulamasına imkan tanır. Çerezlerin
11
+ süresi 30 gün sonra sonra sona erer.
12
+ enable_cookies_action: Çerezleri etkinleştir
13
+ top_level_interaction_heading: Tarayıcınızın %{app} kimliğini doğrulaması gerekiyor
14
+ top_level_interaction_body: Tarayıcınız, Shopify tarafından açılmadan önce %{app}
15
+ gibi uygulamaların sizden çerezlere erişim izni istemesini zorunlu tutuyor.
16
+ top_level_interaction_action: Devam
17
+ request_storage_access_heading: "%{app} uygulamasının çerezlere erişmesi gerekiyor"
18
+ request_storage_access_body: Böylece uygulama, kişisel bilgilerinizi geçici olarak
19
+ saklayıp kimliğinizi doğrulayabilir. Devam et'e tıklayın ve çerezlerin uygulamayı
20
+ kullanmasına izin verin.
21
+ request_storage_access_footer: Çerezlerin süresi 30 gün sonra sonra sona erer.
22
+ request_storage_access_action: Devam
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  zh-CN:
3
- logged_out: 已成功注销
3
+ logged_out: 已成功退出
4
4
  could_not_log_in: 无法登录到 Shopify 商店
5
- invalid_shop_url: 商店域无效
5
+ invalid_shop_url: 商店域名无效
6
6
  enable_cookies_heading: 从 %{app} 启用 Cookie
7
7
  enable_cookies_body: 您必须在此浏览器中手动启用 Cookie 才能在 Shopify 中使用 %{app}。
8
8
  enable_cookies_footer: Cookie 使此应用能够通过暂时存储您的偏好设置和个人信息来验证您的身份。这些信息将在 30 天后过期。
9
9
  enable_cookies_action: 启用 Cookie
10
10
  top_level_interaction_heading: 您的浏览器需要对 %{app} 进行验证
11
- top_level_interaction_body: 您的浏览器要求类似 %{app} 的第三方应用向您请求访问 Cookie,之后 Shopify 才能为您打开它。
11
+ top_level_interaction_body: 您的浏览器要求类似 %{app} 的应用向您请求访问 Cookie,之后 Shopify 才能为您打开它。
12
12
  top_level_interaction_action: 继续
13
13
  request_storage_access_heading: "%{app} 需要访问 Cookie"
14
14
  request_storage_access_body: 这使此应用能够通过暂时存储您的个人信息来验证您的身份。单击继续并启用 Cookie 以使用此应用。
@@ -8,8 +8,7 @@ zh-TW:
8
8
  enable_cookies_footer: Cookie 可讓應用程式暫時儲存您的偏好設定和個人資訊,藉此驗證您的身分,這些資料會在 30 天後失效。
9
9
  enable_cookies_action: 啟用 Cookie
10
10
  top_level_interaction_heading: 您的瀏覽器需要驗證 %{app}
11
- top_level_interaction_body: 您的瀏覽器會要求第三方應用程式 (例如:%{app}) 向您請求 Cookie 的存取權限,然後才讓 Shopify
12
- 為您開啟此應用程式。
11
+ top_level_interaction_body: 您的瀏覽器要求 %{app} 等應用程式向您請求 Cookie 的存取權限,才能讓 Shopify 為您開啟該應用程式。
13
12
  top_level_interaction_action: 繼續
14
13
  request_storage_access_heading: "%{app} 需要 Cookie 存取權限"
15
14
  request_storage_access_body: Cookie 可讓應用程式暫時儲存您的個人資訊,藉此驗證您的身分。按一下繼續並允許 Cookie 使用此應用程式。
data/docs/Quickstart.md CHANGED
@@ -1,11 +1,13 @@
1
1
  Quickstart
2
2
  ==========
3
3
 
4
- Build and deploy a new Shopify App to Heroku in minutes
4
+ Get started building and deploying a new Shopify App to Heroku in just a few minutes. This guide assumes you have Ruby/Rails installed on your computer already; if you haven't done that already start with [this guide.](https://guides.rubyonrails.org/v5.0/getting_started.html#installing-rails)
5
5
 
6
6
  1. New Rails App (with postgres)
7
7
  --------------------------------
8
8
 
9
+ To create a new Rails app and use this generator, open your terminal and run the following commands:
10
+
9
11
  ```sh
10
12
  $ rails new test-app --database=postgresql
11
13
  $ cd test-app
@@ -17,43 +19,51 @@ $ git commit -m 'new rails app'
17
19
  2. Create a new Heroku app
18
20
  --------------------------
19
21
 
20
- The next step is to create a new heroku app. Pull up your heroku dashboard and make a new app!
22
+ The next step is to create a new Heroku app to host your application. If you haven't got a Heroku account yet, create a free account [here](https://www.heroku.com/).
23
+
24
+ Head to the Heroku dashboard and create a new app, or run the following commands with the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli#download-and-install) installed, substituting `name` for the name of your own app:
21
25
 
22
- cli:
26
+ CLI:
23
27
  ```sh
24
28
  $ heroku create name
25
29
  $ heroku git:remote -a name
26
30
  ```
27
31
 
28
- now we need to let git know where the remote server is so we'll be able to deploy later
32
+ Once you have created an app on Heroku, we need to let Git know where the Heroku server is so we can deploy to it later. Copy the app's name from your Heroku dashboard and substitute `appname.git` with the name you chose earlier:
29
33
 
30
34
  web:
31
35
  ```sh
32
36
  # https://dashboard.heroku.com/new
33
- $ git remote add heroku git@heroku.com:appinfive.git
37
+ $ git remote add heroku git@heroku.com:appname.git
34
38
  ```
35
39
 
36
- 3. Create a new App in the partners area
40
+ 3. Create a new App in the Shopify Partner dashboard
37
41
  -----------------------------------------
42
+ * Create a Shopify app in the [Partners dashboard](https://partner.shopify.com). For this tutorial, you can choose either a public or custom app, but you can [learn about App Types here.](https://help.shopify.com/en/manual/apps/app-types)
38
43
  [https://app.shopify.com/services/partners/api_clients](https://app.shopify.com/services/partners/api_clients)
39
- * set the callback url to `https://<name>.herokuapp.com/`
40
- * choose an embedded app
41
- * set the redirect_uri to `https://<name>.herokuapp.com/auth/shopify/callback`
42
-
44
+ * Set the callback url to `https://<appname>.herokuapp.com/`
45
+ * Choose an embedded app
46
+ * Set the app's `redirect_uri` to `https://<appname>.herokuapp.com/auth/shopify/callback`
43
47
 
44
- 4. Add ShopifyApp to gemfile
48
+ 4. Add ShopifyApp to Gemfile
45
49
  ----------------------------
50
+
51
+ Run these commands to add the `shopify_app` Gem to your app:
52
+
46
53
  ```sh
47
54
  $ echo "gem 'shopify_app'" >> Gemfile
48
55
  $ bundle install
49
56
  ```
50
57
 
51
- Note - its recommended to use the latest released version. Check the git tags to see the latest release and then add it to your Gemfile e.g `gem 'shopify_app', '~> 7.0.0'`
58
+ **Note:** we recommend using the latest version of Shopify Gem. Check the [Git tags](https://github.com/Shopify/shopify_app/tags) to see the latest release version and then add it to your Gemfile e.g `gem 'shopify_app', '~> 7.0.0'`
52
59
 
53
60
  5. Run the ShopifyApp generator
54
61
  -------------------------------
62
+
63
+ Generate the code for your app by running these commands:
64
+
55
65
  ```sh
56
- # use the keys from your app in the partners area
66
+ # Use the keys from your app you created in the partners area
57
67
  $ rails generate shopify_app --api_key <shopify_api_key> --secret <shopify_api_secret>
58
68
  $ git add .
59
69
  $ git commit -m 'generated shopify app'
@@ -61,10 +71,12 @@ $ git commit -m 'generated shopify app'
61
71
 
62
72
  If you forget to set your keys or redirect uri above, you will find them in the shopify_app initializer at: `/config/initializers/shopify_app.rb`.
63
73
 
64
- We recommend adding a gem or utilizing ENV variables to handle your keys before releasing your app.
74
+ We recommend adding a gem or utilizing environment variables (`.env`) to handle your keys before releasing your app. [Learn more about using environment variables.](https://www.honeybadger.io/blog/ruby-guide-environment-variables/)
65
75
 
66
- 6. Deploy
76
+ 6. Deploy your app
67
77
  ---------
78
+
79
+ Once you've generated your app, push it into your Heroku environment to see it up and running:
68
80
  ```sh
69
81
  $ git push heroku
70
82
  $ heroku run rake db:migrate
@@ -72,4 +84,20 @@ $ heroku run rake db:migrate
72
84
 
73
85
  7. Install the App!
74
86
  -------------------
75
- `https://<name>.herokuapp.com/`
87
+
88
+ Ensure you have created a [development store](https://help.shopify.com/en/api/getting-started/making-your-first-request#create-a-development-store) using the Shopify Partner Dashboard. If you don't already have one, [create one by following these instructions](https://help.shopify.com/en/api/getting-started/making-your-first-request#create-a-development-store).
89
+
90
+ ##### Note: The following step will cause your store to become `transfer-disabled.` Read more about store transfer and why it's important [here](https://help.shopify.com/en/api/guides/store-transfers#transfer-disabled-stores). This is an irreversible change, so be sure you don't plan to transfer this store to a merchant.
91
+
92
+ Install the app onto your new development store using the Partner Dashboard. Log in to your account, visit the apps page, click the app you created earlier, and looking for the `Test your app` instructions where you can select a store to install your app on.
93
+
94
+ ![Installing an app on the partners dashboard dropdown](/docs/install-on-dev-shop.png)
95
+
96
+ ### OR
97
+
98
+ ![Installing an app on the partners dashboard card](/docs/test-your-app.png)
99
+
100
+ 8. Great work!
101
+ -------------------
102
+
103
+ You're done creating your first app on Shopify. Keep going and learn more by [diving into our full documentation](https://help.shopify.com/en/api/getting-started), or join our [community of developers.](https://community.shopify.com/c/Shopify-Apps/bd-p/shopify-apps)
data/docs/Releasing.md CHANGED
@@ -3,7 +3,6 @@ Releasing ShopifyApp
3
3
  1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4
4
  2. Create a pull request with the following changes:
5
5
  * Update the version of ShopifyApp in lib/shopify_app/version.rb
6
- * Update the version in package.json
7
6
  * Add a CHANGELOG entry for the new release with the date
8
7
  * Change the title of the PR to something like: "Packaging for release X.Y.Z"
9
8
  3. Merge your pull request
Binary file
Binary file
data/karma.conf.js CHANGED
@@ -26,6 +26,7 @@ module.exports = function(config) {
26
26
  preprocessors: {
27
27
  'test/javascripts/**/*test.js': ['webpack'],
28
28
  },
29
+ webpack: {},
29
30
  reporters: karmaReporters,
30
31
  port: 9876,
31
32
  colors: true,
@@ -14,7 +14,7 @@ module ShopifyApp
14
14
 
15
15
  after_authenticate_job_config =
16
16
  " config.after_authenticate_job = "\
17
- "{ job: Shopify::AfterAuthenticateJob, inline: false }\n"
17
+ "{ job: \"Shopify::AfterAuthenticateJob\", inline: false }\n"
18
18
 
19
19
  inject_into_file(
20
20
  'config/initializers/shopify_app.rb',
@@ -23,7 +23,7 @@ module ShopifyApp
23
23
  )
24
24
 
25
25
  unless initializer.include?(after_authenticate_job_config)
26
- shell.say "Error adding after_authneticate_job to config. Add this line manually: #{after_authenticate_job_config}", :red
26
+ shell.say("Error adding after_authenticate_job to config. Add this line manually: #{after_authenticate_job_config}", :red)
27
27
  end
28
28
  end
29
29
 
@@ -0,0 +1,39 @@
1
+ require 'rails/generators/base'
2
+
3
+ module ShopifyApp
4
+ module Generators
5
+ class AddMarketingActivityExtensionGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def generate_app_extension
9
+ template "marketing_activities_controller.rb", "app/controllers/marketing_activities_controller.rb"
10
+ generate_routes
11
+ end
12
+
13
+ private
14
+
15
+ def generate_routes
16
+ inject_into_file(
17
+ 'config/routes.rb',
18
+ optimize_indentation(routes, 2),
19
+ after: "root :to => 'home#index'\n"
20
+ )
21
+ end
22
+
23
+ def routes
24
+ <<~EOS
25
+
26
+ resource :marketing_activities, only: [:create, :update] do
27
+ patch :resume
28
+ patch :pause
29
+ patch :delete
30
+ post :republish
31
+ post :preload_form_data
32
+ post :preview
33
+ post :errors
34
+ end
35
+ EOS
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MarketingActivitiesController < ShopifyApp::ExtensionVerificationController
4
+ def preload_form_data
5
+ preload_data = {
6
+ "form_data": {}
7
+ }
8
+ render(json: preload_data, status: :ok)
9
+ end
10
+
11
+ def update
12
+ render(json: {}, status: :accepted)
13
+ end
14
+
15
+ def pause
16
+ render(json: {}, status: :accepted)
17
+ end
18
+
19
+ def resume
20
+ render(json: {}, status: :accepted)
21
+ end
22
+
23
+ def delete
24
+ render(json: {}, status: :accepted)
25
+ end
26
+
27
+ def preview
28
+ placeholder_img = "https://cdn.shopify.com/s/files/1/0533/2089/files/placeholder-images-image_small.png"
29
+ preview_response = {
30
+ "desktop": {
31
+ "preview_url": placeholder_img,
32
+ "content_type": "text/html",
33
+ "width": 360,
34
+ "height": 200
35
+ },
36
+ "mobile": {
37
+ "preview_url": placeholder_img,
38
+ "content_type": "text/html",
39
+ "width": 360,
40
+ "height": 200
41
+ }
42
+ }
43
+ render(json: preview_response, status: :ok)
44
+ end
45
+
46
+ def create
47
+ render(json: {}, status: :ok)
48
+ end
49
+
50
+ def republish
51
+ render(json: {}, status: :accepted)
52
+ end
53
+
54
+ def errors
55
+ request_id = params[:request_id]
56
+ message = params[:message]
57
+
58
+ Rails.logger.info("[Marketing Activity App Error Feedback] Request id: #{request_id}, message: #{message}")
59
+
60
+ render(json: {}, status: :ok)
61
+ end
62
+ end
@@ -11,12 +11,6 @@ module ShopifyApp
11
11
 
12
12
  def create_home_index_view
13
13
  copy_file 'index.html.erb', 'app/views/home/index.html.erb'
14
- if embedded_app?
15
- prepend_to_file(
16
- 'app/views/home/index.html.erb',
17
- File.read(File.expand_path(find_in_source_paths('shopify_app_ready_script.html.erb')))
18
- )
19
- end
20
14
  end
21
15
 
22
16
  def add_home_index_route
@@ -2,7 +2,7 @@
2
2
 
3
3
  <ul>
4
4
  <% @products.each do |product| %>
5
- <li><%= link_to product.title, "https://#{@shop_session.domain}/admin/products/#{product.id}", target: "_top" %></li>
5
+ <li><%= link_to product.title, "https://#{@current_shopify_session.domain}/admin/products/#{product.id}", target: "_top" %></li>
6
6
  <% end %>
7
7
  </ul>
8
8
 
@@ -7,20 +7,14 @@ module ShopifyApp
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
 
9
9
  class_option :application_name, type: :array, default: ['My', 'Shopify', 'App']
10
- class_option :api_key, type: :string, default: '<api_key>'
11
- class_option :secret, type: :string, default: '<secret>'
12
- class_option :old_secret, type: :string, default: '<old_secret>'
13
10
  class_option :scope, type: :array, default: ['read_products']
14
11
  class_option :embedded, type: :string, default: 'true'
15
- class_option :api_version, type: :string, default: ShopifyAPI::ApiVersion.latest_stable_version.to_s
12
+ class_option :api_version, type: :string, default: nil
16
13
 
17
14
  def create_shopify_app_initializer
18
15
  @application_name = format_array_argument(options['application_name'])
19
- @api_key = options['api_key']
20
- @secret = options['secret']
21
- @old_secret = options['old_secret']
22
16
  @scope = format_array_argument(options['scope'])
23
- @api_version = options['api_version']
17
+ @api_version = options['api_version'] || ShopifyAPI::Meta.admin_versions.find(&:latest_supported).handle
24
18
 
25
19
  template 'shopify_app.rb', 'config/initializers/shopify_app.rb'
26
20
  end
@@ -42,16 +36,38 @@ module ShopifyApp
42
36
  end
43
37
 
44
38
  def create_embedded_app_layout
45
- if embedded_app?
46
- copy_file 'embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb'
47
- copy_file '_flash_messages.html.erb', 'app/views/layouts/_flash_messages.html.erb'
39
+ return unless embedded_app?
40
+
41
+ copy_file 'embedded_app.html.erb', 'app/views/layouts/embedded_app.html.erb'
42
+ copy_file '_flash_messages.html.erb', 'app/views/layouts/_flash_messages.html.erb'
43
+
44
+ if ShopifyApp.use_webpacker?
45
+ copy_file('shopify_app.js', 'app/javascript/shopify_app/shopify_app.js')
46
+ copy_file('flash_messages.js', 'app/javascript/shopify_app/flash_messages.js')
47
+ copy_file('shopify_app_index.js', 'app/javascript/shopify_app/index.js')
48
+ append_to_file('app/javascript/packs/application.js', 'require("shopify_app")')
49
+ else
50
+ copy_file('shopify_app.js', 'app/assets/javascripts/shopify_app.js')
51
+ copy_file('flash_messages.js', 'app/assets/javascripts/flash_messages.js')
48
52
  end
49
53
  end
50
54
 
55
+ def create_user_agent_initializer
56
+ template 'user_agent.rb', 'config/initializers/user_agent.rb'
57
+ end
58
+
51
59
  def mount_engine
52
60
  route "mount ShopifyApp::Engine, at: '/'"
53
61
  end
54
62
 
63
+ def insert_hosts_into_development_config
64
+ inject_into_file(
65
+ 'config/environments/development.rb',
66
+ " config.hosts = (config.hosts rescue []) << /\\h+.ngrok.io/\n",
67
+ after: "Rails.application.configure do\n"
68
+ )
69
+ end
70
+
55
71
  private
56
72
 
57
73
  def embedded_app?
@@ -1,19 +1,3 @@
1
1
  <% content_for :javascript do %>
2
- <script type="text/javascript">
3
- var eventName = typeof(Turbolinks) !== 'undefined' ? 'turbolinks:load' : 'DOMContentLoaded';
4
-
5
- if (!document.documentElement.hasAttribute("data-turbolinks-preview")) {
6
- document.addEventListener(eventName, function flash() {
7
- <% if flash[:notice] %>
8
- ShopifyApp.flashNotice(<%== flash[:notice].to_json %>);
9
- <% end %>
10
-
11
- <% if flash[:error] %>
12
- ShopifyApp.flashError(<%== flash[:error].to_json %>);
13
- <% end %>
14
-
15
- document.removeEventListener(eventName, flash)
16
- });
17
- }
18
- </script>
2
+ <%= content_tag(:div, nil, id: 'shopify-app-flash', data: { flash: { notice: flash[:notice], error: flash[:error] } }) %>
19
3
  <% end %>
@@ -5,7 +5,11 @@
5
5
  <% application_name = ShopifyApp.configuration.application_name %>
6
6
  <title><%= application_name %></title>
7
7
  <%= stylesheet_link_tag 'application' %>
8
- <%= javascript_include_tag 'application', "data-turbolinks-track" => true %>
8
+ <% if ShopifyApp.use_webpacker? %>
9
+ <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
10
+ <% else %>
11
+ <%= javascript_include_tag 'application', "data-turbolinks-track" => true %>
12
+ <% end %>
9
13
  <%= csrf_meta_tags %>
10
14
  </head>
11
15
 
@@ -20,16 +24,13 @@
20
24
 
21
25
  <%= render 'layouts/flash_messages' %>
22
26
 
23
- <script src="https://cdn.shopify.com/s/assets/external/app.js?<%= Time.now.strftime('%Y%m%d%H') %>"></script>
27
+ <script src="https://unpkg.com/@shopify/app-bridge"></script>
24
28
 
25
- <script type="text/javascript">
26
- ShopifyApp.init({
27
- apiKey: "<%= ShopifyApp.configuration.api_key %>",
28
- shopOrigin: "<%= "https://#{ @shop_session.domain }" if @shop_session %>",
29
- debug: <%= Rails.env.development? ? 'true' : 'false' %>,
30
- forceRedirect: true
31
- });
32
- </script>
29
+ <%= content_tag(:div, nil, id: 'shopify-app-init', data: {
30
+ api_key: ShopifyApp.configuration.api_key,
31
+ shop_origin: (@current_shopify_session.domain if @current_shopify_session),
32
+ debug: Rails.env.development?
33
+ } ) %>
33
34
 
34
35
  <% if content_for?(:javascript) %>
35
36
  <div id="ContentForJavascript" data-turbolinks-temporary>
@@ -0,0 +1,26 @@
1
+ var eventName = typeof(Turbolinks) !== 'undefined' ? 'turbolinks:load' : 'DOMContentLoaded';
2
+
3
+ if (!document.documentElement.hasAttribute("data-turbolinks-preview")) {
4
+ document.addEventListener(eventName, function flash() {
5
+ var flashData = JSON.parse(document.getElementById('shopify-app-flash').dataset.flash);
6
+
7
+ var Toast = window['app-bridge'].actions.Toast;
8
+
9
+ if (flashData.notice) {
10
+ Toast.create(app, {
11
+ message: flashData.notice,
12
+ duration: 5000,
13
+ }).dispatch(Toast.Action.SHOW);
14
+ }
15
+
16
+ if (flashData.error) {
17
+ Toast.create(app, {
18
+ message: flashData.error,
19
+ duration: 5000,
20
+ isError: true,
21
+ }).dispatch(Toast.Action.SHOW);
22
+ }
23
+
24
+ document.removeEventListener(eventName, flash)
25
+ });
26
+ }
@@ -0,0 +1,15 @@
1
+ document.addEventListener('DOMContentLoaded', () => {
2
+ var data = document.getElementById('shopify-app-init').dataset;
3
+ var AppBridge = window['app-bridge'];
4
+ var createApp = AppBridge.default;
5
+ window.app = createApp({
6
+ apiKey: data.apiKey,
7
+ shopOrigin: data.shopOrigin,
8
+ });
9
+
10
+ var actions = AppBridge.actions;
11
+ var TitleBar = actions.TitleBar;
12
+ TitleBar.create(app, {
13
+ title: data.page,
14
+ });
15
+ });
@@ -1,12 +1,15 @@
1
1
  ShopifyApp.configure do |config|
2
2
  config.application_name = "<%= @application_name %>"
3
- config.api_key = "<%= @api_key %>"
4
- config.secret = "<%= @secret %>"
3
+ config.api_key = ENV['SHOPIFY_API_KEY']
4
+ config.secret = ENV['SHOPIFY_API_SECRET']
5
5
  config.old_secret = "<%= @old_secret %>"
6
6
  config.scope = "<%= @scope %>" # Consult this page for more scope options:
7
7
  # https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes
8
8
  config.embedded_app = <%= embedded_app? %>
9
9
  config.after_authenticate_job = false
10
10
  config.api_version = "<%= @api_version %>"
11
- config.session_repository = ShopifyApp::InMemorySessionStore
11
+ config.shop_session_repository = 'ShopifyApp::InMemoryShopSessionStore'
12
12
  end
13
+
14
+ # ShopifyApp::Utils.fetch_known_api_versions # Uncomment to fetch known api versions from shopify servers on boot
15
+ # 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
@@ -0,0 +1,2 @@
1
+ require('./shopify_app')
2
+ require('./flash_messages')
@@ -16,4 +16,5 @@ provider :shopify,
16
16
 
17
17
  strategy.options[:client_options][:site] = shop
18
18
  strategy.options[:old_client_secret] = ShopifyApp.configuration.old_secret
19
+ strategy.options[:per_user_permissions] = strategy.session[:user_tokens]
19
20
  }
@@ -0,0 +1,5 @@
1
+ module ShopifyAPI
2
+ class Base < ActiveResource::Base
3
+ self.headers['User-Agent'] << " | ShopifyApp/#{ShopifyApp::VERSION}"
4
+ end
5
+ end
@@ -16,7 +16,7 @@ module ShopifyApp
16
16
  end
17
17
 
18
18
  def update_shopify_app_initializer
19
- gsub_file 'config/initializers/shopify_app.rb', 'ShopifyApp::InMemorySessionStore', 'Shop'
19
+ gsub_file 'config/initializers/shopify_app.rb', 'ShopifyApp::InMemoryShopSessionStore', 'Shop'
20
20
  end
21
21
 
22
22
  def create_shop_fixtures
@@ -1,5 +1,5 @@
1
1
  class Shop < ActiveRecord::Base
2
- include ShopifyApp::SessionStorage
2
+ include ShopifyApp::ShopSessionStorage
3
3
 
4
4
  def api_version
5
5
  ShopifyApp.configuration.api_version