shopify_toolkit 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b8574729a741fe496f0377291bf3a93c0bf25df56aa03b9b37f5694e9161f8a
4
- data.tar.gz: a38af4ad93e5b3dd0e18694b4627c5d220b73bddf657d22b1a23ffe87268c9da
3
+ metadata.gz: 7e5e83e71a4d7f6e6d0d8746e307076e7908f4e6c03d28820e99fde10557c6ba
4
+ data.tar.gz: c9d9bce64d5af477e1e46a18dc18b175088fde22288c2d97e935c495f06beb42
5
5
  SHA512:
6
- metadata.gz: f1b5bc3beb644866a7110b0f8bebc531e310a7f3e2bdf25ab89da50bcd3741de7d7f082af0e180371e64108bfbdbb1efb5b38ff7f4dc50a26c8b8eb51898b406
7
- data.tar.gz: 6a6b7dfdd94a7bae0480d801f685a1fb0f62999be5ad2024b21d8833c6bd72065545f514587986df53ba67a384d61f3f0cb0c6669e171a94769e7f90b02dbe60
6
+ metadata.gz: 7c39acdbf5c2b15e1b0c5276aefd65063857bae0da5431b9a929b55d2d8fe51517ba40c71ffe508ddda2100965c378f9a99c494de398afc906cfdb5674e65b7c
7
+ data.tar.gz: cfa96c9301a1502eb02ba5fb5c854ffa8a5e72a4960910ba17cd82d475c9edeeab39989fe5d5f6c879b94b7f55835be6e334100cec24304ba1a56621e0fb5faa
@@ -8,7 +8,37 @@ module ShopifyToolkit::Schema
8
8
  extend self
9
9
  include ShopifyToolkit::MetafieldStatements
10
10
  include ShopifyToolkit::Migration::Logging
11
+
12
+ delegate :logger, to: Rails
13
+
11
14
  SCHEMA_PATH = "config/shopify/schema.rb"
15
+ # https://shopify.dev/docs/api/admin-graphql/2024-10/enums/MetafieldOwnerType
16
+ OWNER_TYPES = %i[
17
+ api_permissions
18
+ articles
19
+ blogs
20
+ carttransforms
21
+ collections
22
+ companies
23
+ company_locations
24
+ customers
25
+ delivery_customizations
26
+ discounts
27
+ draftorders
28
+ fulfillment_constraint_rules
29
+ gift_card_transactions
30
+ locations
31
+ markets
32
+ orders
33
+ order_routing_location_rules
34
+ pages
35
+ payment_customizations
36
+ products
37
+ productvariants
38
+ selling_plans
39
+ shops
40
+ validations
41
+ ].freeze
12
42
 
13
43
  def load!
14
44
  path = Rails.root.join(SCHEMA_PATH)
@@ -38,10 +68,12 @@ module ShopifyToolkit::Schema
38
68
  instance_eval(&block)
39
69
  end
40
70
 
41
- def fetch_definitions
71
+ def fetch_definitions(owner_type:)
72
+ owner_type = owner_type.to_s.singularize.upcase
73
+
42
74
  query = <<~GRAPHQL
