shopify_app 13.5.0 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56264e18e59398228e56a0a26dc752989b527d7ce935f0375a872fd89c88b4b9
4
- data.tar.gz: a9c8ff9c9828278f7fff6013a09ec6bf3ea8f4542c700c5fe57bf16e33ed1f68
3
+ metadata.gz: eb6669e0b864299f689103042e4c59cb4ddc7e53481b559275b64accc6e390b9
4
+ data.tar.gz: 9e3481e24e1e44ef799ac573025e532814acff362d0c9ea3f44b3e4000a68037
5
5
  SHA512:
6
- metadata.gz: cbd3b18c84d6e69c01516f7b74927ba3d236cd17ad2d88a68cc1c93dfd1f8d20aa614507adf031625e088612001d71dbbb116bb267865b1924674d2a6f937e6f
7
- data.tar.gz: 82b859132159cf85fb3af1607296b20aa040ca30515a6225fa3887ee938dd721f11be2939ea2d9179a448e80ae3d2e7316749bd237ee8344fa0cf1fe862d6a7b
6
+ metadata.gz: 13f7898748c764d9093d8479ce61a3b1f2d5e9d3ebf7b04a952af7587ef243f9c785c3573c45a915a909a6b9d6cb15ea0d63ab34ed424c45401419f331aa141d
7
+ data.tar.gz: ba8649d90387c3c5c8050ad69923a9e56509955016c5d8bfd955e8870bf0d55f6ed3956dc1643e2f11aa655730e82504e7c28a472a7fcc542a4977b76169ebf4
@@ -13,7 +13,6 @@ cache:
13
13
  yarn: true
14
14
 
15
15
  rvm:
16
- - 2.4
17
16
  - 2.5
18
17
  - 2.6
19
18
  - 2.7
@@ -1,3 +1,9 @@
1
+ 14.0.0
2
+ ------
3
+ * Ruby 2.4 is no longer supported by this gem
4
+ * Bump gemspec ruby dependency to 2.5
5
+ * (Beta) Add `--with-session-token` flag to the Shopify App generator to create an app that is compatible with App Bridge Authentication
6
+
1
7
  13.5.0
2
8
  ------
3
9
  * Add `signal_access_token_required` helper method for apps to indicate access token has expired and that a new one is required
data/README.md CHANGED
@@ -74,7 +74,7 @@ Generators
74
74
 
75
75
  ### Default Generator
76
76
 
77
- The default generator will run the `install`, `shop`, and `home_controller` generators. This is the recommended way to start a new app from scratch:
77
+ The default generator will run the `install`, `shop`, `authenticated_controller`, and `home_controller` generators. This is the recommended way to start a new app from scratch:
78
78
 
