From 53a67418526234489f14a8f9f49e6223615ce510 Mon Sep 17 00:00:00 2001 From: Andy Liu Date: Wed, 30 Oct 2024 17:38:20 -0400 Subject: [PATCH] make parse type untyped and possibly sort arrays when checking for equality --- lib/shopify_api/webhooks/registration.rb | 2 +- lib/shopify_api/webhooks/registrations/event_bridge.rb | 2 +- lib/shopify_api/webhooks/registrations/http.rb | 2 +- lib/shopify_api/webhooks/registrations/pub_sub.rb | 2 +- lib/shopify_api/webhooks/registry.rb | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/shopify_api/webhooks/registration.rb b/lib/shopify_api/webhooks/registration.rb index eb786b70e..1452d2045 100644 --- a/lib/shopify_api/webhooks/registration.rb +++ b/lib/shopify_api/webhooks/registration.rb @@ -48,7 +48,7 @@ def mutation_name(webhook_id); end sig { abstract.returns(String) } def build_check_query; end - sig { abstract.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, String]) } + sig { abstract.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, T.untyped]) } def parse_check_result(body); end sig { params(webhook_id: T.nilable(String)).returns(String) } diff --git a/lib/shopify_api/webhooks/registrations/event_bridge.rb b/lib/shopify_api/webhooks/registrations/event_bridge.rb index beb65b0ac..5fbaed3b3 100644 --- a/lib/shopify_api/webhooks/registrations/event_bridge.rb +++ b/lib/shopify_api/webhooks/registrations/event_bridge.rb @@ -45,7 +45,7 @@ def build_check_query QUERY end - sig { override.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, String]) } + sig { override.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, T.untyped]) } def parse_check_result(body) edges = body.dig("data", "webhookSubscriptions", "edges") || {} webhook_id = nil diff --git a/lib/shopify_api/webhooks/registrations/http.rb b/lib/shopify_api/webhooks/registrations/http.rb index 9c33f2b7b..d7c094eda 100644 --- a/lib/shopify_api/webhooks/registrations/http.rb +++ b/lib/shopify_api/webhooks/registrations/http.rb @@ -51,7 +51,7 @@ def build_check_query QUERY end - sig { override.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, String]) } + sig { override.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, T.untyped]) } def parse_check_result(body) edges = body.dig("data", "webhookSubscriptions", "edges") || {} webhook_id = nil diff --git a/lib/shopify_api/webhooks/registrations/pub_sub.rb b/lib/shopify_api/webhooks/registrations/pub_sub.rb index 9c06f2711..138f18f1a 100644 --- a/lib/shopify_api/webhooks/registrations/pub_sub.rb +++ b/lib/shopify_api/webhooks/registrations/pub_sub.rb @@ -50,7 +50,7 @@ def build_check_query QUERY end - sig { override.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, String]) } + sig { override.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, T.untyped]) } def parse_check_result(body) edges = body.dig("data", "webhookSubscriptions", "edges") || {} webhook_id = nil diff --git a/lib/shopify_api/webhooks/registry.rb b/lib/shopify_api/webhooks/registry.rb index ac5e70b53..cb1b9c5bc 100644 --- a/lib/shopify_api/webhooks/registry.rb +++ b/lib/shopify_api/webhooks/registry.rb @@ -221,8 +221,8 @@ def webhook_registration_needed?(client, registration) "Failed to check if webhook was already registered" unless check_response.ok? parsed_check_result = registration.parse_check_result(T.cast(check_response.body, T::Hash[String, T.untyped])) must_register = parsed_check_result[:current_address] != registration.callback_address || - parsed_check_result[:fields] != registration.fields || - parsed_check_result[:metafield_namespaces] != registration.metafield_namespaces + parsed_check_result[:fields]&.sort != registration.fields&.sort || + parsed_check_result[:metafield_namespaces]&.sort != registration.metafield_namespaces&.sort { webhook_id: parsed_check_result[:webhook_id], must_register: must_register } end