spree_api 4.1.13 → 4.2.0.rc4

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v2/storefront/order_concern.rb +4 -0
  3. data/app/controllers/spree/api/base_controller.rb +9 -5
  4. data/app/controllers/spree/api/errors_controller.rb +1 -1
  5. data/app/controllers/spree/api/v1/shipments_controller.rb +16 -6
  6. data/app/controllers/spree/api/v1/taxons_controller.rb +6 -1
  7. data/app/controllers/spree/api/v1/users_controller.rb +35 -9
  8. data/app/controllers/spree/api/v2/base_controller.rb +6 -25
  9. data/app/controllers/spree/api/v2/resource_controller.rb +82 -0
  10. data/app/controllers/spree/api/v2/storefront/account/addresses_controller.rb +3 -11
  11. data/app/controllers/spree/api/v2/storefront/account/credit_cards_controller.rb +7 -15
  12. data/app/controllers/spree/api/v2/storefront/account/orders_controller.rb +5 -24
  13. data/app/controllers/spree/api/v2/storefront/account_controller.rb +1 -5
  14. data/app/controllers/spree/api/v2/storefront/countries_controller.rb +9 -16
  15. data/app/controllers/spree/api/v2/storefront/order_status_controller.rb +1 -5
  16. data/app/controllers/spree/api/v2/storefront/products_controller.rb +4 -14
  17. data/app/controllers/spree/api/v2/storefront/stores_controller.rb +2 -6
  18. data/app/controllers/spree/api/v2/storefront/taxons_controller.rb +4 -14
  19. data/app/helpers/spree/api/api_helpers.rb +4 -3
  20. data/app/models/spree/api_dependencies.rb +4 -2
  21. data/app/serializers/spree/v2/storefront/address_serializer.rb +8 -3
  22. data/app/serializers/spree/v2/storefront/base_serializer.rb +1 -1
  23. data/app/serializers/spree/v2/storefront/country_serializer.rb +6 -0
  24. data/app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb +3 -1
  25. data/app/serializers/spree/v2/storefront/product_property_serializer.rb +7 -2
  26. data/app/serializers/spree/v2/storefront/product_serializer.rb +17 -6
  27. data/app/serializers/spree/v2/storefront/shipment_serializer.rb +3 -1
  28. data/app/serializers/spree/v2/storefront/shipping_rate_serializer.rb +3 -1
  29. data/app/serializers/spree/v2/storefront/store_serializer.rb +3 -1
  30. data/app/serializers/spree/v2/storefront/taxon_serializer.rb +11 -3
  31. data/app/serializers/spree/v2/storefront/user_serializer.rb +3 -1
  32. data/app/serializers/spree/v2/storefront/variant_serializer.rb +13 -5
  33. data/app/views/spree/api/v1/products/show.rabl +4 -0
  34. data/config/locales/en.yml +1 -1
  35. data/docs/oauth/index.yml +78 -15
  36. data/docs/v2/storefront/index.yaml +3409 -672
  37. data/lib/spree/api/controller_setup.rb +0 -1
  38. data/lib/spree_api.rb +1 -1
  39. data/spree_api.gemspec +2 -2
  40. metadata +14 -13
@@ -2,17 +2,7 @@ module Spree
2
2
  module Api
3
3
  module V2
4
4
  module Storefront
5
- class CountriesController < ::Spree::Api::V2::BaseController
6
- include Spree::Api::V2::CollectionOptionsHelpers
7
-
8
- def index
9
- render_serialized_payload { serialize_collection(collection) }
10
- end
11
-
12
- def show
13
- render_serialized_payload { serialize_resource(resource) }
14
- end
15
-
5
+ class CountriesController < ::Spree::Api::V2::ResourceController
16
6
  private
17
7
 
18
8
  def serialize_collection(collection)
@@ -24,12 +14,15 @@ module Spree
24
14
  resource,
25
15
  include: resource_includes,
