shopify-sinatra-app 0.7.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 824f5c84a183bf093bf35cb931166ed811fafb4dcdb32664a9c3027a56acf38f
4
- data.tar.gz: 4369c1e33e0032792d4016f772bd041f3eb85aea722e015a9d7e1aed48e29f78
3
+ metadata.gz: 4dc86b5d946b17ee4bde67fbbc9c6ce4bdae741bfd10b34eb5b9eef269d8d30a
4
+ data.tar.gz: 3512d0ee6d5722ff8277256e5333e2ca779cd7381c0807add32e2787bfe3834d
5
5
  SHA512:
6
- metadata.gz: e64a1b720743bde0a66a79c39d5574d62f9867da1c7bb479a96253051197efb6e21f0a9366c59d1d98d503478b50a69c3707ba4300fefda601e26a78f7b5f042
7
- data.tar.gz: 7ff7babe886332b170e4ae052669acba61a922ee2b814a77b0d52d0c72ce5920ad7171e80956dcdac81358e4489acf17002448f6f784f2dacf9d57744b2c85a4
6
+ metadata.gz: 3cef0cd037591e3d7d19d13e65732b03587e1761dbe2dab73e31c95477d327332644a71aab4f898d7f3fc3cf45c2e3ca9ee7b8ec352862499b100f636395d69c
7
+ data.tar.gz: cbeeef8e569450e84ed861d8bd8ef53b0d1770b7d45256a5e4f73eb58de38ac225f2c07a7fd70360fc75d41fa3dc1adf6d9a4cc16ffeb3c3e534af3c188d03f1
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.5.3
4
+ - 2.6.3
5
5
 
6
6
  gemfile: example/Gemfile
7
7
 
data/CHANGELOG CHANGED
@@ -1,3 +1,30 @@
1
+ 0.12.0
2
+ ------
3
+ * Update to use the Shopify AppBridge instead of the ESDK
4
+ * This change is mostly to generated files so you'll need to apply those updates
5
+ to your own versions.
6
+ * shop_origin no longer includes protocol
7
+ * return_to re-worked to function with the AppBridge
8
+
9
+ 0.11.0
10
+ ------
11
+ * remove rack-flash3 use sinatra-flash instead
12
+ * remove a duplicate config of sessions that was breaking the same_site fix
13
+ * remove a runtime dependency that didn't end up being used for the same_site fix but was added anyways
14
+ * update ruby and rake versions
15
+
16
+ 0.10.0
17
+ ------
18
+ * Add the api_version to settings and update to 2019-07
19
+
20
+ 0.9.0
21
+ -----
22
+ * set secure and and same_site options on the session cookie. Fixes auth with the upcoming chrome 80 release
23
+
24
+ 0.8.0
25
+ -----
26
+ * Shopify updated the way sessions are created: https://github.com/Shopify/shopify_api/blob/master/README.md#-breaking-change-notice-for-version-700-, updating code to reflect these changes.
27
+
1
28
  0.7.0
2
29
  -----
3
30
  * make base_url private (users can add back in their app easily if needed)
data/README.md CHANGED
@@ -128,7 +128,7 @@ note - a flash must be followed by a redirect or it won't work!
128
128
 
129
129
  Developing
130
130
  ----------
