Sha256: d8c80b3a51fa028f1a435ecd908fa355069f96b6d305dfea45aa4da7823c9bb6

Contents?: true

Size: 1.77 KB

Versions: 12

Compression:

Stored size: 1.77 KB

Contents

# typed: strict
# frozen_string_literal: true

module ShopifyAPI
  module Webhooks
    module Registrations
      class EventBridge < Registration
        extend T::Sig

        sig { override.returns(String) }
        def callback_address
          @path
        end

        sig { override.returns(T::Hash[Symbol, String]) }
        def subscription_args
          { arn: callback_address, includeFields: fields, metafieldNamespaces: metafield_namespaces }.compact
        end

        sig { override.params(webhook_id: T.nilable(String)).returns(String) }
        def mutation_name(webhook_id)
          webhook_id ? "eventBridgeWebhookSubscriptionUpdate" : "eventBridgeWebhookSubscriptionCreate"
        end

        sig { override.returns(String) }
        def build_check_query
          <<~QUERY
            {
              webhookSubscriptions(first: 1, topics: #{@topic}) {
                edges {
                  node {
                    id
                    endpoint {
                      __typename
                      ... on WebhookEventBridgeEndpoint {
                        arn
                      }
                    }
                  }
                }
              }
            }
          QUERY
        end

        sig { override.params(body: T::Hash[String, T.untyped]).returns(T::Hash[Symbol, String]) }
        def parse_check_result(body)
          edges = body.dig("data", "webhookSubscriptions", "edges") || {}
          webhook_id = nil
          current_address = nil
          unless edges.empty?
            node = edges[0]["node"]
            webhook_id = node["id"].to_s
            current_address = node["endpoint"]["arn"].to_s
          end
          { webhook_id: webhook_id, current_address: current_address }
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
shopify_api-14.6.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-14.5.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-14.4.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-14.3.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-14.2.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-14.1.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-14.0.1 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-14.0.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-13.4.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-13.3.1 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-13.3.0 lib/shopify_api/webhooks/registrations/event_bridge.rb
shopify_api-13.2.0 lib/shopify_api/webhooks/registrations/event_bridge.rb