26
16
  fields: sparse_fields,
27
- params: { include_states: true }
17
+ params: resource_serializer_params
28
18
  ).serializable_hash
29
19
  end
30
20
 
31
- def collection
32
- collection_finder.new(scope, params).call
21
+ def resource_serializer_params
22
+ {
23
+ include_states: true,
24
+ current_store: current_store
25
+ }
33
26
  end
34
27
 
35
28
  def resource
@@ -52,8 +45,8 @@ module Spree
52
45
  Spree::Api::Dependencies.storefront_country_finder.constantize
53
46
  end
54
47
 
55
- def scope
56
- Spree::Country.accessible_by(current_ability, :show)
48
+ def model_class
49
+ Spree::Country
57
50
  end
58
51
  end
59
52
  end
@@ -2,15 +2,11 @@ module Spree
2
2
  module Api
3
3
  module V2
4
4
  module Storefront
5
- class OrderStatusController < ::Spree::Api::V2::BaseController
5
+ class OrderStatusController < ::Spree::Api::V2::ResourceController
6
6
  include Spree::Api::V2::Storefront::OrderConcern
7
7
 
8
8
  before_action :ensure_order_token
9
9
 
10
- def show
11
- render_serialized_payload { serialize_resource(resource) }
12
- end
13
-
14
10
  private
15
11
 
16
12
  def resource
@@ -2,21 +2,11 @@ module Spree
2
2
  module Api
3
3
  module V2
4
4
  module Storefront
5
- class ProductsController < ::Spree::Api::V2::BaseController
6
- include Spree::Api::V2::CollectionOptionsHelpers
7
-
8
- def index
9
- render_serialized_payload { serialize_collection(paginated_collection) }
10
- end
11
-
12
- def show
13
- render_serialized_payload { serialize_resource(resource) }
14
- end
15
-
5
+ class ProductsController < ::Spree::Api::V2::ResourceController
16
6
  private
17
7
 
18
8
  def sorted_collection
19
- collection_sorter.new(collection, params, current_currency).call
9
+ collection_sorter.new(collection, current_currency, params, allowed_sort_attributes).call
20
10
  end
21
11
 
22
12
  def collection
@@ -43,8 +33,8 @@ module Spree
43
33
  Spree::Api::Dependencies.storefront_product_serializer.constantize
44
34
  end
45
35
 
46
- def scope
47
- Spree::Product.accessible_by(current_ability, :show).includes(scope_includes)
36
+ def model_class
37
+ Spree::Product
48
38
  end
49
39
 
50
40
  def scope_includes
@@ -2,14 +2,10 @@ module Spree
2
2
  module Api
3
3
  module V2
4
4
  module Storefront
5
- class StoresController < ::Spree::Api::V2::BaseController
6
- def show
7
- render_serialized_payload { serialize_resource(resource) }
8
- end
9
-
5
+ class StoresController < ::Spree::Api::V2::ResourceController
10
6
  private
11
7
 
12
- def scope
8
+ def model_class
13
9
  Spree::Store
14
10
  end
15
11
 
@@ -2,17 +2,7 @@ module Spree
2
2
  module Api
3
3
  module V2
4
4
  module Storefront
5
- class TaxonsController < ::Spree::Api::V2::BaseController
6
- include Spree::Api::V2::CollectionOptionsHelpers
7
-
8
- def index
9
- render_serialized_payload { serialize_collection(paginated_collection) }
10
- end
11
-
12
- def show
13
- render_serialized_payload { serialize_resource(resource) }
14
- end
15
-
5
+ class TaxonsController < ::Spree::Api::V2::ResourceController
16
6
  private
17
7
 
18
8
  def collection_serializer
@@ -39,8 +29,8 @@ module Spree
39
29
  scope.find_by(permalink: params[:id]) || scope.find(params[:id])
40
30
  end
41
31
 
42
- def scope
43
- Spree::Taxon.accessible_by(current_ability, :show).includes(scope_includes)
32
+ def model_class
33
+ Spree::Taxon
44
34
  end
45
35
 
46
36
  def scope_includes
@@ -51,7 +41,7 @@ module Spree
51
41
  children: node_includes,
52
42
  taxonomy: [root: node_includes],
53
43
  products: [],
54
- icon: []
44
+ icon: [attachment_attachment: :blob]
55
45
  }
56
46
  end
57
47
  end
@@ -116,7 +116,7 @@ module Spree
116
116
  @@address_attributes = [
117
117
  :id, :firstname, :lastname, :full_name, :address1, :address2, :city,
118
118
  :zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
119
- :state_name, :state_text
119
+ :label, :state_name, :state_text
120
120
  ]
121
121
 
122
122
  @@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
@@ -161,8 +161,9 @@ module Spree
161
161
 
162
162
  @@store_attributes = [
163
163
  :id, :name, :url, :meta_description, :meta_keywords, :seo_title,
164
- :mail_from_address, :default_currency, :code, :default,
165
- :facebook, :twitter, :instagram
164
+ :mail_from_address, :customer_support_email, :default_currency,
165
+ :code, :default, :facebook, :twitter, :instagram,
166
+ :supported_currencies
166
167
  ]
167
168
 
168
169
  @@tag_attributes = [:id, :name]
@@ -15,7 +15,8 @@ module Spree
15
15
  :storefront_product_serializer, :storefront_taxon_serializer, :storefront_taxon_finder, :storefront_find_by_variant_finder,
16
16
  :storefront_cart_update_service, :storefront_cart_estimate_shipping_rates_service, :storefront_estimated_shipment_serializer,
17
17
  :storefront_store_serializer, :storefront_address_serializer, :storefront_order_serializer,
18
- :storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder
18
+ :storefront_account_create_address_service, :storefront_account_update_address_service, :storefront_address_finder,
19
+ :storefront_collection_sorter
19
20
  ].freeze
20
21
 
21
22
  attr_accessor *INJECTION_POINTS
@@ -69,7 +70,8 @@ module Spree
69
70
  @storefront_order_serializer = 'Spree::V2::Storefront::CartSerializer'
70
71
 
71
72
  # sorters
72
- @storefront_order_sorter = Spree::Dependencies.order_sorter
73
+ @storefront_collection_sorter = Spree::Dependencies.collection_sorter
74
+ @storefront_order_sorter = Spree::Dependencies.collection_sorter
73
75
  @storefront_products_sorter = Spree::Dependencies.products_sorter
74
76
 
75
77
  # paginators
@@ -5,10 +5,15 @@ module Spree
5
5
  set_type :address
6
6
 
7
7
  attributes :firstname, :lastname, :address1, :address2, :city, :zipcode, :phone, :state_name,
8
- :company, :country_name, :country_iso3, :country_iso
8
+ :company, :country_name, :country_iso3, :country_iso, :label
9
9
 
10
- attribute :state_code, &:state_abbr
11
- attribute :state_name, &:state_name_text
10
+ attribute :state_code do |address|
11
+ address.state_abbr
12
+ end
13
+
14
+ attribute :state_name do |address|
15
+ address.state_name_text
16
+ end
12
17
  end
13
18
  end
14
19
  end
@@ -2,7 +2,7 @@ module Spree
2
2
  module V2
3
3
  module Storefront
4
4
  class BaseSerializer
5
- include FastJsonapi::ObjectSerializer
5
+ include JSONAPI::Serializer
6
6
  end
7
7
  end
8
8
  end
@@ -12,6 +12,12 @@ module Spree
12
12
  end
13
13
 
14
14
  has_many :states, if: proc { |_record, params| params && params[:include_states] }
15
+
16
+ has_many :checkout_zone_applicable_states,
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)
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -6,7 +6,9 @@ module Spree
6
6
 
7
7
  attributes :name, :selected, :cost, :tax_amount, :shipping_method_id
8
8
 
9
- attribute :final_price, &:cost
9
+ attribute :final_price do |shipping_rate|
10
+ shipping_rate.cost
11
+ end
10
12
 
11
13
  attributes :display_cost, :display_final_price do |object, params|
12
14
  Spree::Money.new(object.cost, currency: params[:currency])
@@ -6,8 +6,13 @@ module Spree
6
6
 
7
7
  attribute :value
8
8
 
9
- attribute :name, &:property_name
10
- attribute :description, &:property_presentation
9
+ attribute :name do |product_property|
10
+ product_property.property_name
11
+ end
12
+
13
+ attribute :description do |product_property|
14
+ product_property.property_presentation
15
+ end
11
16
  end
12
17
  end
13
18
  end
@@ -5,13 +5,24 @@ module Spree
5
5
  set_type :product
6
6
 
7
7
  attributes :name, :description, :price, :currency, :display_price,
8
- :available_on, :slug, :meta_description, :meta_keywords,
9
- :updated_at
8
+ :compare_at_price, :display_compare_at_price, :available_on,
9
+ :slug, :meta_description, :meta_keywords, :updated_at
10
10
 
11
- attribute :purchasable, &:purchasable?
12
- attribute :in_stock, &:in_stock?
13
- attribute :backorderable, &:backorderable?
14
- attribute :available, &:available?
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
15
26
 
16
27
  has_many :variants
17
28
  has_many :option_types
@@ -7,7 +7,9 @@ module Spree
7
7
  attributes :number, :final_price, :display_final_price,
8
8
  :state, :shipped_at, :tracking_url
9
9
 
10
- attribute :free, &:free?
10
+ attribute :free do |shipment|
11
+ shipment.free?
12
+ end
11
13
 
12
14
  has_many :shipping_rates
13
15
 
@@ -7,7 +7,9 @@ module Spree
7
7
  attributes :name, :selected, :final_price, :display_final_price, :cost,
8
8
  :display_cost, :tax_amount, :display_tax_amount, :shipping_method_id
9
9
 
10
- attribute :free, &:free?
10
+ attribute :free do |shipping_rate|
11
+ shipping_rate.free?
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -6,7 +6,9 @@ module Spree
6
6
 
7
7
  attributes :name, :url, :meta_description, :meta_keywords, :seo_title, :default_currency, :default, :supported_currencies, :facebook,
8
8
  :twitter, :instagram, :default_locale, :customer_support_email, :default_country_id, :description,
9
- :address, :contact_phone, :contact_email
9
+ :address, :contact_phone
10
+
11
+ has_one :default_country, serializer: :country, record_type: :country, id_method_name: :default_country_id
10
12
  end
11
13
  end
12
14
  end
@@ -7,9 +7,17 @@ module Spree
7
7
  attributes :name, :pretty_name, :permalink, :seo_title, :description, :meta_title, :meta_description,
8
8
  :meta_keywords, :left, :right, :position, :depth, :updated_at
9
9
 
10
- attribute :is_root, &:root?
11
- attribute :is_child, &:child?
12
- attribute :is_leaf, &:leaf?
10
+ attribute :is_root do |taxon|
11
+ taxon.root?
12
+ end
13
+
14
+ attribute :is_child do |taxon|
15
+ taxon.child?
16
+ end
17
+
18
+ attribute :is_leaf do |taxon|
19
+ taxon.leaf?
20
+ end
13
21
 
14
22
  belongs_to :parent, record_type: :taxon, serializer: :taxon
15
23
  belongs_to :taxonomy, record_type: :taxonomy
@@ -6,7 +6,9 @@ module Spree
6
6
 
7
7
  attributes :email
8
8
 
9
- attribute :store_credits, &:total_available_store_credit
9
+ attribute :store_credits do |user|
10
+ user.total_available_store_credit
11
+ end
10
12
 