131
- The embedded app sdk won't load non https content so you'll need to use a forwarding service like [ngrok](https://ngrok.com/) or [forwardhq](https://forwardhq.com/). Set your application url in the [Shopify Partner area](https://app.shopify.com/services/partners/api_clients) to your forwarded url. However The redirect_uri should still be `http://localhost:4567/auth/shopify/callback` which will allow you to install your app on a live shop while running it locally.
131
+ The embedded app sdk won't load non https content so you'll need to use a forwarding service like [ngrok](https://ngrok.com/) or [forwardhq](https://forwardhq.com/). Set your application url in the [Shopify Partner area](https://app.shopify.com/services/partners/api_clients) to your forwarded url and set the redirect_uri to your forwarded url + `/auth/shopify/callback` which will allow you to install your app on a live shop while running it locally.
132
132
 
133
133
  To run the app locally we use `foreman` which comes with the [Heroku Toolbelt](https://devcenter.heroku.com/articles/quickstart). Foreman handles running our application and setting our credentials as environment variables. To run the application type:
134
134
 
data/example/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source 'https://rubygems.org'
2
- ruby '2.5.3'
2
+ ruby '2.6.3'
3
3
 
4
4
  gem 'shopify-sinatra-app', path: '../'
5
5
  gem 'sinatra-activerecord'
6
- gem 'rack-flash3', require: 'rack-flash'
6
+ gem 'sinatra-flash'
7
7
 
8
8
  group :production do
9
9
  gem 'pg'
@@ -15,7 +15,7 @@ group :development, :test do
15
15
  end
16
16
 
17
17
  group :development do
18
- gem 'rake'
18
+ gem 'rake', '>= 12.3.3'
19
19
  gem 'foreman'
20
20
  gem 'dotenv'
21
21
  end
data/example/db/schema.rb CHANGED
@@ -2,11 +2,11 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # Note that this schema.rb definition is the authoritative source for your
6
- # database schema. If you need to create the application database on another
7
- # system, you should be using db:schema:load, not running all the migrations
8
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
- # you'll amass, the slower it'll run and the greater likelihood for issues).
5
+ # This file is the source Rails uses to define your schema when running `rails
6
+ # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
data/example/src/app.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'sinatra/shopify-sinatra-app'
2
+ require 'sinatra/flash'
2
3
 
3
4
  class SinatraApp < Sinatra::Base
4
5
  register Sinatra::Shopify
6
+ register Sinatra::Flash
5
7
 
6
8
  # set the scope that your app needs, read more here:
7
9
  # http://docs.shopify.com/api/tutorials/oauth
@@ -23,8 +23,9 @@ class AppTest < Minitest::Test
23
23
 
24
24
  def test_root_with_session
25
25
  set_session
26
- fake 'https://testshop.myshopify.com/admin/shop.json', body: {myshopify_domain: @shop_name}.to_json
27
- fake 'https://testshop.myshopify.com/admin/products.json?limit=10', body: '{}'
26
+ api_url = "https://testshop.myshopify.com/admin/api/#{app.settings.api_version}"
27
+ fake "#{api_url}/shop.json", body: {myshopify_domain: @shop_name}.to_json
28
+ fake "#{api_url}/products.json?limit=10", body: '{}'
28
29
  get '/'
29
30
  assert last_response.ok?
30
31
  end
@@ -1,11 +1,25 @@
1
1
  <script type="text/javascript">
2
- ShopifyApp.ready(function(){
3
- <% if flash[:notice] %>
4
- ShopifyApp.flashNotice("<%= flash[:notice] %>");
5
- <% end %>
6
-
7
- <% if flash[:error] %>
8
- ShopifyApp.flashError("<%= flash[:error] %>");
9
- <% end %>
10
- });
2
+ var AppBridge = window['app-bridge'];
3
+
4
+ var actions = AppBridge.actions;
5
+ var Toast = actions.Toast;
6
+
7
+ <% if flash[:notice] %>
8
+ var notice = Toast.create(app, {
9
+ message: "<%= flash[:notice] %>",
10
+ duration: 5000
11
+ });
12
+
13
+ notice.dispatch(Toast.Action.SHOW);
14
+ <% end %>
15
+
16
+ <% if flash[:error] %>
17
+ var notice = Toast.create(app, {
18
+ message: "<%= flash[:error] %>",
19
+ duration: 5000,
20
+ isError: true,
21
+ });
22
+
23
+ notice.dispatch(Toast.Action.SHOW);
24
+ <% end %>
11
25
  </script>
@@ -1,7 +1,10 @@
1
1
  <script type="text/javascript">
2
- ShopifyApp.ready(function(){
3
- ShopifyApp.Bar.initialize({
4
- icon: '<%= "#{base_url}/icon.png" %>'
5
- });
2
+ var AppBridge = window['app-bridge'];
3
+
4
+ var actions = AppBridge.actions;
5
+ var TitleBar = actions.TitleBar;
6
+
7
+ var titleBar = TitleBar.create(app, {
8
+ icon: '<%= "#{base_url}/icon.png" %>'
6
9
  });
7
10
  </script>
@@ -1,12 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
- <script src="https://cdn.shopify.com/s/assets/external/app.js"></script>
4
+ <script src="https://unpkg.com/@shopify/app-bridge"></script>
5
5
  <script type="text/javascript">
6
- ShopifyApp.init({
6
+ var AppBridge = window['app-bridge'];
7
+ var createApp = AppBridge.default;
8
+
9
+ var app = createApp({
7
10
  apiKey: "<%= SinatraApp.settings.api_key %>",
8
11
  shopOrigin: "<%= shop_origin %>",
9
- debug: true
10
12
  });
11
13
  </script>
12
14
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous">
@@ -1,7 +1,6 @@
1
1
  require 'sinatra/base'
2
2
  require 'sinatra/activerecord'
3
3
 
4
- require 'rack-flash'
5
4
  require 'attr_encrypted'
6
5
  require 'active_support/all'
7
6
 
@@ -21,9 +20,9 @@ module Sinatra
21
20
  session.clear
22
21
  end
23
22
 
24
- # for the esdk initializer
23
+ # for the app bridge initializer
25
24
  def shop_origin
26
- "https://#{session[:shopify][:shop]}"
25
+ "#{session[:shopify][:shop]}"
27
26
  end
28
27
 
29
28
  def shopify_session(&blk)
@@ -75,7 +74,7 @@ module Sinatra
75
74
  def authenticate(return_to = '/', return_params = nil)
76
75
  if shop_name = sanitized_shop_name
77
76
  session[:return_params] = return_params if return_params
78
- redirect_url = "/auth/shopify?shop=#{shop_name}&return_to=#{base_url}#{return_to}"
77
+ redirect_url = "#{base_url}/auth/shopify"
79
78
  redirect_javascript redirect_url
80
79
  else
81
80
  redirect '/install'
@@ -83,7 +82,7 @@ module Sinatra
83
82
  end
84
83
 
85
84
  def activate_shopify_api(shop_name, token)
86
- api_session = ShopifyAPI::Session.new(shop_name, token)
85
+ api_session = ShopifyAPI::Session.new(domain: shop_name, token: token, api_version: settings.api_version)
87
86
  ShopifyAPI::Base.activate_session(api_session)
88
87
  end
89
88
 
@@ -102,19 +101,37 @@ module Sinatra
102
101
  <meta charset="utf-8" />
103
102
  <base target="_top">
104
103
  <title>Redirecting…</title>
105
-
104
+ <script src="https://unpkg.com/@shopify/app-bridge"></script>
106
105
  <script type='text/javascript'>
106
+ var AppBridge = window['app-bridge'];
107
+ var createApp = AppBridge.createApp;
108
+ var actions = AppBridge.actions;
109
+ var Redirect = actions.Redirect;
110
+
111
+ var apiKey = '#{settings.api_key}';
112
+ var redirectUri = '#{url}';
113
+ var shopOrigin = '#{sanitized_shop_name}';
114
+
115
+ var permissionUrl = 'https://'+
116
+ shopOrigin+
117
+ '/admin'+
118
+ '/oauth/authorize?client_id='+
119
+ apiKey+
120
+ '&scope=#{settings.scope}&redirect_uri='+
121
+ redirectUri;
122
+
107
123
  // If the current window is the 'parent', change the URL by setting location.href
108
124
  if (window.top == window.self) {
109
- window.top.location.href = #{url.to_json};
125
+ window.location.assign(permissionUrl);
110
126
 
111
- // If the current window is the 'child', change the parent's URL with postMessage
127
+ // If the current window is the 'child', change the parent's URL with Shopify App Bridge's Redirect action
112
128
  } else {
113
- message = JSON.stringify({
114
- message: 'Shopify.API.remoteRedirect',
115
- data: { location: window.location.origin + #{url.to_json} }
129
+ var app = createApp({
130
+ apiKey: apiKey,
131
+ shopOrigin: shopOrigin
116
132
  });
117
- window.parent.postMessage(message, 'https://#{sanitized_shop_name}');
133
+
134
+ Redirect.create(app).dispatch(Redirect.Action.REMOTE, permissionUrl);
118
135
  }
119
136
  </script>
120
137
  </head>
@@ -157,6 +174,7 @@ module Sinatra
157
174
  def self.registered(app)
158
175
  app.helpers Shopify::Methods
159
176
  app.register Sinatra::ActiveRecordExtension
177
+ app.enable :inline_templates
160
178
 
161
179
  app.set :database_file, File.expand_path('config/database.yml')
162
180
  app.set :views, File.expand_path('views')
@@ -164,19 +182,18 @@ module Sinatra
164
182
  app.set :erb, layout: :'layouts/application'
165
183
  app.set :protection, except: :frame_options
166
184
 
167
- app.enable :sessions
168
- app.enable :inline_templates
169
-
185
+ app.set :api_version, '2019-07'
170
186
  app.set :scope, 'read_products, read_orders'
171
187
 
172
188
  app.set :api_key, ENV['SHOPIFY_API_KEY']
173
189
  app.set :shared_secret, ENV['SHOPIFY_SHARED_SECRET']
174
190
  app.set :secret, ENV['SECRET']
175
191
 
176
- app.use Rack::Flash, sweep: true
177
192
  app.use Rack::MethodOverride
178
193
  app.use Rack::Session::Cookie, key: 'rack.session',
179
194
  path: '/',
195
+ secure: true,
196
+ same_site: 'None',
180
197
  secret: app.settings.secret,
181
198
  expire_after: 60 * 30 # half an hour in seconds
182
199
 
@@ -231,10 +248,10 @@ module Sinatra
231
248
 
232
249
  after_shopify_auth()
233
250
 
234
- return_to = env['omniauth.params']['return_to']
235
251
  return_params = session[:return_params]
236
252
  session.delete(:return_params)
237
253
 
254
+ return_to = '/'
238
255
  return_to += "?#{return_params.to_query}" if return_params.present?
239
256
 
240
257
  redirect return_to
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'shopify-sinatra-app'
3
- s.version = '0.7.0'
3
+ s.version = '0.12.0'
4
4
 
5
5
  s.summary = 'A classy shopify app'
6
6
  s.description = 'A Sinatra extension for building Shopify Apps. Akin to the shopify_app gem but for Sinatra'
@@ -15,14 +15,14 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_runtime_dependency 'sinatra', '~> 2.0.2'
17
17
  s.add_runtime_dependency 'sinatra-activerecord', '~> 2.0.9'
18
- s.add_runtime_dependency 'rack-flash3', '~> 1.0.5'
19
18
  s.add_runtime_dependency 'activesupport'
20
19
  s.add_runtime_dependency 'attr_encrypted', '~> 3.1.0'
21
20
 
22
- s.add_runtime_dependency 'shopify_api'
23
- s.add_runtime_dependency 'omniauth-shopify-oauth2'
21
+ s.add_runtime_dependency 'shopify_api', '>= 7.0.1', '< 9.3.0'
22
+ s.add_runtime_dependency 'omniauth-shopify-oauth2', '>= 2.3.2'
23
+ s.add_runtime_dependency 'omniauth', '1.9.1'
24
24
 
25
- s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'rake', '>= 12.3.3'
26
26
  s.add_development_dependency 'sqlite3'
27
27
  s.add_development_dependency 'minitest'
28
28
  s.add_development_dependency 'rack-test'
data/test.sh CHANGED
@@ -6,5 +6,8 @@ bundle install
6
6
  bundle exec rake db:migrate
7
7
  bundle exec rake test:prepare
8
8
  bundle exec rake test
9
+ EXIT_CODE=$?
9
10
 
10
11
  cd ../../..
12
+
13
+ exit $EXIT_CODE
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-sinatra-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Hughes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-09 00:00:00.000000000 Z
11
+ date: 2021-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.0.9
41
- - !ruby/object:Gem::Dependency
42
- name: rack-flash3
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 1.0.5
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 1.0.5
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: activesupport
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,42 +72,62 @@ dependencies:
86
72
  requirements:
87
73
  - - ">="
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: 7.0.1
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: 9.3.0
90
79
  type: :runtime
91
80
  prerelease: false
92
81
  version_requirements: !ruby/object:Gem::Requirement
93
82
  requirements:
94
83
  - - ">="
95
84
  - !ruby/object:Gem::Version
96
- version: '0'
85
+ version: 7.0.1
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: 9.3.0
97
89
  - !ruby/object:Gem::Dependency
98
90
  name: omniauth-shopify-oauth2
99
91
  requirement: !ruby/object:Gem::Requirement
100
92
  requirements:
101
93
  - - ">="
102
94
  - !ruby/object:Gem::Version
103
- version: '0'
95
+ version: 2.3.2
104
96
  type: :runtime
105
97
  prerelease: false
106
98
  version_requirements: !ruby/object:Gem::Requirement
107
99
  requirements:
108
100
  - - ">="
109
101
  - !ruby/object:Gem::Version
110
- version: '0'
102
+ version: 2.3.2
103
+ - !ruby/object:Gem::Dependency
104
+ name: omniauth
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.9.1
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '='
115
+ - !ruby/object:Gem::Version
116
+ version: 1.9.1
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: rake
113
119
  requirement: !ruby/object:Gem::Requirement
114
120
  requirements:
115
121
  - - ">="
116
122
  - !ruby/object:Gem::Version
117
- version: '0'
123
+ version: 12.3.3
118
124
  type: :development
119
125
  prerelease: false
120
126
  version_requirements: !ruby/object:Gem::Requirement
121
127
  requirements:
122
128
  - - ">="
123
129
  - !ruby/object:Gem::Version
124
- version: '0'
130
+ version: 12.3.3
125
131
  - !ruby/object:Gem::Dependency
126
132
  name: sqlite3
127
133
  requirement: !ruby/object:Gem::Requirement
@@ -250,8 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
256
  - !ruby/object:Gem::Version
251
257
  version: '0'
252
258
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.7.6
259
+ rubygems_version: 3.0.3
255
260
  signing_key:
256
261
  specification_version: 4
257
262
  summary: A classy shopify app