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
Fix: review comments on the typed filters
Damian Legawiecddf13705f743
diff --git a/.changeset/typed-list-filters.md b/.changeset/typed-list-filters.mdindex a34dd8663f..b8ab9f49c7 100644--- a/.changeset/typed-list-filters.md+++ b/.changeset/typed-list-filters.md@@ -6,6 +6,6 @@"@spree/dashboard-core": patch----List methods now accept typed filter and sort parameters, generated from the filters each API endpoint actually accepts. A misspelled filter, a filter the endpoint does not support, or an unknown sort field is now a type error instead of a request that silently returns the unfiltered list. `ProductListParams`, `CategoryListParams`, `CollectionListParams` and `OrderListParams` keep their names and are now generated; they no longer accept arbitrary keys. Filters an app adds through its own extensions are declared by extending `<Resource>FilterExtensions` (for example `ProductFilterExtensions`) with `declare module`.+List methods of documented endpoints now accept typed filter and sort parameters, generated from the filters each endpoint actually accepts; methods of endpoints the API reference does not document yet keep loose parameters. A misspelled filter, a filter the endpoint does not support, or an unknown sort field is now a type error instead of a request that silently returns the unfiltered list. `ProductListParams`, `CategoryListParams`, `CollectionListParams` and `OrderListParams` keep their names and are now generated; they no longer accept arbitrary keys. Filters an app adds through its own extensions are declared by extending `<Resource>FilterExtensions` (for example `ProductFilterExtensions`) with `declare module`.The dashboard's allowed-origins search, delivery zones by profile, and several filters and sorts on payment methods, sellers, option types, markets, custom field definitions and gift cards now take effect; the API used to ignore them.diff --git a/docs/api-reference/admin-api/querying.mdx b/docs/api-reference/admin-api/querying.mdxindex a2861da100..e489dfdcc6 100644--- a/docs/api-reference/admin-api/querying.mdx+++ b/docs/api-reference/admin-api/querying.mdx@@ -60,7 +60,7 @@ Each list endpoint accepts the attributes, associations and scopes its resource| Statuses, prefixed IDs and types | `eq` `not_eq` `in` `not_in` `null` `not_null` || True or false | `eq` `not_eq` `in` `not_in` `true` `false` `null` |-Filters reach associated records at most two levels deep (`line_items_variant_sku_eq`). The API reference lists every endpoint's filters and sortable fields in its `x-spree-filters` entry, and the SDK types each `list()` call from that list, so a misspelled filter or sort field is a compile error rather than an unfiltered response.+Filters reach associated records at most two levels deep (`line_items_variant_sku_eq`). The API reference lists each documented endpoint's filters and sortable fields in its `x-spree-filters` entry, and the SDK types that endpoint's `list()` call from it, so a misspelled filter or sort field is a compile error rather than an unfiltered response. List methods of endpoints the reference does not document yet accept any filter.### Prefixed IDs in filtersdiff --git a/docs/api-reference/store-api/querying.mdx b/docs/api-reference/store-api/querying.mdxindex 942b4006c9..df69fbe589 100644--- a/docs/api-reference/store-api/querying.mdx+++ b/docs/api-reference/store-api/querying.mdx@@ -66,7 +66,7 @@ Each list endpoint accepts the attributes, associations and scopes its resource| Statuses, prefixed IDs and types | `eq` `not_eq` `in` `not_in` `null` `not_null` || True or false | `eq` `not_eq` `in` `not_in` `true` `false` `null` |-Filters reach associated records at most two levels deep (`categories_name_eq`). The API reference lists every endpoint's filters and sortable fields in its `x-spree-filters` entry, and the SDK types each `list()` call from that list, so a misspelled filter or sort field is a compile error rather than an unfiltered response.+Filters reach associated records at most two levels deep (`categories_name_eq`). The API reference lists each documented endpoint's filters and sortable fields in its `x-spree-filters` entry, and the SDK types that endpoint's `list()` call from it, so a misspelled filter or sort field is a compile error rather than an unfiltered response. List methods of endpoints the reference does not document yet accept any filter.### Combining Filtersdiff --git a/docs/developer/core-concepts/search-filtering.mdx b/docs/developer/core-concepts/search-filtering.mdxindex fb9fe0afb9..aa24b3f038 100644--- a/docs/developer/core-concepts/search-filtering.mdx+++ b/docs/developer/core-concepts/search-filtering.mdx@@ -263,7 +263,7 @@ Only attributes explicitly allowed by each resource can be used for filtering. A### Making a field filterable-A resource's filters come from its model's allowlists, and nowhere else. The API reference and the SDK types are generated from them, so whatever you add appears in the [Querying](/api-reference/admin-api/querying#which-filters-an-endpoint-accepts) reference and in the typed `list()` parameters without further work.+A resource's filters come from its model's allowlists, and nowhere else. Spree generates its API reference and SDK types from them, so the [Querying](/api-reference/admin-api/querying#which-filters-an-endpoint-accepts) reference lists what core declares. Filters your app adds take effect in the API immediately; to use them from TypeScript, declare them as shown below, since the published SDK types are generated from core alone.```ruby server/config/initializers/spree.rbSpree.ransack.add_attribute(Spree::Product, :erp_id)diff --git a/packages/admin-sdk/src/types/index.ts b/packages/admin-sdk/src/types/index.tsindex 5a3f099757..c41106209d 100644--- a/packages/admin-sdk/src/types/index.ts+++ b/packages/admin-sdk/src/types/index.ts@@ -9,7 +9,7 @@ export type {PreferencePropertySchema,PreferenceSchema,} from '@spree/sdk-core'-export type * from './filters.generated'+export * from './filters.generated'// Hand-written discovery-endpoint types (controller-shaped, not generated):// entries returned by the delivery-method provider discovery endpoints.export type {diff --git a/packages/sdk-core/src/filters.ts b/packages/sdk-core/src/filters.tsindex a6cbf86771..7fac0c8721 100644--- a/packages/sdk-core/src/filters.ts+++ b/packages/sdk-core/src/filters.ts@@ -73,5 +73,7 @@ export type CustomFieldFilters = {[key: `cf_${string}`]: string | number | boolean | string[] | undefined}-/** A sort field, ascending, or descending with a `-` prefix; several are comma-separated. */-export type SortKey<K extends string> = K | `-${K}` | `${K | `-${K}`},${string}`+type SortField<K extends string> = K | `-${K}`++/** A sort field, ascending or descending with a `-` prefix, or two of them comma-separated. */+export type SortKey<K extends string> = SortField<K> | `${SortField<K>},${SortField<K>}`diff --git a/packages/sdk/src/types/index.ts b/packages/sdk/src/types/index.tsindex a9905a8c81..df97522f89 100644--- a/packages/sdk/src/types/index.ts+++ b/packages/sdk/src/types/index.ts@@ -11,7 +11,7 @@ import type {} from './filters.generated'import type { Cart as CartType } from './generated'-export type * from './filters.generated'+export * from './filters.generated'// Re-export all generated types (unprefixed: Product, Order, etc.)export type {diff --git a/packages/seller-sdk/src/types/index.ts b/packages/seller-sdk/src/types/index.tsindex f108cbba71..8067b6c21b 100644--- a/packages/seller-sdk/src/types/index.ts+++ b/packages/seller-sdk/src/types/index.ts@@ -42,7 +42,7 @@ export interface AuthTokens {sellers: SellerSummary[]}-export type * from './filters.generated'+export * from './filters.generated'export type { default as Delivery } from './generated/Delivery'// Named enums — open string unions for lists an extension may extend (statuses, fee kinds)export type * from './generated/Enums'diff --git a/spree/api/app/controllers/spree/api/v3/resource_controller.rb b/spree/api/app/controllers/spree/api/v3/resource_controller.rbindex a67bd38511..82db210481 100644--- a/spree/api/app/controllers/spree/api/v3/resource_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/resource_controller.rb@@ -414,6 +414,9 @@ module Spreeresolver = api_type_resolver(attribute.delete_prefix("#{reflection.name}_"), reflection.klass, depth + 1)return resolver if resolver+ rescue NameError+ # A reflection naming a class this installation does not load.+ nextendnilend