spree_api 4.2.3.1 → 4.3.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -1
  3. data/app/controllers/concerns/spree/api/v2/caching.rb +33 -0
  4. data/app/controllers/concerns/spree/api/v2/product_list_includes.rb +23 -0
  5. data/app/controllers/spree/api/v1/classifications_controller.rb +4 -3
  6. data/app/controllers/spree/api/v1/orders_controller.rb +5 -1
  7. data/app/controllers/spree/api/v1/products_controller.rb +2 -2
  8. data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -1
  9. data/app/controllers/spree/api/v2/base_controller.rb +29 -6
  10. data/app/controllers/spree/api/v2/platform/addresses_controller.rb +19 -0
  11. data/app/controllers/spree/api/v2/platform/classifications_controller.rb +43 -0
  12. data/app/controllers/spree/api/v2/platform/cms_pages_controller.rb +15 -0
  13. data/app/controllers/spree/api/v2/platform/cms_sections_controller.rb +34 -0
  14. data/app/controllers/spree/api/v2/platform/countries_controller.rb +19 -0
  15. data/app/controllers/spree/api/v2/platform/menu_items_controller.rb +35 -0
  16. data/app/controllers/spree/api/v2/platform/menus_controller.rb +19 -0
  17. data/app/controllers/spree/api/v2/platform/option_types_controller.rb +15 -0
  18. data/app/controllers/spree/api/v2/platform/option_values_controller.rb +19 -0
  19. data/app/controllers/spree/api/v2/platform/products_controller.rb +33 -0
  20. data/app/controllers/spree/api/v2/platform/resource_controller.rb +112 -0
  21. data/app/controllers/spree/api/v2/platform/taxons_controller.rb +30 -0
  22. data/app/controllers/spree/api/v2/platform/users_controller.rb +28 -0
  23. data/app/controllers/spree/api/v2/resource_controller.rb +24 -7
  24. data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +2 -14
  25. data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +13 -11
  26. data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +6 -2
  27. data/app/controllers/spree/api/v2/storefront/account_controller.rb +32 -1
  28. data/app/controllers/spree/api/v2/storefront/cart_controller.rb +28 -6
  29. data/app/controllers/spree/api/v2/storefront/checkout_controller.rb +2 -1
  30. data/app/controllers/spree/api/v2/storefront/cms_pages_controller.rb +41 -0
  31. data/app/controllers/spree/api/v2/storefront/countries_controller.rb +9 -14
  32. data/app/controllers/spree/api/v2/storefront/menus_controller.rb +35 -0
  33. data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +1 -1
  34. data/app/controllers/spree/api/v2/storefront/products_controller.rb +10 -12
  35. data/app/controllers/spree/api/v2/storefront/stores_controller.rb +1 -1
  36. data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +7 -8
  37. data/app/helpers/spree/api/v2/display_money_helper.rb +2 -2
  38. data/app/models/spree/api_configuration.rb +4 -1
  39. data/app/models/spree/api_dependencies.rb +20 -5
  40. data/app/serializers/concerns/spree/api/v2/resource_serializer_concern.rb +16 -0
  41. data/app/serializers/spree/api/v2/base_serializer.rb +32 -0
  42. data/app/serializers/spree/api/v2/platform/address_serializer.rb +15 -0
  43. data/app/serializers/spree/api/v2/platform/base_serializer.rb +10 -0
  44. data/app/serializers/spree/api/v2/platform/classification_serializer.rb +14 -0
  45. data/app/serializers/spree/api/v2/platform/cms_page_serializer.rb +13 -0
  46. data/app/serializers/spree/api/v2/platform/cms_section_serializer.rb +11 -0
  47. data/app/serializers/spree/api/v2/platform/country_serializer.rb +13 -0
  48. data/app/serializers/spree/api/v2/platform/image_serializer.rb +15 -0
  49. data/app/serializers/spree/api/v2/platform/menu_item_serializer.rb +27 -0
  50. data/app/serializers/spree/api/v2/platform/menu_serializer.rb +13 -0
  51. data/app/serializers/spree/api/v2/platform/option_type_serializer.rb +13 -0
  52. data/app/serializers/spree/api/v2/platform/option_value_serializer.rb +13 -0
  53. data/app/serializers/spree/api/v2/platform/product_property_serializer.rb +11 -0
  54. data/app/serializers/spree/api/v2/platform/product_serializer.rb +78 -0
  55. data/app/serializers/spree/api/v2/platform/state_serializer.rb +13 -0
  56. data/app/serializers/spree/api/v2/platform/stock_item_serializer.rb +20 -0
  57. data/app/serializers/spree/api/v2/platform/stock_location_serializer.rb +16 -0
  58. data/app/serializers/spree/api/v2/platform/store_serializer.rb +14 -0
  59. data/app/serializers/spree/api/v2/platform/tax_category_serializer.rb +13 -0
  60. data/app/serializers/spree/api/v2/platform/taxon_image_serializer.rb +13 -0
  61. data/app/serializers/spree/api/v2/platform/taxon_serializer.rb +38 -0
  62. data/app/serializers/spree/api/v2/platform/taxonomy_serializer.rb +14 -0
  63. data/app/serializers/spree/api/v2/platform/user_serializer.rb +37 -0
  64. data/app/serializers/spree/api/v2/platform/variant_serializer.rb +57 -0
  65. data/app/serializers/spree/v2/storefront/base_serializer.rb +3 -2
  66. data/app/serializers/spree/v2/storefront/cms_page_serializer.rb +14 -0
  67. data/app/serializers/spree/v2/storefront/cms_section_serializer.rb +28 -0
  68. data/app/serializers/spree/v2/storefront/country_serializer.rb +4 -4
  69. data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +2 -0
  70. data/app/serializers/spree/v2/storefront/menu_item_serializer.rb +43 -0
  71. data/app/serializers/spree/v2/storefront/menu_serializer.rb +13 -0
  72. data/app/serializers/spree/v2/storefront/product_property_serializer.rb +1 -1
  73. data/app/serializers/spree/v2/storefront/product_serializer.rb +20 -11
  74. data/app/serializers/spree/v2/storefront/store_serializer.rb +10 -0
  75. data/app/serializers/spree/v2/storefront/taxon_serializer.rb +6 -5
  76. data/config/initializers/doorkeeper.rb +8 -1
  77. data/config/initializers/rabl.rb +9 -0
  78. data/config/locales/en.yml +1 -1
  79. data/config/routes.rb +115 -3
  80. data/db/migrate/20210727102516_change_integer_id_columns_type.rb +9 -0
  81. data/docs/oauth/index.yml +4 -4
  82. data/docs/v2/platform/index.yaml +2505 -0
  83. data/docs/v2/storefront/index.yaml +3508 -1220
  84. data/lib/spree/api/engine.rb +6 -17
  85. data/lib/spree/api/testing_support/v2/base.rb +1 -1
  86. data/lib/spree/api/testing_support/v2/platform_contexts.rb +214 -0
  87. data/lib/spree/api/testing_support/v2/serializers_params.rb +14 -0
  88. data/lib/spree/api.rb +1 -0
  89. data/spree_api.gemspec +6 -3
  90. metadata +110 -13
  91. data/app/assets/javascripts/spree/api/main.js +0 -36
  92. data/app/assets/javascripts/spree/api/storefront/cart.js +0 -49
