spree_api 5.1.0.beta3 → 5.1.0.rc1

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: 372516f7b98eecd75dbb03724a3bc7472b9d09745502f5cf8980aff4bf511847
4
- data.tar.gz: 0e0f426db7f21e2efdec616e922e63efc5da81867117e64020be18ec5933b900
3
+ metadata.gz: a0f927e718e33bb6fd02e6700486268417da7fa69705112444a289cd2e0f6c02
4
+ data.tar.gz: 8882e1d01b9a4d13c2f53a7f59a965d9a82de59cc7b81d299c51e36d7f7e2a82
5
5
  SHA512:
6
- metadata.gz: e775c684859f3dde910518f1acd5ed7545215c2ee8ad5562a1085197c1a9c1ab064875fc4fe9827d56881622523be8f93d467a1c4d97d8ee315dd6efa8b80560
7
- data.tar.gz: 270e2536eef094252293a2888e75347e15446e6c405261cd6b8c57d3d24712e8361d9ce99a7d50622a9af8d384cf02bb0f29fcdd23ca19f7eff7ba02ecf4cd91
6
+ metadata.gz: a2cd84be93d0300cd3cb45a0093c70e373d725c7ada5bf9772931321b5c5a9e7b347fb29109e9d78d3a3f5ee5ade0e507e624695ddd5382a9b3e8a1a3fa20634
7
+ data.tar.gz: 7be8feeea237ce2247fa9ecb02a629342fb802a3351ec703f0b376aed4b729d63eba16a939ad6eebc62a7e5ab2bb96d4b5bcfd7dd03dc3e0cb30f08eb9ef1e64
@@ -20,6 +20,8 @@ module Spree
20
20
  rescue_from ArgumentError, with: :error_during_processing
21
21
  rescue_from ActionDispatch::Http::Parameters::ParseError, with: :error_during_processing
22
22
 
23
+ # Returns the content type for the API
24
+ # @return [String] The content type, eg 'application/vnd.api+json'
23
25
  def content_type
24
26
  Spree::Api::Config[:api_v2_content_type]
25
27
  end
@@ -42,18 +44,28 @@ module Spree
42
44
  ).serializable_hash
43
45
  end
44
46
 
47
+ # Returns a paginated collection
48
+ # @return [Array] The paginated collection
45
49
  def paginated_collection
46
50
  @paginated_collection ||= collection_paginator.new(sorted_collection, params).call
47
51
  end
48
52
 
53
+ # Returns the collection paginator
54
+ # @return [Class] The collection paginator class, default is Spree::Shared::Paginate
49
55
  def collection_paginator
50
56
  Spree::Api::Dependencies.storefront_collection_paginator.constantize
51
57
  end
52
58
 
59
+ # Renders a serialized payload with the given status code
60
+ # @param status [Integer] HTTP status code to return, eg 200, 201, 204
61
+ # @yield [Hash] The serialized data to render
53
62
  def render_serialized_payload(status = 200)
54
63
  render json: yield, status: status, content_type: content_type
55
64
  end
56
65
 
66
+ # Renders a serialized error payload with the given status code
67
+ # @param status [Integer] HTTP status code to return
68
+ # @yield [Hash] The serialized data to render
57
69
  def render_error_payload(error, status = 422)
58
70
  json = if error.is_a?(ActiveModel::Errors)
59
71
  { error: error.full_messages.to_sentence, errors: error.messages }
@@ -66,6 +78,9 @@ module Spree
66
78
  render json: json, status: status, content_type: content_type
67
79
  end
68
80
 
81
+ # Renders a serialized result payload with the given status code
82
+ # @param result [Object] The result to render
83
+ # @param ok_status [Integer] HTTP status code to return if the result is successful, eg 200, 201, 204
69
84
  def render_result(result, ok_status = 200)
70
85
  if result.success?
71
86
  render_serialized_payload(ok_status) { serialize_resource(result.value) }
@@ -74,6 +89,8 @@ module Spree
74
89
  end
75
90
  end
76
91
 
92
+ # Returns the current Spree user
93
+ # @return [Spree.user_class] The current Spree user
77
94
  def spree_current_user
78
95
  return nil unless doorkeeper_token
79
96
  return @spree_current_user if defined?(@spree_current_user)
@@ -86,10 +103,17 @@ module Spree
86
103
 
87
104
  alias try_spree_current_user spree_current_user # for compatibility with spree_legacy_frontend
88
105
 
106
+ # Authorizes the current Spree user for the given action and subject
107
+ # @param action [Symbol] The action to authorize
108
+ # @param subject [Object] The subject to authorize
109
+ # @param args [Array] Additional arguments to pass to the authorize! method
110
+ # @return [void]
89
111
  def spree_authorize!(action, subject, *args)
90
112
  authorize!(action, subject, *args)
91
113
  end
92
114
 
