@reactionary/provider-commercetools 0.0.63 → 0.0.64
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/core/client.js +43 -77
- package/core/initialize.js +10 -8
- package/core/token-cache.js +35 -0
- package/package.json +2 -2
- package/providers/cart.provider.js +89 -106
- package/providers/category.provider.js +3 -3
- package/providers/checkout.provider.js +4 -5
- package/providers/identity.provider.js +8 -11
- package/providers/inventory.provider.js +7 -7
- package/providers/order.provider.js +5 -7
- package/providers/price.provider.js +6 -6
- package/providers/product-search.provider.js +3 -3
- package/providers/product.provider.js +7 -6
- package/providers/profile.provider.js +3 -3
- package/providers/store.provider.js +3 -3
- package/src/core/client.d.ts +15 -16
- package/src/core/initialize.d.ts +2 -2
- package/src/core/token-cache.d.ts +8 -0
- package/src/providers/cart.provider.d.ts +3 -1
- package/src/providers/category.provider.d.ts +3 -1
- package/src/providers/checkout.provider.d.ts +3 -1
- package/src/providers/identity.provider.d.ts +3 -1
- package/src/providers/inventory.provider.d.ts +4 -2
- package/src/providers/order.provider.d.ts +3 -1
- package/src/providers/price.provider.d.ts +3 -1
- package/src/providers/product-search.provider.d.ts +3 -1
- package/src/providers/product.provider.d.ts +3 -1
- package/src/providers/profile.provider.d.ts +3 -1
- package/src/providers/store.provider.d.ts +3 -1
package/core/client.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClientBuilder
|
|
3
|
-
} from "@commercetools/ts-client";
|
|
1
|
+
import { ClientBuilder } from "@commercetools/ts-client";
|
|
4
2
|
import { createApiBuilderFromCtpClient } from "@commercetools/platform-sdk";
|
|
5
3
|
import { randomUUID } from "crypto";
|
|
6
4
|
import {
|
|
@@ -10,47 +8,41 @@ import {
|
|
|
10
8
|
} from "@reactionary/core";
|
|
11
9
|
import * as crypto from "crypto";
|
|
12
10
|
import createDebug from "debug";
|
|
13
|
-
import {
|
|
11
|
+
import { RequestContextTokenCache } from "./token-cache.js";
|
|
14
12
|
const debug = createDebug("reactionary:commercetools");
|
|
15
|
-
class
|
|
16
|
-
constructor(context) {
|
|
13
|
+
class CommercetoolsClient {
|
|
14
|
+
constructor(config, context) {
|
|
15
|
+
this.config = config;
|
|
17
16
|
this.context = context;
|
|
17
|
+
this.cache = new RequestContextTokenCache(this.context);
|
|
18
18
|
}
|
|
19
|
-
async
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
);
|
|
23
|
-
if (!session) {
|
|
24
|
-
return {
|
|
25
|
-
refreshToken: void 0,
|
|
26
|
-
token: "",
|
|
27
|
-
expirationTime: (/* @__PURE__ */ new Date()).getTime()
|
|
28
|
-
};
|
|
19
|
+
async getClient() {
|
|
20
|
+
if (!this.client) {
|
|
21
|
+
this.client = this.createClient();
|
|
29
22
|
}
|
|
30
|
-
return
|
|
31
|
-
refreshToken: session.refreshToken,
|
|
32
|
-
token: session.token,
|
|
33
|
-
expirationTime: session.expirationTime
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async set(cache, tokenCacheOptions) {
|
|
37
|
-
const session = CommercetoolsSessionSchema.parse(
|
|
38
|
-
this.context.session["PROVIDER_COMMERCETOOLS"] || {}
|
|
39
|
-
);
|
|
40
|
-
this.context.session["PROVIDER_COMMERCETOOLS"] = session;
|
|
41
|
-
session.refreshToken = cache.refreshToken;
|
|
42
|
-
session.token = cache.token;
|
|
43
|
-
session.expirationTime = cache.expirationTime;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
class CommercetoolsClient {
|
|
47
|
-
constructor(config) {
|
|
48
|
-
this.config = config;
|
|
23
|
+
return this.client;
|
|
49
24
|
}
|
|
50
|
-
async
|
|
51
|
-
|
|
25
|
+
async createClient() {
|
|
26
|
+
let session = await this.cache.get();
|
|
27
|
+
const isNewSession = !session || session.token.length === 0;
|
|
28
|
+
if (isNewSession) {
|
|
29
|
+
await this.becomeGuest();
|
|
30
|
+
session = await this.cache.get();
|
|
31
|
+
}
|
|
32
|
+
let builder = this.createBaseClientBuilder();
|
|
33
|
+
builder = builder.withRefreshTokenFlow({
|
|
34
|
+
credentials: {
|
|
35
|
+
clientId: this.config.clientId,
|
|
36
|
+
clientSecret: this.config.clientSecret
|
|
37
|
+
},
|
|
38
|
+
host: this.config.authUrl,
|
|
39
|
+
projectKey: this.config.projectKey,
|
|
40
|
+
refreshToken: session.refreshToken || "",
|
|
41
|
+
tokenCache: this.cache
|
|
42
|
+
});
|
|
43
|
+
return createApiBuilderFromCtpClient(builder.build());
|
|
52
44
|
}
|
|
53
|
-
async register(username, password
|
|
45
|
+
async register(username, password) {
|
|
54
46
|
const registrationBuilder = this.createBaseClientBuilder().withAnonymousSessionFlow({
|
|
55
47
|
host: this.config.authUrl,
|
|
56
48
|
projectKey: this.config.projectKey,
|
|
@@ -69,11 +61,10 @@ class CommercetoolsClient {
|
|
|
69
61
|
password
|
|
70
62
|
}
|
|
71
63
|
}).execute();
|
|
72
|
-
const login = await this.login(username, password
|
|
64
|
+
const login = await this.login(username, password);
|
|
73
65
|
return login;
|
|
74
66
|
}
|
|
75
|
-
async login(username, password
|
|
76
|
-
const cache = new RequestContextTokenCache(reqCtx);
|
|
67
|
+
async login(username, password) {
|
|
77
68
|
const loginBuilder = this.createBaseClientBuilder().withPasswordFlow({
|
|
78
69
|
host: this.config.authUrl,
|
|
79
70
|
projectKey: this.config.projectKey,
|
|
@@ -82,7 +73,7 @@ class CommercetoolsClient {
|
|
|
82
73
|
clientSecret: this.config.clientSecret,
|
|
83
74
|
user: { username, password }
|
|
84
75
|
},
|
|
85
|
-
tokenCache: cache,
|
|
76
|
+
tokenCache: this.cache,
|
|
86
77
|
scopes: this.config.scopes
|
|
87
78
|
});
|
|
88
79
|
const loginClient = createApiBuilderFromCtpClient(loginBuilder.build());
|
|
@@ -99,16 +90,13 @@ class CommercetoolsClient {
|
|
|
99
90
|
}
|
|
100
91
|
});
|
|
101
92
|
}
|
|
102
|
-
async logout(
|
|
103
|
-
|
|
104
|
-
await cache.set({ token: "", refreshToken: "", expirationTime: 0 });
|
|
93
|
+
async logout() {
|
|
94
|
+
await this.cache.set({ token: "", refreshToken: "", expirationTime: 0 });
|
|
105
95
|
return AnonymousIdentitySchema.parse({});
|
|
106
96
|
}
|
|
107
|
-
async introspect(
|
|
108
|
-
const session =
|
|
109
|
-
|
|
110
|
-
);
|
|
111
|
-
if (!session.token) {
|
|
97
|
+
async introspect() {
|
|
98
|
+
const session = await this.cache.get();
|
|
99
|
+
if (!session || !session.token) {
|
|
112
100
|
return AnonymousIdentitySchema.parse({});
|
|
113
101
|
}
|
|
114
102
|
const authHeader = "Basic " + Buffer.from(
|
|
@@ -135,7 +123,7 @@ class CommercetoolsClient {
|
|
|
135
123
|
}
|
|
136
124
|
return AnonymousIdentitySchema.parse({});
|
|
137
125
|
}
|
|
138
|
-
async becomeGuest(
|
|
126
|
+
async becomeGuest() {
|
|
139
127
|
const credentials = Buffer.from(
|
|
140
128
|
`${this.config.clientId}:${this.config.clientSecret}`
|
|
141
129
|
).toString("base64");
|
|
@@ -153,34 +141,13 @@ class CommercetoolsClient {
|
|
|
153
141
|
}
|
|
154
142
|
);
|
|
155
143
|
const result = await response.json();
|
|
156
|
-
cache.set({
|
|
144
|
+
this.cache.set({
|
|
157
145
|
expirationTime: (/* @__PURE__ */ new Date()).getTime() + Number(result.expires_in),
|
|
158
146
|
token: result.access_token,
|
|
159
147
|
refreshToken: result.refresh_token
|
|
160
148
|
});
|
|
161
149
|
}
|
|
162
|
-
|
|
163
|
-
const cache = new RequestContextTokenCache(reqCtx);
|
|
164
|
-
let session = await cache.get();
|
|
165
|
-
const isNewSession = !session || session.token.length === 0;
|
|
166
|
-
if (isNewSession) {
|
|
167
|
-
await this.becomeGuest(cache);
|
|
168
|
-
session = await cache.get();
|
|
169
|
-
}
|
|
170
|
-
let builder = this.createBaseClientBuilder(reqCtx);
|
|
171
|
-
builder = builder.withRefreshTokenFlow({
|
|
172
|
-
credentials: {
|
|
173
|
-
clientId: this.config.clientId,
|
|
174
|
-
clientSecret: this.config.clientSecret
|
|
175
|
-
},
|
|
176
|
-
host: this.config.authUrl,
|
|
177
|
-
projectKey: this.config.projectKey,
|
|
178
|
-
refreshToken: session.refreshToken || "",
|
|
179
|
-
tokenCache: cache
|
|
180
|
-
});
|
|
181
|
-
return createApiBuilderFromCtpClient(builder.build());
|
|
182
|
-
}
|
|
183
|
-
createBaseClientBuilder(reqCtx) {
|
|
150
|
+
createBaseClientBuilder() {
|
|
184
151
|
let builder = new ClientBuilder().withProjectKey(this.config.projectKey).withQueueMiddleware({
|
|
185
152
|
concurrency: 20
|
|
186
153
|
}).withConcurrentModificationMiddleware({
|
|
@@ -207,7 +174,7 @@ class CommercetoolsClient {
|
|
|
207
174
|
host: this.config.apiUrl,
|
|
208
175
|
httpClient: fetch
|
|
209
176
|
});
|
|
210
|
-
const correlationId =
|
|
177
|
+
const correlationId = this.context.correlationId || "REACTIONARY-" + (typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : randomUUID());
|
|
211
178
|
builder = builder.withCorrelationIdMiddleware({
|
|
212
179
|
generate: () => correlationId
|
|
213
180
|
});
|
|
@@ -218,6 +185,5 @@ class CommercetoolsClient {
|
|
|
218
185
|
}
|
|
219
186
|
}
|
|
220
187
|
export {
|
|
221
|
-
CommercetoolsClient
|
|
222
|
-
RequestContextTokenCache
|
|
188
|
+
CommercetoolsClient
|
|
223
189
|
};
|
package/core/initialize.js
CHANGED
|
@@ -16,32 +16,34 @@ import { CommercetoolsInventoryProvider } from "../providers/inventory.provider.
|
|
|
16
16
|
import { CommercetoolsPriceProvider } from "../providers/price.provider.js";
|
|
17
17
|
import { CommercetoolsCategoryProvider } from "../providers/category.provider.js";
|
|
18
18
|
import { CommercetoolsCheckoutProvider } from "../providers/index.js";
|
|
19
|
+
import { CommercetoolsClient, CommercetoolsClient as CTCustomerClient } from "./client.js";
|
|
19
20
|
function withCommercetoolsCapabilities(configuration, capabilities) {
|
|
20
21
|
return (cache, context) => {
|
|
21
22
|
const client = {};
|
|
23
|
+
const commercetoolsClient = new CommercetoolsClient(configuration, context);
|
|
22
24
|
if (capabilities.product) {
|
|
23
|
-
client.product = new CommercetoolsProductProvider(configuration, ProductSchema, cache, context);
|
|
25
|
+
client.product = new CommercetoolsProductProvider(configuration, ProductSchema, cache, context, commercetoolsClient);
|
|
24
26
|
}
|
|
25
27
|
if (capabilities.productSearch) {
|
|
26
|
-
client.productSearch = new CommercetoolsSearchProvider(configuration, ProductSearchResultItemSchema, cache, context);
|
|
28
|
+
client.productSearch = new CommercetoolsSearchProvider(configuration, ProductSearchResultItemSchema, cache, context, commercetoolsClient);
|
|
27
29
|
}
|
|
28
30
|
if (capabilities.identity) {
|
|
29
|
-
client.identity = new CommercetoolsIdentityProvider(configuration, IdentitySchema, cache, context);
|
|
31
|
+
client.identity = new CommercetoolsIdentityProvider(configuration, IdentitySchema, cache, context, commercetoolsClient);
|
|
30
32
|
}
|
|
31
33
|
if (capabilities.cart) {
|
|
32
|
-
client.cart = new CommercetoolsCartProvider(configuration, CartSchema, cache, context);
|
|
34
|
+
client.cart = new CommercetoolsCartProvider(configuration, CartSchema, cache, context, commercetoolsClient);
|
|
33
35
|
}
|
|
34
36
|
if (capabilities.inventory) {
|
|
35
|
-
client.inventory = new CommercetoolsInventoryProvider(configuration, InventorySchema, cache, context);
|
|
37
|
+
client.inventory = new CommercetoolsInventoryProvider(configuration, InventorySchema, cache, context, commercetoolsClient);
|
|
36
38
|
}
|
|
37
39
|
if (capabilities.price) {
|
|
38
|
-
client.price = new CommercetoolsPriceProvider(configuration, PriceSchema, cache, context);
|
|
40
|
+
client.price = new CommercetoolsPriceProvider(configuration, PriceSchema, cache, context, commercetoolsClient);
|
|
39
41
|
}
|
|
40
42
|
if (capabilities.category) {
|
|
41
|
-
client.category = new CommercetoolsCategoryProvider(configuration, CategorySchema, cache, context);
|
|
43
|
+
client.category = new CommercetoolsCategoryProvider(configuration, CategorySchema, cache, context, commercetoolsClient);
|
|
42
44
|
}
|
|
43
45
|
if (capabilities.checkout) {
|
|
44
|
-
client.checkout = new CommercetoolsCheckoutProvider(configuration, CheckoutSchema, cache, context);
|
|
46
|
+
client.checkout = new CommercetoolsCheckoutProvider(configuration, CheckoutSchema, cache, context, commercetoolsClient);
|
|
45
47
|
}
|
|
46
48
|
return client;
|
|
47
49
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CommercetoolsSessionSchema } from "../schema/session.schema.js";
|
|
2
|
+
class RequestContextTokenCache {
|
|
3
|
+
constructor(context) {
|
|
4
|
+
this.context = context;
|
|
5
|
+
}
|
|
6
|
+
async get(tokenCacheOptions) {
|
|
7
|
+
const session = CommercetoolsSessionSchema.parse(
|
|
8
|
+
this.context.session["PROVIDER_COMMERCETOOLS"] || {}
|
|
9
|
+
);
|
|
10
|
+
if (!session) {
|
|
11
|
+
return {
|
|
12
|
+
refreshToken: void 0,
|
|
13
|
+
token: "",
|
|
14
|
+
expirationTime: (/* @__PURE__ */ new Date()).getTime()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
refreshToken: session.refreshToken,
|
|
19
|
+
token: session.token,
|
|
20
|
+
expirationTime: session.expirationTime
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async set(cache, tokenCacheOptions) {
|
|
24
|
+
const session = CommercetoolsSessionSchema.parse(
|
|
25
|
+
this.context.session["PROVIDER_COMMERCETOOLS"] || {}
|
|
26
|
+
);
|
|
27
|
+
this.context.session["PROVIDER_COMMERCETOOLS"] = session;
|
|
28
|
+
session.refreshToken = cache.refreshToken;
|
|
29
|
+
session.token = cache.token;
|
|
30
|
+
session.expirationTime = cache.expirationTime;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
RequestContextTokenCache
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-commercetools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.64",
|
|
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.64",
|
|
8
8
|
"debug": "^4.4.3",
|
|
9
9
|
"zod": "4.1.9",
|
|
10
10
|
"@commercetools/ts-client": "^4.2.1",
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CartItemSchema,
|
|
3
|
-
CartProvider
|
|
4
|
-
} from "@reactionary/core";
|
|
5
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
1
|
+
import { CartItemSchema, CartProvider } from "@reactionary/core";
|
|
6
2
|
import {
|
|
7
3
|
CommercetoolsCartIdentifierSchema,
|
|
8
4
|
CommercetoolsOrderIdentifierSchema
|
|
9
5
|
} from "../schema/commercetools.schema.js";
|
|
10
6
|
class CommercetoolsCartProvider extends CartProvider {
|
|
11
|
-
constructor(config, schema, cache, context) {
|
|
7
|
+
constructor(config, schema, cache, context, client) {
|
|
12
8
|
super(schema, cache, context);
|
|
13
9
|
this.config = config;
|
|
10
|
+
this.client = client;
|
|
14
11
|
}
|
|
15
12
|
async getById(payload) {
|
|
16
13
|
try {
|
|
@@ -27,51 +24,47 @@ class CommercetoolsCartProvider extends CartProvider {
|
|
|
27
24
|
if (!cartIdentifier.key) {
|
|
28
25
|
cartIdentifier = await this.createCart();
|
|
29
26
|
}
|
|
30
|
-
return this.applyActions(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
action: "recalculate"
|
|
27
|
+
return this.applyActions(cartIdentifier, [
|
|
28
|
+
{
|
|
29
|
+
action: "addLineItem",
|
|
30
|
+
quantity: payload.quantity,
|
|
31
|
+
sku: payload.variant.sku,
|
|
32
|
+
// FIXME: This should be dynamic, probably as part of the context...
|
|
33
|
+
distributionChannel: {
|
|
34
|
+
typeId: "channel",
|
|
35
|
+
key: "OnlineFfmChannel"
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
action: "recalculate"
|
|
40
|
+
}
|
|
41
|
+
]);
|
|
43
42
|
}
|
|
44
43
|
async remove(payload) {
|
|
45
|
-
return this.applyActions(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
);
|
|
44
|
+
return this.applyActions(payload.cart, [
|
|
45
|
+
{
|
|
46
|
+
action: "removeLineItem",
|
|
47
|
+
lineItemId: payload.item.key
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
action: "recalculate"
|
|
51
|
+
}
|
|
52
|
+
]);
|
|
57
53
|
}
|
|
58
54
|
async changeQuantity(payload) {
|
|
59
55
|
if (payload.quantity === 0) {
|
|
60
56
|
return this.getById({ cart: payload.cart });
|
|
61
57
|
}
|
|
62
|
-
return this.applyActions(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
);
|
|
58
|
+
return this.applyActions(payload.cart, [
|
|
59
|
+
{
|
|
60
|
+
action: "changeLineItemQuantity",
|
|
61
|
+
lineItemId: payload.item.key,
|
|
62
|
+
quantity: payload.quantity
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
action: "recalculate"
|
|
66
|
+
}
|
|
67
|
+
]);
|
|
75
68
|
}
|
|
76
69
|
async getActiveCartId() {
|
|
77
70
|
const client = await this.getClient();
|
|
@@ -132,64 +125,55 @@ class CommercetoolsCartProvider extends CartProvider {
|
|
|
132
125
|
return this.applyActions(payload.cart, actions);
|
|
133
126
|
}
|
|
134
127
|
setBillingAddress(payload) {
|
|
135
|
-
return this.applyActions(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
streetName: payload.billingAddress.streetAddress,
|
|
149
|
-
streetNumber: payload.billingAddress.streetNumber
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
action: "setCustomerEmail",
|
|
154
|
-
email: payload.notificationEmailAddress
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
action: "setCountry",
|
|
158
|
-
country: payload.billingAddress.countryCode || this.context.taxJurisdiction.countryCode || "US"
|
|
128
|
+
return this.applyActions(payload.cart, [
|
|
129
|
+
{
|
|
130
|
+
action: "setBillingAddress",
|
|
131
|
+
address: {
|
|
132
|
+
email: payload.notificationEmailAddress,
|
|
133
|
+
mobile: payload.notificationPhoneNumber,
|
|
134
|
+
country: payload.billingAddress.countryCode || this.context.taxJurisdiction.countryCode || "US",
|
|
135
|
+
firstName: payload.billingAddress.firstName,
|
|
136
|
+
lastName: payload.billingAddress.lastName,
|
|
137
|
+
city: payload.billingAddress.city,
|
|
138
|
+
postalCode: payload.billingAddress.postalCode,
|
|
139
|
+
streetName: payload.billingAddress.streetAddress,
|
|
140
|
+
streetNumber: payload.billingAddress.streetNumber
|
|
159
141
|
}
|
|
160
|
-
|
|
161
|
-
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
action: "setCustomerEmail",
|
|
145
|
+
email: payload.notificationEmailAddress
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
action: "setCountry",
|
|
149
|
+
country: payload.billingAddress.countryCode || this.context.taxJurisdiction.countryCode || "US"
|
|
150
|
+
}
|
|
151
|
+
]);
|
|
162
152
|
}
|
|
163
153
|
applyCouponCode(payload) {
|
|
164
|
-
return this.applyActions(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
);
|
|
154
|
+
return this.applyActions(payload.cart, [
|
|
155
|
+
{
|
|
156
|
+
action: "addDiscountCode",
|
|
157
|
+
code: payload.couponCode
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
action: "recalculate"
|
|
161
|
+
}
|
|
162
|
+
]);
|
|
176
163
|
}
|
|
177
164
|
removeCouponCode(payload) {
|
|
178
|
-
return this.applyActions(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
id: payload.couponCode,
|
|
185
|
-
typeId: "discount-code"
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
action: "recalculate"
|
|
165
|
+
return this.applyActions(payload.cart, [
|
|
166
|
+
{
|
|
167
|
+
action: "removeDiscountCode",
|
|
168
|
+
discountCode: {
|
|
169
|
+
id: payload.couponCode,
|
|
170
|
+
typeId: "discount-code"
|
|
190
171
|
}
|
|
191
|
-
|
|
192
|
-
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
action: "recalculate"
|
|
175
|
+
}
|
|
176
|
+
]);
|
|
193
177
|
}
|
|
194
178
|
async checkout(payload) {
|
|
195
179
|
const client = await this.getClient();
|
|
@@ -225,15 +209,12 @@ class CommercetoolsCartProvider extends CartProvider {
|
|
|
225
209
|
quantity: item.quantity
|
|
226
210
|
})
|
|
227
211
|
);
|
|
228
|
-
const response = await this.applyActions(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
]
|
|
236
|
-
);
|
|
212
|
+
const response = await this.applyActions(newCartId, [
|
|
213
|
+
...cartItemAdds,
|
|
214
|
+
{
|
|
215
|
+
action: "recalculate"
|
|
216
|
+
}
|
|
217
|
+
]);
|
|
237
218
|
await client.carts.withId({ ID: payload.cart.key }).delete({
|
|
238
219
|
queryArgs: {
|
|
239
220
|
version: currentCart.body.version || 0,
|
|
@@ -281,8 +262,10 @@ class CommercetoolsCartProvider extends CartProvider {
|
|
|
281
262
|
* In the future, maybe we can delay this upgrade until we actually need it.
|
|
282
263
|
*/
|
|
283
264
|
async getClient() {
|
|
284
|
-
const client = await
|
|
285
|
-
const clientWithProject = client.withProjectKey({
|
|
265
|
+
const client = await this.client.getClient();
|
|
266
|
+
const clientWithProject = client.withProjectKey({
|
|
267
|
+
projectKey: this.config.projectKey
|
|
268
|
+
});
|
|
286
269
|
return {
|
|
287
270
|
carts: clientWithProject.me().carts(),
|
|
288
271
|
activeCart: clientWithProject.me().activeCart(),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CategoryProvider, createPaginatedResponseSchema } from "@reactionary/core";
|
|
2
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
3
2
|
class CommercetoolsCategoryProvider extends CategoryProvider {
|
|
4
|
-
constructor(config, schema, cache, context) {
|
|
3
|
+
constructor(config, schema, cache, context, client) {
|
|
5
4
|
super(schema, cache, context);
|
|
6
5
|
this.config = config;
|
|
6
|
+
this.client = client;
|
|
7
7
|
}
|
|
8
8
|
async getClient() {
|
|
9
|
-
const client = await
|
|
9
|
+
const client = await this.client.getClient();
|
|
10
10
|
return client.withProjectKey({ projectKey: this.config.projectKey }).categories();
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -8,11 +8,9 @@ import {
|
|
|
8
8
|
ShippingInstructionSchema,
|
|
9
9
|
ShippingMethodSchema
|
|
10
10
|
} from "@reactionary/core";
|
|
11
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
12
11
|
import {
|
|
13
12
|
CommercetoolsCartIdentifierSchema,
|
|
14
|
-
CommercetoolsCheckoutIdentifierSchema
|
|
15
|
-
CommercetoolsOrderIdentifierSchema
|
|
13
|
+
CommercetoolsCheckoutIdentifierSchema
|
|
16
14
|
} from "../schema/commercetools.schema.js";
|
|
17
15
|
class CheckoutNotReadyForFinalizationError extends Error {
|
|
18
16
|
constructor(checkoutIdentifier) {
|
|
@@ -24,12 +22,13 @@ class CheckoutNotReadyForFinalizationError extends Error {
|
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
class CommercetoolsCheckoutProvider extends CheckoutProvider {
|
|
27
|
-
constructor(config, schema, cache, context) {
|
|
25
|
+
constructor(config, schema, cache, context, client) {
|
|
28
26
|
super(schema, cache, context);
|
|
29
27
|
this.config = config;
|
|
28
|
+
this.client = client;
|
|
30
29
|
}
|
|
31
30
|
async getClient() {
|
|
32
|
-
const client = await
|
|
31
|
+
const client = await this.client.getClient();
|
|
33
32
|
return {
|
|
34
33
|
payments: client.withProjectKey({ projectKey: this.config.projectKey }).me().payments(),
|
|
35
34
|
carts: client.withProjectKey({ projectKey: this.config.projectKey }).me().carts(),
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
IdentityProvider
|
|
3
3
|
} from "@reactionary/core";
|
|
4
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
5
4
|
class CommercetoolsIdentityProvider extends IdentityProvider {
|
|
6
|
-
constructor(config, schema, cache, context) {
|
|
5
|
+
constructor(config, schema, cache, context, client) {
|
|
7
6
|
super(schema, cache, context);
|
|
8
7
|
this.config = config;
|
|
8
|
+
this.client = client;
|
|
9
9
|
}
|
|
10
10
|
async getSelf(payload) {
|
|
11
|
-
const
|
|
12
|
-
const identity = await client.introspect(this.context);
|
|
11
|
+
const identity = await this.client.introspect();
|
|
13
12
|
return identity;
|
|
14
13
|
}
|
|
15
14
|
async login(payload) {
|
|
16
|
-
const identity = await
|
|
15
|
+
const identity = await this.client.login(
|
|
17
16
|
payload.username,
|
|
18
|
-
payload.password
|
|
19
|
-
this.context
|
|
17
|
+
payload.password
|
|
20
18
|
);
|
|
21
19
|
return identity;
|
|
22
20
|
}
|
|
23
21
|
async logout(payload) {
|
|
24
|
-
const identity = await
|
|
22
|
+
const identity = await this.client.logout();
|
|
25
23
|
return identity;
|
|
26
24
|
}
|
|
27
25
|
async register(payload) {
|
|
28
|
-
const identity = await
|
|
26
|
+
const identity = await this.client.register(
|
|
29
27
|
payload.username,
|
|
30
|
-
payload.password
|
|
31
|
-
this.context
|
|
28
|
+
payload.password
|
|
32
29
|
);
|
|
33
30
|
return identity;
|
|
34
31
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { InventoryProvider } from "@reactionary/core";
|
|
2
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
3
2
|
class CommercetoolsInventoryProvider extends InventoryProvider {
|
|
4
|
-
constructor(config, schema, cache, context) {
|
|
3
|
+
constructor(config, schema, cache, context, client) {
|
|
5
4
|
super(schema, cache, context);
|
|
6
5
|
this.config = config;
|
|
6
|
+
this.client = client;
|
|
7
7
|
}
|
|
8
8
|
async getClient() {
|
|
9
|
-
const client = await
|
|
10
|
-
return client.withProjectKey({ projectKey: this.config.projectKey })
|
|
9
|
+
const client = await this.client.getClient();
|
|
10
|
+
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
11
11
|
}
|
|
12
12
|
async getBySKU(payload) {
|
|
13
|
-
const client = await
|
|
14
|
-
const channel = await client.
|
|
13
|
+
const client = await this.getClient();
|
|
14
|
+
const channel = await client.channels().withKey({ key: payload.fulfilmentCenter.key }).get().execute();
|
|
15
15
|
const channelId = channel.body.id;
|
|
16
|
-
const remote = await client.
|
|
16
|
+
const remote = await client.inventory().get({
|
|
17
17
|
queryArgs: {
|
|
18
18
|
where: "sku=:sku AND supplyChannel(id=:channel)",
|
|
19
19
|
"var.sku": payload.variant.sku,
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { OrderItemSchema, OrderProvider } from "@reactionary/core";
|
|
2
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
3
2
|
import { CommercetoolsOrderIdentifierSchema } from "../schema/commercetools.schema.js";
|
|
4
3
|
class CommercetoolsOrderProvider extends OrderProvider {
|
|
5
|
-
constructor(config, schema, cache, context) {
|
|
4
|
+
constructor(config, schema, cache, context, client) {
|
|
6
5
|
super(schema, cache, context);
|
|
7
6
|
this.config = config;
|
|
7
|
+
this.client = client;
|
|
8
8
|
}
|
|
9
9
|
async getClient() {
|
|
10
|
-
const client = await
|
|
11
|
-
this.context
|
|
12
|
-
);
|
|
10
|
+
const client = await this.client.getClient();
|
|
13
11
|
return client.withProjectKey({ projectKey: this.config.projectKey }).me().orders();
|
|
14
12
|
}
|
|
15
13
|
async getById(payload) {
|
|
16
|
-
const client = await
|
|
14
|
+
const client = await this.getClient();
|
|
17
15
|
try {
|
|
18
|
-
const remote = await client.
|
|
16
|
+
const remote = await client.withId({ ID: payload.order.key }).get().execute();
|
|
19
17
|
return this.parseSingle(remote.body);
|
|
20
18
|
} catch (e) {
|
|
21
19
|
return this.createEmptyOrder();
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { PriceProvider, TieredPriceSchema } from "@reactionary/core";
|
|
2
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
3
2
|
class CommercetoolsPriceProvider extends PriceProvider {
|
|
4
|
-
constructor(config, schema, cache, context) {
|
|
3
|
+
constructor(config, schema, cache, context, client) {
|
|
5
4
|
super(schema, cache, context);
|
|
6
5
|
this.config = config;
|
|
6
|
+
this.client = client;
|
|
7
7
|
}
|
|
8
8
|
async getClient() {
|
|
9
|
-
const client = await
|
|
10
|
-
this.context
|
|
11
|
-
);
|
|
9
|
+
const client = await this.client.getClient();
|
|
12
10
|
return client.withProjectKey({ projectKey: this.config.projectKey }).productProjections();
|
|
13
11
|
}
|
|
14
12
|
async getBySKUs(payload) {
|
|
@@ -19,13 +17,15 @@ class CommercetoolsPriceProvider extends PriceProvider {
|
|
|
19
17
|
staged: false,
|
|
20
18
|
priceCountry: this.context.taxJurisdiction.countryCode,
|
|
21
19
|
priceCustomerGroup: void 0,
|
|
22
|
-
|
|
20
|
+
// FIXME: Hardcoded value for testing, for now...
|
|
21
|
+
priceChannel: "7293d166-27a3-4136-b7c5-7b4dc3cfce40",
|
|
23
22
|
priceCurrency: this.context.languageContext.currencyCode,
|
|
24
23
|
where: "variants(sku in (:skus)) OR (masterVariant(sku in (:skus))) ",
|
|
25
24
|
"var.skus": payload.map((p) => p.variant.sku),
|
|
26
25
|
limit: payload.length
|
|
27
26
|
}
|
|
28
27
|
}).execute();
|
|
28
|
+
console.log("response: ", response.body);
|
|
29
29
|
const result = [];
|
|
30
30
|
const allReturnedVariants = [...response.body.results.map((x) => x.variants).flat(), ...response.body.results.map((x) => x.masterVariant).flat()];
|
|
31
31
|
for (const p of payload) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createPaginatedResponseSchema, FacetIdentifierSchema, FacetValueIdentifierSchema, ImageSchema, ProductOptionIdentifierSchema, ProductSearchProvider, ProductSearchResultFacetSchema, ProductSearchResultFacetValueSchema, ProductSearchResultItemVariantSchema, ProductVariantIdentifierSchema, ProductVariantOptionSchema } from "@reactionary/core";
|
|
2
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
3
2
|
import createDebug from "debug";
|
|
4
3
|
const debug = createDebug("reactionary:commercetools:search");
|
|
5
4
|
class CommercetoolsSearchProvider extends ProductSearchProvider {
|
|
6
|
-
constructor(config, schema, cache, context) {
|
|
5
|
+
constructor(config, schema, cache, context, client) {
|
|
7
6
|
super(schema, cache, context);
|
|
8
7
|
this.config = config;
|
|
8
|
+
this.client = client;
|
|
9
9
|
}
|
|
10
10
|
async getClient() {
|
|
11
|
-
const client = await
|
|
11
|
+
const client = await this.client.getClient();
|
|
12
12
|
return client.withProjectKey({ projectKey: this.config.projectKey }).productProjections();
|
|
13
13
|
}
|
|
14
14
|
async queryByTerm(payload) {
|
|
@@ -8,20 +8,20 @@ import {
|
|
|
8
8
|
ProductVariantIdentifierSchema,
|
|
9
9
|
ProductVariantSchema
|
|
10
10
|
} from "@reactionary/core";
|
|
11
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
12
11
|
class CommercetoolsProductProvider extends ProductProvider {
|
|
13
|
-
constructor(config, schema, cache, context) {
|
|
12
|
+
constructor(config, schema, cache, context, client) {
|
|
14
13
|
super(schema, cache, context);
|
|
15
14
|
this.config = config;
|
|
15
|
+
this.client = client;
|
|
16
16
|
}
|
|
17
17
|
async getClient() {
|
|
18
|
-
const client = await
|
|
18
|
+
const client = await this.client.getClient();
|
|
19
19
|
return client.withProjectKey({ projectKey: this.config.projectKey }).productProjections();
|
|
20
20
|
}
|
|
21
21
|
async getById(payload) {
|
|
22
22
|
const client = await this.getClient();
|
|
23
23
|
try {
|
|
24
|
-
const remote = await client.
|
|
24
|
+
const remote = await client.withKey({ key: payload.id }).get().execute();
|
|
25
25
|
return this.parseSingle(remote.body);
|
|
26
26
|
} catch (error) {
|
|
27
27
|
return this.createEmptyProduct(payload.id);
|
|
@@ -31,7 +31,8 @@ class CommercetoolsProductProvider extends ProductProvider {
|
|
|
31
31
|
const client = await this.getClient();
|
|
32
32
|
const remote = await client.get({
|
|
33
33
|
queryArgs: {
|
|
34
|
-
|
|
34
|
+
// FIXME: Hardcoded locale
|
|
35
|
+
where: "slug(en = :slug)",
|
|
35
36
|
"var.slug": payload.slug
|
|
36
37
|
}
|
|
37
38
|
}).execute();
|
|
@@ -54,7 +55,7 @@ class CommercetoolsProductProvider extends ProductProvider {
|
|
|
54
55
|
}
|
|
55
56
|
parseSingle(data) {
|
|
56
57
|
const base = this.newModel();
|
|
57
|
-
base.identifier = { key: data.id };
|
|
58
|
+
base.identifier = { key: data.key || data.id };
|
|
58
59
|
base.name = data.name[this.context.languageContext.locale];
|
|
59
60
|
base.slug = data.slug[this.context.languageContext.locale];
|
|
60
61
|
if (data.description) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ProfileProvider } from "@reactionary/core";
|
|
2
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
3
2
|
class CommercetoolsProfileProvider extends ProfileProvider {
|
|
4
|
-
constructor(config, schema, cache, context) {
|
|
3
|
+
constructor(config, schema, cache, context, client) {
|
|
5
4
|
super(schema, cache, context);
|
|
6
5
|
this.config = config;
|
|
6
|
+
this.client = client;
|
|
7
7
|
}
|
|
8
8
|
async getClient() {
|
|
9
|
-
const client = await
|
|
9
|
+
const client = await this.client.getClient();
|
|
10
10
|
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
11
11
|
}
|
|
12
12
|
async getSelf(payload) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StoreProvider } from "@reactionary/core";
|
|
2
|
-
import { CommercetoolsClient } from "../core/client.js";
|
|
3
2
|
class CommercetoolsStoreProvider extends StoreProvider {
|
|
4
|
-
constructor(config, schema, cache, context) {
|
|
3
|
+
constructor(config, schema, cache, context, client) {
|
|
5
4
|
super(schema, cache, context);
|
|
6
5
|
this.config = config;
|
|
6
|
+
this.client = client;
|
|
7
7
|
}
|
|
8
8
|
async getClient() {
|
|
9
|
-
const client = await
|
|
9
|
+
const client = await this.client.getClient();
|
|
10
10
|
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
11
11
|
}
|
|
12
12
|
async queryByProximity(payload) {
|
package/src/core/client.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { ClientBuilder
|
|
1
|
+
import { ClientBuilder } from '@commercetools/ts-client';
|
|
2
|
+
import { type ApiRoot } from '@commercetools/platform-sdk';
|
|
2
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
3
4
|
import { type AnonymousIdentity, type GuestIdentity, type RegisteredIdentity, type RequestContext } from '@reactionary/core';
|
|
4
|
-
|
|
5
|
-
protected context: RequestContext;
|
|
6
|
-
constructor(context: RequestContext);
|
|
7
|
-
get(tokenCacheOptions?: TokenCacheOptions): Promise<TokenStore | undefined>;
|
|
8
|
-
set(cache: TokenStore, tokenCacheOptions?: TokenCacheOptions): Promise<void>;
|
|
9
|
-
}
|
|
5
|
+
import { RequestContextTokenCache } from './token-cache.js';
|
|
10
6
|
export declare class CommercetoolsClient {
|
|
11
7
|
protected config: CommercetoolsConfiguration;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
protected context: RequestContext;
|
|
9
|
+
protected cache: RequestContextTokenCache;
|
|
10
|
+
protected client: Promise<ApiRoot> | undefined;
|
|
11
|
+
constructor(config: CommercetoolsConfiguration, context: RequestContext);
|
|
12
|
+
getClient(): Promise<ApiRoot>;
|
|
13
|
+
protected createClient(): Promise<ApiRoot>;
|
|
14
|
+
register(username: string, password: string): Promise<{
|
|
15
15
|
[x: string]: unknown;
|
|
16
16
|
meta: {
|
|
17
17
|
[x: string]: unknown;
|
|
@@ -28,7 +28,7 @@ export declare class CommercetoolsClient {
|
|
|
28
28
|
};
|
|
29
29
|
type: "Registered";
|
|
30
30
|
}>;
|
|
31
|
-
login(username: string, password: string
|
|
31
|
+
login(username: string, password: string): Promise<{
|
|
32
32
|
[x: string]: unknown;
|
|
33
33
|
meta: {
|
|
34
34
|
[x: string]: unknown;
|
|
@@ -45,7 +45,7 @@ export declare class CommercetoolsClient {
|
|
|
45
45
|
};
|
|
46
46
|
type: "Registered";
|
|
47
47
|
}>;
|
|
48
|
-
logout(
|
|
48
|
+
logout(): Promise<{
|
|
49
49
|
[x: string]: unknown;
|
|
50
50
|
meta: {
|
|
51
51
|
[x: string]: unknown;
|
|
@@ -58,8 +58,7 @@ export declare class CommercetoolsClient {
|
|
|
58
58
|
};
|
|
59
59
|
type: "Anonymous";
|
|
60
60
|
}>;
|
|
61
|
-
introspect(
|
|
62
|
-
protected becomeGuest(
|
|
63
|
-
protected
|
|
64
|
-
protected createBaseClientBuilder(reqCtx?: RequestContext): ClientBuilder;
|
|
61
|
+
introspect(): Promise<AnonymousIdentity | GuestIdentity | RegisteredIdentity>;
|
|
62
|
+
protected becomeGuest(): Promise<void>;
|
|
63
|
+
protected createBaseClientBuilder(): ClientBuilder;
|
|
65
64
|
}
|
package/src/core/initialize.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Cache, ProductProvider, ProductSearchProvider, IdentityProvider, CartProvider, InventoryProvider, PriceProvider, CategoryProvider, StoreProvider, CheckoutProvider, OrderProvider, RequestContext } from "@reactionary/core";
|
|
2
2
|
import type { CommercetoolsCapabilities } from "../schema/capabilities.schema.js";
|
|
3
3
|
import type { CommercetoolsConfiguration } from "../schema/configuration.schema.js";
|
|
4
|
-
type
|
|
4
|
+
type CommercetoolsProviderSet<T extends CommercetoolsCapabilities> = (T['cart'] extends true ? {
|
|
5
5
|
cart: CartProvider;
|
|
6
6
|
} : object) & (T['product'] extends true ? {
|
|
7
7
|
product: ProductProvider;
|
|
@@ -22,5 +22,5 @@ type CommercetoolsClient<T extends CommercetoolsCapabilities> = (T['cart'] exten
|
|
|
22
22
|
} : object) & (T['checkout'] extends true ? {
|
|
23
23
|
checkout: CheckoutProvider;
|
|
24
24
|
} : object);
|
|
25
|
-
export declare function withCommercetoolsCapabilities<T extends CommercetoolsCapabilities>(configuration: CommercetoolsConfiguration, capabilities: T): (cache: Cache, context: RequestContext) =>
|
|
25
|
+
export declare function withCommercetoolsCapabilities<T extends CommercetoolsCapabilities>(configuration: CommercetoolsConfiguration, capabilities: T): (cache: Cache, context: RequestContext) => CommercetoolsProviderSet<T>;
|
|
26
26
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TokenCache, TokenCacheOptions, TokenStore } from "@commercetools/ts-client";
|
|
2
|
+
import type { RequestContext } from "@reactionary/core";
|
|
3
|
+
export declare class RequestContextTokenCache implements TokenCache {
|
|
4
|
+
protected context: RequestContext;
|
|
5
|
+
constructor(context: RequestContext);
|
|
6
|
+
get(tokenCacheOptions?: TokenCacheOptions): Promise<TokenStore | undefined>;
|
|
7
|
+
set(cache: TokenStore, tokenCacheOptions?: TokenCacheOptions): Promise<void>;
|
|
8
|
+
}
|
|
@@ -3,9 +3,11 @@ import type { CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationI
|
|
|
3
3
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
4
4
|
import type { z } from 'zod';
|
|
5
5
|
import type { Cart as CTCart, MyCartUpdateAction } from '@commercetools/platform-sdk';
|
|
6
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
6
7
|
export declare class CommercetoolsCartProvider<T extends Cart = Cart> extends CartProvider<T> {
|
|
7
8
|
protected config: CommercetoolsConfiguration;
|
|
8
|
-
|
|
9
|
+
protected client: CommercetoolsClient;
|
|
10
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
9
11
|
getById(payload: CartQueryById): Promise<T>;
|
|
10
12
|
add(payload: CartMutationItemAdd): Promise<T>;
|
|
11
13
|
remove(payload: CartMutationItemRemove): Promise<T>;
|
|
@@ -3,9 +3,11 @@ import type { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb
|
|
|
3
3
|
import type z from "zod";
|
|
4
4
|
import type { CommercetoolsConfiguration } from "../schema/configuration.schema.js";
|
|
5
5
|
import type { ByProjectKeyCategoriesRequestBuilder } from "@commercetools/platform-sdk";
|
|
6
|
+
import type { CommercetoolsClient } from "../core/client.js";
|
|
6
7
|
export declare class CommercetoolsCategoryProvider<T extends Category = Category> extends CategoryProvider<T> {
|
|
7
8
|
protected config: CommercetoolsConfiguration;
|
|
8
|
-
|
|
9
|
+
protected client: CommercetoolsClient;
|
|
10
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
9
11
|
protected getClient(): Promise<ByProjectKeyCategoriesRequestBuilder>;
|
|
10
12
|
/**
|
|
11
13
|
* Look it up by the category ID (key in commercetools), and if not there, return a placeholder.
|
|
@@ -4,13 +4,15 @@ import type z from 'zod';
|
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
import type { MyCartUpdateAction } from '@commercetools/platform-sdk';
|
|
6
6
|
import type { Address as CTAddress, Payment as CTPayment, Cart as CTCart } from '@commercetools/platform-sdk';
|
|
7
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
7
8
|
export declare class CheckoutNotReadyForFinalizationError extends Error {
|
|
8
9
|
checkoutIdentifier: CheckoutIdentifier;
|
|
9
10
|
constructor(checkoutIdentifier: CheckoutIdentifier);
|
|
10
11
|
}
|
|
11
12
|
export declare class CommercetoolsCheckoutProvider<T extends Checkout = Checkout> extends CheckoutProvider<T> {
|
|
12
13
|
protected config: CommercetoolsConfiguration;
|
|
13
|
-
|
|
14
|
+
protected client: CommercetoolsClient;
|
|
15
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
14
16
|
protected getClient(): Promise<{
|
|
15
17
|
payments: import("@commercetools/platform-sdk").ByProjectKeyMePaymentsRequestBuilder;
|
|
16
18
|
carts: import("@commercetools/platform-sdk").ByProjectKeyMeCartsRequestBuilder;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type Identity, type IdentityMutationLogin, type IdentityQuerySelf, type RequestContext, type Cache, IdentityProvider, type IdentityMutationRegister } from '@reactionary/core';
|
|
2
2
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
3
3
|
import type z from 'zod';
|
|
4
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
4
5
|
export declare class CommercetoolsIdentityProvider<T extends Identity = Identity> extends IdentityProvider<T> {
|
|
5
6
|
protected config: CommercetoolsConfiguration;
|
|
6
|
-
|
|
7
|
+
protected client: CommercetoolsClient;
|
|
8
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
7
9
|
getSelf(payload: IdentityQuerySelf): Promise<T>;
|
|
8
10
|
login(payload: IdentityMutationLogin): Promise<T>;
|
|
9
11
|
logout(payload: Record<string, never>): Promise<T>;
|
|
@@ -3,10 +3,12 @@ import { InventoryProvider } from '@reactionary/core';
|
|
|
3
3
|
import type z from 'zod';
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
import type { InventoryEntry } from '@commercetools/platform-sdk';
|
|
6
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
6
7
|
export declare class CommercetoolsInventoryProvider<T extends Inventory = Inventory> extends InventoryProvider<T> {
|
|
7
8
|
protected config: CommercetoolsConfiguration;
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
protected client: CommercetoolsClient;
|
|
10
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
11
|
+
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
10
12
|
getBySKU(payload: InventoryQueryBySKU): Promise<T>;
|
|
11
13
|
protected parseSingle(body: InventoryEntry): T;
|
|
12
14
|
}
|
|
@@ -2,9 +2,11 @@ import type { RequestContext, Cache, Order, OrderQueryById } from '@reactionary/
|
|
|
2
2
|
import { OrderProvider } from '@reactionary/core';
|
|
3
3
|
import type z from 'zod';
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
5
6
|
export declare class CommercetoolsOrderProvider<T extends Order = Order> extends OrderProvider<T> {
|
|
6
7
|
protected config: CommercetoolsConfiguration;
|
|
7
|
-
|
|
8
|
+
protected client: CommercetoolsClient;
|
|
9
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
8
10
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyMeOrdersRequestBuilder>;
|
|
9
11
|
getById(payload: OrderQueryById): Promise<T>;
|
|
10
12
|
protected parseSingle(_body: unknown): T;
|
|
@@ -2,9 +2,11 @@ import { PriceProvider } from '@reactionary/core';
|
|
|
2
2
|
import type { PriceQueryBySku, RequestContext, Price, Cache } from '@reactionary/core';
|
|
3
3
|
import type z from 'zod';
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
5
6
|
export declare class CommercetoolsPriceProvider<T extends Price = Price> extends PriceProvider<T> {
|
|
6
7
|
protected config: CommercetoolsConfiguration;
|
|
7
|
-
|
|
8
|
+
protected client: CommercetoolsClient;
|
|
9
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
8
10
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyProductProjectionsRequestBuilder>;
|
|
9
11
|
getBySKUs(payload: PriceQueryBySku[]): Promise<T[]>;
|
|
10
12
|
getBySKU(payload: PriceQueryBySku): Promise<T>;
|
|
@@ -3,9 +3,11 @@ import type { Cache, ProductSearchQueryByTerm, RequestContext, ProductSearchResu
|
|
|
3
3
|
import type z from 'zod';
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
import type { ProductVariant as CTProductVariant, FacetResult, ProductProjection, ProductProjectionPagedSearchResponse } from '@commercetools/platform-sdk';
|
|
6
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
6
7
|
export declare class CommercetoolsSearchProvider<T extends ProductSearchResultItem = ProductSearchResultItem> extends ProductSearchProvider<T> {
|
|
7
8
|
protected config: CommercetoolsConfiguration;
|
|
8
|
-
|
|
9
|
+
protected client: CommercetoolsClient;
|
|
10
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
9
11
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyProductProjectionsRequestBuilder>;
|
|
10
12
|
queryByTerm(payload: ProductSearchQueryByTerm): Promise<ProductSearchResult>;
|
|
11
13
|
protected parseSingle(body: ProductProjection): T;
|
|
@@ -4,9 +4,11 @@ import type { CommercetoolsConfiguration } from '../schema/configuration.schema.
|
|
|
4
4
|
import type { ProductProjection, ProductVariant as CTProductVariant, Attribute as CTAttribute } from '@commercetools/platform-sdk';
|
|
5
5
|
import type { Product, ProductVariant, ProductQueryById, ProductQueryBySKU, ProductQueryBySlug, RequestContext, ProductAttribute, ProductAttributeValue } from '@reactionary/core';
|
|
6
6
|
import type { Cache } from '@reactionary/core';
|
|
7
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
7
8
|
export declare class CommercetoolsProductProvider<T extends Product = Product> extends ProductProvider<T> {
|
|
8
9
|
protected config: CommercetoolsConfiguration;
|
|
9
|
-
|
|
10
|
+
protected client: CommercetoolsClient;
|
|
11
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
10
12
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyProductProjectionsRequestBuilder>;
|
|
11
13
|
getById(payload: ProductQueryById): Promise<T>;
|
|
12
14
|
getBySlug(payload: ProductQueryBySlug): Promise<T | null>;
|
|
@@ -4,9 +4,11 @@ import type z from 'zod';
|
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
import type { Cache } from '@reactionary/core';
|
|
6
6
|
import type { Customer } from '@commercetools/platform-sdk';
|
|
7
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
7
8
|
export declare class CommercetoolsProfileProvider<T extends Profile = Profile> extends ProfileProvider<T> {
|
|
8
9
|
protected config: CommercetoolsConfiguration;
|
|
9
|
-
|
|
10
|
+
protected client: CommercetoolsClient;
|
|
11
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
10
12
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
11
13
|
getSelf(payload: ProfileQuerySelf): Promise<T>;
|
|
12
14
|
update(payload: ProfileMutationUpdate): Promise<T>;
|
|
@@ -4,9 +4,11 @@ import type z from 'zod';
|
|
|
4
4
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
5
5
|
import type { Channel } from '@commercetools/platform-sdk';
|
|
6
6
|
import type { Store } from '@reactionary/core';
|
|
7
|
+
import type { CommercetoolsClient } from '../core/client.js';
|
|
7
8
|
export declare class CommercetoolsStoreProvider<T extends Store = Store> extends StoreProvider<T> {
|
|
8
9
|
protected config: CommercetoolsConfiguration;
|
|
9
|
-
|
|
10
|
+
protected client: CommercetoolsClient;
|
|
11
|
+
constructor(config: CommercetoolsConfiguration, schema: z.ZodType<T>, cache: Cache, context: RequestContext, client: CommercetoolsClient);
|
|
10
12
|
protected getClient(): Promise<import("@commercetools/platform-sdk").ByProjectKeyRequestBuilder>;
|
|
11
13
|
queryByProximity(payload: StoreQueryByProximity): Promise<Array<T>>;
|
|
12
14
|
protected parseSingle(body: Channel): T;
|