shopify_app 11.7.0 → 11.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +29 -19
- data/docs/Quickstart.md +44 -16
- data/docs/install-on-dev-shop.png +0 -0
- data/docs/test-your-app.png +0 -0
- data/lib/shopify_app/session/session_storage.rb +6 -17
- data/lib/shopify_app/session/storage_strategies/shop_storage_strategy.rb +5 -6
- data/lib/shopify_app/session/storage_strategies/user_storage_strategy.rb +5 -7
- data/lib/shopify_app/version.rb +1 -1
- data/package.json +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b458ca32eeb9b1c13643fbb77333b744b7c95b015fec2a485e5fa4d3a18410c4
|
4
|
+
data.tar.gz: 84c33e75b4862583968a4ee6abf13fc0f455ed3977db33e7e130420d14ebca6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fde0d0d3c6e77a05afbad57a7db60866f738d5520453394027ab2bda81b31fb615ce0db59f0147327dce90ed1e0b6b9093129b49778d4f65550abfca7ad2c8d
|
7
|
+
data.tar.gz: 475d5a91322c9f4e59a4b2977a781fc4f3c74db719142f9af06e6d51843fda44537993f1a4620e3db538760f16f7bf017eeab7126464826b1fe701bf8b222945
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
11.7.1
|
2
|
+
-----
|
3
|
+
* Fix to allow SessionStorage to be flexible on what model names that the are used for storing shop and user data
|
4
|
+
|
1
5
|
11.7.0
|
2
6
|
-----
|
3
7
|
* Move ExtensionVerificationController from engine to app controllers, as being in the engine makes ActionController::Base get loaded before app initiates [#855](https://github.com/Shopify/shopify_app/pull/855)
|
4
8
|
* Add back per-user token support (added in 11.5.0, reverted in 11.5.1)
|
9
|
+
* If you have an override on the `self.store(auth_session)` method on your `SessionRepository` model, the method signature must be changed as according to this [change](https://github.com/Shopify/shopify_app/pull/856/files#diff-deaed2b262ec885f4e36de05621e41eaR18)
|
5
10
|
|
6
11
|
11.6.0
|
7
12
|
-----
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Shopify Application Rails engine and generator
|
|
13
13
|
Table of Contents
|
14
14
|
-----------------
|
15
15
|
- [Introduction](#introduction)
|
16
|
-
- [
|
16
|
+
- [Become a Shopify App Developer](#become-a-shopify-app-developer)
|
17
17
|
- [Installation](#installation)
|
18
18
|
- [Generators](#generators)
|
19
19
|
- [Mounting the Engine](#mounting-the-engine)
|
@@ -31,25 +31,25 @@ Table of Contents
|
|
31
31
|
|
32
32
|
Introduction
|
33
33
|
-----------
|
34
|
-
This gem includes a Rails Engine and generators for writing Rails applications using the Shopify API. The Engine provides a SessionsController and all the required code for authenticating with a shop via Oauth (other authentication methods are not supported).
|
34
|
+
Get started with the [Shopify Admin API](https://help.shopify.com/en/api/getting-started) faster; This gem includes a Rails Engine and generators for writing Rails applications using the Shopify API. The Engine provides a SessionsController and all the required code for authenticating with a shop via Oauth (other authentication methods are not supported).
|
35
35
|
|
36
|
-
*Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete
|
36
|
+
*Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete your files.*
|
37
37
|
|
38
|
-
|
38
|
+
Learn how to create and deploy a new Shopify App to Heroku with our [quickstart guide](https://github.com/Shopify/shopify_app/blob/master/docs/Quickstart.md), or dive in in less than 5 minutes with this quickstart video:
|
39
39
|
|
40
40
|
[https://www.youtube.com/watch?v=yGxeoAHlQOg](https://www.youtube.com/watch?v=yGxeoAHlQOg)
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
Becoming a Shopify App Developer
|
42
|
+
Become a Shopify App Developer
|
45
43
|
--------------------------------
|
46
|
-
If you don't have a Shopify Partner account
|
44
|
+
To become a Shopify App Developer you'll need a [Shopify Partner account.](http://shopify.com/partners) If you don't have a Shopify Partner account, head to http://shopify.com/partners to create one before you start.
|
45
|
+
|
46
|
+
Once you have a Partner account, [create a new application in the Partner Dashboard](https://help.shopify.com/en/api/tools/partner-dashboard/your-apps) to get an API key and other API credentials.
|
47
47
|
|
48
|
-
|
48
|
+
To create an application for development set your new app's `App URL` to the URL provided by [your tunnel](#app-tunneling), ensuring that you use `https://`. If you are not planning to embed your app inside the Shopify admin or receive webhooks, set your redirect URL to `http://localhost:3000/` and the `Whitelisted redirection URL(s)` to contain `<App URL>/auth/shopify/callback`.
|
49
49
|
|
50
50
|
Installation
|
51
51
|
------------
|
52
|
-
To get started add shopify_app to your Gemfile and bundle install
|
52
|
+
To get started add `shopify_app` to your Gemfile and run `bundle install`:
|
53
53
|
|
54
54
|
``` sh
|
55
55
|
# Create a new rails app
|
@@ -61,7 +61,7 @@ $ echo "gem 'shopify_app'" >> Gemfile
|
|
61
61
|
$ bundle install
|
62
62
|
```
|
63
63
|
|
64
|
-
Now we are ready to run any of the shopify_app
|
64
|
+
Now we are ready to run any of the [generators](#generators) included with `shopify_app`. The following section explains the generators and what you can do with them.
|
65
65
|
|
66
66
|
|
67
67
|
#### Rails Compatibility
|
@@ -74,24 +74,24 @@ 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
|
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:
|
78
78
|
|
79
79
|
```sh
|
80
80
|
$ rails generate shopify_app
|
81
81
|
```
|
82
82
|
|
83
|
-
After running the generator, you will need to run `rails db:migrate` to add tables to your database. You can start your app with `bundle exec rails server` and install your app by visiting localhost.
|
83
|
+
After running the generator, you will need to run `rails db:migrate` to add new tables to your database. You can start your app with `bundle exec rails server` and install your app by visiting `http://localhost` in your web browser.
|
84
84
|
|
85
85
|
### API Keys
|
86
86
|
|
87
|
-
The default and install generators have been updated to source Shopify API key and secret from
|
87
|
+
The default and install generators have been updated to source Shopify API key and secret from an Environment (`.env`) variables file, which you will need to create with the following format:
|
88
88
|
|
89
89
|
```
|
90
90
|
SHOPIFY_API_KEY=your api key
|
91
91
|
SHOPIFY_API_SECRET=your api secret
|
92
92
|
```
|
93
93
|
|
94
|
-
These values can be found on the "App Setup" page in the [Shopify Partners Dashboard][dashboard].
|
94
|
+
These values can be found on the "App Setup" page in the [Shopify Partners Dashboard][dashboard]. If you are checking your code into a code repository, ensure your `.gitignore` prevents your `.env` file from being checked into any publicly accessible code.
|
95
95
|
|
96
96
|
### Install Generator
|
97
97
|
|
@@ -123,7 +123,7 @@ After running the `install` generator, you can start your app with `bundle exec
|
|
123
123
|
$ rails generate shopify_app:home_controller
|
124
124
|
```
|
125
125
|
|
126
|
-
This generator creates an example home controller and view which fetches and displays products using the
|
126
|
+
This generator creates an example home controller and view which fetches and displays products using the Shopify API
|
127
127
|
|
128
128
|
|
129
129
|
### App Proxy Controller Generator
|
@@ -213,7 +213,7 @@ Authentication
|
|
213
213
|
|
214
214
|
### ShopifyApp::SessionRepository
|
215
215
|
|
216
|
-
`ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are stored and retrieved for shops. The `SessionRepository` is configured in the `config/initializers/shopify_app.rb` file and can be set to any object that implements `self.store(auth_session)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id.
|
216
|
+
`ShopifyApp::SessionRepository` allows you as a developer to define how your sessions are stored and retrieved for shops. The `SessionRepository` is configured in the `config/initializers/shopify_app.rb` file and can be set to any object that implements `self.store(auth_session, *args)` which stores the session and returns a unique identifier and `self.retrieve(id)` which returns a `ShopifyAPI::Session` for the passed id. These methods are already implemented as part of the `ShopifyApp::SessionStorage` concern, but can be overridden for custom implementation.
|
217
217
|
|
218
218
|
If you only run the install generator then by default you will have an in memory store but it **won't work** on multi-server environments including Heroku. For multi-server environments, implement one of the following token-storage strategies.
|
219
219
|
|
@@ -233,6 +233,8 @@ This will generate a user model which will be the storage for the tokens necessa
|
|
233
233
|
|
234
234
|
The current Shopify user will be stored in the rails session at `session[:shopify_user]`
|
235
235
|
|
236
|
+
In this mode, The `self.store(auth_session, *args)` will be invoked with a Shopify User object hash, which is then used to store the token as part of a user record, rather than a store record.
|
237
|
+
|
236
238
|
This will change the type of token that Shopify returns and it will only be valid for a short time. Read more about `Online access` [here](https://help.shopify.com/api/getting-started/authentication/oauth). Note that this means you won't be able to use this token to respond to Webhooks.
|
237
239
|
|
238
240
|
#### Migrating from shop-based to user-based token strategy
|
@@ -406,9 +408,11 @@ strategy.options[:old_client_secret] = ShopifyApp.configuration.old_secret
|
|
406
408
|
App Tunneling
|
407
409
|
-------------
|
408
410
|
|
409
|
-
Your local app needs to be accessible from the public Internet in order to install it on a
|
411
|
+
Your local app needs to be accessible from the public Internet in order to install it on a Shopify store, to use the [App Proxy Controller](#app-proxy-controller-generator) or receive Webhooks.
|
412
|
+
|
413
|
+
Use a tunneling service like [ngrok](https://ngrok.com/), [Forward](https://forwardhq.com/), [Beeceptor](https://beeceptor.com/), [Mockbin](http://mockbin.org/), or [Hookbin](https://hookbin.com/) to make your development environment accessible to the internet.
|
410
414
|
|
411
|
-
For example with [ngrok](https://ngrok.com/), run this command to set up
|
415
|
+
For example with [ngrok](https://ngrok.com/), run this command to set up a tunnel proxy to Rails' default port:
|
412
416
|
|
413
417
|
```sh
|
414
418
|
ngrok http 3000
|
@@ -455,6 +459,12 @@ Questions or problems?
|
|
455
459
|
- [Ask questions!](https://ecommerce.shopify.com/c/shopify-apis-and-technology)
|
456
460
|
- [Read the docs!](https://help.shopify.com/api/guides)
|
457
461
|
|
462
|
+
Upgrading to 11.7.0
|
463
|
+
---------------------------
|
464
|
+
|
465
|
+
### Session storage method signature breaking change
|
466
|
+
If you override `def self.store(auth_session)` method in your session storage model (e.g. Shop), the method signature has changed to `def self.store(auth_session, *args)` in order to support user-based token storage. Please update your method signature to include the second argument.
|
467
|
+
|
458
468
|
Rails 6 Compatibility
|
459
469
|
---------------------
|
460
470
|
|
data/docs/Quickstart.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
Quickstart
|
2
2
|
==========
|
3
3
|
|
4
|
-
|
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
|
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
|
-
|
26
|
+
CLI:
|
23
27
|
```sh
|
24
28
|
$ heroku create name
|
25
29
|
$ heroku git:remote -a name
|
26
30
|
```
|
27
31
|
|
28
|
-
|
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:
|
37
|
+
$ git remote add heroku git@heroku.com:appname.git
|
34
38
|
```
|
35
39
|
|
36
|
-
3. Create a new App in the
|
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
|
-
*
|
40
|
-
*
|
41
|
-
*
|
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
|
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
|
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
|
-
#
|
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
|
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
|
-
|
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)
|
Binary file
|
Binary file
|
@@ -3,6 +3,12 @@ module ShopifyApp
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
+
if ShopifyApp.configuration.per_user_tokens?
|
7
|
+
extend ShopifyApp::SessionStorage::UserStorageStrategy
|
8
|
+
else
|
9
|
+
extend ShopifyApp::SessionStorage::ShopStorageStrategy
|
10
|
+
end
|
11
|
+
|
6
12
|
validates :shopify_token, presence: true
|
7
13
|
validates :api_version, presence: true
|
8
14
|
validates :shopify_domain, presence: true,
|
@@ -19,22 +25,5 @@ module ShopifyApp
|
|
19
25
|
&block
|
20
26
|
)
|
21
27
|
end
|
22
|
-
|
23
|
-
class_methods do
|
24
|
-
|
25
|
-
def strategy_klass
|
26
|
-
ShopifyApp.configuration.per_user_tokens? ?
|
27
|
-
ShopifyApp::SessionStorage::UserStorageStrategy :
|
28
|
-
ShopifyApp::SessionStorage::ShopStorageStrategy
|
29
|
-
end
|
30
|
-
|
31
|
-
def store(auth_session, user: nil)
|
32
|
-
strategy_klass.store(auth_session, user)
|
33
|
-
end
|
34
|
-
|
35
|
-
def retrieve(id)
|
36
|
-
strategy_klass.retrieve(id)
|
37
|
-
end
|
38
|
-
end
|
39
28
|
end
|
40
29
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module ShopifyApp
|
2
2
|
module SessionStorage
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
shop = Shop.find_or_initialize_by(shopify_domain: auth_session.domain)
|
3
|
+
module ShopStorageStrategy
|
4
|
+
def store(auth_session, *args)
|
5
|
+
shop = find_or_initialize_by(shopify_domain: auth_session.domain)
|
7
6
|
shop.shopify_token = auth_session.token
|
8
7
|
shop.save!
|
9
8
|
shop.id
|
10
9
|
end
|
11
10
|
|
12
|
-
def
|
11
|
+
def retrieve(id)
|
13
12
|
return unless id
|
14
|
-
if shop =
|
13
|
+
if shop = self.find_by(id: id)
|
15
14
|
ShopifyAPI::Session.new(
|
16
15
|
domain: shop.shopify_domain,
|
17
16
|
token: shop.shopify_token,
|
@@ -1,18 +1,17 @@
|
|
1
1
|
module ShopifyApp
|
2
2
|
module SessionStorage
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
user = User.find_or_initialize_by(shopify_user_id: user[:id])
|
3
|
+
module UserStorageStrategy
|
4
|
+
def store(auth_session, user)
|
5
|
+
user = find_or_initialize_by(shopify_user_id: user[:id])
|
7
6
|
user.shopify_token = auth_session.token
|
8
7
|
user.shopify_domain = auth_session.domain
|
9
8
|
user.save!
|
10
9
|
user.id
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
12
|
+
def retrieve(id)
|
14
13
|
return unless id
|
15
|
-
if user =
|
14
|
+
if user = self.find_by(shopify_user_id: id)
|
16
15
|
ShopifyAPI::Session.new(
|
17
16
|
domain: user.shopify_domain,
|
18
17
|
token: user.shopify_token,
|
@@ -20,7 +19,6 @@ module ShopifyApp
|
|
20
19
|
)
|
21
20
|
end
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
data/lib/shopify_app/version.rb
CHANGED
data/package.json
CHANGED
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: 11.7.
|
4
|
+
version: 11.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: browser_sniffer
|
@@ -278,6 +278,8 @@ files:
|
|
278
278
|
- docs/Quickstart.md
|
279
279
|
- docs/Releasing.md
|
280
280
|
- docs/Troubleshooting.md
|
281
|
+
- docs/install-on-dev-shop.png
|
282
|
+
- docs/test-your-app.png
|
281
283
|
- images/app-proxy-screenshot.png
|
282
284
|
- karma.conf.js
|
283
285
|
- lib/generators/shopify_app/add_after_authenticate_job/add_after_authenticate_job_generator.rb
|