@reactionary/provider-commercetools 0.3.12 → 0.3.13
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/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-commercetools",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.3.
|
|
7
|
+
"@reactionary/core": "0.3.13",
|
|
8
8
|
"debug": "^4.4.3",
|
|
9
9
|
"zod": "4.1.9",
|
|
10
10
|
"@commercetools/ts-client": "^4.2.1",
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
success,
|
|
16
16
|
error,
|
|
17
17
|
ProductReviewSchema,
|
|
18
|
-
ProductRatingSummarySchema
|
|
18
|
+
ProductRatingSummarySchema,
|
|
19
|
+
ProductReviewPaginatedResultSchema
|
|
19
20
|
} from "@reactionary/core";
|
|
20
21
|
class CommercetoolsProductReviewsProvider extends ProductReviewsProvider {
|
|
21
22
|
constructor(config, cache, context, commercetools) {
|
|
@@ -60,10 +61,10 @@ class CommercetoolsProductReviewsProvider extends ProductReviewsProvider {
|
|
|
60
61
|
}
|
|
61
62
|
return success(summary);
|
|
62
63
|
} else {
|
|
63
|
-
return
|
|
64
|
+
return success(this.createEmptyProductRatingSummary({ product: query.product }));
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
async
|
|
67
|
+
async findReviews(query) {
|
|
67
68
|
const client = await this.getClient();
|
|
68
69
|
const pageNumber = query.paginationOptions?.pageNumber ?? 1;
|
|
69
70
|
const pageSize = query.paginationOptions?.pageSize ?? 20;
|
|
@@ -75,7 +76,13 @@ class CommercetoolsProductReviewsProvider extends ProductReviewsProvider {
|
|
|
75
76
|
throw e;
|
|
76
77
|
});
|
|
77
78
|
if (!product || !product.body) {
|
|
78
|
-
return
|
|
79
|
+
return success({
|
|
80
|
+
items: [],
|
|
81
|
+
totalCount: 0,
|
|
82
|
+
pageSize,
|
|
83
|
+
pageNumber,
|
|
84
|
+
totalPages: 0
|
|
85
|
+
});
|
|
79
86
|
}
|
|
80
87
|
const whereClause = `target(typeId="product" and id="${product.body.id}")`;
|
|
81
88
|
const sort = ["createdAt desc"];
|
|
@@ -90,7 +97,14 @@ class CommercetoolsProductReviewsProvider extends ProductReviewsProvider {
|
|
|
90
97
|
const reviews = response.body.results.map(
|
|
91
98
|
(review) => this.parseSingle(review, query.product.key)
|
|
92
99
|
);
|
|
93
|
-
|
|
100
|
+
const returnedResult = {
|
|
101
|
+
items: reviews,
|
|
102
|
+
totalCount: response.body.total || reviews.length,
|
|
103
|
+
pageSize,
|
|
104
|
+
pageNumber,
|
|
105
|
+
totalPages: Math.ceil((response.body.total || reviews.length) / Math.max(pageSize, 1))
|
|
106
|
+
};
|
|
107
|
+
return success(returnedResult);
|
|
94
108
|
}
|
|
95
109
|
async submitReview(mutation) {
|
|
96
110
|
if (!(this.context.session.identityContext.identity.type === "Registered")) {
|
|
@@ -148,13 +162,13 @@ __decorateClass([
|
|
|
148
162
|
], CommercetoolsProductReviewsProvider.prototype, "getRatingSummary", 1);
|
|
149
163
|
__decorateClass([
|
|
150
164
|
Reactionary({
|
|
151
|
-
outputSchema:
|
|
165
|
+
outputSchema: ProductReviewPaginatedResultSchema,
|
|
152
166
|
cache: true,
|
|
153
167
|
cacheTimeToLiveInSeconds: 60,
|
|
154
168
|
currencyDependentCaching: false,
|
|
155
169
|
localeDependentCaching: true
|
|
156
170
|
})
|
|
157
|
-
], CommercetoolsProductReviewsProvider.prototype, "
|
|
171
|
+
], CommercetoolsProductReviewsProvider.prototype, "findReviews", 1);
|
|
158
172
|
__decorateClass([
|
|
159
173
|
Reactionary({
|
|
160
174
|
outputSchema: ProductReviewSchema,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProductReviewsProvider } from '@reactionary/core';
|
|
2
|
-
import type { ProductReview, ProductRatingSummary, ProductReviewsListQuery, ProductReviewsGetRatingSummaryQuery, ProductReviewMutationSubmit, Result, RequestContext, Cache } from '@reactionary/core';
|
|
2
|
+
import type { ProductReview, ProductRatingSummary, ProductReviewPaginatedResult, ProductReviewsListQuery, ProductReviewsGetRatingSummaryQuery, ProductReviewMutationSubmit, Result, RequestContext, Cache } from '@reactionary/core';
|
|
3
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
4
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
5
5
|
import type { Review as CTReview } from '@commercetools/platform-sdk';
|
|
@@ -10,7 +10,7 @@ export declare class CommercetoolsProductReviewsProvider extends ProductReviewsP
|
|
|
10
10
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
11
11
|
protected getAdminClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
12
12
|
getRatingSummary(query: ProductReviewsGetRatingSummaryQuery): Promise<Result<ProductRatingSummary>>;
|
|
13
|
-
|
|
13
|
+
findReviews(query: ProductReviewsListQuery): Promise<Result<ProductReviewPaginatedResult>>;
|
|
14
14
|
submitReview(mutation: ProductReviewMutationSubmit): Promise<Result<ProductReview>>;
|
|
15
15
|
protected parseSingle(review: CTReview, productKey: string): ProductReview;
|
|
16
16
|
}
|