43
75
  query {
44
- metafieldDefinitions(first: 250, ownerType: PRODUCT) {
76
+ metafieldDefinitions(first: 250, ownerType: #{owner_type}) {
45
77
  nodes {
46
78
  id
47
79
  name
@@ -74,57 +106,71 @@ module ShopifyToolkit::Schema
74
106
  }
75
107
  GRAPHQL
76
108
 
77
- result = shopify_admin_client.query(query:).tap { handle_shopify_admin_client_errors(_1) }.body
109
+ result =
110
+ shopify_admin_client
111
+ .query(query:)
112
+ .tap { handle_shopify_admin_client_errors(_1) }
113
+ .body
78
114
 
79
115
  result.dig("data", "metafieldDefinitions", "nodes") || []
80
116
  end
81
117
 
82
118
  def generate_schema_content
83
- definitions = fetch_definitions
119
+ definitions =
120
+ OWNER_TYPES.flat_map { |owner_type| fetch_definitions(owner_type:) }
121
+
84
122
  content = StringIO.new
85
123
  content << <<~RUBY
86
- # This file is auto-generated from the current state of the Shopify metafields.
87
- # Instead of editing this file, please use the metafields migration feature of ShopifyToolkit
88
- # to incrementally modify your metafields, and then regenerate this schema definition.
89
- #
90
- # This file is the source used to define your metafields when running `bin/rails shopify:schema:load`.
91
- #
92
- # It's strongly recommended that you check this file into your version control system.
93
- ShopifyToolkit::Schema.define do
94
- RUBY
95
-
96
- definitions.each do |defn|
97
- owner_type = defn["ownerType"].downcase.pluralize.to_sym
98
- key = defn["key"].to_sym
99
- type = defn["type"]["name"].to_sym
100
- name = defn["name"]
101
- namespace = defn["namespace"]&.to_sym
102
- description = defn["description"]
103
- validations = defn["validations"]&.map { |v| v.transform_keys(&:to_sym) }
104
- capabilities = defn["capabilities"]&.transform_keys(&:to_sym)&.transform_values { |v| v.transform_keys(&:to_sym) }
105
-
106
- args = [owner_type, key, type]
107
- kwargs = { name: name }
108
- kwargs[:namespace] = namespace if namespace && namespace != :custom
109
- kwargs[:description] = description if description
110
- kwargs[:validations] = validations if validations.present?
111
-
112
- # Only include capabilities if they have non-default values
113
- if capabilities.present?
114
- has_non_default_capabilities =
115
- capabilities.any? do |cap, value|
116
- case cap
117
- when :smartCollectionCondition, :adminFilterable
118
- value[:enabled] == true
119
- else
120
- true
124
+ # This file is auto-generated from the current state of the Shopify metafields.
125
+ # Instead of editing this file, please use the metafields migration feature of ShopifyToolkit
126
+ # to incrementally modify your metafields, and then regenerate this schema definition.
127
+ #
128
+ # This file is the source used to define your metafields when running `bin/rails shopify:schema:load`.
129
+ #
130
+ # It's strongly recommended that you check this file into your version control system.
131
+ ShopifyToolkit::Schema.define do
132
+ RUBY
133
+
134
+ # Sort for consistent output
135
+ definitions
136
+ .sort_by { [_1["ownerType"], _1["namespace"], _1["key"]] }
137
+ .each do
138
+ owner_type = _1["ownerType"].downcase.pluralize.to_sym
139
+ key = _1["key"].to_sym
140
+ type = _1["type"]["name"].to_sym
141
+ name = _1["name"]
142
+ namespace = _1["namespace"]&.to_sym
143
+ description = _1["description"]
144
+ validations = _1["validations"]&.map { |v| v.transform_keys(&:to_sym) }
145
+ capabilities =
146
+ _1["capabilities"]
147
+ &.transform_keys(&:to_sym)
148
+ &.transform_values { |v| v.transform_keys(&:to_sym) }
149
+
150
+ args = [owner_type, key, type]
151
+ kwargs = { name: name }
152
+ kwargs[:namespace] = namespace if namespace && namespace != :custom
153
+ kwargs[:description] = description if description
154
+ kwargs[:validations] = validations if validations.present?
155
+
156
+ # Only include capabilities if they have non-default values
157
+ if capabilities.present?
158
+ has_non_default_capabilities =
159
+ capabilities.any? do |cap, value|
160
+ case cap
161
+ when :smartCollectionCondition, :adminFilterable
162
+ value[:enabled] == true
163
+ else
164
+ true
165
+ end
121
166
  end
122
- end
123
- kwargs[:capabilities] = capabilities if has_non_default_capabilities
124
- end
167
+ kwargs[:capabilities] = capabilities if has_non_default_capabilities
168
+ end
125
169
 
126
- content.puts " create_metafield #{args.map(&:inspect).join(", ")}, #{kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")}"
127
- end
170
+ args_string = args.map(&:inspect).join(", ")
171
+ kwargs_string = kwargs.map { |k, v| "#{k}: #{v.inspect}" }.join(", ")
172
+ content.puts " create_metafield #{args_string}, #{kwargs_string}"
173
+ end
128
174
 
129
175
  content.puts "end"
130
176
  content.string
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ShopifyToolkit
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
8
8
  - Nebulab Team
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-14 00:00:00.000000000 Z
11
+ date: 2025-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties