@reactionary/commercetools 0.6.3
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/README.md +11 -0
- package/capabilities/cart.capability.js +324 -0
- package/capabilities/category.capability.js +198 -0
- package/capabilities/checkout.capability.js +374 -0
- package/capabilities/identity.capability.js +95 -0
- package/capabilities/index.js +15 -0
- package/capabilities/inventory.capability.js +63 -0
- package/capabilities/order-search.capability.js +106 -0
- package/capabilities/order.capability.js +48 -0
- package/capabilities/price.capability.js +114 -0
- package/capabilities/product-associations.capability.js +120 -0
- package/capabilities/product-list.capability.js +393 -0
- package/capabilities/product-reviews.capability.js +193 -0
- package/capabilities/product-search.capability.js +297 -0
- package/capabilities/product.capability.js +103 -0
- package/capabilities/profile.capability.js +337 -0
- package/capabilities/store.capability.js +51 -0
- package/core/capability-descriptors.js +274 -0
- package/core/client.js +318 -0
- package/core/initialize.js +47 -0
- package/core/initialize.types.js +8 -0
- package/core/token-cache.js +36 -0
- package/factories/cart/cart.factory.js +110 -0
- package/factories/category/category.factory.js +40 -0
- package/factories/checkout/checkout-initializer-overrides.example.js +67 -0
- package/factories/checkout/checkout.factory.js +235 -0
- package/factories/identity/identity.factory.js +14 -0
- package/factories/inventory/inventory.factory.js +30 -0
- package/factories/order/order.factory.js +114 -0
- package/factories/order-search/order-search.factory.js +68 -0
- package/factories/price/price.factory.js +52 -0
- package/factories/product/product-capability-custom-method-only.example.js +38 -0
- package/factories/product/product-capability-schema-signature-extension.example.js +46 -0
- package/factories/product/product-factory-baseline.example.js +10 -0
- package/factories/product/product-factory-schema-and-parse-extension.example.js +25 -0
- package/factories/product/product-factory-schema-extension.example.js +18 -0
- package/factories/product/product-initializer-factory-extension.example.js +33 -0
- package/factories/product/product.factory.js +151 -0
- package/factories/product/utils.example.js +8 -0
- package/factories/product-associations/product-associations.factory.js +63 -0
- package/factories/product-list/product-list.factory.js +65 -0
- package/factories/product-reviews/product-reviews.factory.js +42 -0
- package/factories/product-search/product-search.factory.js +114 -0
- package/factories/profile/profile.factory.js +62 -0
- package/factories/store/store.factory.js +29 -0
- package/index.js +28 -0
- package/package.json +17 -0
- package/schema/capabilities.schema.js +46 -0
- package/schema/commercetools.schema.js +30 -0
- package/schema/configuration.schema.js +19 -0
- package/schema/session.schema.js +9 -0
- package/src/capabilities/cart.capability.d.ts +34 -0
- package/src/capabilities/category.capability.d.ts +47 -0
- package/src/capabilities/checkout.capability.d.ts +39 -0
- package/src/capabilities/identity.capability.d.ts +14 -0
- package/src/capabilities/index.d.ts +15 -0
- package/src/capabilities/inventory.capability.d.ts +13 -0
- package/src/capabilities/order-search.capability.d.ts +13 -0
- package/src/capabilities/order.capability.d.ts +13 -0
- package/src/capabilities/price.capability.d.ts +18 -0
- package/src/capabilities/product-associations.capability.d.ts +17 -0
- package/src/capabilities/product-list.capability.d.ts +29 -0
- package/src/capabilities/product-reviews.capability.d.ts +18 -0
- package/src/capabilities/product-search.capability.d.ts +82 -0
- package/src/capabilities/product.capability.d.ts +17 -0
- package/src/capabilities/profile.capability.d.ts +30 -0
- package/src/capabilities/store.capability.d.ts +13 -0
- package/src/core/capability-descriptors.d.ts +16 -0
- package/src/core/client.d.ts +55 -0
- package/src/core/initialize.d.ts +5 -0
- package/src/core/initialize.types.d.ts +118 -0
- package/src/core/token-cache.d.ts +9 -0
- package/src/factories/cart/cart.factory.d.ts +14 -0
- package/src/factories/category/category.factory.d.ts +11 -0
- package/src/factories/checkout/checkout-initializer-overrides.example.d.ts +1 -0
- package/src/factories/checkout/checkout.factory.d.ts +18 -0
- package/src/factories/identity/identity.factory.d.ts +8 -0
- package/src/factories/inventory/inventory.factory.d.ts +9 -0
- package/src/factories/order/order.factory.d.ts +9 -0
- package/src/factories/order-search/order-search.factory.d.ts +11 -0
- package/src/factories/price/price.factory.d.ts +11 -0
- package/src/factories/product/product-capability-custom-method-only.example.d.ts +1 -0
- package/src/factories/product/product-capability-schema-signature-extension.example.d.ts +1 -0
- package/src/factories/product/product-factory-baseline.example.d.ts +1 -0
- package/src/factories/product/product-factory-schema-and-parse-extension.example.d.ts +1 -0
- package/src/factories/product/product-factory-schema-extension.example.d.ts +1 -0
- package/src/factories/product/product-initializer-factory-extension.example.d.ts +1 -0
- package/src/factories/product/product.factory.d.ts +18 -0
- package/src/factories/product/utils.example.d.ts +4 -0
- package/src/factories/product-associations/product-associations.factory.d.ts +15 -0
- package/src/factories/product-list/product-list.factory.d.ts +17 -0
- package/src/factories/product-reviews/product-reviews.factory.d.ts +14 -0
- package/src/factories/product-search/product-search.factory.d.ts +13 -0
- package/src/factories/profile/profile.factory.d.ts +11 -0
- package/src/factories/store/store.factory.d.ts +9 -0
- package/src/index.d.ts +28 -0
- package/src/schema/capabilities.schema.d.ts +104 -0
- package/src/schema/commercetools.schema.d.ts +30 -0
- package/src/schema/configuration.schema.d.ts +30 -0
- package/src/schema/session.schema.d.ts +7 -0
- package/src/test/client-builder-merge-extensions.example.d.ts +1 -0
- package/src/test/test-utils.d.ts +27 -0
- package/test/client-builder-merge-extensions.example.js +94 -0
- package/test/test-utils.js +27 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClientBuilder,
|
|
3
|
+
createInitialRequestContext,
|
|
4
|
+
NoOpCache,
|
|
5
|
+
ProductSchema,
|
|
6
|
+
StoreSchema
|
|
7
|
+
} from "@reactionary/core";
|
|
8
|
+
import * as z from "zod";
|
|
9
|
+
import { withCommercetoolsCapabilities } from "../core/initialize.js";
|
|
10
|
+
import { CommercetoolsProductFactory } from "../factories/product/product.factory.js";
|
|
11
|
+
import { CommercetoolsStoreFactory } from "../factories/store/store.factory.js";
|
|
12
|
+
import { assertNotAny, assertType } from "../factories/product/utils.example.js";
|
|
13
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
14
|
+
extendedProductValue: z.string()
|
|
15
|
+
});
|
|
16
|
+
class ExtendedCommercetoolsProductFactory extends CommercetoolsProductFactory {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(ExtendedProductSchema);
|
|
19
|
+
}
|
|
20
|
+
parseProduct(context, data) {
|
|
21
|
+
const base = super.parseProduct(context, data);
|
|
22
|
+
return this.productSchema.parse({
|
|
23
|
+
...base,
|
|
24
|
+
extendedProductValue: "from-product-factory"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const ExtendedStoreSchema = StoreSchema.safeExtend({
|
|
29
|
+
extendedStoreValue: z.string()
|
|
30
|
+
});
|
|
31
|
+
class ExtendedCommercetoolsStoreFactory extends CommercetoolsStoreFactory {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(ExtendedStoreSchema);
|
|
34
|
+
}
|
|
35
|
+
parseStore(context, data) {
|
|
36
|
+
const base = super.parseStore(context, data);
|
|
37
|
+
return this.storeSchema.parse({
|
|
38
|
+
...base,
|
|
39
|
+
extendedStoreValue: "from-store-factory"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const config = {
|
|
44
|
+
apiUrl: "https://api.example.invalid",
|
|
45
|
+
authUrl: "https://auth.example.invalid",
|
|
46
|
+
clientId: "test-client",
|
|
47
|
+
clientSecret: "test-secret",
|
|
48
|
+
projectKey: "test-project",
|
|
49
|
+
scopes: [],
|
|
50
|
+
paymentMethods: [],
|
|
51
|
+
facetFieldsForSearch: []
|
|
52
|
+
};
|
|
53
|
+
function createMergedClientExample() {
|
|
54
|
+
const cache = new NoOpCache();
|
|
55
|
+
const context = createInitialRequestContext();
|
|
56
|
+
const withProduct = withCommercetoolsCapabilities(config, {
|
|
57
|
+
product: {
|
|
58
|
+
enabled: true,
|
|
59
|
+
factory: new ExtendedCommercetoolsProductFactory()
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const withStore = withCommercetoolsCapabilities(config, {
|
|
63
|
+
store: {
|
|
64
|
+
enabled: true,
|
|
65
|
+
factory: new ExtendedCommercetoolsStoreFactory()
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const client = new ClientBuilder(context).withCache(cache).withCapability(withProduct).withCapability(withStore).build();
|
|
69
|
+
client.product.getById({
|
|
70
|
+
identifier: { key: "p-1" }
|
|
71
|
+
}).then((result) => {
|
|
72
|
+
assertNotAny(result);
|
|
73
|
+
if (result.success) {
|
|
74
|
+
assertNotAny(result.value);
|
|
75
|
+
assertNotAny(result.value.extendedProductValue);
|
|
76
|
+
assertType(result.value.extendedProductValue);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
client.store.queryByProximity({
|
|
80
|
+
longitude: 10,
|
|
81
|
+
latitude: 56,
|
|
82
|
+
distance: 50,
|
|
83
|
+
limit: 5
|
|
84
|
+
}).then((result) => {
|
|
85
|
+
assertNotAny(result);
|
|
86
|
+
if (result.success) {
|
|
87
|
+
const first = result.value[0];
|
|
88
|
+
assertNotAny(first);
|
|
89
|
+
assertNotAny(first.extendedStoreValue);
|
|
90
|
+
assertType(first.extendedStoreValue);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return client;
|
|
94
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PaymentMethodSchema } from "@reactionary/core";
|
|
2
|
+
import { PaymentMethodIdentifierSchema } from "@reactionary/core";
|
|
3
|
+
function getCommercetoolsTestConfiguration() {
|
|
4
|
+
return {
|
|
5
|
+
apiUrl: process.env["CTP_API_URL"] || "",
|
|
6
|
+
authUrl: process.env["CTP_AUTH_URL"] || "",
|
|
7
|
+
clientId: process.env["CTP_CLIENT_ID"] || "",
|
|
8
|
+
clientSecret: process.env["CTP_CLIENT_SECRET"] || "",
|
|
9
|
+
projectKey: process.env["CTP_PROJECT_KEY"] || "",
|
|
10
|
+
scopes: (process.env["CTP_SCOPES"] || "").split(",").map((x) => x.trim()).filter((x) => x && x.length > 0),
|
|
11
|
+
paymentMethods: [
|
|
12
|
+
PaymentMethodSchema.parse({
|
|
13
|
+
identifier: PaymentMethodIdentifierSchema.parse({
|
|
14
|
+
paymentProcessor: "stripe",
|
|
15
|
+
method: "stripe",
|
|
16
|
+
name: "Stripe"
|
|
17
|
+
}),
|
|
18
|
+
description: "Stripe payment gateway",
|
|
19
|
+
isPunchOut: true
|
|
20
|
+
})
|
|
21
|
+
],
|
|
22
|
+
facetFieldsForSearch: []
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
getCommercetoolsTestConfiguration
|
|
27
|
+
};
|