115
+ # Raises an AccessDenied error if the current Spree user is nil
116
+ # @raise [CanCan::AccessDenied] If the current Spree user is nil
93
117
  def require_spree_current_user
94
118
  raise CanCan::AccessDenied if spree_current_user.nil?
95
119
  end
@@ -100,10 +124,13 @@ module Spree
100
124
  end
101
125
 
102
126
  # this method can be extended in extensions or developer applications
127
+ # @return [Hash] The ability options
103
128
  def ability_options
104
129
  { store: current_store }
105
130
  end
106
131
 
132
+ # Returns the requested includes
133
+ # @return [Array] The requested includes
107
134
  def request_includes
108
135
  # if API user wants to receive only the bare-minimum
109
136
  # the API will return only the main resource without any included
@@ -114,6 +141,8 @@ module Spree
114
141
  end
115
142
  end
116
143
 
144
+ # Returns the resource includes, useful to avoid N+1 queries
145
+ # @return [Array] The resource includes, eg [:images, :variants]
117
146
  def resource_includes
118
147
  (request_includes || default_resource_includes).map(&:intern)
119
148
  end
@@ -127,6 +156,8 @@ module Spree
127
156
  []
128
157
  end
129
158
 
159
+ # Returns the JSON API sparse fields
160
+ # @return [Hash] The sparse fields, eg { product: [:name, :description] }
130
161
  def sparse_fields
131
162
  return unless params[:fields]&.respond_to?(:each)
132
163
 
@@ -137,6 +168,9 @@ module Spree
137
168
  fields.presence
138
169
  end
139
170
 
171
+ # Returns the serializer global params
172
+ # all of these params are passed down to the serializer
173
+ # @return [Hash] The serializer params
140
174
  def serializer_params
141
175
  {
142
176
  currency: current_currency,
@@ -149,28 +183,43 @@ module Spree
149
183
  }
150
184
  end
151
185
 
186
+ # Renders a 404 error payload
187
+ # @param exception [Exception] The exception to render
188
+ # @return [void]
152
189
  def record_not_found(exception)
153
190
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
154
191
 
155
192
  render_error_payload(I18n.t(:resource_not_found, scope: 'spree.api'), 404)
156
193
  end
157
194
 
195
+ # Renders a 403 error payload
196
+ # @param exception [Exception] The exception to render
197
+ # @return [void]
158
198
  def access_denied(exception)
159
199
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
160
200
 
161
201
  render_error_payload(exception.message, 403)
162
202
  end
163
203
 
204
+ # Renders a 401 error payload
205
+ # @param exception [Exception] The exception to render
206
+ # @return [void]
164
207
  def access_denied_401(exception)
165
208
  render_error_payload(exception.message, 401)
166
209
  end
167
210
 
211
+ # Renders a 500 error payload when a payment gateway error occurs
212
+ # @param exception [Exception] The exception to render
213
+ # @return [void]
168
214
  def gateway_error(exception)
169
215
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
170
216
 
171
217
  render_error_payload(exception.message)
172
218
  end
173
219
 
220
+ # Renders a 400 error payload when an error occurs during parameter parsing
221
+ # @param exception [Exception] The exception to render
222
+ # @return [void]
174
223
  def error_during_processing(exception)
175
224
  Rails.error.report(exception, context: { user_id: spree_current_user&.id }, source: 'spree.api')
176
225
 
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class GiftCardsController < ResourceController
6
+ private
7
+
8
+ def model_class
9
+ Spree::GiftCard
10
+ end
11
+
12
+ def permitted_resource_params
13
+ params.require(:gift_card).permit(permitted_gift_card_attributes)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -25,6 +25,11 @@ module Spree
25
25
  def spree_permitted_attributes
26
26
  super + [:password, :password_confirmation]
27
27
  end
28
+
29
+ # we need to override this method to avoid trying to create user role when creating a user
30
+ def ensure_current_store(_resource)
31
+ # do nothing
32
+ end
28
33
  end
29
34
  end
30
35
  end
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Platform
5
+ class GiftCardSerializer < BaseSerializer
6
+ include ResourceSerializerConcern
7
+
8
+ set_type :gift_card
9
+
10
+ belongs_to :user
11
+
12
+ has_many :orders
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -58,6 +58,7 @@ module Spree
58
58
  id_method_name: :ship_address_id,
59
59
  serializer: :address,
60
60
  record_type: :address
61
+ belongs_to :gift_card, serializer: :gift_card
61
62
  end
62
63
  end
63
64
  end
@@ -0,0 +1,14 @@
1
+ module Spree
2
+ module V2
3
+ module Storefront
4
+ class GiftCardSerializer < BaseSerializer
5
+ set_type :gift_card
6
+
7
+ attributes :amount, :amount_used, :amount_remaining, :display_amount, :display_amount_used,
8
+ :display_amount_remaining, :expires_at
9
+
10
+ attribute :code, &:display_code
11
+ end
12
+ end
13
+ end
14
+ end
@@ -29,6 +29,9 @@ en:
29
29
  digitals:
