Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Typed the nested calculator in the SDKs' generated types
Damian Legawiec41108a21067d
diff --git a/packages/admin-sdk/src/types/generated/PromotionAction.ts b/packages/admin-sdk/src/types/generated/PromotionAction.tsindex 8a9da5e755..fc8f0d00be 100644--- a/packages/admin-sdk/src/types/generated/PromotionAction.ts+++ b/packages/admin-sdk/src/types/generated/PromotionAction.ts@@ -1,6 +1,7 @@-// Typelizer digest 8d0072956ba947daf41d4eabb1263560+// Typelizer digest 20b35888d4843bd485f0955ec705dcdf//// DO NOT MODIFY: This file was automatically generated by Typelizer.+import type {TypedPromotionCalculator} from '@/types'interface PromotionAction {id: string;@@ -10,7 +11,7 @@ interface PromotionAction {type: string;promotion_id: string;preferences: Record<string, unknown>;- calculator: { type: string; preferences: Record<string, unknown> } | null;+ calculator: TypedPromotionCalculator | null;line_items: Array<{ variant_id: string; quantity: number }> | null;}diff --git a/packages/admin-sdk/src/types/generated/index.ts b/packages/admin-sdk/src/types/generated/index.tsindex b0f7c6390e..dce8e3bd5d 100644--- a/packages/admin-sdk/src/types/generated/index.ts+++ b/packages/admin-sdk/src/types/generated/index.ts@@ -146,3 +146,4 @@ export type { default as Variant } from './Variant'export type { default as WebhookDelivery } from './WebhookDelivery'export type { default as WebhookEndpoint } from './WebhookEndpoint'export type { default as WebhookEvent } from './WebhookEvent'+export type * from '../preferences'diff --git a/packages/admin-sdk/src/types/preferences.ts b/packages/admin-sdk/src/types/preferences.tsindex 9e2c5453ed..66eb3b65d5 100644--- a/packages/admin-sdk/src/types/preferences.ts+++ b/packages/admin-sdk/src/types/preferences.ts@@ -17,13 +17,13 @@ type Narrowed<Resource, Map> = {}[keyof Map]/** Settings of the `category_rule` commission rule. */-export interface CommissionRuleCategoryRulePreferences {+export type CommissionRuleCategoryRulePreferences = {/** Prefixed `ctg_` ids. */category_ids: Array<string>}/** Settings of the `item_total_rule` commission rule. */-export interface CommissionRuleItemTotalRulePreferences {+export type CommissionRuleItemTotalRulePreferences = {/** An amount, as an exact decimal string. */min_amount: string | null/** An amount, as an exact decimal string. */@@ -34,7 +34,7 @@ export interface CommissionRuleItemTotalRulePreferences {export type CommissionRuleProductRulePreferences = Record<string, never>/** Settings of the `seller_rule` commission rule. */-export interface CommissionRuleSellerRulePreferences {+export type CommissionRuleSellerRulePreferences = {/** Prefixed `sel_` ids. */seller_ids: Array<string>}@@ -54,7 +54,7 @@ export interface CommissionRulePreferencesMap {export type TypedCommissionRule = Narrowed<CommissionRule, CommissionRulePreferencesMap>/** Settings of the `digital_delivery` delivery calculator. */-export interface DeliveryCalculatorDigitalDeliveryPreferences {+export type DeliveryCalculatorDigitalDeliveryPreferences = {amounts: Record<string, string>/** An amount, as an exact decimal string. */amount: string@@ -63,12 +63,12 @@ export interface DeliveryCalculatorDigitalDeliveryPreferences {}/** Settings of the `flat_percent_item_total` delivery calculator. */-export interface DeliveryCalculatorFlatPercentItemTotalPreferences {+export type DeliveryCalculatorFlatPercentItemTotalPreferences = {flat_percent: string}/** Settings of the `flat_rate` delivery calculator. */-export interface DeliveryCalculatorFlatRatePreferences {+export type DeliveryCalculatorFlatRatePreferences = {amounts: Record<string, string>/** An amount, as an exact decimal string. */amount: string@@ -77,7 +77,7 @@ export interface DeliveryCalculatorFlatRatePreferences {}/** Settings of the `flexi_rate` delivery calculator. */-export interface DeliveryCalculatorFlexiRatePreferences {+export type DeliveryCalculatorFlexiRatePreferences = {/** An amount, as an exact decimal string. */first_item: string/** An amount, as an exact decimal string. */@@ -88,7 +88,7 @@ export interface DeliveryCalculatorFlexiRatePreferences {}/** Settings of the `per_item` delivery calculator. */-export interface DeliveryCalculatorPerItemPreferences {+export type DeliveryCalculatorPerItemPreferences = {amounts: Record<string, string>/** An amount, as an exact decimal string. */amount: string@@ -97,7 +97,7 @@ export interface DeliveryCalculatorPerItemPreferences {}/** Settings of the `price_sack` delivery calculator. */-export interface DeliveryCalculatorPriceSackPreferences {+export type DeliveryCalculatorPriceSackPreferences = {/** An amount, as an exact decimal string. */minimal_amount: string/** An amount, as an exact decimal string. */@@ -121,14 +121,22 @@ export interface DeliveryCalculatorPreferencesMap {price_sack: DeliveryCalculatorPriceSackPreferences}+/** A delivery calculator, its `preferences` typed by its `type`. */+export type TypedDeliveryCalculator = {+ [Type in keyof DeliveryCalculatorPreferencesMap]: {+ type: Type+ preferences: DeliveryCalculatorPreferencesMap[Type]+ }+}[keyof DeliveryCalculatorPreferencesMap]+/** Settings of the `channel_rule` delivery method rule. */-export interface DeliveryMethodRuleChannelRulePreferences {+export type DeliveryMethodRuleChannelRulePreferences = {/** Prefixed `ch_` ids. */channel_ids: Array<string>}/** Settings of the `company_rule` delivery method rule. */-export interface DeliveryMethodRuleCompanyRulePreferences {+export type DeliveryMethodRuleCompanyRulePreferences = {company_orders_only: boolean}@@ -136,7 +144,7 @@ export interface DeliveryMethodRuleCompanyRulePreferences {export type DeliveryMethodRuleExcludedProductsRulePreferences = Record<string, never>/** Settings of the `item_total_rule` delivery method rule. */-export interface DeliveryMethodRuleItemTotalRulePreferences {+export type DeliveryMethodRuleItemTotalRulePreferences = {/** An amount, as an exact decimal string. */minimum_amount: string | null/** An amount, as an exact decimal string. */@@ -144,13 +152,13 @@ export interface DeliveryMethodRuleItemTotalRulePreferences {}/** Settings of the `volume_rule` delivery method rule. */-export interface DeliveryMethodRuleVolumeRulePreferences {+export type DeliveryMethodRuleVolumeRulePreferences = {minimum_volume: string | nullmaximum_volume: string | null}/** Settings of the `weight_rule` delivery method rule. */-export interface DeliveryMethodRuleWeightRulePreferences {+export type DeliveryMethodRuleWeightRulePreferences = {minimum_weight: string | nullmaximum_weight: string | null}@@ -204,7 +212,7 @@ export interface OrderRoutingRulePreferencesMap {export type TypedOrderRoutingRule = Narrowed<OrderRoutingRule, OrderRoutingRulePreferencesMap>/** Settings of the `bogus` payment method. */-export interface PaymentMethodBogusPreferences {+export type PaymentMethodBogusPreferences = {dummy_key: string/** Masked when read (`••••1234`); send it back unchanged to keep it, `null` to clear it. */dummy_secret_key: string | null@@ -234,31 +242,31 @@ export interface PaymentMethodPreferencesMap {export type TypedPaymentMethod = Narrowed<PaymentMethod, PaymentMethodPreferencesMap>/** Settings of the `channel_rule` price rule. */-export interface PriceRuleChannelRulePreferences {+export type PriceRuleChannelRulePreferences = {/** Prefixed `ch_` ids. */channel_ids: Array<string>}/** Settings of the `customer_group_rule` price rule. */-export interface PriceRuleCustomerGroupRulePreferences {+export type PriceRuleCustomerGroupRulePreferences = {/** Prefixed `cg_` ids. */customer_group_ids: Array<string>}/** Settings of the `market_rule` price rule. */-export interface PriceRuleMarketRulePreferences {+export type PriceRuleMarketRulePreferences = {/** Prefixed `mkt_` ids. */market_ids: Array<string>}/** Settings of the `user_rule` price rule. */-export interface PriceRuleUserRulePreferences {+export type PriceRuleUserRulePreferences = {/** Prefixed `cust_` ids. */user_ids: Array<string>}/** Settings of the `volume_rule` price rule. */-export interface PriceRuleVolumeRulePreferences {+export type PriceRuleVolumeRulePreferences = {min_quantity: numbermax_quantity: number | null}@@ -279,12 +287,12 @@ export interface PriceRulePreferencesMap {export type TypedPriceRule = Narrowed<PriceRule, PriceRulePreferencesMap>/** Settings of the `flat_percent_item_total` promotion calculator. */-export interface PromotionCalculatorFlatPercentItemTotalPreferences {+export type PromotionCalculatorFlatPercentItemTotalPreferences = {flat_percent: string}/** Settings of the `flat_rate` promotion calculator. */-export interface PromotionCalculatorFlatRatePreferences {+export type PromotionCalculatorFlatRatePreferences = {/** An amount, as an exact decimal string. */amount: string/** Format: `currency`. */@@ -293,7 +301,7 @@ export interface PromotionCalculatorFlatRatePreferences {}/** Settings of the `flexi_rate` promotion calculator. */-export interface PromotionCalculatorFlexiRatePreferences {+export type PromotionCalculatorFlexiRatePreferences = {/** An amount, as an exact decimal string. */first_item: string/** An amount, as an exact decimal string. */@@ -305,13 +313,13 @@ export interface PromotionCalculatorFlexiRatePreferences {}/** Settings of the `percent_on_line_item` promotion calculator. */-export interface PromotionCalculatorPercentOnLineItemPreferences {+export type PromotionCalculatorPercentOnLineItemPreferences = {percent: stringapply_only_on_full_priced_items: boolean}/** Settings of the `tiered_flat_rate` promotion calculator. */-export interface PromotionCalculatorTieredFlatRatePreferences {+export type PromotionCalculatorTieredFlatRatePreferences = {tiers: Array<{ threshold: string; value: string }>/** An amount, as an exact decimal string. */base_amount: string@@ -320,7 +328,7 @@ export interface PromotionCalculatorTieredFlatRatePreferences {}/** Settings of the `tiered_percent` promotion calculator. */-export interface PromotionCalculatorTieredPercentPreferences {+export type PromotionCalculatorTieredPercentPreferences = {tiers: Array<{ threshold: string; value: string }>base_percent: string}@@ -338,19 +346,27 @@ export interface PromotionCalculatorPreferencesMap {tiered_percent: PromotionCalculatorTieredPercentPreferences}+/** A promotion calculator, its `preferences` typed by its `type`. */+export type TypedPromotionCalculator = {+ [Type in keyof PromotionCalculatorPreferencesMap]: {+ type: Type+ preferences: PromotionCalculatorPreferencesMap[Type]+ }+}[keyof PromotionCalculatorPreferencesMap]+/** Settings of the `category` promotion rule. */-export interface PromotionRuleCategoryPreferences {+export type PromotionRuleCategoryPreferences = {match_policy: 'any' | 'all'}/** Settings of the `channel` promotion rule. */-export interface PromotionRuleChannelPreferences {+export type PromotionRuleChannelPreferences = {/** Prefixed `ch_` ids. */channel_ids: Array<string>}/** Settings of the `country` promotion rule. */-export interface PromotionRuleCountryPreferences {+export type PromotionRuleCountryPreferences = {country_codes: Array<string>country_id: number | null/** Format: `iso-country`. */@@ -358,7 +374,7 @@ export interface PromotionRuleCountryPreferences {}/** Settings of the `currency` promotion rule. */-export interface PromotionRuleCurrencyPreferences {+export type PromotionRuleCurrencyPreferences = {/** Format: `currency`. */currency: string | null}@@ -367,7 +383,7 @@ export interface PromotionRuleCurrencyPreferences {export type PromotionRuleCustomerPreferences = Record<string, never>/** Settings of the `customer_group` promotion rule. */-export interface PromotionRuleCustomerGroupPreferences {+export type PromotionRuleCustomerGroupPreferences = {/** Prefixed `cg_` ids. */customer_group_ids: Array<string>}@@ -379,7 +395,7 @@ export type PromotionRuleCustomerLoggedInPreferences = Record<string, never>export type PromotionRuleFirstOrderPreferences = Record<string, never>/** Settings of the `item_total` promotion rule. */-export interface PromotionRuleItemTotalPreferences {+export type PromotionRuleItemTotalPreferences = {/** An amount, as an exact decimal string. */amount_min: stringoperator_min: string@@ -389,7 +405,7 @@ export interface PromotionRuleItemTotalPreferences {}/** Settings of the `market` promotion rule. */-export interface PromotionRuleMarketPreferences {+export type PromotionRuleMarketPreferences = {/** Prefixed `mkt_` ids. */market_ids: Array<string>}@@ -398,14 +414,14 @@ export interface PromotionRuleMarketPreferences {export type PromotionRuleOneUsePerUserPreferences = Record<string, never>/** Settings of the `option_value` promotion rule. */-export interface PromotionRuleOptionValuePreferences {+export type PromotionRuleOptionValuePreferences = {match_policy: 'any'/** Prefixed `optval_` ids. */eligible_values: Array<string>}/** Settings of the `product` promotion rule. */-export interface PromotionRuleProductPreferences {+export type PromotionRuleProductPreferences = {match_policy: 'any' | 'all' | 'none'}@@ -433,7 +449,7 @@ export interface PromotionRulePreferencesMap {export type TypedPromotionRule = Narrowed<PromotionRule, PromotionRulePreferencesMap>/** Settings of the `accept_terms` seller requirement. */-export interface SellerRequirementAcceptTermsPreferences {+export type SellerRequirementAcceptTermsPreferences = {terms_body: string | null/** Format: `date`. */terms_effective_from: string | null@@ -447,7 +463,7 @@ export type SellerRequirementAttestationPreferences = Record<string, never>export type SellerRequirementBillingAddressPreferences = Record<string, never>/** Settings of the `complete_profile` seller requirement. */-export interface SellerRequirementCompleteProfilePreferences {+export type SellerRequirementCompleteProfilePreferences = {require_about: booleanrequire_logo: booleanrequire_cover_photo: boolean@@ -461,7 +477,7 @@ export type SellerRequirementDeliveryMethodPreferences = Record<string, never>export type SellerRequirementDocumentPreferences = Record<string, never>/** Settings of the `minimum_products` seller requirement. */-export interface SellerRequirementMinimumProductsPreferences {+export type SellerRequirementMinimumProductsPreferences = {minimum_count: number}diff --git a/packages/admin-sdk/src/zod/generated/DeliveryMethod.ts b/packages/admin-sdk/src/zod/generated/DeliveryMethod.tsindex 7a3afe3b24..a97e47b69b 100644--- a/packages/admin-sdk/src/zod/generated/DeliveryMethod.ts+++ b/packages/admin-sdk/src/zod/generated/DeliveryMethod.ts@@ -33,7 +33,7 @@ export const DeliveryMethodSchema = z.object({fulfillment_provider: z.string(),pickup_point_provider: z.string().nullable(),rate_provider: z.string().nullable(),- calculator: z.object({ type: z.string(), preferences: z.record(z.string(), z.unknown()) }).nullable(),+ calculator: z.any().nullable(),});export type DeliveryMethod = z.infer<typeof DeliveryMethodSchema>;diff --git a/packages/admin-sdk/src/zod/generated/PromotionAction.ts b/packages/admin-sdk/src/zod/generated/PromotionAction.tsindex 4f2a325aa6..f1a24b069d 100644--- a/packages/admin-sdk/src/zod/generated/PromotionAction.ts+++ b/packages/admin-sdk/src/zod/generated/PromotionAction.ts@@ -8,7 +8,7 @@ export const PromotionActionSchema = z.object({type: z.string(),promotion_id: z.string(),preferences: z.record(z.string(), z.unknown()),- calculator: z.object({ type: z.string(), preferences: z.record(z.string(), z.unknown()) }).nullable(),+ calculator: z.any().nullable(),line_items: z.array(z.object({ variant_id: z.string(), quantity: z.number() })).nullable(),});diff --git a/packages/seller-sdk/src/types/generated/DeliveryMethod.ts b/packages/seller-sdk/src/types/generated/DeliveryMethod.tsindex 04a5f0c3ef..956fd4dcd2 100644--- a/packages/seller-sdk/src/types/generated/DeliveryMethod.ts+++ b/packages/seller-sdk/src/types/generated/DeliveryMethod.ts@@ -1,7 +1,7 @@-// Typelizer digest bfa1ac542621d909937b45d8b40b807b+// Typelizer digest 35d16b27e840e4a37423a0694924fd04//// DO NOT MODIFY: This file was automatically generated by Typelizer.-import type {DeliveryMethodRule} from '@/types'+import type {TypedDeliveryCalculator, DeliveryMethodRule} from '@/types'type DeliveryMethod = {id: string;@@ -21,7 +21,7 @@ type DeliveryMethod = {editable: boolean;delivery_profile_id: string | null;delivery_zone_id: string | null;- calculator: { type: string; preferences: Record<string, unknown> } | null;+ calculator: TypedDeliveryCalculator | null;}export default DeliveryMethod;diff --git a/packages/seller-sdk/src/types/generated/index.ts b/packages/seller-sdk/src/types/generated/index.tsindex 56db7464d6..f66ca355f5 100644--- a/packages/seller-sdk/src/types/generated/index.ts+++ b/packages/seller-sdk/src/types/generated/index.ts@@ -54,3 +54,4 @@ export type { default as TeamMember } from './TeamMember'export type { default as Transfer } from './Transfer'export type { default as Variant } from './Variant'export type { default as Seller } from './Seller'+export type * from '../preferences'diff --git a/packages/seller-sdk/src/types/preferences.ts b/packages/seller-sdk/src/types/preferences.tsindex 8b56a8bd85..ecb6b59a44 100644--- a/packages/seller-sdk/src/types/preferences.ts+++ b/packages/seller-sdk/src/types/preferences.ts@@ -10,7 +10,7 @@ type Narrowed<Resource, Map> = {}[keyof Map]/** Settings of the `digital_delivery` delivery calculator. */-export interface DeliveryCalculatorDigitalDeliveryPreferences {+export type DeliveryCalculatorDigitalDeliveryPreferences = {amounts: Record<string, string>/** An amount, as an exact decimal string. */amount: string@@ -19,12 +19,12 @@ export interface DeliveryCalculatorDigitalDeliveryPreferences {}/** Settings of the `flat_percent_item_total` delivery calculator. */-export interface DeliveryCalculatorFlatPercentItemTotalPreferences {+export type DeliveryCalculatorFlatPercentItemTotalPreferences = {flat_percent: string}/** Settings of the `flat_rate` delivery calculator. */-export interface DeliveryCalculatorFlatRatePreferences {+export type DeliveryCalculatorFlatRatePreferences = {amounts: Record<string, string>/** An amount, as an exact decimal string. */amount: string@@ -33,7 +33,7 @@ export interface DeliveryCalculatorFlatRatePreferences {}/** Settings of the `flexi_rate` delivery calculator. */-export interface DeliveryCalculatorFlexiRatePreferences {+export type DeliveryCalculatorFlexiRatePreferences = {/** An amount, as an exact decimal string. */first_item: string/** An amount, as an exact decimal string. */@@ -44,7 +44,7 @@ export interface DeliveryCalculatorFlexiRatePreferences {}/** Settings of the `per_item` delivery calculator. */-export interface DeliveryCalculatorPerItemPreferences {+export type DeliveryCalculatorPerItemPreferences = {amounts: Record<string, string>/** An amount, as an exact decimal string. */amount: string@@ -53,7 +53,7 @@ export interface DeliveryCalculatorPerItemPreferences {}/** Settings of the `price_sack` delivery calculator. */-export interface DeliveryCalculatorPriceSackPreferences {+export type DeliveryCalculatorPriceSackPreferences = {/** An amount, as an exact decimal string. */minimal_amount: string/** An amount, as an exact decimal string. */@@ -77,14 +77,22 @@ export interface DeliveryCalculatorPreferencesMap {price_sack: DeliveryCalculatorPriceSackPreferences}+/** A delivery calculator, its `preferences` typed by its `type`. */+export type TypedDeliveryCalculator = {+ [Type in keyof DeliveryCalculatorPreferencesMap]: {+ type: Type+ preferences: DeliveryCalculatorPreferencesMap[Type]+ }+}[keyof DeliveryCalculatorPreferencesMap]+/** Settings of the `channel_rule` delivery method rule. */-export interface DeliveryMethodRuleChannelRulePreferences {+export type DeliveryMethodRuleChannelRulePreferences = {/** Prefixed `ch_` ids. */channel_ids: Array<string>}/** Settings of the `company_rule` delivery method rule. */-export interface DeliveryMethodRuleCompanyRulePreferences {+export type DeliveryMethodRuleCompanyRulePreferences = {company_orders_only: boolean}@@ -92,7 +100,7 @@ export interface DeliveryMethodRuleCompanyRulePreferences {export type DeliveryMethodRuleExcludedProductsRulePreferences = Record<string, never>/** Settings of the `item_total_rule` delivery method rule. */-export interface DeliveryMethodRuleItemTotalRulePreferences {+export type DeliveryMethodRuleItemTotalRulePreferences = {/** An amount, as an exact decimal string. */minimum_amount: string | null/** An amount, as an exact decimal string. */@@ -100,13 +108,13 @@ export interface DeliveryMethodRuleItemTotalRulePreferences {}/** Settings of the `volume_rule` delivery method rule. */-export interface DeliveryMethodRuleVolumeRulePreferences {+export type DeliveryMethodRuleVolumeRulePreferences = {minimum_volume: string | nullmaximum_volume: string | null}/** Settings of the `weight_rule` delivery method rule. */-export interface DeliveryMethodRuleWeightRulePreferences {+export type DeliveryMethodRuleWeightRulePreferences = {minimum_weight: string | nullmaximum_weight: string | null}diff --git a/packages/seller-sdk/src/zod/generated/DeliveryMethod.ts b/packages/seller-sdk/src/zod/generated/DeliveryMethod.tsindex c26d0e1c3a..6f52034e47 100644--- a/packages/seller-sdk/src/zod/generated/DeliveryMethod.ts+++ b/packages/seller-sdk/src/zod/generated/DeliveryMethod.ts@@ -20,7 +20,7 @@ export const DeliveryMethodSchema = z.object({editable: z.boolean(),delivery_profile_id: z.string().nullable(),delivery_zone_id: z.string().nullable(),- calculator: z.object({ type: z.string(), preferences: z.record(z.string(), z.unknown()) }).nullable(),+ calculator: z.any().nullable(),});export type DeliveryMethod = z.infer<typeof DeliveryMethodSchema>;diff --git a/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rbindex 4c9fa10722..9e9cb580f7 100644--- a/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/admin/delivery_method_serializer.rb@@ -13,7 +13,7 @@ module Spreedelivery_origin_group_id: [:string, nullable: true],delivery_zone_id: [:string, nullable: true],stock_location_ids: [:string, multi: true],- calculator: '{ type: string; preferences: Record<string, unknown> } | null',+ calculator: 'TypedDeliveryCalculator | null',markup_flat: [:string, nullable: true],markup_percent: [:string, nullable: true],available_to_sellers: :boolean,diff --git a/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rbindex 07f92dc84f..70027b4f9e 100644--- a/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/admin/promotion_action_serializer.rb@@ -13,7 +13,7 @@ module Spreetypelize type: [:string, comment: 'Action type. Built-in: create_adjustment, create_item_adjustments, create_line_items, free_shipping. Extensions may register more.'],promotion_id: :string,preferences: 'Record<string, unknown>',- calculator: '{ type: string; preferences: Record<string, unknown> } | null',+ calculator: 'TypedPromotionCalculator | null',line_items: 'Array<{ variant_id: string; quantity: number }> | null'attributes created_at: :iso8601, updated_at: :iso8601diff --git a/spree/api/app/serializers/spree/api/v3/seller/delivery_method_serializer.rb b/spree/api/app/serializers/spree/api/v3/seller/delivery_method_serializer.rbindex 1a145e190f..54eeadd2f7 100644--- a/spree/api/app/serializers/spree/api/v3/seller/delivery_method_serializer.rb+++ b/spree/api/app/serializers/spree/api/v3/seller/delivery_method_serializer.rb@@ -22,7 +22,7 @@ module Spreeeditable: :boolean,delivery_profile_id: [:string, nullable: true],delivery_zone_id: [:string, nullable: true],- calculator: '{ type: string; preferences: Record<string, unknown> } | null'+ calculator: 'TypedDeliveryCalculator | null'attributes :admin_name, :storefront_visible, :tracking_url,created_at: :iso8601, updated_at: :iso8601diff --git a/spree/api/lib/spree/api/preference_types.rb b/spree/api/lib/spree/api/preference_types.rbindex f85acdb646..c507329d90 100644--- a/spree/api/lib/spree/api/preference_types.rb+++ b/spree/api/lib/spree/api/preference_types.rb@@ -23,7 +23,7 @@ module Spree}.freeze# Families serialized as rows of their own; calculators are nested in- # their owner and get only the map.+ # their owner, whose serializer types `calculator` with `Typed<Family>`.RESOURCES = (PreferenceFamilies::REGISTRIES.keys - %w[DeliveryCalculator PromotionCalculator]).freeze# @return [Hash{String => String}] file contents keyed by path under the monorepo root@@ -31,10 +31,19 @@ module SpreeFILES.transform_values { |families| source(PreferenceFamilies.schemas(families)) }end+ # Typelizer imports a type a serializer names (`TypedDeliveryCalculator`)+ # from its generated index, so that index re-exports these types too.+ INDEX_EXPORT = "export type * from '../preferences'\n".freeze+# @param root [Pathname] the monorepo root# @return [void]def write!(root)- render.each { |path, content| File.write(root.join(path), content) }+ render.each do |path, content|+ File.write(root.join(path), content)++ index = root.join(path).dirname.join('generated/index.ts')+ File.write(index, index.read + INDEX_EXPORT) if index.exist? && !index.read.include?(INDEX_EXPORT)+ endendprivate@@ -67,7 +76,9 @@ module Spreenext "/** Settings of the `#{type}` #{label}: none. */\nexport type #{name} = Record<string, never>\n" if properties.empty?fields = properties.map { |key, property| "#{field_comment(property)} #{key}: #{ts_type(property)}\n" }.join- "/** Settings of the `#{type}` #{label}. */\nexport interface #{name} {\n#{fields}}\n"+ # A type, not an interface, so it stays assignable to+ # `Record<string, unknown>`, which generic preference forms take.+ "/** Settings of the `#{type}` #{label}. */\nexport type #{name} = {\n#{fields}}\n"endmap = "#{family}PreferencesMap"@@ -76,7 +87,15 @@ module Spreeparts << "/**\n * The settings of each #{label} type Spree ships, by `type`. An interface,\n" \" * so an extension types its own by declaration merging.\n */\n" \"#{ignore}export interface #{map} {#{"\n#{entries}" if entries.present?}}\n"- parts << "/** #{label.match?(/\A[aeiou]/) ? 'An' : 'A'} #{label} whose `preferences` are typed by its `type`. */\nexport type Typed#{family} = Narrowed<#{family}, #{map}>\n" if resource+ article = label.match?(/\A[aeiou]/) ? 'An' : 'A'+ parts << if resource+ "/** #{article} #{label} whose `preferences` are typed by its `type`. */\nexport type Typed#{family} = Narrowed<#{family}, #{map}>\n"+ else+ # A calculator is nested in its owner, which types its+ # `calculator` field with this union.+ "/** #{article} #{label}, its `preferences` typed by its `type`. */\n" \+ "export type Typed#{family} = {\n [Type in keyof #{map}]: {\n type: Type\n preferences: #{map}[Type]\n }\n}[keyof #{map}]\n"+ endpartsenddiff --git a/spree/api/spec/lib/spree/api/preference_types_spec.rb b/spree/api/spec/lib/spree/api/preference_types_spec.rbindex df4e283ec2..2fd76e45a3 100644--- a/spree/api/spec/lib/spree/api/preference_types_spec.rb+++ b/spree/api/spec/lib/spree/api/preference_types_spec.rb@@ -16,13 +16,21 @@ RSpec.describe Spree::Api::PreferenceTypes dosource = generator.render.fetch('packages/admin-sdk/src/types/preferences.ts')expect(source).to include(- "export interface PromotionRuleItemTotalPreferences {\n /** An amount, as an exact decimal string. */\n amount_min: string\n"+ "export type PromotionRuleItemTotalPreferences = {\n /** An amount, as an exact decimal string. */\n amount_min: string\n")expect(source).to include(" item_total: PromotionRuleItemTotalPreferences\n")expect(source).to include(" match_policy: 'any' | 'all' | 'none'\n")expect(source).to include("export type TypedPromotionRule = Narrowed<PromotionRule, PromotionRulePreferencesMap>\n")end+ it 'lets a generated type name a preference type through the generated index' do+ described_class::FILES.each_key do |path|+ index = monorepo_root.join(path).dirname.join('generated/index.ts')++ expect(index.read).to include(described_class::INDEX_EXPORT), "#{index} does not re-export the preference types"+ end+ end+it 'gives the seller panel only the families a seller writes' dosource = generator.render.fetch('packages/seller-sdk/src/types/preferences.ts')