spree_api 6.0.0.rc3 → 6.0.0.rc5

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 (156) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/spree/api/v3/admin/email_template_lookup.rb +6 -1
  3. data/app/controllers/concerns/spree/api/v3/admin/reporting_authorization.rb +17 -8
  4. data/app/controllers/concerns/spree/api/v3/admin/store_context.rb +7 -0
  5. data/app/controllers/concerns/spree/api/v3/admin_authentication.rb +61 -0
  6. data/app/controllers/concerns/spree/api/v3/allowed_redirect_url.rb +27 -0
  7. data/app/controllers/concerns/spree/api/v3/cart_resolvable.rb +8 -2
  8. data/app/controllers/concerns/spree/api/v3/error_handler.rb +49 -0
  9. data/app/controllers/concerns/spree/api/v3/params_normalizer.rb +76 -7
  10. data/app/controllers/concerns/spree/api/v3/scoped_authorization.rb +66 -5
  11. data/app/controllers/spree/api/v3/admin/companies/addresses_controller.rb +7 -1
  12. data/app/controllers/spree/api/v3/admin/companies/tax_exemption_certificates_controller.rb +11 -5
  13. data/app/controllers/spree/api/v3/admin/concerns/external_references.rb +3 -0
  14. data/app/controllers/spree/api/v3/admin/custom_fields_controller.rb +30 -8
  15. data/app/controllers/spree/api/v3/admin/customers/addresses_controller.rb +4 -0
  16. data/app/controllers/spree/api/v3/admin/customers_controller.rb +1 -6
  17. data/app/controllers/spree/api/v3/admin/exports_controller.rb +15 -3
  18. data/app/controllers/spree/api/v3/admin/gift_cards_controller.rb +1 -8
  19. data/app/controllers/spree/api/v3/admin/imports_controller.rb +12 -3
  20. data/app/controllers/spree/api/v3/admin/markets_controller.rb +3 -1
  21. data/app/controllers/spree/api/v3/admin/me_controller.rb +21 -1
  22. data/app/controllers/spree/api/v3/admin/oauth/application_tokens_controller.rb +56 -0
  23. data/app/controllers/spree/api/v3/admin/oauth/applications_controller.rb +55 -0
  24. data/app/controllers/spree/api/v3/admin/oauth/authorizations_controller.rb +294 -0
  25. data/app/controllers/spree/api/v3/admin/order_groups_controller.rb +1 -1
  26. data/app/controllers/spree/api/v3/admin/orders/fulfillments_controller.rb +8 -0
  27. data/app/controllers/spree/api/v3/admin/orders/items_controller.rb +1 -0
  28. data/app/controllers/spree/api/v3/admin/orders/returns_controller.rb +7 -0
  29. data/app/controllers/spree/api/v3/admin/orders_controller.rb +20 -7
  30. data/app/controllers/spree/api/v3/admin/package_types_controller.rb +2 -3
  31. data/app/controllers/spree/api/v3/admin/products/variants_controller.rb +3 -4
  32. data/app/controllers/spree/api/v3/admin/products_controller.rb +5 -3
  33. data/app/controllers/spree/api/v3/admin/purchase_orders_controller.rb +1 -0
  34. data/app/controllers/spree/api/v3/admin/reporting_controller.rb +20 -14
  35. data/app/controllers/spree/api/v3/admin/stock_levels_controller.rb +1 -1
  36. data/app/controllers/spree/api/v3/admin/store_controller.rb +1 -1
  37. data/app/controllers/spree/api/v3/admin/tags_controller.rb +8 -5
  38. data/app/controllers/spree/api/v3/admin/tax_exemption_reasons_controller.rb +58 -0
  39. data/app/controllers/spree/api/v3/admin/tax_rates_controller.rb +0 -1
  40. data/app/controllers/spree/api/v3/admin/translations/batches_controller.rb +17 -11
  41. data/app/controllers/spree/api/v3/admin/variants_controller.rb +96 -1
  42. data/app/controllers/spree/api/v3/oauth/authorizations_controller.rb +72 -0
  43. data/app/controllers/spree/api/v3/oauth/metadata_controller.rb +57 -0
  44. data/app/controllers/spree/api/v3/oauth/server_metadata_controller.rb +57 -0
  45. data/app/controllers/spree/api/v3/resource_controller.rb +36 -5
  46. data/app/controllers/spree/api/v3/seller/package_types_controller.rb +2 -2
  47. data/app/controllers/spree/api/v3/seller/products_controller.rb +7 -61
  48. data/app/controllers/spree/api/v3/seller/resource_controller.rb +2 -6
  49. data/app/controllers/spree/api/v3/store/carts/addresses_controller.rb +53 -0
  50. data/app/controllers/spree/api/v3/store/carts_controller.rb +7 -8
  51. data/app/controllers/spree/api/v3/store/companies/addresses_controller.rb +4 -0
  52. data/app/controllers/spree/api/v3/store/customer/addresses_controller.rb +4 -0
  53. data/app/controllers/spree/api/v3/store/customer/data_requests_controller.rb +19 -1
  54. data/app/controllers/spree/api/v3/store/customer/password_resets_controller.rb +3 -14
  55. data/app/controllers/spree/api/v3/store/data_request_confirmations_controller.rb +23 -0
  56. data/app/controllers/spree/api/v3/store/data_requests_controller.rb +56 -0
  57. data/app/controllers/spree/api/v3/store/newsletter_subscribers_controller.rb +2 -11
  58. data/app/request_schemas/spree/api/v3/admin/email_template_preview_request_schema.rb +4 -0
  59. data/app/request_schemas/spree/api/v3/admin/variant_request_schema.rb +21 -0
  60. data/app/request_schemas/spree/api/v3/seller/price_request_schema.rb +20 -0
  61. data/app/request_schemas/spree/api/v3/seller/variant_request_schema.rb +19 -0
  62. data/app/request_schemas/spree/api/v3/variant_request_schema.rb +8 -13
  63. data/app/serializers/spree/api/v3/address_owner_serializer.rb +27 -0
  64. data/app/serializers/spree/api/v3/address_serializer.rb +5 -1
  65. data/app/serializers/spree/api/v3/admin/address_owner_serializer.rb +10 -0
  66. data/app/serializers/spree/api/v3/admin/address_serializer.rb +1 -10
  67. data/app/serializers/spree/api/v3/admin/api_key_serializer.rb +1 -1
  68. data/app/serializers/spree/api/v3/admin/catalog_assignment_serializer.rb +1 -1
  69. data/app/serializers/spree/api/v3/admin/catalog_price_serializer.rb +1 -1
  70. data/app/serializers/spree/api/v3/admin/collection_rule_serializer.rb +1 -1
  71. data/app/serializers/spree/api/v3/admin/collection_serializer.rb +1 -1
  72. data/app/serializers/spree/api/v3/admin/commission_line_serializer.rb +2 -2
  73. data/app/serializers/spree/api/v3/admin/commission_rate_serializer.rb +1 -1
  74. data/app/serializers/spree/api/v3/admin/consent_record_serializer.rb +1 -1
  75. data/app/serializers/spree/api/v3/admin/email_template_serializer.rb +1 -1
  76. data/app/serializers/spree/api/v3/admin/fulfillment_serializer.rb +2 -0
  77. data/app/serializers/spree/api/v3/admin/line_item_serializer.rb +2 -0
  78. data/app/serializers/spree/api/v3/admin/oauth_access_token_serializer.rb +62 -0
  79. data/app/serializers/spree/api/v3/admin/oauth_application_serializer.rb +56 -0
  80. data/app/serializers/spree/api/v3/admin/oauth_consent_request_serializer.rb +25 -0
  81. data/app/serializers/spree/api/v3/admin/oauth_protected_resource_serializer.rb +27 -0
  82. data/app/serializers/spree/api/v3/admin/oauth_redirect_serializer.rb +17 -0
  83. data/app/serializers/spree/api/v3/admin/order_serializer.rb +1 -1
  84. data/app/serializers/spree/api/v3/admin/package_type_serializer.rb +3 -3
  85. data/app/serializers/spree/api/v3/admin/payment_capture_event_serializer.rb +16 -0
  86. data/app/serializers/spree/api/v3/admin/payment_serializer.rb +12 -1
  87. data/app/serializers/spree/api/v3/admin/permission_serializer.rb +1 -1
  88. data/app/serializers/spree/api/v3/admin/price_list_serializer.rb +1 -1
  89. data/app/serializers/spree/api/v3/admin/purchase_order_serializer.rb +1 -1
  90. data/app/serializers/spree/api/v3/admin/return_serializer.rb +2 -0
  91. data/app/serializers/spree/api/v3/admin/seller_requirement_status_serializer.rb +1 -1
  92. data/app/serializers/spree/api/v3/admin/seller_serializer.rb +2 -2
  93. data/app/serializers/spree/api/v3/admin/seller_transfer_serializer.rb +1 -1
  94. data/app/serializers/spree/api/v3/admin/shipping_label_serializer.rb +3 -3
  95. data/app/serializers/spree/api/v3/admin/stock_location_serializer.rb +1 -1
  96. data/app/serializers/spree/api/v3/admin/stock_receipt_item_serializer.rb +2 -2
  97. data/app/serializers/spree/api/v3/admin/stock_receipt_serializer.rb +1 -1
  98. data/app/serializers/spree/api/v3/admin/stock_transfer_serializer.rb +1 -1
  99. data/app/serializers/spree/api/v3/admin/store_serializer.rb +1 -0
  100. data/app/serializers/spree/api/v3/admin/tax_exemption_certificate_serializer.rb +7 -3
  101. data/app/serializers/spree/api/v3/admin/tax_exemption_reason_serializer.rb +20 -0
  102. data/app/serializers/spree/api/v3/admin/tax_identifier_serializer.rb +2 -2
  103. data/app/serializers/spree/api/v3/admin/tax_line_serializer.rb +1 -1
  104. data/app/serializers/spree/api/v3/admin/tax_rate_serializer.rb +1 -2
  105. data/app/serializers/spree/api/v3/admin/variant_serializer.rb +1 -1
  106. data/app/serializers/spree/api/v3/admin/webhook_delivery_serializer.rb +4 -1
  107. data/app/serializers/spree/api/v3/base_serializer.rb +41 -5
  108. data/app/serializers/spree/api/v3/claim_serializer.rb +1 -1
  109. data/app/serializers/spree/api/v3/collection_serializer.rb +1 -1
  110. data/app/serializers/spree/api/v3/company_invitation_serializer.rb +1 -1
  111. data/app/serializers/spree/api/v3/company_serializer.rb +1 -1
  112. data/app/serializers/spree/api/v3/data_request_confirmation_requested_event_serializer.rb +28 -0
  113. data/app/serializers/spree/api/v3/data_request_event_serializer.rb +1 -1
  114. data/app/serializers/spree/api/v3/data_request_serializer.rb +8 -4
  115. data/app/serializers/spree/api/v3/delivery_serializer.rb +1 -1
  116. data/app/serializers/spree/api/v3/delivery_zone_member_serializer.rb +1 -1
  117. data/app/serializers/spree/api/v3/discount_serializer.rb +1 -1
  118. data/app/serializers/spree/api/v3/file_upload_serializer.rb +1 -1
  119. data/app/serializers/spree/api/v3/fulfillment_serializer.rb +1 -1
  120. data/app/serializers/spree/api/v3/media_event_serializer.rb +1 -1
  121. data/app/serializers/spree/api/v3/media_serializer.rb +1 -1
  122. data/app/serializers/spree/api/v3/option_type_serializer.rb +1 -1
  123. data/app/serializers/spree/api/v3/order_group_serializer.rb +2 -2
  124. data/app/serializers/spree/api/v3/order_serializer.rb +4 -2
  125. data/app/serializers/spree/api/v3/payment_serializer.rb +1 -1
  126. data/app/serializers/spree/api/v3/product_filter_availability_option_serializer.rb +1 -1
  127. data/app/serializers/spree/api/v3/product_filter_option_serializer.rb +1 -1
  128. data/app/serializers/spree/api/v3/seller/address_serializer.rb +3 -2
  129. data/app/serializers/spree/api/v3/seller/order_serializer.rb +3 -3
  130. data/app/serializers/spree/api/v3/seller/package_type_serializer.rb +3 -3
  131. data/app/serializers/spree/api/v3/seller/profile_serializer.rb +2 -2
  132. data/app/serializers/spree/api/v3/seller/requirement_status_serializer.rb +1 -1
  133. data/app/serializers/spree/api/v3/seller/tax_identifier_serializer.rb +1 -1
  134. data/app/serializers/spree/api/v3/seller/variant_serializer.rb +1 -1
  135. data/app/serializers/spree/api/v3/shipping_label_event_serializer.rb +1 -1
  136. data/app/serializers/spree/api/v3/stock_movement_serializer.rb +1 -1
  137. data/app/serializers/spree/api/v3/stock_receipt_event_serializer.rb +1 -1
  138. data/app/serializers/spree/api/v3/variant_serializer.rb +2 -2
  139. data/app/services/spree/api/v3/filter_table.rb +22 -3
  140. data/app/services/spree/api/v3/request_schema.rb +64 -17
  141. data/config/locales/en.yml +1 -0
  142. data/config/routes.rb +80 -12
  143. data/lib/spree/api/agent_membership_map.rb +73 -0
  144. data/lib/spree/api/agent_resource_map.rb +350 -0
  145. data/lib/spree/api/agent_workflow_endpoints.rb +113 -0
  146. data/lib/spree/api/agent_write_schemas.rb +131 -0
  147. data/lib/spree/api/dependencies.rb +5 -4
  148. data/lib/spree/api/engine.rb +40 -0
  149. data/lib/spree/api/enum_types.rb +118 -0
  150. data/lib/spree/api/extension_fields.rb +167 -0
  151. data/lib/spree/api/oauth.rb +243 -0
  152. data/lib/spree/api/openapi/filter_documentation.rb +8 -1
  153. data/lib/spree/api/typelizer_generation.rb +5 -0
  154. data/lib/spree/api.rb +8 -0
  155. data/lib/typelizer/open_enums.rb +48 -10
  156. metadata +37 -6
@@ -0,0 +1,27 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ # Which address book an entry came out of. A checkout offering the
5
+ # buyer's own addresses beside their company's sites has to label the
6
+ # two, and the owner is the only thing that tells a warehouse from
7
+ # somebody's flat.
8
+ class AddressOwnerSerializer < BaseSerializer
9
+ typelize type: [:string, enum: %w[customer company seller], enum_type_name: 'AddressOwnerType'],
10
+ name: [:string, nullable: true]
11
+
12
+ attribute :type do |owner|
13
+ Spree::Base.polymorphic_api_type(owner.class.to_s)
14
+ end
15
+
16
+ # What to call the book. A company node answers with its own name, so
17
+ # a division's own sites and the headquarters sites it inherits are
18
+ # told apart rather than filed under one heading. A customer's book is
19
+ # the caller's own and needs no name — "your addresses" is the client's
20
+ # word for it, in the shopper's language.
21
+ attribute :name do |owner|
22
+ owner.name if owner.is_a?(Spree::Company)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -12,7 +12,7 @@ module Spree
12
12
  country_iso: [:string, deprecated: 'Use `country_code`. Removed in 6.1.'],
13
13
  country_name: :string,
14
14
  quick_checkout: :boolean, is_default_billing: :boolean, is_default_shipping: :boolean,
15
- label: [:string, nullable: true]
15
+ label: [:string, nullable: true], owner: { nullable: true }
16
16
 
17
17
  # What the address is filed under in whichever book owns it — a
18
18
  # customer's ("Home") or a company node's ("Northern Warehouse").
@@ -31,6 +31,10 @@ module Spree
31
31
  attribute :state_name do |address|
32
32
  address.state_name.presence || address.state&.name
33
33
  end
34
+
35
+ # The address book the entry belongs to. Null for an address in no
36
+ # book: one a guest typed in, or the copy a placed order keeps.
37
+ one :owner, resource: proc { Spree.api.address_owner_serializer }
34
38
  end
35
39
  end
36
40
  end
@@ -0,0 +1,10 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ class AddressOwnerSerializer < V3::AddressOwnerSerializer
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -7,8 +7,6 @@ module Spree
7
7
  %i[state_abbr country_iso].each { |key| _attributes.delete(key) }
8
8
 
9
9
  typelize customer_id: [:string, nullable: true],
10
- owner_id: [:string, nullable: true],
11
- owner_type: [:string, nullable: true],
12
10
  latitude: [:number, nullable: true],
13
11
  longitude: [:number, nullable: true],
14
12
  metadata: 'Record<string, unknown>'
@@ -29,14 +27,7 @@ module Spree
29
27
 