79
79
  ```sh
80
80
  $ rails generate shopify_app
@@ -123,6 +123,16 @@ $ rails generate shopify_app:home_controller
123
123
 
124
124
  This generator creates an example home controller and view which fetches and displays products using the Shopify API.
125
125
 
126
+ Options include:
127
+ * __[beta]__ `with-session-token`: This flag generates an unauthenticated home_controller and a protected sample products_controller. It also creates a home view that leverages a session token to fetch products from your products_controller. Use this flag if you plan to build a single-page application or to secure your app using JWT session tokens (e.g. `--with-session-token` or `--with-session-token true`).
128
+
129
+ ### Products Controller Generator
130
+
131
+ ```sh
132
+ $ rails generate shopify_app:products_controller
133
+ ```
134
+
135
+ This generator creates an example products API controller to fetch products using the Shopify API.
126
136
 
127
137
  ### App Proxy Controller Generator
128
138
 
@@ -7,7 +7,7 @@ module ShopifyApp
7
7
  class AuthenticatedControllerGenerator < Rails::Generators::Base
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
10
- def create_home_controller
10
+ def create_authenticated_controller
11
11
  template('authenticated_controller.rb', 'app/controllers/authenticated_controller.rb')
12
12
  end
13
13
  end
@@ -6,21 +6,39 @@ module ShopifyApp
6
6
  class HomeControllerGenerator < Rails::Generators::Base
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
 
9
+ class_option :with_session_token, type: :boolean, default: false
10
+
9
11
  def create_home_controller
10
- template('home_controller.rb', 'app/controllers/home_controller.rb')
12
+ @with_session_token = options['with_session_token']
13
+
14
+ template(home_controller_template, 'app/controllers/home_controller.rb')
15
+ end
16
+
17
+ def create_products_controller
18
+ generate("shopify_app:products_controller") if with_session_token?
11
19
  end
12
20
 
13
21
  def create_home_index_view
14
- copy_file('index.html.erb', 'app/views/home/index.html.erb')
22
+ template('index.html.erb', 'app/views/home/index.html.erb')
15
23
  end
16
24
 
17
25
  def add_home_index_route
18
26
  route("root :to => 'home#index'")
19
27
  end
20
28
 
29
+ private
30
+
21
31
  def embedded_app?
22
32
  ShopifyApp.configuration.embedded_app?
23
33
  end
34
+
35
+ def with_session_token?
36
+ @with_session_token
37
+ end
38
+
39
+ def home_controller_template
40
+ with_session_token? ? 'unauthenticated_home_controller.rb' : 'home_controller.rb'
41
+ end
24
42
  end
25
43
  end
26
44
  end
@@ -1,21 +1,71 @@
1
- <h2>Products</h2>
1
+ <!DOCTYPE html>
2
+ <html lang="<%= I18n.locale %>">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <link
7
+ rel="stylesheet"
8
+ href="https://unpkg.com/@shopify/polaris@4.25.0/styles.min.css"
9
+ />
10
+ <% if @with_session_token %> <script>
11
+ document.addEventListener("DOMContentLoaded", async function() {
12
+ var SessionToken = window["app-bridge"].actions.SessionToken
13
+ var app = window.app;
2
14
 
3
- <ul>
4
- <% @products.each do |product| %>
5
- <li><%= link_to product.title, "https://#{@current_shopify_session.domain}/admin/products/#{product.id}", target: "_top" %></li>
6
- <% end %>
7
- </ul>
15
+ app.dispatch(
16
+ SessionToken.request(),
17
+ );
8
18
 
9
- <hr>
19
+ // Save a session token for future requests
20
+ window.sessionToken = await new Promise((resolve) => {
21
+ app.subscribe(SessionToken.ActionType.RESPOND, (data) => {
22
+ resolve(data.sessionToken || "");
23
+ });
24
+ });
10
25
 
11
- <h2>Webhooks</h2>
26
+ var fetchProducts = function() {
27
+ var headers = new Headers({ "Authorization": "Bearer " + window.sessionToken });
28
+ return fetch("/products", { headers })
29
+ .then(response => response.json())
30
+ .then(data => {
31
+ var products = data.products;
12
32
 
13
- <% if @webhooks.present? %>
14
- <ul>
15
- <% @webhooks.each do |webhook| %>
16
- <li><%= webhook.topic %> : <%= webhook.address %></li>
17
- <% end %>
18
- </ul>
19
- <% else %>
20
- <p>This app has not created any webhooks for this Shop. Add webhooks to your ShopifyApp initializer if you need webhooks</p>
21
- <% end %>
33
+ if (products === undefined || products.length == 0) {
34
+ document.getElementById("products").innerHTML = "<br>No products to display.";
35
+ } else {
36
+ var list = "";
37
+ products.forEach((product) => {
38
+ var link = `<a target="_top" href="https://<%%= @shop_origin %>/admin/products/${product.id}">`
39
+ list += "<li>" + link + product.title + "</a></li>";
40
+ });
41
+ document.getElementById("products").innerHTML = "<ul>" + list + "</ul>";
42
+ }
43
+ });
44
+ }();
45
+ });
46
+ </script>
47
+ <% end %> </head>
48
+ <body>
49
+ <h2>Products</h2>
50
+ <% if @with_session_token %> <div id="products"><br>Loading...</div><% else %>
51
+ <ul>
52
+ <%% @products.each do |product| %>
53
+ <li><%%= link_to product.title, "https://#{@current_shopify_session.domain}/admin/products/#{product.id}", target: "_top" %></li>
54
+ <%% end %>
55
+ </ul>
56
+
57
+ <hr>
58
+
59
+ <h2>Webhooks</h2>
60
+
61
+ <%% if @webhooks.present? %>
62
+ <ul>
63
+ <%% @webhooks.each do |webhook| %>
64
+ <li><%%= webhook.topic %> : <%%= webhook.address %></li>
65
+ <%% end %>
66
+ </ul>
67
+ <%% else %>
68
+ <p>This app has not created any webhooks for this Shop. Add webhooks to your ShopifyApp initializer if you need webhooks</p>
69
+ <%% end %><% end %>
70
+ </body>
71
+ </html>
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class HomeController < ApplicationController
4
+ include ShopifyApp::EmbeddedApp
5
+ include ShopifyApp::RequireKnownShop
6
+
7
+ def index
8
+ @shop_origin = current_shopify_domain
9
+ end
10
+ end
@@ -28,7 +28,7 @@
28
28
 
29
29
  <%= content_tag(:div, nil, id: 'shopify-app-init', data: {
30
30
  api_key: ShopifyApp.configuration.api_key,
31
- shop_origin: (@current_shopify_session.domain if @current_shopify_session),
31
+ shop_origin: @shop_origin || (@current_shopify_session.domain if @current_shopify_session),
32
32
  debug: Rails.env.development?
33
33
  } ) %>
34
34
 
@@ -9,6 +9,7 @@ ShopifyApp.configure do |config|
9
9
  config.after_authenticate_job = false
10
10
  config.api_version = "<%= @api_version %>"
11
11
  config.shop_session_repository = 'Shop'
12
+ config.allow_jwt_authentication = true
12
13
  end
13
14
 
14
15
  # ShopifyApp::Utils.fetch_known_api_versions # Uncomment to fetch known api versions from shopify servers on boot
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ module ShopifyApp
6
+ module Generators
7
+ class ProductsControllerGenerator < Rails::Generators::Base
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ def create_products_controller
11
+ template('products_controller.rb', 'app/controllers/products_controller.rb')
12
+ end
13
+
14
+ def add_products_route
15
+ route("get '/products', :to => 'products#index'")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ProductsController < AuthenticatedController
4
+ def index
5
+ @products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
6
+ render(json: { products: @products })
7
+ end
8
+ end
@@ -11,7 +11,7 @@ module ShopifyApp
11
11
  generate("shopify_app:install #{@opts.join(' ')}")
12
12
  generate("shopify_app:shop_model")
13
13
  generate("shopify_app:authenticated_controller")
14
- generate("shopify_app:home_controller")
14
+ generate("shopify_app:home_controller #{@opts.join(' ')}")
15
15
  end
16
16
  end
17
17
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ShopifyApp
3
- VERSION = '13.5.0'
3
+ VERSION = '14.0.0'
4
4
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopify_app",
3
- "version": "13.4.0",
3
+ "version": "13.6.0",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -2532,9 +2532,9 @@
2532
2532
  "dev": true
2533
2533
  },
2534
2534
  "elliptic": {
2535
- "version": "6.5.1",
2536
- "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.1.tgz",
2537
- "integrity": "sha512-xvJINNLbTeWQjrl6X+7eQCrIy/YPv5XCpKW6kB5mKvtnGILoLDcySuwomfdzt0BMdLNVnuRNTuzKNHj0bva1Cg==",
2535
+ "version": "6.5.3",
2536
+ "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz",
2537
+ "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==",
2538
2538
  "dev": true,
2539
2539
  "requires": {
2540
2540
  "bn.js": "^4.4.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shopify_app",
3
- "version": "13.5.0",
3
+ "version": "14.0.0",
4
4
  "repository": "git@github.com:Shopify/shopify_app.git",
5
5
  "author": "Shopify",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.author = "Shopify"
10
10
  s.summary = 'This gem is used to get quickly started with the Shopify API'
11
11
 
12
- s.required_ruby_version = ">= 2.4"
12
+ s.required_ruby_version = ">= 2.5"
13
13
 
14
14
  s.metadata['allowed_push_host'] = 'https://rubygems.org'
15
15
 
data/yarn.lock CHANGED
@@ -1293,9 +1293,9 @@ bluebird@^3.3.0, bluebird@^3.5.5:
1293
1293
  integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==
1294
1294
 
1295
1295
  bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
1296
- version "4.11.8"
1297
- resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
1298
- integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==
1296
+ version "4.11.9"
1297
+ resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828"
1298
+ integrity sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==
1299
1299
 
1300
1300
  body-parser@^1.16.1:
1301
1301
  version "1.19.0"
@@ -2039,9 +2039,9 @@ electron-to-chromium@^1.3.247:
2039
2039
  integrity sha512-wGt+OivF1C1MPwaSv3LJ96ebNbLAWlx3HndivDDWqwIVSQxmhL17Y/YmwUdEMtS/bPyommELt47Dct0/VZNQBQ==
2040
2040
 
2041
2041
  elliptic@^6.0.0:
2042
- version "6.5.1"
2043
- resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.1.tgz#c380f5f909bf1b9b4428d028cd18d3b0efd6b52b"
2044
- integrity sha512-xvJINNLbTeWQjrl6X+7eQCrIy/YPv5XCpKW6kB5mKvtnGILoLDcySuwomfdzt0BMdLNVnuRNTuzKNHj0bva1Cg==
2042
+ version "6.5.3"
2043
+ resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.3.tgz#cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6"
2044
+ integrity sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==
2045
2045
  dependencies:
2046
2046
  bn.js "^4.4.0"
2047
2047
  brorand "^1.0.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.5.0
4
+ version: 14.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
11
+ date: 2020-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: browser_sniffer
@@ -330,6 +330,7 @@ files:
330
330
  - lib/generators/shopify_app/home_controller/home_controller_generator.rb
331
331
  - lib/generators/shopify_app/home_controller/templates/home_controller.rb
332
332
  - lib/generators/shopify_app/home_controller/templates/index.html.erb
333
+ - lib/generators/shopify_app/home_controller/templates/unauthenticated_home_controller.rb
333
334
  - lib/generators/shopify_app/install/install_generator.rb
334
335
  - lib/generators/shopify_app/install/templates/_flash_messages.html.erb
335
336
  - lib/generators/shopify_app/install/templates/embedded_app.html.erb
@@ -341,6 +342,8 @@ files:
341
342
  - lib/generators/shopify_app/install/templates/shopify_app_index.js
342
343
  - lib/generators/shopify_app/install/templates/shopify_provider.rb
343
344
  - lib/generators/shopify_app/install/templates/user_agent.rb
345
+ - lib/generators/shopify_app/products_controller/products_controller_generator.rb
346
+ - lib/generators/shopify_app/products_controller/templates/products_controller.rb
344
347
  - lib/generators/shopify_app/rotate_shopify_token_job/rotate_shopify_token_job_generator.rb
345
348
  - lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token.rake
346
349
  - lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb
@@ -406,7 +409,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
406
409
  requirements:
407
410
  - - ">="
408
411
  - !ruby/object:Gem::Version
409
- version: '2.4'
412
+ version: '2.5'
410
413
  required_rubygems_version: !ruby/object:Gem::Requirement
411
414
  requirements:
412
415
  - - ">="