medusa-product-helper 0.0.13 → 0.0.16

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 (22) hide show
  1. package/.medusa/server/src/api/store/product-helper/products/route.js +76 -0
  2. package/.medusa/server/src/api/store/product-helper/products/validators.js +2 -1
  3. package/.medusa/server/src/config/product-helper-options.js +15 -1
  4. package/.medusa/server/src/index.js +101 -0
  5. package/.medusa/server/src/providers/filter-providers/availability-provider.js +96 -0
  6. package/.medusa/server/src/providers/filter-providers/base-filter-provider.js +32 -0
  7. package/.medusa/server/src/providers/filter-providers/base-product-provider.js +122 -0
  8. package/.medusa/server/src/providers/filter-providers/category-provider.js +55 -0
  9. package/.medusa/server/src/providers/filter-providers/collection-provider.js +53 -0
  10. package/.medusa/server/src/providers/filter-providers/index.js +94 -0
  11. package/.medusa/server/src/providers/filter-providers/metadata-provider.js +88 -0
  12. package/.medusa/server/src/providers/filter-providers/price-range-provider.js +108 -0
  13. package/.medusa/server/src/providers/filter-providers/promotion-provider.js +197 -0
  14. package/.medusa/server/src/providers/filter-providers/promotion-window-provider.js +125 -0
  15. package/.medusa/server/src/providers/filter-providers/rating-provider.js +92 -0
  16. package/.medusa/server/src/services/dynamic-filter-service.js +814 -0
  17. package/.medusa/server/src/services/filter-provider-loader.js +155 -0
  18. package/.medusa/server/src/services/filter-provider-registry.js +142 -0
  19. package/.medusa/server/src/services/product-filter-service.js +230 -0
  20. package/.medusa/server/src/utils/query-parser.js +103 -0
  21. package/README.md +89 -0
  22. package/package.json +3 -3
package/README.md CHANGED
@@ -147,6 +147,17 @@ const plugins = [
147
147
  // Require products to have at least one review
148
148
  require_reviews: false,
149
149
  },
150
+ // Custom filter providers (optional)
151
+ filterProviders: [
152
+ // File path (relative to project root)
153
+ "./src/providers/margin-provider.ts",
154
+ // Or module reference
155
+ "@my-org/custom-filters/brand-provider",
156
+ ],
157
+ // Disable specific built-in providers (optional)
158
+ disableBuiltInProviders: [
159
+ // "rating", // Uncomment to disable rating filter provider
160
+ ],
150
161
  },
151
162
  },
152
163
  ]
@@ -230,6 +241,84 @@ Configure rating-based filtering:
230
241
  - `max`: Maximum rating (0-5)
231
242
  - `require_reviews`: Require at least one review
232
243
 
244
+ #### Filter Providers
245
+
246
+ Configure custom filter providers:
247
+ - `filterProviders`: Array of file paths or module references to custom filter providers
248
+ - `disableBuiltInProviders`: Array of provider identifiers to disable (e.g., `["rating"]`)
249
+
250
+ See the [Provider Development Guide](./PROVIDER_DEVELOPMENT_GUIDE.md) for details on creating custom filter providers.
251
+
252
+ ## Dynamic Filter Provider System
253
+
254
+ The plugin includes a provider-based dynamic filter system that allows you to extend product filtering capabilities without modifying the plugin code. All built-in filters (category, collection, metadata, price range, etc.) are implemented as filter providers, and you can add your own custom providers.
255
+
256
+ ### Built-in Filter Providers
257
+
258
+ The plugin includes the following built-in filter providers:
259
+
260
+ - **Category Filter** (`category_id`): Filter products by category IDs
261
+ - **Collection Filter** (`collection_id`): Filter products by collection IDs
262
+ - **Metadata Filter** (`metadata`): Filter products by metadata with allowlist validation
263
+ - **Price Range Filter** (`price_range`): Filter products by price range (min/max)
264
+ - **Promotion Window Filter** (`promotion_window`): Filter products by promotion date windows
265
+ - **Availability Filter** (`availability`): Filter products by availability status
266
+ - **Rating Filter** (`rating`): Filter products by rating (min/max)
267
+ - **Base Product Filters** (`base_product`): Filter by ID, handle, tags, sales channel
268
+
269
+ ### Using Filters
270
+
271
+ All filters are available through the `/store/product-helper/products` endpoint:
272
+
273
+ ```bash
274
+ # Filter by category
275
+ GET /store/product-helper/products?category_id=cat_123,cat_456
276
+
277
+ # Filter by price range
278
+ GET /store/product-helper/products?price_min=10&price_max=100
279
+
280
+ # Filter by metadata (if filterable)
281
+ GET /store/product-helper/products?metadata[brand]=nike&metadata[color]=red
282
+
283
+ # Multiple filters
284
+ GET /store/product-helper/products?category_id=cat_123&price_min=10&rating_min=4
285
+ ```
286
+
287
+ ### Custom Filter Providers
288
+
289
+ You can create custom filter providers to add new filtering capabilities. See the [Provider Development Guide](./PROVIDER_DEVELOPMENT_GUIDE.md) for complete documentation.
290
+
291
+ **Quick Example:**
292
+
293
+ ```typescript
294
+ // src/providers/margin-provider.ts
295
+ import { BaseFilterProvider } from "medusa-product-helper/providers/filter-providers"
296
+
297
+ export class MarginFilterProvider extends BaseFilterProvider {
298
+ static readonly identifier = "margin"
299
+ static readonly displayName = "Margin Filter"
300
+
301
+ apply(filters: Record<string, unknown>, value: unknown): Record<string, unknown> {
302
+ if (!value || typeof value !== "object") return filters
303
+
304
+ const { min, max } = value as { min?: number; max?: number }
305
+ // Apply margin filter logic...
306
+ return filters
307
+ }
308
+ }
309
+ ```
310
+
311
+ Then register it in `medusa-config.ts`:
312
+
313
+ ```typescript
314
+ {
315
+ resolve: "medusa-product-helper",
316
+ options: {
317
+ filterProviders: ["./src/providers/margin-provider.ts"],
318
+ },
319
+ }
320
+ ```
321
+
233
322
  ## Wishlist Feature
234
323
 
235
324
  The plugin includes a comprehensive wishlist feature that allows customers to save products they're interested in and admins to view wishlist statistics.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "medusa-product-helper",
3
- "version": "0.0.13",
3
+ "version": "0.0.16",
4
4
  "description": "A starter for Medusa plugins.",
5
5
  "author": "Medusa (https://medusajs.com)",
6
6
  "license": "MIT",
@@ -37,10 +37,10 @@
37
37
  "@medusajs/admin-sdk": "2.11.2",
38
38
  "@medusajs/cli": "2.11.2",
39
39
  "@medusajs/framework": "2.11.2",
40
+ "@medusajs/icons": "2.11.2",
40
41
  "@medusajs/medusa": "2.11.2",
41
42
  "@medusajs/test-utils": "2.11.2",
42
43
  "@medusajs/ui": "4.0.25",
43
- "@medusajs/icons": "2.11.2",
44
44
  "@swc/core": "1.5.7",
45
45
  "@types/node": "^20.0.0",
46
46
  "@types/react": "^18.3.2",
@@ -68,4 +68,4 @@
68
68
  "engines": {
69
69
  "node": ">=20"
70
70
  }
71
- }
71
+ }