30
28
  prefixed_id_attributes customer_id: :customer_owner
31
29
 
32
- # Who the row belongs to — a customer's book, a company node's, or a
33
- # seller's billing address. `customer_id` above stays as the
34
- # customer-only shorthand the customers surface reads.
35
- prefixed_id_attributes :owner
36
-
37
- attribute :owner_type do |address|
38
- Spree::Base.polymorphic_api_type(address.owner_type)
39
- end
30
+ one :owner, resource: proc { Spree.api.admin_address_owner_serializer }
40
31
  end
41
32
  end
42
33
  end
@@ -12,7 +12,7 @@ module Spree
12
12
  # via {#plaintext_token} below — it is `nil` everywhere else.
13
13
  class ApiKeySerializer < V3::BaseSerializer
14
14
  typelize name: :string,
15
- key_type: [:string, enum: Spree::ApiKey::KEY_TYPES],
15
+ key_type: [:string, enum: Spree::ApiKey::KEY_TYPES, enum_type_name: 'ApiKeyType'],
16
16
  token_prefix: [:string, nullable: true],
17
17
  plaintext_token: [:string, nullable: true],
18
18
  scopes: [:string, multi: true],
@@ -3,7 +3,7 @@ module Spree
3
3
  module V3
4
4
  module Admin
5
5
  class CatalogAssignmentSerializer < V3::BaseSerializer
6
- typelize catalog_id: :string, assignable_type: :string, assignable_id: :string,
6
+ typelize catalog_id: :string, assignable_type: [:string, enum: Spree::CatalogAssignment::ASSIGNABLE_TYPES.map { |type| Spree::Base.polymorphic_api_type(type) }, enum_type_name: 'CatalogAssignableType'], assignable_id: :string,
7
7
  assignable_name: [:string, nullable: true]
8
8
 
9
9
  attributes created_at: :iso8601
@@ -17,7 +17,7 @@ module Spree
17
17
  _attributes.delete(:id)
18
18
 
19
19
  typelize id: 'string | null', label: 'string | null', sku: 'string | null',
20
- currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'], source: [:string, enum: Spree::CatalogPrice::SOURCES], break_count: :number
20
+ currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'], source: [:string, enum: Spree::CatalogPrice::SOURCES, enum_type_name: 'CatalogPriceSource'], break_count: :number
21
21
 
22
22
  # The variant this prices, so a row can name what it is showing —
23
23
  # a product's variants can be priced differently, and one figure
@@ -8,7 +8,7 @@ module Spree
8
8
  # wire shorthand (e.g. "tag"), matching every other typed-rule
9
9
  # serializer and what the writer accepts.
10
10
  class CollectionRuleSerializer < BaseSerializer
11
- typelize type: [:string, comment: 'Rule type. Built-in: tag, available_on, sale. Extensions may register more.'], value: [:string, nullable: true], match_policy: [:string, enum: Spree::CollectionRule::MATCH_POLICIES]
11
+ typelize type: [:string, comment: 'Rule type. Built-in: tag, available_on, sale. Extensions may register more.'], value: [:string, nullable: true], match_policy: [:string, enum: Spree::CollectionRule::MATCH_POLICIES, enum_type_name: 'CollectionRuleMatchPolicy']
12
12
 
13
13
  attributes :value, :match_policy
14
14
 
@@ -8,7 +8,7 @@ module Spree
8
8
  class CollectionSerializer < V3::CollectionSerializer
9
9
  include Spree::Api::V3::Admin::Translatable
10
10
 
11
- typelize automatic: :boolean, rules_match_policy: [:string, enum: Spree::Collection::RULES_MATCH_POLICIES],
11
+ typelize automatic: :boolean, rules_match_policy: [:string, enum: Spree::Collection::RULES_MATCH_POLICIES, enum_type_name: 'MatchPolicy'],
12
12
  metadata: 'Record<string, unknown>'
13
13
 
14
14
  attributes :automatic, :rules_match_policy, :metadata,
@@ -19,8 +19,8 @@ module Spree
19
19
  line_item_id: 'string | null',
20
20
  fulfillment_id: 'string | null',
21
21
  commission_rate_id: 'string | null',
22
- kind: [:string, enum: Spree::CommissionRate::KINDS],
23
- taxability_reason: 'string | null',
22
+ kind: [:string, enum: Spree::CommissionRate::KINDS, enum_type_name: 'CommissionKind'],
23
+ taxability_reason: [:string, nullable: true, enum: Spree::TaxLine::BUILT_IN_TAXABILITY_REASONS, enum_type_name: 'TaxabilityReason'],
24
24
  country_code: [:string, nullable: true, enum: Spree::IsoData.country_codes, enum_type_name: 'CountryCode'],
25
25
  state_code: 'string | null',
26
26
  currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode']
@@ -15,7 +15,7 @@ module Spree
15
15
  enabled: :boolean,
16
16
  position: :number,
17
17
  global: :boolean,
18
- kind: [:string, enum: Spree::CommissionRate::KINDS],
18
+ kind: [:string, enum: Spree::CommissionRate::KINDS, enum_type_name: 'CommissionKind'],
19
19
  amounts: 'Record<string, string>',
20
20
  bounds: 'Record<string, { min_amount: string | null; max_amount: string | null }>',
21
21
  tax_inclusive: :boolean,
@@ -5,7 +5,7 @@ module Spree
5
5
  # Admin API Consent Record Serializer
6
6
  # The evidence trail behind a customer's consent state.
7
7
  class ConsentRecordSerializer < BaseSerializer
8
- typelize purpose: :string, source: [:string, enum: Spree::ConsentRecord::SOURCES], accepted: :boolean,
8
+ typelize purpose: :string, source: [:string, enum: Spree::ConsentRecord::SOURCES, enum_type_name: 'ConsentSource'], accepted: :boolean,
9
9
  email: [:string, nullable: true],
10
10
  ip_address: [:string, nullable: true],
11
11
  recorded_at: [:string, nullable: true],
@@ -7,7 +7,7 @@ module Spree
7
7
  # default, and the draft in progress.
8
8
  class EmailTemplateSerializer < V3::BaseSerializer
9
9
  typelize key: :string,
10
- kind: [:string, enum: Spree::Emails::EditableTemplates::KINDS.map(&:to_s)],
10
+ kind: [:string, enum: Spree::Emails::EditableTemplates::KINDS.map(&:to_s), enum_type_name: 'EmailTemplateKind'],
11
11
  language: :string,
12
12
  customized: :boolean,
13
13
  customized_languages: [:string, multi: true],
@@ -3,6 +3,8 @@ module Spree
3
3
  module V3
4
4
  module Admin
5
5
  class FulfillmentSerializer < V3::FulfillmentSerializer
6
+ include Concerns::ExternalReferencesAttribute
7
+
6
8
  without_formatted_money
7
9
 
8
10
  # The Admin API has no guest gating — money fields inherited from the
@@ -5,6 +5,8 @@ module Spree
5
5
  # Admin API Line Item Serializer
6
6
  # Extends the store serializer with metadata visibility
7
7
  class LineItemSerializer < V3::LineItemSerializer
8
+ include Concerns::ExternalReferencesAttribute
9
+
8
10
  without_formatted_money
9
11
 
10
12
  # The Admin API has no guest gating — money fields inherited from the