@@ -0,0 +1,57 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class VariantSerializer < BaseSerializer
6
+ include ::Spree::Api::V2::ResourceSerializerConcern
7
+ include ::Spree::Api::V2::DisplayMoneyHelper
8
+
9
+ attributes :name, :options_text, :total_on_hand
10
+
11
+ attribute :purchasable do |product|
12
+ product.purchasable?
13
+ end
14
+
15
+ attribute :in_stock do |product|
16
+ product.in_stock?
17
+ end
18
+
19
+ attribute :backorderable do |product|
20
+ product.backorderable?
21
+ end
22
+
23
+ attribute :available do |product|
24
+ product.available?
25
+ end
26
+
27
+ attribute :currency do |_product, params|
28
+ params[:currency]
29
+ end
30
+
31
+ attribute :price do |object, params|
32
+ price(object, params[:currency])
33
+ end
34
+
35
+ attribute :display_price do |object, params|
36
+ display_price(object, params[:currency])
37
+ end
38
+
39
+ attribute :compare_at_price do |object, params|
40
+ compare_at_price(object, params[:currency])
41
+ end
42
+
43
+ attribute :display_compare_at_price do |object, params|
44
+ display_compare_at_price(object, params[:currency])
45
+ end
46
+
47
+ belongs_to :product
48
+ belongs_to :tax_category
49
+ has_many :images
50
+ has_many :option_values
51
+ has_many :stock_items
52
+ has_many :stock_locations
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,8 +1,9 @@
1
+ require 'active_support/cache'
2
+
1
3
  module Spree
2
4
  module V2
3
5
  module Storefront
4
- class BaseSerializer
5
- include JSONAPI::Serializer
6
+ class BaseSerializer < ::Spree::Api::V2::BaseSerializer
6
7
  end
7
8
  end
8
9
  end
@@ -0,0 +1,14 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class CmsPageSerializer < BaseSerializer
5
+ set_type :cms_page
6
+
7
+ attributes :title, :content, :locale, :meta_description, :meta_title,
8
+ :slug, :type
9
+
10
+ has_many :cms_sections, serializer: :cms_section
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class CmsSectionSerializer < BaseSerializer
5
+ set_type :cms_section
6
+
7
+ attributes :name, :content, :settings, :link, :fit, :type, :position
8
+
9
+ Spree::CmsSection::IMAGE_COUNT.each do |count|
10
+ Spree::CmsSection::IMAGE_SIZE.each do |size|
11
+ attribute "img_#{count}_#{size}".to_sym do |section|
12
+ if section.send("image_#{count}").attached? && section.send("img_#{count}_#{size}").present?
13
+ url_helpers = Rails.application.routes.url_helpers
14
+ url_helpers.rails_representation_path(section.send("img_#{count}_#{size}"), only_path: true)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ attribute :is_fullscreen do |section|
21
+ section.fullscreen?
22
+ end
23
+
24
+ belongs_to :linked_resource, polymorphic: true
25
+ end
26
+ end
27
+ end
28
+ end
@@ -7,16 +7,16 @@ module Spree
7
7
  attributes :iso, :iso3, :iso_name, :name, :states_required,
8
8
  :zipcode_required
9
9
 
10
- attribute :default do |object|
11
- object.default?
10
+ attribute :default do |object, params|
11
+ object.default?(params[:store])
12
12
  end
13
13
 
14
14
  has_many :states, if: proc { |_record, params| params && params[:include_states] }
15
15
 
16
16
  has_many :checkout_zone_applicable_states,
17
17
  serializer: ::Spree::V2::Storefront::StateSerializer,
18
- if: proc { |_record, params| params && params[:current_store].present? } do |object, params|
19
- params[:current_store].states_available_for_checkout(object)
18
+ if: proc { |_record, params| params && params[:store].present? } do |object, params|
19
+ params[:store].states_available_for_checkout(object)
20
20
  end
21
21
  end
22
22
  end
@@ -4,6 +4,8 @@ module Spree
4
4
  class EstimatedShippingRateSerializer < BaseSerializer
5
5
  set_type :shipping_rate
6
6
 
7
+ cache_options store: nil
8
+
7
9
  attributes :name, :selected, :cost, :tax_amount, :shipping_method_id
8
10
 
9
11
  attribute :final_price do |shipping_rate|
@@ -0,0 +1,43 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class MenuItemSerializer < BaseSerializer
5
+ set_type :menu_item
6
+
7
+ attributes :code, :name, :subtitle, :link, :new_window, :lft, :rgt, :depth
8
+
9
+ attribute :is_container do |menu_item|
10
+ menu_item.container?
11
+ end
12
+
13
+ attribute :is_root do |menu_item|
14
+ menu_item.root?
15
+ end
16
+
17
+ attribute :is_child do |menu_item|
18
+ menu_item.child?
19
+ end
20
+
21
+ attribute :is_leaf do |menu_item|
22
+ menu_item.leaf?
23
+ end
24
+
25
+ has_one :image,
26
+ object_method_name: :icon,
27
+ id_method_name: :icon_id,
28
+ record_type: :image,
29
+ serializer: :image
30
+
31
+ belongs_to :menu, serializer: :menu
32
+ belongs_to :parent, record_type: :menu_item, serializer: :menu_item
33
+ belongs_to :linked_resource, polymorphic: {
34
+ Spree::Cms::Pages::StandardPage => :cms_page,
35
+ Spree::Cms::Pages::FeaturePage => :cms_page,
36
+ Spree::Cms::Pages::Homepage => :cms_page
37
+ }
38
+
39
+ has_many :children, record_type: :menu_item, serializer: :menu_item
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class MenuSerializer < BaseSerializer
5
+ set_type :menu
6
+
7
+ attributes :name, :location, :locale
8
+
9
+ has_many :menu_items
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,7 +4,7 @@ module Spree
4
4
  class ProductPropertySerializer < BaseSerializer
5
5
  set_type :product_property
6
6
 
7
- attribute :value
7
+ attribute :value, :filter_param
8
8
 
9
9
  attribute :name do |product_property|
10
10
  product_property.property_name
@@ -47,20 +47,29 @@ module Spree
47
47
  has_many :variants
48
48
  has_many :option_types
49
49
  has_many :product_properties
50
- has_many :taxons
50
+
51
+ has_many :taxons, serializer: :taxon, record_type: :taxon do |object, params|
52
+ object.taxons_for_store(params[:store])
53
+ end
51
54
 
52
55
  # all images from all variants
53
56
  has_many :images,
54
- object_method_name: :variant_images,
55
- id_method_name: :variant_image_ids,
56
- record_type: :image,
57
- serializer: :image
58
-
59
- has_one :default_variant,
60
- object_method_name: :default_variant,
61
- id_method_name: :default_variant_id,
62
- record_type: :variant,
63
- serializer: :variant
57
+ object_method_name: :variant_images,
58
+ id_method_name: :variant_image_ids,
59
+ record_type: :image,
60
+ serializer: :image
61
+
62
+ has_one :default_variant,
63
+ object_method_name: :default_variant,
64
+ id_method_name: :default_variant_id,
65
+ record_type: :variant,
66
+ serializer: :variant
67
+
68
+ has_one :primary_variant,
69
+ object_method_name: :master,
70
+ id_method_name: :master_id,
71
+ record_type: :variant,
72
+ serializer: :variant
64
73
  end
65
74
  end
66
75
  end
@@ -8,7 +8,17 @@ module Spree
8
8
  :twitter, :instagram, :default_locale, :customer_support_email, :default_country_id, :description,
9
9
  :address, :contact_phone, :supported_locales
10
10
 
11
+ has_many :menus
12
+ has_many :cms_pages
13
+
11
14
  has_one :default_country, serializer: :country, record_type: :country, id_method_name: :default_country_id
15
+
16
+ attribute :favicon_path do |store|
17
+ if store.favicon_image.attached?
18
+ url_helpers = Rails.application.routes.url_helpers
19
+ url_helpers.rails_representation_path(store.favicon, only_path: true)
20
+ end
21
+ end
12
22
  end
13
23
  end
14
24
  end
@@ -23,13 +23,14 @@ module Spree
23
23
  belongs_to :taxonomy, record_type: :taxonomy
24
24
 
25
25
  has_many :children, record_type: :taxon, serializer: :taxon
26
- has_many :products, record_type: :product
26
+ has_many :products, record_type: :product,
27
+ if: proc { |_taxon, params| params && params[:include_products] == true }
27
28
 
28
29
  has_one :image,
29
- object_method_name: :icon,
30
- id_method_name: :icon_id,
31
- record_type: :taxon_image,
32
- serializer: :taxon_image
30
+ object_method_name: :icon,
31
+ id_method_name: :icon_id,
32
+ record_type: :taxon_image,
33
+ serializer: :taxon_image
33
34
  end
34
35
  end
35
36
  end
@@ -2,6 +2,7 @@ Doorkeeper.configure do
2
2
  orm :active_record
3
3
  use_refresh_token
4
4
  api_only
5
+ base_controller 'ActionController::API'
5
6
 
6
7
  skip_client_authentication_for_password_grant { true } if defined?(skip_client_authentication_for_password_grant)
7
8
 
@@ -23,9 +24,15 @@ Doorkeeper.configure do
23
24
  current_spree_user&.has_spree_role?('admin') || redirect_to(routes.root_url)
24
25
  end
25
26
 
26
- grant_flows %w(password)
27
+ grant_flows %w[password client_credentials]
28
+
29
+ allow_blank_redirect_uri true
30
+
31
+ handle_auth_errors :raise
27
32
 
28
33
  access_token_methods :from_bearer_authorization, :from_access_token_param
34
+
35
+ optional_scopes :admin, :write, :read
29
36
  end
30
37
 
31
38
  Doorkeeper::AccessGrant.class_eval do
@@ -0,0 +1,9 @@
1
+ Rabl.configure do |config|
2
+ config.include_json_root = false
3
+ config.include_child_root = false
4
+
5
+ # Motivation here it make it call as_json when rendering timestamps
6
+ # and therefore display miliseconds. Otherwise it would fall to
7
+ # JSON.dump which doesn't display the miliseconds
8
+ config.json_engine = ActiveSupport::JSON
9
+ end
@@ -26,7 +26,7 @@ en:
26
26
  cannot_ready: "Cannot ready shipment."
27
27
  stock_location_required: "A stock_location_id parameter must be provided in order to retrieve stock movements."
