@unchainedshop/core-products 4.3.5 → 4.5.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.
Files changed (88) hide show
  1. package/README.md +133 -2
  2. package/lib/db/ProductMediaCollection.d.ts +1 -2
  3. package/lib/db/ProductMediaCollection.js +1 -4
  4. package/lib/db/ProductPriceRates.d.ts +0 -1
  5. package/lib/db/ProductPriceRates.js +1 -2
  6. package/lib/db/ProductReviewsCollection.d.ts +7 -7
  7. package/lib/db/ProductReviewsCollection.js +6 -8
  8. package/lib/db/ProductVariationsCollection.d.ts +6 -6
  9. package/lib/db/ProductVariationsCollection.js +5 -7
  10. package/lib/db/ProductsCollection.d.ts +22 -20
  11. package/lib/db/ProductsCollection.js +17 -23
  12. package/lib/mock/product.d.ts +0 -1
  13. package/lib/mock/product.js +0 -1
  14. package/lib/module/configureProductMediaModule.d.ts +9 -6
  15. package/lib/module/configureProductMediaModule.js +19 -16
  16. package/lib/module/configureProductPrices.d.ts +2 -3
  17. package/lib/module/configureProductPrices.js +4 -7
  18. package/lib/module/configureProductReviewsModule.d.ts +4 -4
  19. package/lib/module/configureProductReviewsModule.js +10 -7
  20. package/lib/module/configureProductTextsModule.d.ts +6 -3
  21. package/lib/module/configureProductTextsModule.js +13 -6
  22. package/lib/module/configureProductVariationsModule.d.ts +11 -6
  23. package/lib/module/configureProductVariationsModule.js +21 -13
  24. package/lib/module/configureProductsModule.d.ts +74 -56
  25. package/lib/module/configureProductsModule.js +34 -33
  26. package/lib/module/utils/getPriceLevels.d.ts +2 -3
  27. package/lib/module/utils/getPriceLevels.js +0 -1
  28. package/lib/module/utils/getPriceRange.d.ts +1 -2
  29. package/lib/module/utils/getPriceRange.js +0 -1
  30. package/lib/products-index.d.ts +13 -14
  31. package/lib/products-index.js +13 -14
  32. package/lib/products-settings.d.ts +0 -1
  33. package/lib/products-settings.js +0 -1
  34. package/package.json +12 -10
  35. package/lib/db/ProductMediaCollection.d.ts.map +0 -1
  36. package/lib/db/ProductMediaCollection.js.map +0 -1
  37. package/lib/db/ProductPriceRates.d.ts.map +0 -1
  38. package/lib/db/ProductPriceRates.js.map +0 -1
  39. package/lib/db/ProductReviewsCollection.d.ts.map +0 -1
  40. package/lib/db/ProductReviewsCollection.js.map +0 -1
  41. package/lib/db/ProductVariationsCollection.d.ts.map +0 -1
  42. package/lib/db/ProductVariationsCollection.js.map +0 -1
  43. package/lib/db/ProductsCollection.d.ts.map +0 -1
  44. package/lib/db/ProductsCollection.js.map +0 -1
  45. package/lib/mock/product.d.ts.map +0 -1
  46. package/lib/mock/product.js.map +0 -1
  47. package/lib/module/configureProductMediaModule.d.ts.map +0 -1
  48. package/lib/module/configureProductMediaModule.js.map +0 -1
  49. package/lib/module/configureProductPrices.d.ts.map +0 -1
  50. package/lib/module/configureProductPrices.js.map +0 -1
  51. package/lib/module/configureProductReviewsModule.d.ts.map +0 -1
  52. package/lib/module/configureProductReviewsModule.js.map +0 -1
  53. package/lib/module/configureProductTextsModule.d.ts.map +0 -1
  54. package/lib/module/configureProductTextsModule.js.map +0 -1
  55. package/lib/module/configureProductVariationsModule.d.ts.map +0 -1
  56. package/lib/module/configureProductVariationsModule.js.map +0 -1
  57. package/lib/module/configureProductsModule.d.ts.map +0 -1
  58. package/lib/module/configureProductsModule.js.map +0 -1
  59. package/lib/module/utils/getPriceLevels.d.ts.map +0 -1
  60. package/lib/module/utils/getPriceLevels.js.map +0 -1
  61. package/lib/module/utils/getPriceRange.d.ts.map +0 -1
  62. package/lib/module/utils/getPriceRange.js.map +0 -1
  63. package/lib/products-index.d.ts.map +0 -1
  64. package/lib/products-index.js.map +0 -1
  65. package/lib/products-settings.d.ts.map +0 -1
  66. package/lib/products-settings.js.map +0 -1
  67. package/src/db/ProductMediaCollection.ts +0 -39
  68. package/src/db/ProductPriceRates.ts +0 -24
  69. package/src/db/ProductReviewsCollection.ts +0 -58
  70. package/src/db/ProductVariationsCollection.ts +0 -46
  71. package/src/db/ProductsCollection.ts +0 -181
  72. package/src/mock/product.ts +0 -47
  73. package/src/module/buildFindSelector.test.ts +0 -105
  74. package/src/module/configureProductMediaModule.ts +0 -271
  75. package/src/module/configureProductPrices.ts +0 -302
  76. package/src/module/configureProductReviewsModule.ts +0 -289
  77. package/src/module/configureProductTextsModule.ts +0 -179
  78. package/src/module/configureProductVariationsModule.ts +0 -287
  79. package/src/module/configureProductsModule.ts +0 -628
  80. package/src/module/utils/configureProductPrices.test.ts +0 -156
  81. package/src/module/utils/getPriceLevels.test.ts +0 -91
  82. package/src/module/utils/getPriceLevels.ts +0 -21
  83. package/src/module/utils/getPriceRange.test.ts +0 -57
  84. package/src/module/utils/getPriceRange.ts +0 -36
  85. package/src/products-index.ts +0 -15
  86. package/src/products-settings.ts +0 -15
  87. package/tests/product-index.test.ts +0 -7
  88. package/tsconfig.json +0 -10
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Products (Unchained Engine)
1
+ [![npm version](https://img.shields.io/npm/v/@unchainedshop/core-products.svg)](https://npmjs.com/package/@unchainedshop/core-products)
2
+ [![License: EUPL-1.2](https://img.shields.io/badge/License-EUPL--1.2-blue.svg)](https://opensource.org/licenses/EUPL-1.2)
2
3
 
3
- This package contains business logic and database abstraction for products in Unchained.
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
@@ -9,4 +9,3 @@ export interface ProductPriceRate {
9
9
  export declare const ProductPriceRates: (db: mongodb.Db) => Promise<{
10
10
  ProductRates: mongodb.Collection<ProductPriceRate>;
11
11
  }>;
12
- //# sourceMappingURL=ProductPriceRates.d.ts.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 enum ProductReviewVoteType {
3
- UPVOTE = "UPVOTE",
4
- DOWNVOTE = "DOWNVOTE",
5
- REPORT = "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 var ProductReviewVoteType;
3
- (function (ProductReviewVoteType) {
4
- ProductReviewVoteType["UPVOTE"] = "UPVOTE";
5
- ProductReviewVoteType["DOWNVOTE"] = "DOWNVOTE";
6
- ProductReviewVoteType["REPORT"] = "REPORT";
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 enum ProductVariationType {
3
- COLOR = "COLOR",
4
- TEXT = "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 var ProductVariationType;
3
- (function (ProductVariationType) {
4
- ProductVariationType["COLOR"] = "COLOR";
5
- ProductVariationType["TEXT"] = "TEXT";
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 enum ProductStatus {
4
- DRAFT = "DRAFT",
5
- ACTIVE = "ACTIVE",
6
- DELETED = "DELETED"
7
- }
8
- export declare enum ProductTypes {
9
- SimpleProduct = "SIMPLE_PRODUCT",
10
- ConfigurableProduct = "CONFIGURABLE_PRODUCT",
11
- BundleProduct = "BUNDLE_PRODUCT",
12
- PlanProduct = "PLAN_PRODUCT",
13
- TokenizedProduct = "TOKENIZED_PRODUCT"
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 enum ProductContractStandard {
34
- ERC721 = "ERC721",
35
- ERC1155 = "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: string;
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 var ProductStatus;
3
- (function (ProductStatus) {
4
- ProductStatus["DRAFT"] = "DRAFT";
5
- ProductStatus["ACTIVE"] = "ACTIVE";
6
- ProductStatus["DELETED"] = "DELETED";
7
- })(ProductStatus || (ProductStatus = {}));
8
- export var ProductTypes;
9
- (function (ProductTypes) {
10
- ProductTypes["SimpleProduct"] = "SIMPLE_PRODUCT";
11
- ProductTypes["ConfigurableProduct"] = "CONFIGURABLE_PRODUCT";
12
- ProductTypes["BundleProduct"] = "BUNDLE_PRODUCT";
13
- ProductTypes["PlanProduct"] = "PLAN_PRODUCT";
14
- ProductTypes["TokenizedProduct"] = "TOKENIZED_PRODUCT";
15
- })(ProductTypes || (ProductTypes = {}));
16
- export var ProductContractStandard;
17
- (function (ProductContractStandard) {
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
@@ -27,4 +27,3 @@ declare const _default: {
27
27
  published: Date;
28
28
  };
29
29
  export default _default;
30
- //# sourceMappingURL=product.d.ts.map
@@ -45,4 +45,3 @@ export default {
45
45
  },
46
46
  published: new Date('2022-12-04T13:31:26.406Z'),
47
47
  };
48
- //# sourceMappingURL=product.js.map
@@ -1,12 +1,13 @@
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.js';
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;
7
7
  }) => Promise<mongodb.WithId<ProductMedia> | null>;
8
- findProductMedias: ({ productId, tags, offset, limit, }: {
9
- productId?: mongodb.Filter<ProductMedia>["assortmentId"];
8
+ findProductMedias: ({ productId, productIds, tags, offset, limit, }: {
9
+ productId?: string;
10
+ productIds?: string[];
10
11
  limit?: number;
11
12
  offset?: number;
12
13
  tags?: string[];
@@ -26,7 +27,10 @@ export declare const configureProductMediaModule: ({ db }: ModuleInput<Record<st
26
27
  }[];
27
28
  }) => Promise<ProductMedia[]>;
28
29
  texts: {
29
- findMediaTexts: ({ productMediaId }: mongodb.Filter<ProductMediaText>, options?: mongodb.FindOptions) => Promise<ProductMediaText[]>;
30
+ findMediaTexts: (query: {
31
+ productMediaId?: string;
32
+ productMediaIds?: string[];
33
+ }, options?: mongodb.FindOptions) => Promise<ProductMediaText[]>;
30
34
  findLocalizedMediaText: ({ productMediaId, locale, }: {
31
35
  productMediaId: string;
32
36
  locale: Intl.Locale;
@@ -36,4 +40,3 @@ export declare const configureProductMediaModule: ({ db }: ModuleInput<Record<st
36
40
  } & Omit<Partial<ProductMediaText>, "productMediaId" | "locale">)[]) => Promise<ProductMediaText[]>;
37
41
  };
38
42
  }>;
39
- //# 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 '../db/ProductMediaCollection.js';
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,12 +37,17 @@ 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
  },
44
- findProductMedias: async ({ productId, tags, offset, limit, }, options) => {
45
- const selector = productId ? { productId } : {};
43
+ findProductMedias: async ({ productId, productIds, tags, offset, limit, }, options) => {
44
+ const selector = {};
45
+ if (productId) {
46
+ selector.productId = productId;
47
+ }
48
+ if (productIds) {
49
+ selector.productId = { $in: productIds };
50
+ }
46
51
  if (tags?.length && tags?.length > 0) {
47
52
  selector.tags = { $all: tags };
48
53
  }
@@ -54,10 +59,8 @@ export const configureProductMediaModule = async ({ db }) => {
54
59
  });
55
60
  return mediaList.toArray();
56
61
  },
57
- // Mutations
58
62
  create: async ({ sortKey, ...doc }) => {
59
63
  if (sortKey === undefined || sortKey === null) {
60
- // Get next sort key
61
64
  const lastProductMedia = (await ProductMedias.findOne({
62
65
  productId: doc.productId,
63
66
  }, {
@@ -103,7 +106,6 @@ export const configureProductMediaModule = async ({ db }) => {
103
106
  })));
104
107
  return deletedResult.deletedCount;
105
108
  },
106
- // This action is specifically used for the bulk migration scripts in the platform package
107
109
  update: async (productMediaId, doc) => {
108
110
  const selector = generateDbFilterById(productMediaId);
109
111
  const modifier = { $set: doc };
@@ -125,19 +127,21 @@ export const configureProductMediaModule = async ({ db }) => {
125
127
  await emit('PRODUCT_REORDER_MEDIA', { productMedias });
126
128
  return productMedias;
127
129
  },
128
- /*
129
- * Product Media Texts
130
- */
131
130
  texts: {
132
- // Queries
133
- findMediaTexts: async ({ productMediaId }, options) => {
134
- return ProductMediaTexts.find({ productMediaId }, options).toArray();
131
+ findMediaTexts: async (query, options) => {
132
+ const selector = {};
133
+ if (query.productMediaId) {
134
+ selector.productMediaId = query.productMediaId;
135
+ }
136
+ if (query.productMediaIds) {
137
+ selector.productMediaId = { $in: query.productMediaIds };
138
+ }
139
+ return ProductMediaTexts.find(selector, options).toArray();
135
140
  },
136
141
  findLocalizedMediaText: async ({ productMediaId, locale, }) => {
137
142
  const text = await findLocalizedText(ProductMediaTexts, { productMediaId }, locale);
138
143
  return text;
139
144
  },
140
- // Mutations
141
145
  updateMediaTexts: async (productMediaId, texts) => {
142
146
  const mediaTexts = (await Promise.all(texts.map(async ({ locale, ...text }) => upsertLocalizedText(productMediaId, new Intl.Locale(locale), text)))).filter(Boolean);
143
147
  return mediaTexts;
@@ -145,4 +149,3 @@ export const configureProductMediaModule = async ({ db }) => {
145
149
  },
146
150
  };
147
151
  };
148
- //# sourceMappingURL=configureProductMediaModule.js.map
@@ -1,5 +1,5 @@
1
- import { ProductPriceRate } from '../db/ProductPriceRates.js';
2
- import { Product, ProductConfiguration, ProductPrice, ProductPriceRange } from '../db/ProductsCollection.js';
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 './utils/getPriceLevels.js';
2
- import { getPriceRange } from './utils/getPriceRange.js';
3
- import { ProductPriceRates } from '../db/ProductPriceRates.js';
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.js';
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;
@@ -31,6 +31,7 @@ export declare const configureProductReviewsModule: ({ db }: ModuleInput<Record<
31
31
  create: (doc: Omit<ProductReview, "_id" | "created" | "votes"> & Pick<Partial<ProductReview>, "created" | "_id">) => Promise<ProductReview>;
32
32
  delete: (productReviewId: string) => Promise<number>;
33
33
  deleteMany: (selector: mongodb.Filter<ProductReview>) => Promise<number>;
34
+ deleteByAuthorId: (authorId: string) => Promise<number>;
34
35
  update: (productReviewId: string, doc: Partial<ProductReview>) => Promise<mongodb.WithId<ProductReview> | null>;
35
36
  votes: {
36
37
  userIdsThatVoted: (productReview: ProductReview, { type }: {
@@ -47,4 +48,3 @@ export declare const configureProductReviewsModule: ({ db }: ModuleInput<Record<
47
48
  removeVote: (productReviewId: string, { userId, type }: ProductVote) => Promise<mongodb.WithId<ProductReview> | null>;
48
49
  };
49
50
  }>;
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 '../db/ProductReviewsCollection.js';
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(),
@@ -101,6 +99,14 @@ export const configureProductReviewsModule = async ({ db }) => {
101
99
  })));
102
100
  return deletionResult.deletedCount;
103
101
  },
102
+ deleteByAuthorId: async (authorId) => {
103
+ const productReviews = await ProductReviews.find({ authorId }, { projection: { _id: 1 } }).toArray();
104
+ const deletionResult = await ProductReviews.deleteMany({ authorId });
105
+ await Promise.all(productReviews.map(async (review) => emit('PRODUCT_REMOVE_REVIEW', {
106
+ productReviewId: review._id,
107
+ })));
108
+ return deletionResult.deletedCount;
109
+ },
104
110
  update: async (productReviewId, doc) => {
105
111
  const productReview = await ProductReviews.findOneAndUpdate(generateDbFilterById(productReviewId), {
106
112
  $set: {
@@ -124,14 +130,12 @@ export const configureProductReviewsModule = async ({ db }) => {
124
130
  deleted: null,
125
131
  });
126
132
  if (type === ProductReviewVoteType.UPVOTE) {
127
- // if this is an upvote, remove the downvote first
128
133
  await removeVote(selector, {
129
134
  userId,
130
135
  type: ProductReviewVoteType.DOWNVOTE,
131
136
  });
132
137
  }
133
138
  if (type === ProductReviewVoteType.DOWNVOTE) {
134
- // if this is a downvote, remove the upvote first
135
139
  await removeVote(selector, {
136
140
  userId,
137
141
  type: ProductReviewVoteType.UPVOTE,
@@ -175,4 +179,3 @@ export const configureProductReviewsModule = async ({ db }) => {
175
179
  },
176
180
  };
177
181
  };
178
- //# sourceMappingURL=configureProductReviewsModule.js.map