@@ -0,0 +1,62 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # One person's live access through a connected client.
6
+ #
7
+ # The token itself is never serialized: it is a bearer credential, and
8
+ # the screen that lists connections only needs to say whose access it
9
+ # is and what that person approved.
10
+ class OauthAccessTokenSerializer < V3::BaseSerializer
11
+ typelize owner_id: [:string, nullable: true],
12
+ owner_type: [:string, nullable: true],
13
+ scopes: [:string, multi: true],
14
+ expired: :boolean
15
+
16
+ attributes created_at: :iso8601
17
+
18
+ # Who connected, without expanding: the id and the kind, so a
19
+ # client can render a reference or follow it.
20
+ attribute :owner_id do |token|
21
+ token.resource_owner.try(:prefixed_id)
22
+ end
23
+
24
+ attribute :owner_type do |token|
25
+ Spree::Base.polymorphic_api_type(token.resource_owner_type)
26
+ end
27
+
28
+ # Who connected, as the record itself rather than a summary of it,
29
+ # so the dashboard shows a person the way it does everywhere else:
30
+ # a name over an email, with an avatar.
31
+ #
32
+ # The serializer follows the record's kind, because a grant's owner
33
+ # is polymorphic — an admin today, a customer when a storefront
34
+ # client needs one. Alba hands the proc the object for exactly this.
35
+ one :resource_owner,
36
+ key: :owner,
37
+ resource: proc { |owner| owner_serializer_for(owner) },
38
+ if: proc { expand?('owner') }
39
+
40
+ # @param owner [Object] the grant's resource owner
41
+ # @return [Class] the serializer for that kind of owner
42
+ def self.owner_serializer_for(owner)
43
+ case Spree::Base.polymorphic_api_type(owner.class.name)
44
+ when 'customer' then Spree.api.admin_customer_serializer
45
+ else Spree.api.admin_admin_user_serializer
46
+ end.to_s.constantize
47
+ end
48
+
49
+ # What this person approved, as permission keys.
50
+ attribute :scopes do |token|
51
+ token.scopes.to_a
52
+ end
53
+
54
+ # Whether the current access token has lapsed. The connection is
55
+ # still live — a refresh mints another — but a merchant reading the
56
+ # list deserves to know which agents hold access right now.
57
+ attribute :expired, &:expired?
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,56 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # Admin API serializer for {Spree::OauthApplication}.
6
+ #
7
+ # Exposes `client_id` but never `secret`. The id is public by
8
+ # design — it is what a merchant pastes into a connector — while the
9
+ # secret is null here anyway, because every MCP client is a public
10
+ # client that proves itself with PKCE instead.
11
+ #
12
+ # `scopes` and `last_authorized_at` come from the live tokens rather than
13
+ # the registration — a client is registered once and granted per
14
+ # consent, so what the merchant approved lives on the token.
15
+ class OauthApplicationSerializer < V3::BaseSerializer
16
+ typelize name: :string,
17
+ client_id: :string,
18
+ connected: :boolean,
19
+ scopes: [:string, multi: true],
20
+ last_authorized_at: [:string, nullable: true],
21
+ authorized_at: [:string, nullable: true],
22
+ authorized_by: [:string, nullable: true],
23
+ redirect_uri: [:string, nullable: true]
24
+
25
+ attributes :name, :redirect_uri, created_at: :iso8601, updated_at: :iso8601
26
+
27
+ attribute :client_id, &:uid
28
+
29
+ # A registration nobody has connected and one whose access was
30
+ # revoked both carry no scopes, so the list alone cannot tell them
31
+ # apart — and a merchant pressing Revoke has to see that it worked.
32
+ attribute :connected, &:connected?
33
+
34
+ attribute :scopes do |application|
35
+ application.live_token_scopes
36
+ end
37
+
38
+ attribute :last_authorized_at do |application|
39
+ application.last_authorized_at&.iso8601
40
+ end
41
+
42
+ attribute :authorized_at do |application|
43
+ application.authorized_at&.iso8601
44
+ end
45
+
46
+ # Who allowed this, in the words a person is known by. On the screen
47
+ # that decides whether to revoke, the permission alone is half the
48
+ # story.
49
+ attribute :authorized_by do |application|
50
+ application.authorized_by.try(:actor_label)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # Admin API serializer for {Spree::OauthConsentRequest}.
6
+ #
7
+ # Alba directly rather than through {BaseSerializer}: a consent
8
+ # request is a computed view with no id to expose, and inheriting one
9
+ # would put a null `id` in every response.
10
+ class OauthConsentRequestSerializer
11
+ include Alba::Resource
12
+ include Typelizer::DSL
13
+
14
+ typelize client_name: :string,
15
+ scopes: [:string, multi: true],
16
+ grantable_scopes: [:string, multi: true],
17
+ resource: [:string, nullable: true],
18
+ redirect_uri: :string
19
+
20
+ attributes :client_name, :scopes, :grantable_scopes, :resource, :redirect_uri
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # Serializer for {Spree::OauthProtectedResource}, the RFC 9728
6
+ # document a client reads to find the authorization server.
7
+ #
8
+ # Alba directly rather than through {BaseSerializer}: the document is
9
+ # a computed view with no id, and inheriting one would put a null
10
+ # `id` in a document the spec defines exactly.
11
+ class OauthProtectedResourceSerializer
12
+ include Alba::Resource
13
+ include Typelizer::DSL
14
+
15
+ typelize resource: :string,
16
+ authorization_servers: [:string, multi: true],
17
+ scopes_supported: [:string, multi: true],
18
+ bearer_methods_supported: [:string, multi: true],
19
+ resource_documentation: :string
20
+
21
+ attributes :resource, :authorization_servers, :scopes_supported,
22
+ :bearer_methods_supported, :resource_documentation
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # Admin API serializer for {Spree::OauthRedirect}.
6
+ class OauthRedirectSerializer
7
+ include Alba::Resource
8
+ include Typelizer::DSL
9
+
10
+ typelize redirect_uri: :string
11
+
12
+ attributes :redirect_uri
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -31,7 +31,7 @@ module Spree
31
31
  total: [:string, nullable: false],
32
32
  amount_due: [:string, nullable: false]
33
33
 
34
- typelize status: [:string, enum: Spree::Order::STATUSES],
34
+ typelize status: [:string, enum: Spree::Order::STATUSES, enum_type_name: 'OrderStatus'],
35
35
  last_ip_address: [:string, nullable: true],
36
36
  considered_risky: :boolean, confirmation_delivered: :boolean,
37
37
  store_owner_notification_delivered: [:boolean, nullable: true],
@@ -7,14 +7,14 @@ module Spree
7
7
  # only — a shopper never picks their packaging.
8
8
  class PackageTypeSerializer < V3::BaseSerializer
9
9
  typelize name: :string,
10
- kind: [:string, enum: Spree::PackageType::KINDS],
10
+ kind: [:string, enum: Spree::PackageType::KINDS, enum_type_name: 'PackageTypeKind'],
11
11
  length: [:string, nullable: true],
12
12
  width: [:string, nullable: true],
13
13
  height: [:string, nullable: true],
14
- dimensions_unit: [:string, enum: Spree::Variant::DIMENSION_UNITS],
14
+ dimensions_unit: [:string, enum: Spree::Variant::DIMENSION_UNITS, enum_type_name: 'DimensionUnit'],
15
15
  weight: [:string, nullable: true],
16
16
  max_weight: [:string, nullable: true],
17
- weight_unit: [:string, enum: Spree::Variant::WEIGHT_UNITS],
17
+ weight_unit: [:string, enum: Spree::Variant::WEIGHT_UNITS, enum_type_name: 'WeightUnit'],
18
18
  volume: [:string, nullable: true],
19
19
  default: :boolean,
20
20
  seller_id: [:string, nullable: true],
@@ -0,0 +1,16 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # Serializes Spree::PaymentCaptureEvent — one capture of money a
6
+ # payment had authorized. A payment captured in parts has one per part.
7
+ class PaymentCaptureEventSerializer < V3::BaseSerializer
8
+ attributes created_at: :iso8601, updated_at: :iso8601
9
+
10
+ money_attributes :amount
11
+ typelize amount: [:string, nullable: false]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -13,11 +13,18 @@ module Spree
13
13
  order_id: [:string, nullable: true],