11
13
  attribute :completed_orders do |object|
12
14
  object.orders.complete.count
@@ -4,12 +4,20 @@ module Spree
4
4
  class VariantSerializer < BaseSerializer
5
5
  set_type :variant
6
6
 
7
- attributes :name, :sku, :price, :currency, :display_price, :weight, :height,
8
- :width, :depth, :is_master, :options_text, :slug, :description
7
+ attributes :sku, :price, :currency, :display_price, :weight, :height,
8
+ :width, :depth, :is_master, :options_text
9
9
 
10
- attribute :purchasable, &:purchasable?
11
- attribute :in_stock, &:in_stock?
12
- attribute :backorderable, &:backorderable?
10
+ attribute :purchasable do |variant|
11
+ variant.purchasable?
12
+ end
13
+
14
+ attribute :in_stock do |variant|
15
+ variant.in_stock?
16
+ end
17
+
18
+ attribute :backorderable do |variant|
19
+ variant.backorderable?
20
+ end
13
21
 
14
22
  belongs_to :product
15
23
  has_many :images
@@ -6,6 +6,10 @@ attributes *product_attributes
6
6
  node(:display_price) { |p| p.display_price.to_s }
7
7
  node(:has_variants, &:has_variants?)
8
8
  node(:taxon_ids, &:taxon_ids)
9
+ node(:display_current_currency_price) do |product|
10
+ price = product.price_in(current_currency)
11
+ Spree::Money.new(price.amount, currency: current_currency).to_s
12
+ end
9
13
 
10
14
  child master: :master do
11
15
  extends 'spree/api/v1/variants/small'
@@ -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_occured: "Following errors occured while attempting this action:"
29
+ shipment_transfer_errors_occurred: "Following errors occured 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
 
@@ -1,17 +1,24 @@
1
1
  openapi: 3.0.0
2
2
  servers:
3
- - url: 'http://localhost:3000/spree_oauth'
3
+ - url: 'https://demo.spreecommerce.org'
4
+ description: demo
5
+ - url: 'http://localhost:3000'
6
+ description: localhost
4
7
  info:
5
8
  version: 1.0.0
6
9
  title: Spree OAuth 2.0 Authentication
7
- description: >-
8
- Spree uses the [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) gem
9
- for handling OAuth. This integration is built into `spree_api` gem.
10
+ description: "For API v2 Spree uses [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) gem for handling OAuth athentication. \n\nSpree supports new token creation and refreshing of existing tokens."
11
+ contact:
12
+ name: Spark Solutions
13
+ url: 'https://sparksolutions.co'
14
+ email: we@sparksolutions.co
15
+ license:
16
+ url: 'https://github.com/spree/spree/blob/master/license.md'
17
+ name: BSD-3-Clause
10
18
  paths:
11
- '/token':
19
+ /spree_oauth/token:
12
20
  post:
13
- description: >-
14
- Creates or refreshes a Bearer token required to authorize calls API calls
21
+ description: Creates or refreshes a Bearer token required to authorize calls API calls
15
22
  tags:
16
23
  - Token
17
24
  operationId: Create or Refresh Token
@@ -22,14 +29,40 @@ paths:
22
29
  application/json:
23
30
  schema:
24
31
  $ref: '#/components/schemas/Token'
32
+ examples:
33
+ create token:
34
+ value:
35
+ access_token: SfM3k8kq5Wkc6xz6rgMlsl-mbygJ1ptq4DR0Ah51vjA
36
+ token_type: Bearer
37
+ expires_in: 7200
38
+ refresh_token: SqJDIwX00fehqHxS6xmb-kzqAlrYe_0EHgekMexVT8k
39
+ created_at: 1581873931
40
+ refresh token:
41
+ value:
42
+ access_token: Es9lLPW2mVaDB80I-I_OdQCw3JfOT1s19YN1naFWx98
43
+ token_type: Bearer
44
+ expires_in: 7200
45
+ refresh_token: j92BxulqIIYtiiaBsuAM1TzGsGSVxaykT4kk8OYHGNY
46
+ created_at: 1581876572
25
47
  requestBody:
