@unchainedshop/core-products 5.0.0-alpha.5 → 5.0.0-alpha.8

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.
package/README.md CHANGED
@@ -13,121 +13,26 @@ npm install @unchainedshop/core-products
13
13
 
14
14
  ## Usage
15
15
 
16
- ```typescript
17
- import { configureProductsModule, ProductType } from '@unchainedshop/core-products';
16
+ The platform initializes this module as `platform.unchainedAPI.modules.products`.
18
17
 
19
- const productsModule = await configureProductsModule({ db });
18
+ ```typescript
19
+ import { ProductType } from '@unchainedshop/core-products';
20
20
 
21
- // Create a product
22
- const productId = await productsModule.create({
23
- type: ProductType.SimpleProduct,
24
- slugs: ['my-product'],
21
+ const { products } = platform.unchainedAPI.modules;
22
+ const product = await products.create({
23
+ type: ProductType.SIMPLE_PRODUCT,
24
+ tags: ['featured'],
25
25
  });
26
-
27
- // Find products
28
- const products = await productsModule.findProducts({
26
+ await products.publish(product);
27
+ const publishedProducts = await products.findProducts({
29
28
  tags: ['featured'],
30
29
  includeDrafts: false,
31
30
  });
32
-
33
- // Publish a product
34
- await productsModule.publish(productId);
35
31
  ```
36
32
 
37
- ## API Overview
38
-
39
- ### Module Configuration
40
-
41
- | Export | Description |
42
- |--------|-------------|
43
- | `configureProductsModule` | Configure and return the products module |
44
-
45
- ### Queries
46
-
47
- | Method | Description |
48
- |--------|-------------|
49
- | `findProduct` | Find product by ID or slug |
50
- | `findProducts` | Find products with filtering and pagination |
51
- | `count` | Count products matching query |
52
- | `productExists` | Check if product exists |
53
-
54
- ### Mutations
55
-
56
- | Method | Description |
57
- |--------|-------------|
58
- | `create` | Create a new product |
59
- | `update` | Update product data |
60
- | `delete` | Soft delete a product |
61
- | `publish` | Publish a draft product |
62
- | `unpublish` | Unpublish a product |
63
- | `addAssignment` | Add product proxy assignment |
64
- | `removeAssignment` | Remove product assignment |
65
-
66
- ### Submodules
67
-
68
- #### Media (`products.media`)
69
- | Method | Description |
70
- |--------|-------------|
71
- | `findProductMedia` | Find media for a product |
72
- | `createMedia` | Add media to product |
73
- | `updateMedia` | Update media metadata |
74
- | `deleteMedia` | Remove media from product |
75
- | `reorderMedia` | Reorder product media |
76
-
77
- #### Prices (`products.prices`)
78
- | Method | Description |
79
- |--------|-------------|
80
- | `findProductPrices` | Get product prices |
81
- | `createPrice` | Add a price |
82
- | `updatePrice` | Update a price |
83
- | `deletePrice` | Remove a price |
84
-
85
- #### Reviews (`products.reviews`)
86
- | Method | Description |
87
- |--------|-------------|
88
- | `findProductReviews` | Find reviews for product |
89
- | `createReview` | Add a review |
90
- | `updateReview` | Update a review |
91
- | `deleteReview` | Remove a review |
92
-
93
- #### Texts (`products.texts`)
94
- | Method | Description |
95
- |--------|-------------|
96
- | `findProductTexts` | Find localized texts |
97
- | `updateTexts` | Update product texts |
98
-
99
- #### Variations (`products.variations`)
100
- | Method | Description |
101
- |--------|-------------|
102
- | `findProductVariations` | Find product variations |
103
- | `createVariation` | Add a variation |
104
- | `updateVariation` | Update a variation |
105
- | `deleteVariation` | Remove a variation |
106
-
107
- ### Constants
108
-
109
- | Export | Description |
110
- |--------|-------------|
111
- | `ProductType` | Product types (SimpleProduct, ConfigurableProduct, BundleProduct, PlanProduct, TokenizedProduct) |
112
- | `ProductStatus` | Product status values (ACTIVE, DRAFT) |
113
-
114
- ### Types
115
-
116
- | Export | Description |
117
- |--------|-------------|
118
- | `Product` | Product document type |
119
- | `ProductQuery` | Query parameters type |
120
- | `ProductsModule` | Module interface type |
121
-
122
- ## Events
33
+ `create` returns the product document, and `publish` accepts that document. The module exposes `media`, `prices`, `reviews`, `texts`, `variations`, `assignments`, and `bundleItems` submodules. Catalog prices are written as `commerce.pricing` entries with `minQuantity` tiers; computed pricing is coordinated by the core pricing services and plugins.
123
34
 
124
- | Event | Description |
125
- |-------|-------------|
126
- | `PRODUCT_CREATE` | Product created |
127
- | `PRODUCT_UPDATE` | Product updated |
128
- | `PRODUCT_REMOVE` | Product deleted |
129
- | `PRODUCT_PUBLISH` | Product published |
130
- | `PRODUCT_UNPUBLISH` | Product unpublished |
35
+ See the [module guide](https://docs.unchained.shop/platform-configuration/modules/products), [pricing guide](https://docs.unchained.shop/concepts/pricing-system), [public exports](src/products-index.ts), and [module implementation](src/module/configureProductsModule.ts).
131
36
 
132
37
  ## License
133
38
 
@@ -63,9 +63,9 @@ export interface ProductCommerce {
63
63
  pricing: ProductPrice[];
64
64
  }
65
65
  export interface ProductTokenization {
66
- contractAddress: string;
66
+ contractAddress?: string;
67
67
  contractStandard: ProductContractStandard;
68
- tokenId: string;
68
+ tokenId?: string;
69
69
  supply: number;
70
70
  ercMetadataProperties?: Record<string, any>;
71
71
  }
@@ -1,6 +1,6 @@
1
1
  import { mongodb, type ModuleInput } from '@unchainedshop/mongodb';
2
2
  import { type SortOption, type Price } from '@unchainedshop/utils';
3
- import { type Product, type ProductAssignment, type ProductBundleItem, type ProductConfiguration, ProductStatus } from '../db/ProductsCollection.ts';
3
+ import { type Product, type ProductAssignment, type ProductBundleItem, type ProductConfiguration, ProductStatus, ProductType } from '../db/ProductsCollection.ts';
4
4
  import { type ProductsSettingsOptions } from '../products-settings.ts';
5
5
  export interface ProductQuery {
6
6
  queryString?: string;
@@ -11,6 +11,7 @@ export interface ProductQuery {
11
11
  slugs?: string[];
12
12
  tags?: string[];
13
13
  skus?: string[];
14
+ type?: ProductType;
14
15
  bundleItemProductIds?: string[];
15
16
  proxyAssignmentProductIds?: string[];
16
17
  }
@@ -22,7 +23,7 @@ export interface ProductDiscount {
22
23
  discountKey: string;
23
24
  context?: any;
24
25
  }
25
- export declare const buildFindSelector: ({ slugs, tags, includeDrafts, includeDeleted, productIds, productSelector, queryString, skus, bundleItemProductIds, proxyAssignmentProductIds, }: ProductQuery) => mongodb.Filter<Product>;
26
+ export declare const buildFindSelector: ({ slugs, tags, includeDrafts, includeDeleted, productIds, productSelector, queryString, skus, type, bundleItemProductIds, proxyAssignmentProductIds, }: ProductQuery) => mongodb.Filter<Product>;
26
27
  export declare const configureProductsModule: (moduleInput: ModuleInput<ProductsSettingsOptions>) => Promise<{
27
28
  findProduct: (params: {
28
29
  productId: string;
@@ -25,11 +25,14 @@ const InternalProductStatus = {
25
25
  DRAFT: null,
26
26
  };
27
27
  const isDraftStatus = (status) => status === ProductStatus.DRAFT || status === InternalProductStatus.DRAFT;
28
- export const buildFindSelector = ({ slugs, tags, includeDrafts = false, includeDeleted = false, productIds, productSelector, queryString, skus, bundleItemProductIds, proxyAssignmentProductIds, }) => {
28
+ export const buildFindSelector = ({ slugs, tags, includeDrafts = false, includeDeleted = false, productIds, productSelector, queryString, skus, type, bundleItemProductIds, proxyAssignmentProductIds, }) => {
29
29
  const selector = productSelector ? { ...productSelector } : {};
30
30
  if (productIds && !selector._id) {
31
31
  selector._id = { $in: productIds };
32
32
  }
33
+ if (type && !selector.type) {
34
+ selector.type = type;
35
+ }
33
36
  if (slugs && !selector.slugs) {
34
37
  selector.slugs = { $in: slugs };
35
38
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-products",
3
3
  "description": "Product catalog management module for the Unchained Engine",
4
- "version": "5.0.0-alpha.5",
4
+ "version": "5.0.0-alpha.8",
5
5
  "main": "lib/products-index.js",
6
6
  "types": "lib/products-index.d.ts",
7
7
  "type": "module",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "homepage": "https://github.com/unchainedshop/unchained#readme",
37
37
  "dependencies": {
38
- "@unchainedshop/events": "^5.0.0-alpha.5",
39
- "@unchainedshop/logger": "^5.0.0-alpha.5",
40
- "@unchainedshop/mongodb": "^5.0.0-alpha.5",
41
- "@unchainedshop/utils": "^5.0.0-alpha.5"
38
+ "@unchainedshop/events": "^5.0.0-alpha.8",
39
+ "@unchainedshop/logger": "^5.0.0-alpha.8",
40
+ "@unchainedshop/mongodb": "^5.0.0-alpha.8",
41
+ "@unchainedshop/utils": "^5.0.0-alpha.8"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^26.2.0",