14
14
  avs_response: [:string, nullable: true],
15
15
  cvv_response_code: [:string, nullable: true],
16
- cvv_response_message: [:string, nullable: true]
16
+ cvv_response_message: [:string, nullable: true],
17
+ gateway_dashboard_payment_url: [:string, nullable: true],
18
+ avs_risky: [:boolean, comment: 'Whether the card issuer reported that the billing address did not match.'],
19
+ cvv_risky: [:boolean, comment: 'Whether the card issuer reported that the security code did not match.']
17
20
 
18
21
  attributes :metadata, :avs_response, :cvv_response_code, :cvv_response_message,
22
+ :gateway_dashboard_payment_url,
19
23
  created_at: :iso8601, updated_at: :iso8601
20
24
 
25
+ attribute(:avs_risky, &:is_avs_risky?)
26
+ attribute(:cvv_risky, &:is_cvv_risky?)
27
+
21
28
  money_attributes :captured_amount
22
29
  typelize captured_amount: [:string, nullable: false]
23
30
 
@@ -41,6 +48,10 @@ module Spree
41
48
  serializer.new(payment.source).to_h
42
49
  end
43
50
 
51
+ many :capture_events,
52
+ resource: proc { Spree.api.admin_payment_capture_event_serializer },
53
+ if: proc { expand?('capture_events') }
54
+
44
55
  one :order,
45
56
  resource: proc { Spree.api.admin_order_serializer },
46
57
  if: proc { expand?('order') }
@@ -10,7 +10,7 @@ module Spree
10
10
  include Alba::Resource
11
11
  include Typelizer::DSL
12
12
 
13
- typelize key: :string, resource: :string, kind: [:string, enum: %w[read write]], group: :string,
13
+ typelize key: :string, resource: :string, kind: [:string, enum: %w[read write], enum_type_name: 'PermissionKind'], group: :string,
14
14
  group_label: :string, label: :string, description: :string
15
15
 
16
16
  attributes :key
@@ -14,7 +14,7 @@ module Spree
14
14
  starts_at: 'string | null',
15
15
  ends_at: 'string | null',
16
16
  deleted_at: 'string | null',
17
- match_policy: [:string, enum: Spree::PriceList::MATCH_POLICIES],
17
+ match_policy: [:string, enum: Spree::PriceList::MATCH_POLICIES, enum_type_name: 'MatchPolicy'],
18
18
  price_adjustment_percentage: 'string | null',
19
19
  adjust_compare_at: :boolean,
20
20
  automatic_pricing: :boolean,
@@ -6,7 +6,7 @@ module Spree
6
6
  # the merchant owes and expects, which no customer ever sees.
7
7
  class PurchaseOrderSerializer < V3::BaseSerializer
8
8
  typelize number: :string,
