@reactionary/provider-commercetools 0.0.65 → 0.0.67
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 +4 -2
- package/core/initialize.js +22 -18
- package/package.json +4 -3
- package/src/core/initialize.d.ts +2 -2
package/core/client.js
CHANGED
|
@@ -24,9 +24,11 @@ class CommercetoolsClient {
|
|
|
24
24
|
}
|
|
25
25
|
async createClient() {
|
|
26
26
|
let session = await this.cache.get();
|
|
27
|
-
const isNewSession = !session || session.
|
|
27
|
+
const isNewSession = !session || !session.refreshToken;
|
|
28
28
|
if (isNewSession) {
|
|
29
|
+
console.log("creating new session...");
|
|
29
30
|
await this.becomeGuest();
|
|
31
|
+
console.log("new session created!");
|
|
30
32
|
session = await this.cache.get();
|
|
31
33
|
}
|
|
32
34
|
let builder = this.createBaseClientBuilder();
|
|
@@ -37,7 +39,7 @@ class CommercetoolsClient {
|
|
|
37
39
|
},
|
|
38
40
|
host: this.config.authUrl,
|
|
39
41
|
projectKey: this.config.projectKey,
|
|
40
|
-
refreshToken: session
|
|
42
|
+
refreshToken: session?.refreshToken || "",
|
|
41
43
|
tokenCache: this.cache
|
|
42
44
|
});
|
|
43
45
|
return createApiBuilderFromCtpClient(builder.build());
|
package/core/initialize.js
CHANGED
|
@@ -8,42 +8,46 @@ import {
|
|
|
8
8
|
CheckoutSchema,
|
|
9
9
|
ProductSearchResultItemSchema
|
|
10
10
|
} from "@reactionary/core";
|
|
11
|
+
import { CommercetoolsCapabilitiesSchema } from "../schema/capabilities.schema.js";
|
|
11
12
|
import { CommercetoolsSearchProvider } from "../providers/product-search.provider.js";
|
|
12
13
|
import { CommercetoolsProductProvider } from "../providers/product.provider.js";
|
|
14
|
+
import { CommercetoolsConfigurationSchema } from "../schema/configuration.schema.js";
|
|
13
15
|
import { CommercetoolsIdentityProvider } from "../providers/identity.provider.js";
|
|
14
16
|
import { CommercetoolsCartProvider } from "../providers/cart.provider.js";
|
|
15
17
|
import { CommercetoolsInventoryProvider } from "../providers/inventory.provider.js";
|
|
16
18
|
import { CommercetoolsPriceProvider } from "../providers/price.provider.js";
|
|
17
19
|
import { CommercetoolsCategoryProvider } from "../providers/category.provider.js";
|
|
18
20
|
import { CommercetoolsCheckoutProvider } from "../providers/index.js";
|
|
19
|
-
import { CommercetoolsClient
|
|
21
|
+
import { CommercetoolsClient } from "./client.js";
|
|
20
22
|
function withCommercetoolsCapabilities(configuration, capabilities) {
|
|
21
23
|
return (cache, context) => {
|
|
22
24
|
const client = {};
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const config = CommercetoolsConfigurationSchema.parse(configuration);
|
|
26
|
+
const caps = CommercetoolsCapabilitiesSchema.parse(capabilities);
|
|
27
|
+
const commercetoolsClient = new CommercetoolsClient(config, context);
|
|
28
|
+
if (caps.product) {
|
|
29
|
+
client.product = new CommercetoolsProductProvider(config, ProductSchema, cache, context, commercetoolsClient);
|
|
26
30
|
}
|
|
27
|
-
if (
|
|
28
|
-
client.productSearch = new CommercetoolsSearchProvider(
|
|
31
|
+
if (caps.productSearch) {
|
|
32
|
+
client.productSearch = new CommercetoolsSearchProvider(config, ProductSearchResultItemSchema, cache, context, commercetoolsClient);
|
|
29
33
|
}
|
|
30
|
-
if (
|
|
31
|
-
client.identity = new CommercetoolsIdentityProvider(
|
|
34
|
+
if (caps.identity) {
|
|
35
|
+
client.identity = new CommercetoolsIdentityProvider(config, IdentitySchema, cache, context, commercetoolsClient);
|
|
32
36
|
}
|
|
33
|
-
if (
|
|
34
|
-
client.cart = new CommercetoolsCartProvider(
|
|
37
|
+
if (caps.cart) {
|
|
38
|
+
client.cart = new CommercetoolsCartProvider(config, CartSchema, cache, context, commercetoolsClient);
|
|
35
39
|
}
|
|
36
|
-
if (
|
|
37
|
-
client.inventory = new CommercetoolsInventoryProvider(
|
|
40
|
+
if (caps.inventory) {
|
|
41
|
+
client.inventory = new CommercetoolsInventoryProvider(config, InventorySchema, cache, context, commercetoolsClient);
|
|
38
42
|
}
|
|
39
|
-
if (
|
|
40
|
-
client.price = new CommercetoolsPriceProvider(
|
|
43
|
+
if (caps.price) {
|
|
44
|
+
client.price = new CommercetoolsPriceProvider(config, PriceSchema, cache, context, commercetoolsClient);
|
|
41
45
|
}
|
|
42
|
-
if (
|
|
43
|
-
client.category = new CommercetoolsCategoryProvider(
|
|
46
|
+
if (caps.category) {
|
|
47
|
+
client.category = new CommercetoolsCategoryProvider(config, CategorySchema, cache, context, commercetoolsClient);
|
|
44
48
|
}
|
|
45
|
-
if (
|
|
46
|
-
client.checkout = new CommercetoolsCheckoutProvider(
|
|
49
|
+
if (caps.checkout) {
|
|
50
|
+
client.checkout = new CommercetoolsCheckoutProvider(config, CheckoutSchema, cache, context, commercetoolsClient);
|
|
47
51
|
}
|
|
48
52
|
return client;
|
|
49
53
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/provider-commercetools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.67",
|
|
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.67",
|
|
8
8
|
"debug": "^4.4.3",
|
|
9
9
|
"zod": "4.1.9",
|
|
10
10
|
"@commercetools/ts-client": "^4.2.1",
|
|
11
11
|
"@commercetools/platform-sdk": "^8.8.0"
|
|
12
12
|
},
|
|
13
|
-
"type": "module"
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false
|
|
14
15
|
}
|
package/src/core/initialize.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Cache, ProductProvider, ProductSearchProvider, IdentityProvider, CartProvider, InventoryProvider, PriceProvider, CategoryProvider, StoreProvider, CheckoutProvider, OrderProvider, RequestContext } from "@reactionary/core";
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
2
|
+
import { type CommercetoolsCapabilities } from "../schema/capabilities.schema.js";
|
|
3
|
+
import { type CommercetoolsConfiguration } from "../schema/configuration.schema.js";
|
|
4
4
|
type CommercetoolsProviderSet<T extends CommercetoolsCapabilities> = (T['cart'] extends true ? {
|
|
5
5
|
cart: CartProvider;
|
|
6
6
|
} : object) & (T['product'] extends true ? {
|