shopify-sinatra-app 0.7.0 → 0.12.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 +1 -1
- data/CHANGELOG +27 -0
- data/README.md +1 -1
- data/example/Gemfile +3 -3
- data/example/db/schema.rb +5 -5
- data/example/src/app.rb +2 -0
- data/example/test/app_test.rb +3 -2
- data/example/views/_flash_messages.erb +23 -9
- data/example/views/_top_bar.erb +7 -4
- data/example/views/layouts/application.erb +5 -3
- data/lib/sinatra/shopify-sinatra-app.rb +34 -17
- data/shopify-sinatra-app.gemspec +5 -5
- data/test.sh +3 -0
- metadata +29 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dc86b5d946b17ee4bde67fbbc9c6ce4bdae741bfd10b34eb5b9eef269d8d30a
|
4
|
+
data.tar.gz: 3512d0ee6d5722ff8277256e5333e2ca779cd7381c0807add32e2787bfe3834d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cef0cd037591e3d7d19d13e65732b03587e1761dbe2dab73e31c95477d327332644a71aab4f898d7f3fc3cf45c2e3ca9ee7b8ec352862499b100f636395d69c
|
7
|
+
data.tar.gz: cbeeef8e569450e84ed861d8bd8ef53b0d1770b7d45256a5e4f73eb58de38ac225f2c07a7fd70360fc75d41fa3dc1adf6d9a4cc16ffeb3c3e534af3c188d03f1
|
data/.travis.yml
CHANGED
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
|
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.
|
2
|
+
ruby '2.6.3'
|
3
3
|
|
4
4
|
gem 'shopify-sinatra-app', path: '../'
|
5
5
|
gem 'sinatra-activerecord'
|
6
|
-
gem '
|
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
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# from scratch.
|
9
|
-
#
|
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
data/example/test/app_test.rb
CHANGED
@@ -23,8 +23,9 @@ class AppTest < Minitest::Test
|
|
23
23
|
|
24
24
|
def test_root_with_session
|
25
25
|
set_session
|
26
|
-
|
27
|
-
fake
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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>
|
data/example/views/_top_bar.erb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
<script type="text/javascript">
|
2
|
-
|
3
|
-
|
4
|
-
|
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://
|
4
|
+
<script src="https://unpkg.com/@shopify/app-bridge"></script>
|
5
5
|
<script type="text/javascript">
|
6
|
-
|
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
|
23
|
+
# for the app bridge initializer
|
25
24
|
def shop_origin
|
26
|
-
"
|
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
|
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.
|
125
|
+
window.location.assign(permissionUrl);
|
110
126
|
|
111
|
-
// If the current window is the 'child', change the parent's URL with
|
127
|
+
// If the current window is the 'child', change the parent's URL with Shopify App Bridge's Redirect action
|
112
128
|
} else {
|
113
|
-
|
114
|
-
|
115
|
-
|
129
|
+
var app = createApp({
|
130
|
+
apiKey: apiKey,
|
131
|
+
shopOrigin: shopOrigin
|
116
132
|
});
|
117
|
-
|
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.
|
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
|
data/shopify-sinatra-app.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'shopify-sinatra-app'
|
3
|
-
s.version = '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
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.
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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
|
-
|
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
|