@unchainedshop/core-products 4.3.4 → 4.4.0
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 +133 -2
- package/lib/db/ProductMediaCollection.d.ts +1 -2
- package/lib/db/ProductMediaCollection.js +1 -4
- package/lib/db/ProductPriceRates.d.ts +0 -1
- package/lib/db/ProductPriceRates.js +1 -2
- package/lib/db/ProductReviewsCollection.d.ts +7 -7
- package/lib/db/ProductReviewsCollection.js +6 -8
- package/lib/db/ProductVariationsCollection.d.ts +6 -6
- package/lib/db/ProductVariationsCollection.js +5 -7
- package/lib/db/ProductsCollection.d.ts +22 -20
- package/lib/db/ProductsCollection.js +17 -23
- package/lib/mock/product.d.ts +0 -1
- package/lib/mock/product.js +0 -1
- package/lib/module/configureProductMediaModule.d.ts +5 -4
- package/lib/module/configureProductMediaModule.js +3 -13
- package/lib/module/configureProductPrices.d.ts +2 -3
- package/lib/module/configureProductPrices.js +4 -7
- package/lib/module/configureProductReviewsModule.d.ts +3 -4
- package/lib/module/configureProductReviewsModule.js +2 -7
- package/lib/module/configureProductTextsModule.d.ts +4 -3
- package/lib/module/configureProductTextsModule.js +2 -5
- package/lib/module/configureProductVariationsModule.d.ts +5 -4
- package/lib/module/configureProductVariationsModule.js +2 -10
- package/lib/module/configureProductsModule.d.ts +55 -50
- package/lib/module/configureProductsModule.js +10 -26
- package/lib/module/utils/getPriceLevels.d.ts +2 -3
- package/lib/module/utils/getPriceLevels.js +0 -1
- package/lib/module/utils/getPriceRange.d.ts +1 -2
- package/lib/module/utils/getPriceRange.js +0 -1
- package/lib/products-index.d.ts +13 -14
- package/lib/products-index.js +13 -14
- package/lib/products-settings.d.ts +0 -1
- package/lib/products-settings.js +0 -1
- package/package.json +11 -10
- package/lib/db/ProductMediaCollection.d.ts.map +0 -1
- package/lib/db/ProductMediaCollection.js.map +0 -1
- package/lib/db/ProductPriceRates.d.ts.map +0 -1
- package/lib/db/ProductPriceRates.js.map +0 -1
- package/lib/db/ProductReviewsCollection.d.ts.map +0 -1
- package/lib/db/ProductReviewsCollection.js.map +0 -1
- package/lib/db/ProductVariationsCollection.d.ts.map +0 -1
- package/lib/db/ProductVariationsCollection.js.map +0 -1
- package/lib/db/ProductsCollection.d.ts.map +0 -1
- package/lib/db/ProductsCollection.js.map +0 -1
- package/lib/mock/product.d.ts.map +0 -1
- package/lib/mock/product.js.map +0 -1
- package/lib/module/configureProductMediaModule.d.ts.map +0 -1
- package/lib/module/configureProductMediaModule.js.map +0 -1
- package/lib/module/configureProductPrices.d.ts.map +0 -1
- package/lib/module/configureProductPrices.js.map +0 -1
- package/lib/module/configureProductReviewsModule.d.ts.map +0 -1
- package/lib/module/configureProductReviewsModule.js.map +0 -1
- package/lib/module/configureProductTextsModule.d.ts.map +0 -1
- package/lib/module/configureProductTextsModule.js.map +0 -1
- package/lib/module/configureProductVariationsModule.d.ts.map +0 -1
- package/lib/module/configureProductVariationsModule.js.map +0 -1
- package/lib/module/configureProductsModule.d.ts.map +0 -1
- package/lib/module/configureProductsModule.js.map +0 -1
- package/lib/module/utils/getPriceLevels.d.ts.map +0 -1
- package/lib/module/utils/getPriceLevels.js.map +0 -1
- package/lib/module/utils/getPriceRange.d.ts.map +0 -1
- package/lib/module/utils/getPriceRange.js.map +0 -1
- package/lib/products-index.d.ts.map +0 -1
- package/lib/products-index.js.map +0 -1
- package/lib/products-settings.d.ts.map +0 -1
- package/lib/products-settings.js.map +0 -1
- package/src/db/ProductMediaCollection.ts +0 -39
- package/src/db/ProductPriceRates.ts +0 -24
- package/src/db/ProductReviewsCollection.ts +0 -58
- package/src/db/ProductVariationsCollection.ts +0 -46
- package/src/db/ProductsCollection.ts +0 -181
- package/src/mock/product.ts +0 -47
- package/src/module/buildFindSelector.test.ts +0 -105
- package/src/module/configureProductMediaModule.ts +0 -268
- package/src/module/configureProductPrices.ts +0 -302
- package/src/module/configureProductReviewsModule.ts +0 -289
- package/src/module/configureProductTextsModule.ts +0 -177
- package/src/module/configureProductVariationsModule.ts +0 -298
- package/src/module/configureProductsModule.ts +0 -628
- package/src/module/utils/configureProductPrices.test.ts +0 -156
- package/src/module/utils/getPriceLevels.test.ts +0 -91
- package/src/module/utils/getPriceLevels.ts +0 -21
- package/src/module/utils/getPriceRange.test.ts +0 -57
- package/src/module/utils/getPriceRange.ts +0 -36
- package/src/products-index.ts +0 -15
- package/src/products-settings.ts +0 -15
- package/tests/product-index.test.ts +0 -7
- package/tsconfig.json +0 -10
package/README.md
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://npmjs.com/package/@unchainedshop/core-products)
|
|
2
|
+
[](https://opensource.org/licenses/EUPL-1.2)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# @unchainedshop/core-products
|
|
5
|
+
|
|
6
|
+
Product management module for the Unchained Engine. Handles products, pricing, media, reviews, texts, and variations.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @unchainedshop/core-products
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { configureProductsModule, ProductType } from '@unchainedshop/core-products';
|
|
18
|
+
|
|
19
|
+
const productsModule = await configureProductsModule({ db });
|
|
20
|
+
|
|
21
|
+
// Create a product
|
|
22
|
+
const productId = await productsModule.create({
|
|
23
|
+
type: ProductType.SimpleProduct,
|
|
24
|
+
slugs: ['my-product'],
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Find products
|
|
28
|
+
const products = await productsModule.findProducts({
|
|
29
|
+
tags: ['featured'],
|
|
30
|
+
includeDrafts: false,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Publish a product
|
|
34
|
+
await productsModule.publish(productId);
|
|
35
|
+
```
|
|
36
|
+
|
|
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
|
|
123
|
+
|
|
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 |
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
EUPL-1.2
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mongodb, TimestampFields } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
2
|
export type ProductMedia = {
|
|
3
3
|
_id: string;
|
|
4
4
|
mediaId: string;
|
|
@@ -18,4 +18,3 @@ export declare const ProductMediaCollection: (db: mongodb.Db) => Promise<{
|
|
|
18
18
|
ProductMedias: mongodb.Collection<ProductMedia>;
|
|
19
19
|
ProductMediaTexts: mongodb.Collection<ProductMediaText>;
|
|
20
20
|
}>;
|
|
21
|
-
//# sourceMappingURL=ProductMediaCollection.d.ts.map
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
2
|
export const ProductMediaCollection = async (db) => {
|
|
3
3
|
const ProductMedias = db.collection('product_media');
|
|
4
4
|
const ProductMediaTexts = db.collection('product_media_texts');
|
|
5
|
-
// ProductMedia Indexes
|
|
6
5
|
await buildDbIndexes(ProductMedias, [
|
|
7
6
|
{ index: { mediaId: 1 } },
|
|
8
7
|
{ index: { productId: 1, sortKey: 1 } },
|
|
9
8
|
{ index: { tags: 1, sortKey: 1 } },
|
|
10
9
|
{ index: { productId: 1, tags: 1, sortKey: 1 } },
|
|
11
10
|
]);
|
|
12
|
-
// ProductMediaTexts indexes
|
|
13
11
|
await buildDbIndexes(ProductMediaTexts, [{ index: { productMediaId: 1 } }, { index: { locale: 1 } }]);
|
|
14
12
|
return {
|
|
15
13
|
ProductMedias,
|
|
16
14
|
ProductMediaTexts,
|
|
17
15
|
};
|
|
18
16
|
};
|
|
19
|
-
//# sourceMappingURL=ProductMediaCollection.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
2
|
export const ProductPriceRates = async (db) => {
|
|
3
3
|
const ProductRates = db.collection('product_rates');
|
|
4
4
|
await buildDbIndexes(ProductRates, [
|
|
@@ -11,4 +11,3 @@ export const ProductPriceRates = async (db) => {
|
|
|
11
11
|
ProductRates,
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=ProductPriceRates.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { mongodb, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
export declare
|
|
3
|
-
UPVOTE
|
|
4
|
-
DOWNVOTE
|
|
5
|
-
REPORT
|
|
6
|
-
}
|
|
1
|
+
import { mongodb, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
export declare const ProductReviewVoteType: {
|
|
3
|
+
readonly UPVOTE: "UPVOTE";
|
|
4
|
+
readonly DOWNVOTE: "DOWNVOTE";
|
|
5
|
+
readonly REPORT: "REPORT";
|
|
6
|
+
};
|
|
7
|
+
export type ProductReviewVoteType = (typeof ProductReviewVoteType)[keyof typeof ProductReviewVoteType];
|
|
7
8
|
export interface ProductVote {
|
|
8
9
|
meta?: any;
|
|
9
10
|
timestamp?: Date;
|
|
@@ -23,4 +24,3 @@ export type ProductReview = {
|
|
|
23
24
|
export declare const ProductReviewsCollection: (db: mongodb.Db) => Promise<{
|
|
24
25
|
ProductReviews: mongodb.Collection<ProductReview>;
|
|
25
26
|
}>;
|
|
26
|
-
//# sourceMappingURL=ProductReviewsCollection.d.ts.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})(ProductReviewVoteType || (ProductReviewVoteType = {}));
|
|
1
|
+
import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
|
+
export const ProductReviewVoteType = {
|
|
3
|
+
UPVOTE: 'UPVOTE',
|
|
4
|
+
DOWNVOTE: 'DOWNVOTE',
|
|
5
|
+
REPORT: 'REPORT',
|
|
6
|
+
};
|
|
8
7
|
export const ProductReviewsCollection = async (db) => {
|
|
9
8
|
const ProductReviews = db.collection('product_reviews');
|
|
10
9
|
if (!isDocumentDBCompatModeEnabled()) {
|
|
@@ -29,4 +28,3 @@ export const ProductReviewsCollection = async (db) => {
|
|
|
29
28
|
ProductReviews,
|
|
30
29
|
};
|
|
31
30
|
};
|
|
32
|
-
//# sourceMappingURL=ProductReviewsCollection.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { mongodb, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
export declare
|
|
3
|
-
COLOR
|
|
4
|
-
TEXT
|
|
5
|
-
}
|
|
1
|
+
import { mongodb, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
export declare const ProductVariationType: {
|
|
3
|
+
readonly COLOR: "COLOR";
|
|
4
|
+
readonly TEXT: "TEXT";
|
|
5
|
+
};
|
|
6
|
+
export type ProductVariationType = (typeof ProductVariationType)[keyof typeof ProductVariationType];
|
|
6
7
|
export type ProductVariation = {
|
|
7
8
|
_id: string;
|
|
8
9
|
key: string;
|
|
@@ -28,4 +29,3 @@ export declare const ProductVariationsCollection: (db: mongodb.Db) => Promise<{
|
|
|
28
29
|
ProductVariations: mongodb.Collection<ProductVariation>;
|
|
29
30
|
ProductVariationTexts: mongodb.Collection<ProductVariationText>;
|
|
30
31
|
}>;
|
|
31
|
-
//# sourceMappingURL=ProductVariationsCollection.d.ts.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(ProductVariationType || (ProductVariationType = {}));
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
+
export const ProductVariationType = {
|
|
3
|
+
COLOR: 'COLOR',
|
|
4
|
+
TEXT: 'TEXT',
|
|
5
|
+
};
|
|
7
6
|
export const ProductVariationsCollection = async (db) => {
|
|
8
7
|
const ProductVariations = db.collection('product_variations');
|
|
9
8
|
const ProductVariationTexts = db.collection('product_variation_texts');
|
|
@@ -17,4 +16,3 @@ export const ProductVariationsCollection = async (db) => {
|
|
|
17
16
|
ProductVariationTexts,
|
|
18
17
|
};
|
|
19
18
|
};
|
|
20
|
-
//# sourceMappingURL=ProductVariationsCollection.js.map
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { mongodb, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
3
|
-
export declare
|
|
4
|
-
DRAFT
|
|
5
|
-
ACTIVE
|
|
6
|
-
DELETED
|
|
7
|
-
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { mongodb, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
import type { Price } from '@unchainedshop/utils';
|
|
3
|
+
export declare const ProductStatus: {
|
|
4
|
+
readonly DRAFT: "DRAFT";
|
|
5
|
+
readonly ACTIVE: "ACTIVE";
|
|
6
|
+
readonly DELETED: "DELETED";
|
|
7
|
+
};
|
|
8
|
+
export type ProductStatus = (typeof ProductStatus)[keyof typeof ProductStatus];
|
|
9
|
+
export declare const ProductType: {
|
|
10
|
+
readonly SIMPLE_PRODUCT: "SIMPLE_PRODUCT";
|
|
11
|
+
readonly CONFIGURABLE_PRODUCT: "CONFIGURABLE_PRODUCT";
|
|
12
|
+
readonly BUNDLE_PRODUCT: "BUNDLE_PRODUCT";
|
|
13
|
+
readonly PLAN_PRODUCT: "PLAN_PRODUCT";
|
|
14
|
+
readonly TOKENIZED_PRODUCT: "TOKENIZED_PRODUCT";
|
|
15
|
+
};
|
|
16
|
+
export type ProductType = (typeof ProductType)[keyof typeof ProductType];
|
|
15
17
|
export interface ProductContractConfiguration {
|
|
16
18
|
tokenId?: string;
|
|
17
19
|
supply?: number;
|
|
@@ -30,10 +32,11 @@ export interface ProductSupply {
|
|
|
30
32
|
lengthInMillimeters?: number;
|
|
31
33
|
widthInMillimeters?: number;
|
|
32
34
|
}
|
|
33
|
-
export declare
|
|
34
|
-
ERC721
|
|
35
|
-
ERC1155
|
|
36
|
-
}
|
|
35
|
+
export declare const ProductContractStandard: {
|
|
36
|
+
readonly ERC721: "ERC721";
|
|
37
|
+
readonly ERC1155: "ERC1155";
|
|
38
|
+
};
|
|
39
|
+
export type ProductContractStandard = (typeof ProductContractStandard)[keyof typeof ProductContractStandard];
|
|
37
40
|
export interface ProductConfiguration {
|
|
38
41
|
key: string;
|
|
39
42
|
value: string;
|
|
@@ -90,7 +93,7 @@ export type Product = {
|
|
|
90
93
|
status?: string | null;
|
|
91
94
|
supply?: ProductSupply;
|
|
92
95
|
tags: string[];
|
|
93
|
-
type:
|
|
96
|
+
type: ProductType;
|
|
94
97
|
warehousing?: ProductWarehousing;
|
|
95
98
|
tokenization?: ProductTokenization;
|
|
96
99
|
} & TimestampFields;
|
|
@@ -110,4 +113,3 @@ export declare const ProductsCollection: (db: mongodb.Db) => Promise<{
|
|
|
110
113
|
Products: mongodb.Collection<Product>;
|
|
111
114
|
ProductTexts: mongodb.Collection<ProductText>;
|
|
112
115
|
}>;
|
|
113
|
-
//# sourceMappingURL=ProductsCollection.d.ts.map
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ProductContractStandard["ERC721"] = "ERC721";
|
|
19
|
-
ProductContractStandard["ERC1155"] = "ERC1155";
|
|
20
|
-
})(ProductContractStandard || (ProductContractStandard = {}));
|
|
1
|
+
import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
|
+
export const ProductStatus = {
|
|
3
|
+
DRAFT: 'DRAFT',
|
|
4
|
+
ACTIVE: 'ACTIVE',
|
|
5
|
+
DELETED: 'DELETED',
|
|
6
|
+
};
|
|
7
|
+
export const ProductType = {
|
|
8
|
+
SIMPLE_PRODUCT: 'SIMPLE_PRODUCT',
|
|
9
|
+
CONFIGURABLE_PRODUCT: 'CONFIGURABLE_PRODUCT',
|
|
10
|
+
BUNDLE_PRODUCT: 'BUNDLE_PRODUCT',
|
|
11
|
+
PLAN_PRODUCT: 'PLAN_PRODUCT',
|
|
12
|
+
TOKENIZED_PRODUCT: 'TOKENIZED_PRODUCT',
|
|
13
|
+
};
|
|
14
|
+
export const ProductContractStandard = {
|
|
15
|
+
ERC721: 'ERC721',
|
|
16
|
+
ERC1155: 'ERC1155',
|
|
17
|
+
};
|
|
21
18
|
export const ProductsCollection = async (db) => {
|
|
22
19
|
const Products = db.collection('products');
|
|
23
20
|
const ProductTexts = db.collection('product_texts');
|
|
@@ -45,7 +42,6 @@ export const ProductsCollection = async (db) => {
|
|
|
45
42
|
},
|
|
46
43
|
]);
|
|
47
44
|
}
|
|
48
|
-
// Product Indexes
|
|
49
45
|
await buildDbIndexes(Products, [
|
|
50
46
|
{ index: { sequence: 1 } },
|
|
51
47
|
{ index: { slugs: 1 } },
|
|
@@ -53,7 +49,6 @@ export const ProductsCollection = async (db) => {
|
|
|
53
49
|
{ index: { tags: 1 } },
|
|
54
50
|
{ index: { 'warehousing.sku': 1 } },
|
|
55
51
|
]);
|
|
56
|
-
// ProductTexts indexes
|
|
57
52
|
await buildDbIndexes(ProductTexts, [
|
|
58
53
|
{ index: { productId: 1 } },
|
|
59
54
|
{ index: { locale: 1 } },
|
|
@@ -65,4 +60,3 @@ export const ProductsCollection = async (db) => {
|
|
|
65
60
|
ProductTexts,
|
|
66
61
|
};
|
|
67
62
|
};
|
|
68
|
-
//# sourceMappingURL=ProductsCollection.js.map
|
package/lib/mock/product.d.ts
CHANGED
package/lib/mock/product.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ModuleInput } from '@unchainedshop/mongodb';
|
|
1
|
+
import type { ModuleInput } from '@unchainedshop/mongodb';
|
|
2
2
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
3
|
-
import { ProductMedia, ProductMediaText } from '../db/ProductMediaCollection.
|
|
3
|
+
import { type ProductMedia, type ProductMediaText } from '../db/ProductMediaCollection.ts';
|
|
4
4
|
export declare const configureProductMediaModule: ({ db }: ModuleInput<Record<string, unknown>>) => Promise<{
|
|
5
5
|
findProductMedia: ({ productMediaId }: {
|
|
6
6
|
productMediaId: string;
|
|
@@ -31,7 +31,8 @@ export declare const configureProductMediaModule: ({ db }: ModuleInput<Record<st
|
|
|
31
31
|
productMediaId: string;
|
|
32
32
|
locale: Intl.Locale;
|
|
33
33
|
}) => Promise<ProductMediaText>;
|
|
34
|
-
updateMediaTexts: (productMediaId: string, texts:
|
|
34
|
+
updateMediaTexts: (productMediaId: string, texts: ({
|
|
35
|
+
locale: ProductMediaText["locale"];
|
|
36
|
+
} & Omit<Partial<ProductMediaText>, "productMediaId" | "locale">)[]) => Promise<ProductMediaText[]>;
|
|
35
37
|
};
|
|
36
38
|
}>;
|
|
37
|
-
//# sourceMappingURL=configureProductMediaModule.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
|
-
import { findLocalizedText, generateDbFilterById, generateDbObjectId, } from '@unchainedshop/mongodb';
|
|
3
|
-
import { ProductMediaCollection } from
|
|
2
|
+
import { findLocalizedText, generateDbFilterById, generateDbObjectId, mongodb, } from '@unchainedshop/mongodb';
|
|
3
|
+
import { ProductMediaCollection, } from "../db/ProductMediaCollection.js";
|
|
4
4
|
const PRODUCT_MEDIA_EVENTS = [
|
|
5
5
|
'PRODUCT_ADD_MEDIA',
|
|
6
6
|
'PRODUCT_REMOVE_MEDIA',
|
|
@@ -37,7 +37,6 @@ export const configureProductMediaModule = async ({ db }) => {
|
|
|
37
37
|
return productMediaText;
|
|
38
38
|
};
|
|
39
39
|
return {
|
|
40
|
-
// Queries
|
|
41
40
|
findProductMedia: async ({ productMediaId }) => {
|
|
42
41
|
return ProductMedias.findOne(generateDbFilterById(productMediaId), {});
|
|
43
42
|
},
|
|
@@ -54,10 +53,8 @@ export const configureProductMediaModule = async ({ db }) => {
|
|
|
54
53
|
});
|
|
55
54
|
return mediaList.toArray();
|
|
56
55
|
},
|
|
57
|
-
// Mutations
|
|
58
56
|
create: async ({ sortKey, ...doc }) => {
|
|
59
57
|
if (sortKey === undefined || sortKey === null) {
|
|
60
|
-
// Get next sort key
|
|
61
58
|
const lastProductMedia = (await ProductMedias.findOne({
|
|
62
59
|
productId: doc.productId,
|
|
63
60
|
}, {
|
|
@@ -103,7 +100,6 @@ export const configureProductMediaModule = async ({ db }) => {
|
|
|
103
100
|
})));
|
|
104
101
|
return deletedResult.deletedCount;
|
|
105
102
|
},
|
|
106
|
-
// This action is specifically used for the bulk migration scripts in the platform package
|
|
107
103
|
update: async (productMediaId, doc) => {
|
|
108
104
|
const selector = generateDbFilterById(productMediaId);
|
|
109
105
|
const modifier = { $set: doc };
|
|
@@ -125,11 +121,7 @@ export const configureProductMediaModule = async ({ db }) => {
|
|
|
125
121
|
await emit('PRODUCT_REORDER_MEDIA', { productMedias });
|
|
126
122
|
return productMedias;
|
|
127
123
|
},
|
|
128
|
-
/*
|
|
129
|
-
* Product Media Texts
|
|
130
|
-
*/
|
|
131
124
|
texts: {
|
|
132
|
-
// Queries
|
|
133
125
|
findMediaTexts: async ({ productMediaId }, options) => {
|
|
134
126
|
return ProductMediaTexts.find({ productMediaId }, options).toArray();
|
|
135
127
|
},
|
|
@@ -137,12 +129,10 @@ export const configureProductMediaModule = async ({ db }) => {
|
|
|
137
129
|
const text = await findLocalizedText(ProductMediaTexts, { productMediaId }, locale);
|
|
138
130
|
return text;
|
|
139
131
|
},
|
|
140
|
-
// Mutations
|
|
141
132
|
updateMediaTexts: async (productMediaId, texts) => {
|
|
142
|
-
const mediaTexts = (await Promise.all(texts.map(async ({ locale, ...
|
|
133
|
+
const mediaTexts = (await Promise.all(texts.map(async ({ locale, ...text }) => upsertLocalizedText(productMediaId, new Intl.Locale(locale), text)))).filter(Boolean);
|
|
143
134
|
return mediaTexts;
|
|
144
135
|
},
|
|
145
136
|
},
|
|
146
137
|
};
|
|
147
138
|
};
|
|
148
|
-
//# sourceMappingURL=configureProductMediaModule.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProductPriceRate } from '../db/ProductPriceRates.
|
|
2
|
-
import { Product, ProductConfiguration, ProductPrice, ProductPriceRange } from '../db/ProductsCollection.
|
|
1
|
+
import { type ProductPriceRate } from '../db/ProductPriceRates.ts';
|
|
2
|
+
import { type Product, type ProductConfiguration, type ProductPrice, type ProductPriceRange } from '../db/ProductsCollection.ts';
|
|
3
3
|
export declare const getDecimals: (originDecimals: any) => any;
|
|
4
4
|
export declare const normalizeRate: (baseCurrency: {
|
|
5
5
|
decimals?: number;
|
|
@@ -63,4 +63,3 @@ export declare const configureProductPricesModule: ({ proxyProducts, db, }: {
|
|
|
63
63
|
updateRates: (rates: ProductPriceRate[]) => Promise<boolean>;
|
|
64
64
|
};
|
|
65
65
|
};
|
|
66
|
-
//# sourceMappingURL=configureProductPrices.d.ts.map
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { getPriceLevels } from
|
|
2
|
-
import { getPriceRange } from
|
|
3
|
-
import { ProductPriceRates } from
|
|
1
|
+
import { getPriceLevels } from "./utils/getPriceLevels.js";
|
|
2
|
+
import { getPriceRange } from "./utils/getPriceRange.js";
|
|
3
|
+
import { ProductPriceRates } from "../db/ProductPriceRates.js";
|
|
4
|
+
import {} from "../db/ProductsCollection.js";
|
|
4
5
|
export const getDecimals = (originDecimals) => {
|
|
5
6
|
if (originDecimals === null || originDecimals === undefined) {
|
|
6
7
|
return 2;
|
|
7
8
|
}
|
|
8
9
|
if (originDecimals > 2) {
|
|
9
|
-
// cryptocurrency, always stored in MAX. 9 decimals
|
|
10
|
-
// WORKAROUND FOR BIGINT PROBLEM!
|
|
11
10
|
return Math.min(originDecimals, 9);
|
|
12
11
|
}
|
|
13
12
|
return originDecimals;
|
|
@@ -172,7 +171,6 @@ export const configureProductPricesModule = ({ proxyProducts, db, }) => {
|
|
|
172
171
|
rate: rate.rate,
|
|
173
172
|
},
|
|
174
173
|
});
|
|
175
|
-
// Archive the others that were still valid
|
|
176
174
|
BulkOp.find({
|
|
177
175
|
baseCurrency: rate.baseCurrency,
|
|
178
176
|
quoteCurrency: rate.quoteCurrency,
|
|
@@ -194,4 +192,3 @@ export const configureProductPricesModule = ({ proxyProducts, db, }) => {
|
|
|
194
192
|
},
|
|
195
193
|
};
|
|
196
194
|
};
|
|
197
|
-
//# sourceMappingURL=configureProductPrices.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ModuleInput } from '@unchainedshop/mongodb';
|
|
1
|
+
import { type ModuleInput } from '@unchainedshop/mongodb';
|
|
2
2
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
3
|
-
import { SortOption } from '@unchainedshop/utils';
|
|
4
|
-
import { ProductReview, ProductReviewVoteType, ProductVote } from '../db/ProductReviewsCollection.
|
|
3
|
+
import { type SortOption } from '@unchainedshop/utils';
|
|
4
|
+
import { type ProductReview, ProductReviewVoteType, type ProductVote } from '../db/ProductReviewsCollection.ts';
|
|
5
5
|
export interface ProductReviewQuery {
|
|
6
6
|
productId?: string;
|
|
7
7
|
authorId?: string;
|
|
@@ -47,4 +47,3 @@ export declare const configureProductReviewsModule: ({ db }: ModuleInput<Record<
|
|
|
47
47
|
removeVote: (productReviewId: string, { userId, type }: ProductVote) => Promise<mongodb.WithId<ProductReview> | null>;
|
|
48
48
|
};
|
|
49
49
|
}>;
|
|
50
|
-
//# sourceMappingURL=configureProductReviewsModule.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assertDocumentDBCompatMode } from '@unchainedshop/mongodb';
|
|
2
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
3
|
-
import { generateDbFilterById, buildSortOptions, generateDbObjectId, } from '@unchainedshop/mongodb';
|
|
3
|
+
import { generateDbFilterById, buildSortOptions, mongodb, generateDbObjectId, } from '@unchainedshop/mongodb';
|
|
4
4
|
import { SortDirection } from '@unchainedshop/utils';
|
|
5
|
-
import { ProductReviewsCollection, ProductReviewVoteType, } from
|
|
5
|
+
import { ProductReviewsCollection, ProductReviewVoteType, } from "../db/ProductReviewsCollection.js";
|
|
6
6
|
const PRODUCT_REVIEW_EVENTS = [
|
|
7
7
|
'PRODUCT_REVIEW_CREATE',
|
|
8
8
|
'PRODUCT_REMOVE_REVIEW',
|
|
@@ -49,7 +49,6 @@ export const configureProductReviewsModule = async ({ db }) => {
|
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
51
|
return {
|
|
52
|
-
// Queries
|
|
53
52
|
findProductReview: async ({ productReviewId }) => ProductReviews.findOne(generateDbFilterById(productReviewId), {}),
|
|
54
53
|
findProductReviews: async ({ offset, limit, sort, ...query }) => {
|
|
55
54
|
const reviewsList = ProductReviews.find(buildFindSelector(query), {
|
|
@@ -66,7 +65,6 @@ export const configureProductReviewsModule = async ({ db }) => {
|
|
|
66
65
|
const productReviewCount = await ProductReviews.countDocuments(generateDbFilterById(productReviewId, { deleted: null }), { limit: 1 });
|
|
67
66
|
return !!productReviewCount;
|
|
68
67
|
},
|
|
69
|
-
// Mutations
|
|
70
68
|
create: async (doc) => {
|
|
71
69
|
const { insertedId: productReviewId } = await ProductReviews.insertOne({
|
|
72
70
|
_id: generateDbObjectId(),
|
|
@@ -124,14 +122,12 @@ export const configureProductReviewsModule = async ({ db }) => {
|
|
|
124
122
|
deleted: null,
|
|
125
123
|
});
|
|
126
124
|
if (type === ProductReviewVoteType.UPVOTE) {
|
|
127
|
-
// if this is an upvote, remove the downvote first
|
|
128
125
|
await removeVote(selector, {
|
|
129
126
|
userId,
|
|
130
127
|
type: ProductReviewVoteType.DOWNVOTE,
|
|
131
128
|
});
|
|
132
129
|
}
|
|
133
130
|
if (type === ProductReviewVoteType.DOWNVOTE) {
|
|
134
|
-
// if this is a downvote, remove the upvote first
|
|
135
131
|
await removeVote(selector, {
|
|
136
132
|
userId,
|
|
137
133
|
type: ProductReviewVoteType.UPVOTE,
|
|
@@ -175,4 +171,3 @@ export const configureProductReviewsModule = async ({ db }) => {
|
|
|
175
171
|
},
|
|
176
172
|
};
|
|
177
173
|
};
|
|
178
|
-
//# sourceMappingURL=configureProductReviewsModule.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Product, ProductText } from '../db/ProductsCollection.
|
|
2
|
+
import type { Product, ProductText } from '../db/ProductsCollection.ts';
|
|
3
3
|
export declare const configureProductTextsModule: ({ Products, ProductTexts, }: {
|
|
4
4
|
Products: mongodb.Collection<Product>;
|
|
5
5
|
ProductTexts: mongodb.Collection<ProductText>;
|
|
@@ -9,7 +9,9 @@ export declare const configureProductTextsModule: ({ Products, ProductTexts, }:
|
|
|
9
9
|
productId: string;
|
|
10
10
|
locale: Intl.Locale;
|
|
11
11
|
}) => Promise<ProductText>;
|
|
12
|
-
updateTexts: (productId: string, texts:
|
|
12
|
+
updateTexts: (productId: string, texts: ({
|
|
13
|
+
locale: ProductText["locale"];
|
|
14
|
+
} & Omit<Partial<ProductText>, "productId" | "locale">)[]) => Promise<ProductText[]>;
|
|
13
15
|
makeSlug: ({ slug, title, productId, }: {
|
|
14
16
|
slug?: string;
|
|
15
17
|
title?: string;
|
|
@@ -20,4 +22,3 @@ export declare const configureProductTextsModule: ({ Products, ProductTexts, }:
|
|
|
20
22
|
excludedProductIds?: string[];
|
|
21
23
|
}) => Promise<number>;
|
|
22
24
|
};
|
|
23
|
-
//# sourceMappingURL=configureProductTextsModule.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
2
|
import { findUnusedSlug } from '@unchainedshop/utils';
|
|
3
|
-
import { findLocalizedText, generateDbFilterById, generateDbObjectId, } from '@unchainedshop/mongodb';
|
|
4
|
-
import { productsSettings } from
|
|
3
|
+
import { mongodb, findLocalizedText, generateDbFilterById, generateDbObjectId, } from '@unchainedshop/mongodb';
|
|
4
|
+
import { productsSettings } from "../products-settings.js";
|
|
5
5
|
const PRODUCT_TEXT_EVENTS = ['PRODUCT_UPDATE_TEXT'];
|
|
6
6
|
export const configureProductTextsModule = ({ Products, ProductTexts, }) => {
|
|
7
7
|
registerEvents(PRODUCT_TEXT_EVENTS);
|
|
@@ -74,7 +74,6 @@ export const configureProductTextsModule = ({ Products, ProductTexts, }) => {
|
|
|
74
74
|
return productText;
|
|
75
75
|
};
|
|
76
76
|
return {
|
|
77
|
-
// Queries
|
|
78
77
|
findTexts: async (query, options) => {
|
|
79
78
|
const texts = ProductTexts.find(query, options);
|
|
80
79
|
return texts.toArray();
|
|
@@ -83,7 +82,6 @@ export const configureProductTextsModule = ({ Products, ProductTexts, }) => {
|
|
|
83
82
|
const text = await findLocalizedText(ProductTexts, { productId }, locale);
|
|
84
83
|
return text;
|
|
85
84
|
},
|
|
86
|
-
// Mutations
|
|
87
85
|
updateTexts: async (productId, texts) => {
|
|
88
86
|
const productTexts = await Promise.all(texts.map(async ({ locale, ...text }) => upsertLocalizedText(productId, new Intl.Locale(locale), text)));
|
|
89
87
|
return productTexts;
|
|
@@ -102,4 +100,3 @@ export const configureProductTextsModule = ({ Products, ProductTexts, }) => {
|
|
|
102
100
|
},
|
|
103
101
|
};
|
|
104
102
|
};
|
|
105
|
-
//# sourceMappingURL=configureProductTextsModule.js.map
|