28
28
  invalid_taxonomy_id: "Invalid taxonomy id."
29
- shipment_transfer_errors_occurred: "Following errors occured while attempting this action:"
29
+ shipment_transfer_errors_occurred: "Following errors occurred while attempting this action:"
30
30
  negative_quantity: "quantity is negative"
31
31
  wrong_shipment_target: "target shipment is the same as original shipment"
32
32
 
data/config/routes.rb CHANGED
@@ -128,7 +128,7 @@ Spree::Core::Engine.add_routes do
128
128
 
129
129
  namespace :v2 do
130
130
  namespace :storefront do
131
- resource :cart, controller: :cart, only: %i[show create] do
131
+ resource :cart, controller: :cart, only: %i[show create destroy] do
132
132
  post :add_item
133
133
  patch :empty
134
134
  delete 'remove_line_item/:line_item_id', to: 'cart#remove_line_item', as: :cart_remove_line_item
@@ -149,11 +149,11 @@ Spree::Core::Engine.add_routes do
149
149
  get :shipping_rates
150
150
  end
151
151
 
152
- resource :account, controller: :account, only: %i[show]
152
+ resource :account, controller: :account, only: %i[show create update]
153
153
 
154
154
  namespace :account do
155
155
  resources :addresses, controller: :addresses
156
- resources :credit_cards, controller: :credit_cards, only: %i[index show]
156
+ resources :credit_cards, controller: :credit_cards, only: %i[index show destroy]
157
157
  resources :orders, controller: :orders, only: %i[index show]
158
158
  end
159
159
 
@@ -163,6 +163,118 @@ Spree::Core::Engine.add_routes do
163
163
  resources :products, only: %i[index show]
164
164
  resources :taxons, only: %i[index show], id: /.+/
165
165
  get '/stores/:code', to: 'stores#show', as: :store
166
+
167
+ resources :menus, only: %i[index show]
168
+ resources :cms_pages, only: %i[index show]
169
+ end
170
+
171
+ namespace :platform do
172
+ # Promotions API
173
+ resources :promotions
174
+
175
+ # Returns API
176
+ resources :customer_returns
177
+ resources :reimbursements
178
+ resources :return_authorizations do
179
+ member do
180
+ put :add
181
+ put :cancel
182
+ put :receive
183
+ end
184
+ end
185
+
186
+ # Product Catalog API
187
+ resources :products
188
+ resources :taxonomies
189
+ resources :taxons
190
+ resources :classifications do
191
+ member do
192
+ put :reposition
193
+ end
194
+ end
195
+ resources :images
196
+ resources :variants
197
+ resources :properties
198
+ resources :product_properties
199
+ resources :option_types
200
+ resources :option_values
201
+
202
+ # Order API
203
+ resources :orders do
204
+ member do
205
+ put :next
206
+ put :advance
207
+ put :approve
208
+ put :cancel
209
+ put :empty
210
+ put :apply_coupon_code
211
+ put :remove_coupon_code
212
+ end
213
+ end
214
+ resources :line_items
215
+ resources :payments do
216
+ member do
217
+ put :authorize
218
+ put :capture
219
+ put :purchase
220
+ put :void
221
+ put :credit
222
+ end
223
+ end
224
+
225
+ # Geo API
226
+ resources :zones
227
+ resources :countries, only: [:index, :show]
228
+ resources :states, only: [:index, :show]
229
+
230
+ # Shipment API
231
+ resources :shipments do
232
+ collection do
233
+ post 'transfer_to_location'
234
+ post 'transfer_to_shipment'
235
+ end
236
+ member do
237
+ put :ready
238
+ put :ship
239
+ put :add
240
+ put :remove
241
+ end
242
+ end
243
+
244
+ # Inventory API
245
+ resources :inventory_units
246
+ resources :stock_items
247
+ resources :stock_locations
248
+ resources :stock_movements
249
+
250
+ # User API
251
+ resources :users
252
+ resources :credit_cards
253
+ resources :addresses
254
+
255
+ # Menu API
256
+ resources :menus
257
+ resource :menu_items do
258
+ member do
259
+ patch :reposition
260
+ end
261
+ end
262
+
263
+ # CMS Pages API
264
+ resources :cms_pages do
265
+ member do
266
+ patch :toggle_visibility
267
+ end
268
+ end
269
+
270
+ resource :cms_sections do
271
+ member do
272
+ patch :reposition
273
+ end
274
+ end
275
+
276
+ # Store API
277
+ resources :stores
166
278
  end
167
279
  end
168
280