Skip to content

Commit c8a8c09

Browse files
authored
Merge branch 'main' into liz/config-to-disable-rest
2 parents 2c54020 + 240be28 commit c8a8c09

File tree

13 files changed

+264
-26
lines changed

13 files changed

+264
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Note: For changes to the API, see https://shopify.dev/changelog?filter=api
44
## Unreleased
55

6+
## 14.7.0
7+
8+
- [#1347](https://github.com/Shopify/shopify-api-ruby/pull/1347) Extend webhook registration to support filters
69
- [#1344](https://github.com/Shopify/shopify-api-ruby/pull/1344) Allow ShopifyAPI::Webhooks::Registry to update a webhook when fields or metafield_namespaces are changed.
710
- [#1343](https://github.com/Shopify/shopify-api-ruby/pull/1343) Make ShopifyAPI::Context::scope parameter optional. `scope` defaults to empty list `[]`.
811
- [#1348](https://github.com/Shopify/shopify-api-ruby/pull/1348) Add config option that will disable the REST API client and REST resources. New apps should use the GraphQL Admin API

Gemfile.lock

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
shopify_api (14.6.0)
4+
shopify_api (14.7.0)
55
activesupport
66
concurrent-ruby
77
hash_diff
@@ -16,20 +16,24 @@ PATH
1616
GEM
1717
remote: https://rubygems.org/
1818
specs:
19-
activesupport (7.1.4)
19+
activesupport (7.1.5)
2020
base64
21+
benchmark (>= 0.3)
2122
bigdecimal
2223
concurrent-ruby (~> 1.0, >= 1.0.2)
2324
connection_pool (>= 2.2.5)
2425
drb
2526
i18n (>= 1.6, < 2)
27+
logger (>= 1.4.2)
2628
minitest (>= 5.1)
2729
mutex_m
30+
securerandom (>= 0.3)
2831
tzinfo (~> 2.0)
2932
addressable (2.8.0)
3033
public_suffix (>= 2.0.2, < 5.0)
3134
ast (2.4.2)
3235
base64 (0.2.0)
36+
benchmark (0.4.0)
3337
bigdecimal (3.1.8)
3438
byebug (11.1.3)
3539
coderay (1.1.3)
@@ -50,21 +54,22 @@ GEM
5054
i18n (1.14.6)
5155
concurrent-ruby (~> 1.0)
5256
json (2.7.1)
53-
jwt (2.9.1)
57+
jwt (2.9.3)
5458
base64
5559
language_server-protocol (3.17.0.3)
60+
logger (1.6.1)
5661
method_source (1.0.0)
5762
mini_mime (1.1.5)
5863
minitest (5.15.0)
5964
mocha (1.13.0)
6065
multi_xml (0.6.0)
61-
mutex_m (0.2.0)
66+
mutex_m (0.3.0)
6267
netrc (0.11.0)
63-
oj (3.16.6)
68+
oj (3.16.7)
6469
bigdecimal (>= 3.0)
6570
ostruct (>= 0.2)
6671
openssl (3.2.0)
67-
ostruct (0.6.0)
72+
ostruct (0.6.1)
6873
parallel (1.24.0)
6974
parser (3.3.0.5)
7075
ast (~> 2.4.1)
@@ -104,7 +109,7 @@ GEM
104109
rubocop-sorbet (0.6.11)
105110
rubocop (>= 0.90.0)
106111
ruby-progressbar (1.13.0)
107-
securerandom (0.3.1)
112+
securerandom (0.3.2)
108113
sorbet (0.5.11230)
109114
sorbet-static (= 0.5.11230)
110115
sorbet-runtime (0.5.11230)

docs/usage/webhooks.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ registration = ShopifyAPI::Webhooks::Registry.add_registration(
8282
)
8383
```
8484

85+
If you need to filter the webhooks you want to receive, you can use a [webhooks filter](https://shopify.dev/docs/apps/build/webhooks/customize/filters), which can be specified on registration through the `filter` parameter.
86+
87+
```ruby
88+
registration = ShopifyAPI::Webhooks::Registry.add_registration(
89+
topic: "products/update",
90+
delivery_method: :http,
91+
handler: WebhookHandler,
92+
filter: "variants.price:>=10.00"
93+
)
94+
```
95+
8596
**Note**: The webhooks you register with Shopify are saved in the Shopify platform, but the local `ShopifyAPI::Webhooks::Registry` needs to be reloaded whenever your server restarts.
8697

8798
### EventBridge and PubSub Webhooks

lib/shopify_api/rest/resources/2024_07/webhook.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
2323
@api_version = T.let(nil, T.nilable(String))
2424
@created_at = T.let(nil, T.nilable(String))
2525
@fields = T.let(nil, T.nilable(T::Array[T.untyped]))
26+
@filter = T.let(nil, T.nilable(String))
2627
@format = T.let(nil, T.nilable(String))
2728
@id = T.let(nil, T.nilable(Integer))
2829
@metafield_namespaces = T.let(nil, T.nilable(T::Array[T.untyped]))

lib/shopify_api/rest/resources/2024_10/webhook.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
2323
@api_version = T.let(nil, T.nilable(String))
2424
@created_at = T.let(nil, T.nilable(String))
2525
@fields = T.let(nil, T.nilable(T::Array[T.untyped]))
26+
@filter = T.let(nil, T.nilable(String))
2627
@format = T.let(nil, T.nilable(String))
2728
@id = T.let(nil, T.nilable(Integer))
2829
@metafield_namespaces = T.let(nil, T.nilable(T::Array[T.untyped]))

lib/shopify_api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# frozen_string_literal: true
33

44
module ShopifyAPI
5-
VERSION = "14.6.0"
5+
VERSION = "14.7.0"
66
end

lib/shopify_api/webhooks/registration.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@ class Registration
2222
sig { returns(T.nilable(T::Array[String])) }
2323
attr_reader :metafield_namespaces
2424

25+
sig { returns(T.nilable(String)) }
26+
attr_reader :filter
27+
2528
sig do
2629
params(topic: String, path: String, handler: T.nilable(T.any(Handler, WebhookHandler)),
2730
fields: T.nilable(T.any(String, T::Array[String])),
28-
metafield_namespaces: T.nilable(T::Array[String])).void
31+
metafield_namespaces: T.nilable(T::Array[String]),
32+
filter: T.nilable(String)).void
2933
end
30-
def initialize(topic:, path:, handler: nil, fields: nil, metafield_namespaces: nil)
34+
def initialize(topic:, path:, handler: nil, fields: nil, metafield_namespaces: nil, filter: nil)
3135
@topic = T.let(topic.gsub("/", "_").upcase, String)
3236
@path = path
3337
@handler = handler
3438
fields_array = fields.is_a?(String) ? fields.split(FIELDS_DELIMITER) : fields
3539
@fields = T.let(fields_array&.map(&:strip)&.compact, T.nilable(T::Array[String]))
3640
@metafield_namespaces = T.let(metafield_namespaces&.map(&:strip)&.compact, T.nilable(T::Array[String]))
41+
@filter = filter
3742
end
3843

3944
sig { abstract.returns(String) }
@@ -54,6 +59,7 @@ def build_check_query; end
5459
current_address: T.nilable(String),
5560
fields: T::Array[String],
5661
metafield_namespaces: T::Array[String],
62+
filter: T.nilable(String),
5763
})
5864
end
5965
def parse_check_result(body); end
@@ -88,6 +94,7 @@ def subscription_response_attributes
8894
attributes = ["id"]
8995
attributes << "includeFields" if @fields
9096
attributes << "metafieldNamespaces" if @metafield_namespaces
97+
attributes << "filter" if @filter
9198
attributes
9299
end
93100
end

lib/shopify_api/webhooks/registrations/event_bridge.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def callback_address
1414

1515
sig { override.returns(T::Hash[Symbol, String]) }
1616
def subscription_args
17-
{ arn: callback_address, includeFields: fields, metafieldNamespaces: metafield_namespaces }.compact
17+
{ arn: callback_address, includeFields: fields,
18+
metafieldNamespaces: metafield_namespaces, filter: filter, }.compact
1819
end
1920

2021
sig { override.params(webhook_id: T.nilable(String)).returns(String) }
@@ -32,6 +33,7 @@ def build_check_query
3233
id
3334
includeFields
3435
metafieldNamespaces
36+
filter
3537
endpoint {
3638
__typename
3739
... on WebhookEventBridgeEndpoint {
@@ -51,23 +53,26 @@ def build_check_query
5153
current_address: T.nilable(String),
5254
fields: T::Array[String],
5355
metafield_namespaces: T::Array[String],
56+
filter: T.nilable(String),
5457
})
5558
end
5659
def parse_check_result(body)
5760
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
5861
webhook_id = nil
5962
fields = []
6063
metafield_namespaces = []
64+
filter = nil
6165
current_address = nil
6266
unless edges.empty?
6367
node = edges[0]["node"]
6468
webhook_id = node["id"].to_s
6569
current_address = node["endpoint"]["arn"].to_s
6670
fields = node["includeFields"] || []
6771
metafield_namespaces = node["metafieldNamespaces"] || []
72+
filter = node["filter"].to_s
6873
end
6974
{ webhook_id: webhook_id, current_address: current_address, fields: fields,
70-
metafield_namespaces: metafield_namespaces, }
75+
metafield_namespaces: metafield_namespaces, filter: filter, }
7176
end
7277
end
7378
end

lib/shopify_api/webhooks/registrations/http.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def callback_address
2020

2121
sig { override.returns(T::Hash[Symbol, String]) }
2222
def subscription_args
23-
{ callbackUrl: callback_address, includeFields: fields, metafieldNamespaces: metafield_namespaces }.compact
23+
{ callbackUrl: callback_address, includeFields: fields,
24+
metafieldNamespaces: metafield_namespaces, filter: filter, }.compact
2425
end
2526

2627
sig { override.params(webhook_id: T.nilable(String)).returns(String) }
@@ -38,6 +39,7 @@ def build_check_query
3839
id
3940
includeFields
4041
metafieldNamespaces
42+
filter
4143
endpoint {
4244
__typename
4345
... on WebhookHttpEndpoint {
@@ -57,13 +59,15 @@ def build_check_query
5759
current_address: T.nilable(String),
5860
fields: T::Array[String],
5961
metafield_namespaces: T::Array[String],
62+
filter: T.nilable(String),
6063
})
6164
end
6265
def parse_check_result(body)
6366
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
6467
webhook_id = nil
6568
fields = []
6669
metafield_namespaces = []
70+
filter = nil
6771
current_address = nil
6872
unless edges.empty?
6973
node = edges[0]["node"]
@@ -76,9 +80,10 @@ def parse_check_result(body)
7680
end
7781
fields = node["includeFields"] || []
7882
metafield_namespaces = node["metafieldNamespaces"] || []
83+
filter = node["filter"].to_s
7984
end
8085
{ webhook_id: webhook_id, current_address: current_address, fields: fields,
81-
metafield_namespaces: metafield_namespaces, }
86+
metafield_namespaces: metafield_namespaces, filter: filter, }
8287
end
8388
end
8489
end

lib/shopify_api/webhooks/registrations/pub_sub.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def subscription_args
1818
project = project_topic_pair[0]
1919
topic = project_topic_pair[1]
2020
{ pubSubProject: project, pubSubTopic: topic, includeFields: fields,
21-
metafieldNamespaces: metafield_namespaces, }.compact
21+
metafieldNamespaces: metafield_namespaces, filter: filter, }.compact
2222
end
2323

2424
sig { override.params(webhook_id: T.nilable(String)).returns(String) }
@@ -36,6 +36,7 @@ def build_check_query
3636
id
3737
includeFields
3838
metafieldNamespaces
39+
filter
3940
endpoint {
4041
__typename
4142
... on WebhookPubSubEndpoint {
@@ -56,13 +57,15 @@ def build_check_query
5657
current_address: T.nilable(String),
5758
fields: T::Array[String],
5859
metafield_namespaces: T::Array[String],
60+
filter: T.nilable(String),
5961
})
6062
end
6163
def parse_check_result(body)
6264
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
6365
webhook_id = nil
6466
fields = []
6567
metafield_namespaces = []
68+
filter = nil
6669
current_address = nil
6770
unless edges.empty?
6871
node = edges[0]["node"]
@@ -71,9 +74,10 @@ def parse_check_result(body)
7174
"pubsub://#{node["endpoint"]["pubSubProject"]}:#{node["endpoint"]["pubSubTopic"]}"
7275
fields = node["includeFields"] || []
7376
metafield_namespaces = node["metafieldNamespaces"] || []
77+
filter = node["filter"].to_s
7478
end
7579
{ webhook_id: webhook_id, current_address: current_address, fields: fields,
76-
metafield_namespaces: metafield_namespaces, }
80+
metafield_namespaces: metafield_namespaces, filter: filter, }
7781
end
7882
end
7983
end

0 commit comments

Comments
 (0)