Skip to content

Commit 1301265

Browse files
authored
Merge pull request #1414 from Shopify/remove-passing-public-storefront-token
[Breaking] Remove deprecated storefront_access_token positional parameter
2 parents 37b95e4 + 069fd51 commit 1301265

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

BREAKING_CHANGES_FOR_V15.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
# Breaking change notice for version 15.0.0
22

3+
## Removal of positional `storefront_access_token` parameter from Storefront GraphQL Client
4+
5+
The `ShopifyAPI::Clients::Graphql::Storefront` class no longer accepts the public Storefront access token as a positional parameter. You must now use the named parameters `private_token:` or `public_token:` instead.
6+
7+
This parameter was deprecated in [PR #1302](https://github.com/Shopify/shopify-api-ruby/pull/1302) (v14.1.0).
8+
9+
### Previous implementation (deprecated in v14.1.0)
10+
11+
```ruby
12+
# Old way: passing token as positional parameter
13+
client = ShopifyAPI::Clients::Graphql::Storefront.new(shop_url, storefront_access_token)
14+
15+
# With API version
16+
client = ShopifyAPI::Clients::Graphql::Storefront.new(shop_url, storefront_access_token, api_version: "2024-01")
17+
```
18+
19+
### New implementation (required in v15.0.0)
20+
21+
```ruby
22+
# Use private token (recommended)
23+
client = ShopifyAPI::Clients::Graphql::Storefront.new(shop_url, private_token: storefront_private_access_token)
24+
25+
# Or use public token
26+
client = ShopifyAPI::Clients::Graphql::Storefront.new(shop_url, public_token: storefront_public_access_token)
27+
28+
# With API version
29+
client = ShopifyAPI::Clients::Graphql::Storefront.new(
30+
shop_url,
31+
private_token: storefront_private_access_token,
32+
api_version: "2024-01"
33+
)
34+
```
35+
36+
For more information on private vs public Storefront access tokens, see [Shopify's authentication documentation](https://shopify.dev/docs/api/usage/authentication#getting-started-with-private-access).
337
## Removal of `LATEST_SUPPORTED_ADMIN_VERSION` and `RELEASE_CANDIDATE_ADMIN_VERSION` constants
438

539
The `LATEST_SUPPORTED_ADMIN_VERSION` and `RELEASE_CANDIDATE_ADMIN_VERSION` constants have been removed to prevent semantic versioning (semver) breaking changes. Previously, these constants would automatically update every quarter when new API versions were released, causing unintended breaking changes for apps.
@@ -68,7 +102,8 @@ Make a module or class that includes or extends `ShopifyAPI::Webhooks::WebhookHa
68102

69103
In v14, adding new fields to the callback would become a breaking change. To make this code more flexible, handlers will now receive an object that can be typed and extended.
70104

71-
`data` will have the following keys
105+
`data` will have the following keys:
106+
72107
- `topic`, `String` - The topic of the webhook
73108
- `shop`, `String` - The shop domain of the webhook
74109
- `body`, `T::Hash[String, T.untyped]`- The body of the webhook

lib/shopify_api/clients/graphql/storefront.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@ class Storefront < Client
88
sig do
99
params(
1010
shop: String,
11-
storefront_access_token: T.nilable(String),
1211
private_token: T.nilable(String),
1312
public_token: T.nilable(String),
1413
api_version: T.nilable(String),
1514
).void
1615
end
17-
def initialize(shop, storefront_access_token = nil, private_token: nil, public_token: nil, api_version: nil)
18-
unless storefront_access_token.nil?
19-
warning = <<~WARNING
20-
DEPRECATED: Use the named parameters for the Storefront token instead of passing
21-
the public token as the second argument. Also, you may want to look into using
22-
the Storefront private access token instead:
23-
https://shopify.dev/docs/api/usage/authentication#getting-started-with-private-access
24-
WARNING
25-
ShopifyAPI::Logger.deprecated(warning, "15.0.0")
16+
def initialize(shop, private_token: nil, public_token: nil, api_version: nil)
17+
token = private_token || public_token
18+
if token.nil?
19+
raise ArgumentError, "Storefront client requires either private_token or public_token to be provided"
2620
end
2721

2822
session = Auth::Session.new(
@@ -32,7 +26,7 @@ def initialize(shop, storefront_access_token = nil, private_token: nil, public_t
3226
is_online: false,
3327
)
3428
super(session: session, base_path: "/api", api_version: api_version)
35-
@storefront_access_token = T.let(T.must(private_token || public_token || storefront_access_token), String)
29+
@storefront_access_token = T.let(token, String)
3630
@storefront_auth_header = T.let(
3731
private_token.nil? ? "X-Shopify-Storefront-Access-Token" : "Shopify-Storefront-Private-Token",
3832
String,

test/clients/graphql/storefront_test.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ def setup
2222

2323
def build_client
2424
if !defined?("@api_version")
25-
ShopifyAPI::Clients::Graphql::Storefront.new(@shop, @storefront_access_token)
25+
ShopifyAPI::Clients::Graphql::Storefront.new(@shop, public_token: @storefront_access_token)
2626
else
27-
ShopifyAPI::Clients::Graphql::Storefront.new(@shop, @storefront_access_token, api_version: @api_version)
27+
ShopifyAPI::Clients::Graphql::Storefront.new(
28+
@shop,
29+
public_token: @storefront_access_token,
30+
api_version: @api_version,
31+
)
2832
end
2933
end
3034

@@ -81,7 +85,7 @@ def test_can_query_using_public_token
8185
end
8286

8387
def test_error_raised_when_no_token_provided
84-
assert_raises(TypeError) { ShopifyAPI::Clients::Graphql::Storefront.new(@shop) }
88+
assert_raises(ArgumentError) { ShopifyAPI::Clients::Graphql::Storefront.new(@shop) }
8589
end
8690
end
8791
end

0 commit comments

Comments
 (0)