26
48
  required: true
27
49
  content:
28
- application/x-www-form-urlencoded:
50
+ application/json:
29
51
  schema:
30
52
  oneOf:
31
53
  - $ref: '#/components/schemas/CreateTokenBody'
32
54
  - $ref: '#/components/schemas/RefreshTokenBody'
55
+ examples:
56
+ create token:
57
+ value:
58
+ grant_type: password
59
+ username: spree@example.com
60
+ password: spree123
61
+ refresh token:
62
+ value:
63
+ grant_type: refresh_token
64
+ refresh_token: SqJDIwX00fehqHxS6xmb-kzqAlrYe_0EHgekMexVT8k
65
+ description: ''
33
66
  components:
34
67
  schemas:
35
68
  Token:
@@ -44,34 +77,64 @@ components:
44
77
  expires_in:
45
78
  type: integer
46
79
  example: 7200
47
- description: 'Time (in seconds) after which the access token will expire'
80
+ description: Time (in seconds) after which the access token will expire
48
81
  refresh_token:
49
82
  type: string
50
83
  example: f5d78642252eeb3f3001f67b196ac21a27afc030462a54060b0ebbdae2b8dc9c
51
84
  created_at:
52
85
  type: integer
53
86
  example: 1539863418
87
+ x-examples:
88
+ create token:
89
+ access_token: SfM3k8kq5Wkc6xz6rgMlsl-mbygJ1ptq4DR0Ah51vjA
90
+ token_type: Bearer
91
+ expires_in: 7200
92
+ refresh_token: SqJDIwX00fehqHxS6xmb-kzqAlrYe_0EHgekMexVT8k
93
+ created_at: 1581873931
94
+ refresh token:
95
+ access_token: Es9lLPW2mVaDB80I-I_OdQCw3JfOT1s19YN1naFWx98
96
+ token_type: Bearer
97
+ expires_in: 7200
98
+ refresh_token: j92BxulqIIYtiiaBsuAM1TzGsGSVxaykT4kk8OYHGNY
99
+ created_at: 1581876572
54
100
  CreateTokenBody:
101
+ type: object
102
+ x-examples:
103
+ example-1:
104
+ grant_type: password
105
+ username: spree@example.com
106
+ password: spree123
55
107
  properties:
56
108
  grant_type:
57
109
  type: string
58
110
  default: password
59
- description: >-
60
- Use `password` to create a token and `refresh_token` to refresh it
111
+ description: Use `password` to create a token and `refresh_token` to refresh it
61
112
  username:
62
113
  type: string
63
114
  description: User email address
64
- example: 'spree@example.com'
115
+ example: spree@example.com
65
116
  password:
66
117
  type: string
67
118
  description: User password
68
- example: 'spree123'
119
+ example: spree123
120
+ required:
121
+ - grant_type
122
+ - username
123
+ - password
69
124
  RefreshTokenBody:
125
+ type: object
70
126
  properties:
71
127
  grant_type:
72
128
  type: string
73
129
  default: refresh_token
74
130
  refresh_token:
75
131
  type: string
76
- description: Rerefresh token obtained from the old created token
77
- example: 27af95fd57a424e5d01aaf5eab1324a8d5c0ca57daf384fae39f811a5144330143301'
132
+ description: Refresh token obtained from the create token response
133
+ example: "27af95fd57a424e5d01aaf5eab1324a8d5c0ca57daf384fae39f811a5144330143301'"
134
+ required:
135
+ - grant_type
136
+ - refresh_token
137
+ x-examples:
138
+ example-1:
139
+ grant_type: refresh_token
140
+ refresh_token: SqJDIwX00fehqHxS6xmb-kzqAlrYe_0EHgekMexVT8k