9
- status: :string,
9
+ status: [:string, enum: Spree::PurchaseOrder.statuses, enum_type_name: 'PurchaseOrderStatus'],
10
10
  currency: [:string, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
11
11
  reference: 'string | null',
12
12
  notes: 'string | null',
@@ -5,6 +5,8 @@ module Spree
5
5
  module V3
6
6
  module Admin
7
7
  class ReturnSerializer < V3::ReturnSerializer
8
+ include Concerns::ExternalReferencesAttribute
9
+
8
10
  without_formatted_money
9
11
 
10
12
  typelize memo: [:string, nullable: true],
@@ -12,7 +12,7 @@ module Spree
12
12
 
13
13
  typelize id: :string, kind: [:string, comment: 'Requirement kind. Built-in: accept_terms, complete_profile, billing_address, returns_address, delivery_method, package_type, minimum_products, payout_account, required_custom_fields, policy, attestation, operator_review, document. Extensions may register more.'], name: :string,
14
14
  description: [:string, nullable: true],
15
- required: :boolean, position: :number, status: [:string, enum: Spree::SellerRequirementStatus::STATUSES],
15
+ required: :boolean, position: :number, status: [:string, enum: Spree::SellerRequirementStatus::STATUSES, enum_type_name: 'SellerRequirementState'],
16
16
  blocking: :boolean, action_url: [:string, nullable: true],
17
17
  blocker: ['{ state: string; message: string | null } | null'],
18
18
  required_policy_name: [:string, nullable: true]
@@ -10,8 +10,8 @@ module Spree
10
10
  legal_name: [:string, nullable: true],
11
11
  registration_number: [:string, nullable: true],
12
12
  contact_email: [:string, nullable: true], billing_email: [:string, nullable: true],
13
- tax_remittance: :string,
14
- payouts_schedule_interval: [:string, nullable: true],
13
+ tax_remittance: [:string, enum: Spree::Seller::TAX_REMITTANCES, enum_type_name: 'TaxRemittance'],
14
+ payouts_schedule_interval: [:string, nullable: true, enum: Spree::Seller::PAYOUT_INTERVALS, enum_type_name: 'PayoutScheduleInterval'],
15
15
  minimum_payout_amount: [:string, nullable: true],
16
16
  holiday_mode_until: [:string, nullable: true],
17
17
  terms_accepted_at: [:string, nullable: true],
@@ -14,7 +14,7 @@ module Spree
14
14
  refund_id: 'string | null',
15
15
  seller_name: 'string | null',
16
16
  order_number: 'string | null',
17
- kind: [:string, enum: Spree::SellerTransfer::KINDS],
17
+ kind: [:string, enum: Spree::SellerTransfer::KINDS, enum_type_name: 'SellerTransferKind'],
18
18
  status: [:string, enum: Spree::SellerTransfer.statuses, enum_type_name: 'SellerTransferStatus'],
19
19
  provider: [:string, comment: 'Payout provider. Built-in: system. Provider gems register more (e.g. stripe).'],
20
20
  amount: :string,
@@ -7,15 +7,15 @@ module Spree
7
7
  # The file is streamed through +download_url+, never linked to storage.
8
8
  class ShippingLabelSerializer < V3::BaseSerializer
9
9
  typelize owner_id: :string,
10
- owner_type: [:string, enum: Spree::ShippingLabel::OWNER_TYPES.map { |type| Spree::Base.polymorphic_api_type(type) }],
11
- source: [:string, enum: Spree::ShippingLabel::SOURCES],
10
+ owner_type: [:string, enum: Spree::ShippingLabel::OWNER_TYPES.map { |type| Spree::Base.polymorphic_api_type(type) }, enum_type_name: 'ShippingLabelOwnerType'],
11
+ source: [:string, enum: Spree::ShippingLabel::SOURCES, enum_type_name: 'ShippingLabelSource'],
12
12
  status: [:string, enum: Spree::ShippingLabel.statuses, enum_type_name: 'ShippingLabelStatus'],
13
13
  carrier: [:string, nullable: true],
14
14
  carrier_name: [:string, nullable: true],
15
15
  service: [:string, nullable: true],
16
16
  tracking_number: [:string, nullable: true],
17
17
  currency: [:string, nullable: true, enum: Spree::Money::Rounding::CURRENCY_CODES, enum_type_name: 'CurrencyCode'],
18
- format: [:string, nullable: true],
18
+ format: [:string, nullable: true, enum: Spree::ShippingLabel::FORMATS, enum_type_name: 'ShippingLabelFormat'],
19
19
  external_id: [:string, nullable: true],
20
20
  integration_id: [:string, nullable: true],
21
21
  download_url: [:string, nullable: true],
@@ -15,7 +15,7 @@ module Spree
15
15
  address2: [:string, nullable: true], state_name: [:string, nullable: true],
16
16
  phone: [:string, nullable: true], company: [:string, nullable: true],
17
17
  kind: [:string, enum: Spree::StockLocation::KINDS, enum_type_name: 'StockLocationKind'],
18
- pickup_stock_policy: [:string, enum: Spree::StockLocation::PICKUP_STOCK_POLICIES],
18
+ pickup_stock_policy: [:string, enum: Spree::StockLocation::PICKUP_STOCK_POLICIES, enum_type_name: 'PickupStockPolicy'],
19
19
  pickup_ready_in_minutes: [:number, nullable: true],
20
20
  pickup_instructions: [:string, nullable: true]
21
21
 
@@ -7,9 +7,9 @@ module Spree
7
7
  class StockReceiptItemSerializer < V3::BaseSerializer
8
8
  typelize quantity_accepted: :number,
9
9
  quantity_rejected: :number,
10
- rejection_reason: [:string, enum: Spree::StockReceiptItem::REJECTION_REASONS, nullable: true],
10
+ rejection_reason: [:string, enum: Spree::StockReceiptItem::REJECTION_REASONS, nullable: true, enum_type_name: 'StockReceiptRejectionReason'],
11
11
  notes: 'string | null',
12
- line_type: [:string, enum: %w[purchase_order_item stock_transfer_item]],
12
+ line_type: [:string, enum: %w[purchase_order_item stock_transfer_item], enum_type_name: 'StockReceiptLineType'],
13
13
  line_id: 'string | null',
14
14
  product_id: 'string | null',
15
15
  variant_id: 'string | null',
@@ -9,7 +9,7 @@ module Spree
9
9
  reference: 'string | null',
10
10
  notes: 'string | null',
11
11
  received_at: :string,
12
- receivable_type: [:string, enum: %w[purchase_order stock_transfer]],
12
+ receivable_type: [:string, enum: %w[purchase_order stock_transfer], enum_type_name: 'StockReceiptReceivableType'],
13
13
  receivable_id: :string,
14
14
  received_by_id: 'string | null',
15
15
  received_by_type: [:string, nullable: true, enum: Spree::Actor::BUILT_IN_KINDS, enum_type_name: 'ActorKind'],
@@ -6,7 +6,7 @@ module Spree
6
6
  # has a middle: `shipped_at` is when the units left the source,
7
7
  # `received_at` when the destination finished counting them in.
8
8
  class StockTransferSerializer < V3::StockTransferSerializer
9
- typelize status: :string,
9
+ typelize status: [:string, enum: Spree::StockTransfer.statuses, enum_type_name: 'StockTransferStatus'],
10
10
  notes: 'string | null',
11
11
  items_count: :number,
12
12
  quantity_shipped_total: :number,
@@ -36,6 +36,7 @@ module Spree
36
36
  # and rate settings are formatted below.
37
37
  preference_attributes Spree::Store, except: %i[order_routing_strategy payout_provider
38
38
  default_minimum_payout_amount default_commission_tax_rate]
39
+ typelize weight_unit: [:string, enum: Spree::Variant::WEIGHT_UNITS, enum_type_name: 'WeightUnit']
39
40
 
40
41
  # Once the counter has issued a number the starting value no longer
41
42
  # applies, so the settings page can say that instead of accepting a