@reactionary/provider-commercetools 0.0.71 → 0.0.73
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.0.
|
|
3
|
+
"version": "0.0.73",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.0.
|
|
7
|
+
"@reactionary/core": "0.0.73",
|
|
8
8
|
"debug": "^4.4.3",
|
|
9
9
|
"zod": "4.1.9",
|
|
10
10
|
"@commercetools/ts-client": "^4.2.1",
|
|
@@ -10,67 +10,83 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
return result;
|
|
11
11
|
};
|
|
12
12
|
import {
|
|
13
|
+
CustomerPriceQuerySchema,
|
|
14
|
+
ListPriceQuerySchema,
|
|
13
15
|
PriceProvider,
|
|
14
|
-
PriceQueryBySkuSchema,
|
|
15
16
|
PriceSchema,
|
|
16
17
|
Reactionary,
|
|
17
18
|
TieredPriceSchema
|
|
18
19
|
} from "@reactionary/core";
|
|
19
|
-
import z from "zod";
|
|
20
20
|
class CommercetoolsPriceProvider extends PriceProvider {
|
|
21
21
|
constructor(config, schema, cache, context, client) {
|
|
22
22
|
super(schema, cache, context);
|
|
23
23
|
this.config = config;
|
|
24
24
|
this.client = client;
|
|
25
25
|
}
|
|
26
|
-
async
|
|
27
|
-
const client = await this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
async getCustomerPrice(payload) {
|
|
27
|
+
const client = await this.getClient();
|
|
28
|
+
const priceChannelId = "ee6e75e9-c9ab-4e2f-85f1-d8c734d0cb86";
|
|
29
|
+
const response = await client.productProjections().get({
|
|
30
|
+
queryArgs: {
|
|
31
|
+
staged: false,
|
|
32
|
+
priceCountry: this.context.taxJurisdiction.countryCode,
|
|
33
|
+
priceCustomerGroup: void 0,
|
|
34
|
+
priceChannel: priceChannelId,
|
|
35
|
+
priceCurrency: this.context.languageContext.currencyCode,
|
|
36
|
+
where: "variants(sku in (:skus)) OR (masterVariant(sku in (:skus))) ",
|
|
37
|
+
"var.skus": [payload.variant.sku],
|
|
38
|
+
limit: 1
|
|
39
|
+
}
|
|
40
|
+
}).execute();
|
|
41
|
+
const result = response.body.results[0];
|
|
42
|
+
const sku = [result.masterVariant, ...result.variants].find(
|
|
43
|
+
(x) => x.sku === payload.variant.sku
|
|
44
|
+
);
|
|
45
|
+
return this.parseSingle(sku, { includeDiscounts: true });
|
|
32
46
|
}
|
|
33
|
-
async
|
|
47
|
+
async getListPrice(payload) {
|
|
34
48
|
const client = await this.getClient();
|
|
35
|
-
const
|
|
49
|
+
const priceChannelId = "ee6e75e9-c9ab-4e2f-85f1-d8c734d0cb86";
|
|
36
50
|
const response = await client.productProjections().get({
|
|
37
51
|
queryArgs: {
|
|
38
52
|
staged: false,
|
|
39
53
|
priceCountry: this.context.taxJurisdiction.countryCode,
|
|
40
54
|
priceCustomerGroup: void 0,
|
|
41
|
-
|
|
42
|
-
priceChannel: "ee6e75e9-c9ab-4e2f-85f1-d8c734d0cb86",
|
|
55
|
+
priceChannel: priceChannelId,
|
|
43
56
|
priceCurrency: this.context.languageContext.currencyCode,
|
|
44
57
|
where: "variants(sku in (:skus)) OR (masterVariant(sku in (:skus))) ",
|
|
45
58
|
"var.skus": [payload.variant.sku],
|
|
46
59
|
limit: 1
|
|
47
60
|
}
|
|
48
61
|
}).execute();
|
|
49
|
-
const
|
|
62
|
+
const result = response.body.results[0];
|
|
63
|
+
const sku = [result.masterVariant, ...result.variants].find(
|
|
64
|
+
(x) => x.sku === payload.variant.sku
|
|
65
|
+
);
|
|
50
66
|
return this.parseSingle(sku);
|
|
51
67
|
}
|
|
52
|
-
|
|
68
|
+
async getClient() {
|
|
69
|
+
const client = await this.client.getClient();
|
|
70
|
+
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
71
|
+
}
|
|
72
|
+
parseSingle(_body, options = { includeDiscounts: false }) {
|
|
53
73
|
const body = _body;
|
|
54
74
|
const price = body.price;
|
|
55
75
|
if (!price) {
|
|
56
76
|
return this.createEmptyPriceResult(body.sku);
|
|
57
77
|
}
|
|
58
78
|
const base = this.newModel();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
71
|
-
return tp;
|
|
72
|
-
});
|
|
73
|
-
base.tieredPrices = p;
|
|
79
|
+
if (options.includeDiscounts) {
|
|
80
|
+
const discountedPrice = price.discounted?.value || price.value;
|
|
81
|
+
base.unitPrice = {
|
|
82
|
+
value: discountedPrice.centAmount / 100,
|
|
83
|
+
currency: price.value.currencyCode
|
|
84
|
+
};
|
|
85
|
+
} else {
|
|
86
|
+
base.unitPrice = {
|
|
87
|
+
value: price.value.centAmount / 100,
|
|
88
|
+
currency: price.value.currencyCode
|
|
89
|
+
};
|
|
74
90
|
}
|
|
75
91
|
base.identifier = {
|
|
76
92
|
variant: {
|
|
@@ -99,16 +115,16 @@ class CommercetoolsPriceProvider extends PriceProvider {
|
|
|
99
115
|
}
|
|
100
116
|
__decorateClass([
|
|
101
117
|
Reactionary({
|
|
102
|
-
inputSchema:
|
|
103
|
-
outputSchema:
|
|
118
|
+
inputSchema: CustomerPriceQuerySchema,
|
|
119
|
+
outputSchema: PriceSchema
|
|
104
120
|
})
|
|
105
|
-
], CommercetoolsPriceProvider.prototype, "
|
|
121
|
+
], CommercetoolsPriceProvider.prototype, "getCustomerPrice", 1);
|
|
106
122
|
__decorateClass([
|
|
107
123
|
Reactionary({
|
|
108
|
-
inputSchema:
|
|
124
|
+
inputSchema: ListPriceQuerySchema,
|
|
109
125
|
outputSchema: PriceSchema
|
|
110
126
|
})
|
|
111
|
-
], CommercetoolsPriceProvider.prototype, "
|
|
127
|
+
], CommercetoolsPriceProvider.prototype, "getListPrice", 1);
|
|
112
128
|
export {
|
|
113
129
|
CommercetoolsPriceProvider
|
|
114
130
|
};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { PriceProvider } from '@reactionary/core';
|
|
2
|
-
import type {
|
|
3
|
-
import z from 'zod';
|
|
2
|
+
import type { RequestContext, Price, Cache, CustomerPriceQuery, ListPriceQuery } from '@reactionary/core';
|
|
4
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
4
|
import type { CommercetoolsClient } from '../core/client.js';
|
|
5
|
+
import type z from 'zod';
|
|
6
6
|
export declare class CommercetoolsPriceProvider<T extends Price = Price> extends PriceProvider<T> {
|
|
7
7
|
protected config: CommercetoolsConfiguration;
|
|
8
8
|
protected client: CommercetoolsClient;
|
|
9
9
|
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
10
|
+
getCustomerPrice(payload: CustomerPriceQuery): Promise<T>;
|
|
11
|
+
getListPrice(payload: ListPriceQuery): Promise<T>;
|
|
10
12
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
protected parseSingle(_body: unknown, options?: {
|
|
14
|
+
includeDiscounts: boolean;
|
|
15
|
+
}): T;
|
|
14
16
|
protected getChannels(): Promise<{
|
|
15
17
|
offer: string;
|
|
16
18
|
list: string;
|