30
30
  missing_file: 'Missing Digital Item: attachment'
31
31
  unauthorized: Error, you are not authorized to access this asset
32
+ gift_card:
33
+ amount_not_valid: Gift card amount is not valid
34
+ not_found: Gift card is not found
32
35
  metadata:
33
36
  invalid_params: Public and private metadata parameters should be objects
34
37
  wishlist:
data/config/routes.rb CHANGED
@@ -205,6 +205,9 @@ Spree::Core::Engine.add_routes do
205
205
  resources :events, only: :index
206
206
  resources :subscribers
207
207
  end
208
+
209
+ # Gift Cards API
210
+ resources :gift_cards
208
211
  end
209
212
 
210
213
  namespace :data_feeds do
@@ -32,6 +32,10 @@ module Spree
32
32
  storefront_checkout_get_shipping_rates_service: -> { Spree::Dependencies.checkout_get_shipping_rates_service },
33
33
  storefront_checkout_select_shipping_method_service: -> { Spree::Dependencies.checkout_select_shipping_method_service },
34
34
 
35
+ # gift cards
36
+ storefront_gift_card_apply_service: -> { Spree::Dependencies.gift_card_apply_service },
37
+ storefront_gift_card_remove_service: -> { Spree::Dependencies.gift_card_remove_service },
38
+
35
39
  # account services
36
40
  storefront_account_create_service: -> { Spree::Dependencies.account_create_service },
37
41
  storefront_account_update_service: -> { Spree::Dependencies.account_update_service },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0.beta3
4
+ version: 5.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-05-29 00:00:00.000000000 Z
13
+ date: 2025-07-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jsonapi-rspec
@@ -102,14 +102,14 @@ dependencies:
102
102
  requirements:
103
103
  - - '='
104
104
  - !ruby/object:Gem::Version
105
- version: 5.1.0.beta3
105
+ version: 5.1.0.rc1
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - '='
111
111
  - !ruby/object:Gem::Version
112
- version: 5.1.0.beta3
112
+ version: 5.1.0.rc1
113
113
  description: Spree's API
114
114
  email:
115
115
  - hello@spreecommerce.org
@@ -137,6 +137,7 @@ files:
137
137
  - app/controllers/spree/api/v2/platform/data_feeds_controller.rb
138
138
  - app/controllers/spree/api/v2/platform/digital_links_controller.rb
139
139
  - app/controllers/spree/api/v2/platform/digitals_controller.rb
140
+ - app/controllers/spree/api/v2/platform/gift_cards_controller.rb
140
141
  - app/controllers/spree/api/v2/platform/line_items_controller.rb
141
142
  - app/controllers/spree/api/v2/platform/option_types_controller.rb
142
143
  - app/controllers/spree/api/v2/platform/option_values_controller.rb
@@ -225,6 +226,7 @@ files:
225
226
  - app/serializers/spree/api/v2/platform/data_feed_serializer.rb
226
227
  - app/serializers/spree/api/v2/platform/digital_link_serializer.rb
227
228
  - app/serializers/spree/api/v2/platform/digital_serializer.rb
229
+ - app/serializers/spree/api/v2/platform/gift_card_serializer.rb
228
230
  - app/serializers/spree/api/v2/platform/image_serializer.rb
229
231
  - app/serializers/spree/api/v2/platform/inventory_unit_serializer.rb
230
232
  - app/serializers/spree/api/v2/platform/line_item_serializer.rb
@@ -291,6 +293,7 @@ files:
291
293
  - app/serializers/spree/v2/storefront/credit_card_serializer.rb
292
294
  - app/serializers/spree/v2/storefront/digital_link_serializer.rb
293
295
  - app/serializers/spree/v2/storefront/estimated_shipping_rate_serializer.rb
296
+ - app/serializers/spree/v2/storefront/gift_card_serializer.rb
294
297
  - app/serializers/spree/v2/storefront/image_serializer.rb
295
298
  - app/serializers/spree/v2/storefront/line_item_serializer.rb
296
299
  - app/serializers/spree/v2/storefront/option_type_serializer.rb
@@ -364,9 +367,9 @@ licenses:
364
367
  - BSD-3-Clause
365
368
  metadata:
366
369
  bug_tracker_uri: https://github.com/spree/spree/issues
367
- changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.beta3
370
+ changelog_uri: https://github.com/spree/spree/releases/tag/v5.1.0.rc1
368
371
  documentation_uri: https://docs.spreecommerce.org/
369
- source_code_uri: https://github.com/spree/spree/tree/v5.1.0.beta3
372
+ source_code_uri: https://github.com/spree/spree/tree/v5.1.0.rc1
370
373
  post_install_message:
371
374
  rdoc_options: []
372
375
  require_paths: