class ShopifyAPI::Webhooks::Request

def hmac

def hmac
  Digest.hexencode(Base64.decode64(T.cast(@headers["x-shopify-hmac-sha256"], String)))
end

def initialize(raw_body:, headers:)

def initialize(raw_body:, headers:)
  # normalize the headers by forcing lowercase, removing any prepended "http"s, and changing underscores to dashes
  headers = headers.to_h { |k, v| [k.to_s.downcase.sub("http_", "").gsub("_", "-"), v] }
  missing_headers = []
  [
    "x-shopify-topic",
    "x-shopify-hmac-sha256",
    "x-shopify-shop-domain",
  ].each { |header| missing_headers << header unless headers.include?(header) }
  unless missing_headers.empty?
    raise Errors::InvalidWebhookError,
      "Missing one or more of the required HTTP headers to process webhooks: #{missing_headers}"
  end
  @headers = headers
  @raw_body = raw_body
end

def parsed_body

def parsed_body
  JSON.parse(@raw_body)
end

def shop

def shop
  T.cast(@headers["x-shopify-shop-domain"], String)
end

def to_signable_string

def to_signable_string
  @raw_body
end

def topic

def topic
  T.cast(@headers["x-shopify-topic"], String)
end