@unchainedshop/api 3.1.12 → 3.1.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/lib/errors.d.ts +1 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -0
- package/lib/errors.js.map +1 -1
- package/lib/express/chatRouter.d.ts +3 -0
- package/lib/express/chatRouter.d.ts.map +1 -0
- package/lib/express/chatRouter.js +86 -0
- package/lib/express/chatRouter.js.map +1 -0
- package/lib/express/createApolloMiddleware.d.ts +4 -0
- package/lib/express/createApolloMiddleware.d.ts.map +1 -0
- package/lib/express/createApolloMiddleware.js +36 -0
- package/lib/express/createApolloMiddleware.js.map +1 -0
- package/lib/express/createSingleSignOnMiddleware.d.ts +5 -0
- package/lib/express/createSingleSignOnMiddleware.d.ts.map +1 -0
- package/lib/express/createSingleSignOnMiddleware.js +71 -0
- package/lib/express/createSingleSignOnMiddleware.js.map +1 -0
- package/lib/hashPassword.d.ts +2 -0
- package/lib/hashPassword.d.ts.map +1 -0
- package/lib/hashPassword.js +5 -0
- package/lib/hashPassword.js.map +1 -0
- package/lib/loaders/assortmentMediaTextLoader.js +1 -1
- package/lib/loaders/assortmentMediaTextLoader.js.map +1 -1
- package/lib/loaders/assortmentTextLoader.js +1 -1
- package/lib/loaders/assortmentTextLoader.js.map +1 -1
- package/lib/loaders/filterTextLoader.js +1 -1
- package/lib/loaders/filterTextLoader.js.map +1 -1
- package/lib/loaders/index.d.ts.map +1 -1
- package/lib/loaders/index.js.map +1 -1
- package/lib/loaders/productMediaTextLoader.d.ts.map +1 -1
- package/lib/loaders/productMediaTextLoader.js +1 -1
- package/lib/loaders/productMediaTextLoader.js.map +1 -1
- package/lib/loaders/productTextLoader.d.ts.map +1 -1
- package/lib/loaders/productTextLoader.js +1 -1
- package/lib/loaders/productTextLoader.js.map +1 -1
- package/lib/mcp/index.d.ts.map +1 -1
- package/lib/mcp/index.js +1 -1
- package/lib/mcp/index.js.map +1 -1
- package/lib/mcp/tools/addProductAssignmentHandler.d.ts +52 -0
- package/lib/mcp/tools/addProductAssignmentHandler.d.ts.map +1 -0
- package/lib/mcp/tools/addProductAssignmentHandler.js +97 -0
- package/lib/mcp/tools/addProductAssignmentHandler.js.map +1 -0
- package/lib/mcp/tools/countriesHandler.d.ts +60 -0
- package/lib/mcp/tools/countriesHandler.d.ts.map +1 -0
- package/lib/mcp/tools/countriesHandler.js +48 -0
- package/lib/mcp/tools/countriesHandler.js.map +1 -0
- package/lib/mcp/tools/countryHandler.d.ts +20 -0
- package/lib/mcp/tools/countryHandler.d.ts.map +1 -0
- package/lib/mcp/tools/countryHandler.js +34 -0
- package/lib/mcp/tools/countryHandler.js.map +1 -0
- package/lib/mcp/tools/createProduct.d.ts +138 -0
- package/lib/mcp/tools/createProduct.d.ts.map +1 -0
- package/lib/mcp/tools/createProduct.js +60 -0
- package/lib/mcp/tools/createProduct.js.map +1 -0
- package/lib/mcp/tools/createProductVariationHandler.d.ts +84 -0
- package/lib/mcp/tools/createProductVariationHandler.d.ts.map +1 -0
- package/lib/mcp/tools/createProductVariationHandler.js +67 -0
- package/lib/mcp/tools/createProductVariationHandler.js.map +1 -0
- package/lib/mcp/tools/currenciesHandler.d.ts +60 -0
- package/lib/mcp/tools/currenciesHandler.d.ts.map +1 -0
- package/lib/mcp/tools/currenciesHandler.js +50 -0
- package/lib/mcp/tools/currenciesHandler.js.map +1 -0
- package/lib/mcp/tools/currencyHandler.d.ts +20 -0
- package/lib/mcp/tools/currencyHandler.d.ts.map +1 -0
- package/lib/mcp/tools/currencyHandler.js +34 -0
- package/lib/mcp/tools/currencyHandler.js.map +1 -0
- package/lib/mcp/tools/getProduct.d.ts +0 -3
- package/lib/mcp/tools/getProduct.d.ts.map +1 -1
- package/lib/mcp/tools/getProduct.js +0 -324
- package/lib/mcp/tools/getProduct.js.map +1 -1
- package/lib/mcp/tools/languageHandler.d.ts +20 -0
- package/lib/mcp/tools/languageHandler.d.ts.map +1 -0
- package/lib/mcp/tools/languageHandler.js +31 -0
- package/lib/mcp/tools/languageHandler.js.map +1 -0
- package/lib/mcp/tools/languagesHandler.d.ts +60 -0
- package/lib/mcp/tools/languagesHandler.d.ts.map +1 -0
- package/lib/mcp/tools/languagesHandler.js +42 -0
- package/lib/mcp/tools/languagesHandler.js.map +1 -0
- package/lib/mcp/tools/listProducts.d.ts.map +1 -1
- package/lib/mcp/tools/listProducts.js +0 -13
- package/lib/mcp/tools/listProducts.js.map +1 -1
- package/lib/mcp/tools/normalizeMediaUrl.d.ts +3 -0
- package/lib/mcp/tools/normalizeMediaUrl.d.ts.map +1 -0
- package/lib/mcp/tools/normalizeMediaUrl.js +21 -0
- package/lib/mcp/tools/normalizeMediaUrl.js.map +1 -0
- package/lib/mcp/tools/productsCountHandler.d.ts +32 -0
- package/lib/mcp/tools/productsCountHandler.d.ts.map +1 -0
- package/lib/mcp/tools/productsCountHandler.js +33 -0
- package/lib/mcp/tools/productsCountHandler.js.map +1 -0
- package/lib/mcp/tools/publishProduct.d.ts +20 -0
- package/lib/mcp/tools/publishProduct.d.ts.map +1 -0
- package/lib/mcp/tools/publishProduct.js +40 -0
- package/lib/mcp/tools/publishProduct.js.map +1 -0
- package/lib/mcp/tools/removeProduct.d.ts +20 -0
- package/lib/mcp/tools/removeProduct.d.ts.map +1 -0
- package/lib/mcp/tools/removeProduct.js +34 -0
- package/lib/mcp/tools/removeProduct.js.map +1 -0
- package/lib/mcp/tools/removeProductVariationHandler.d.ts +20 -0
- package/lib/mcp/tools/removeProductVariationHandler.d.ts.map +1 -0
- package/lib/mcp/tools/removeProductVariationHandler.js +43 -0
- package/lib/mcp/tools/removeProductVariationHandler.js.map +1 -0
- package/lib/mcp/tools/unPublishProduct.d.ts +20 -0
- package/lib/mcp/tools/unPublishProduct.d.ts.map +1 -0
- package/lib/mcp/tools/unPublishProduct.js +40 -0
- package/lib/mcp/tools/unPublishProduct.js.map +1 -0
- package/lib/mcp/tools/updateProduct.d.ts +56 -0
- package/lib/mcp/tools/updateProduct.d.ts.map +1 -0
- package/lib/mcp/tools/updateProduct.js +44 -0
- package/lib/mcp/tools/updateProduct.js.map +1 -0
- package/lib/mcp/tools/updateProductCommerceHandler.d.ts +166 -0
- package/lib/mcp/tools/updateProductCommerceHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductCommerceHandler.js +64 -0
- package/lib/mcp/tools/updateProductCommerceHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductPlanHandler.d.ts +72 -0
- package/lib/mcp/tools/updateProductPlanHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductPlanHandler.js +51 -0
- package/lib/mcp/tools/updateProductPlanHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductSupplyHandler.d.ts +64 -0
- package/lib/mcp/tools/updateProductSupplyHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductSupplyHandler.js +52 -0
- package/lib/mcp/tools/updateProductSupplyHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductTextsHandler.d.ts +114 -0
- package/lib/mcp/tools/updateProductTextsHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductTextsHandler.js +50 -0
- package/lib/mcp/tools/updateProductTextsHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.d.ts +72 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.js +49 -0
- package/lib/mcp/tools/updateProductTokenizationHandler.js.map +1 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.d.ts +48 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.d.ts.map +1 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.js +45 -0
- package/lib/mcp/tools/updateProductWarehousingHandler.js.map +1 -0
- package/lib/mcp/utils/getNormalizedProductDetails.d.ts +26 -0
- package/lib/mcp/utils/getNormalizedProductDetails.d.ts.map +1 -0
- package/lib/mcp/utils/getNormalizedProductDetails.js +36 -0
- package/lib/mcp/utils/getNormalizedProductDetails.js.map +1 -0
- package/lib/mcp/utils/normalizeMediaUrl.d.ts +3 -0
- package/lib/mcp/utils/normalizeMediaUrl.d.ts.map +1 -0
- package/lib/mcp/utils/normalizeMediaUrl.js +21 -0
- package/lib/mcp/utils/normalizeMediaUrl.js.map +1 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts +3 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js +6 -0
- package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js.map +1 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.d.ts +6 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.js +27 -0
- package/lib/resolvers/mutations/accounts/disableTOTP.js.map +1 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.d.ts +6 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.js +20 -0
- package/lib/resolvers/mutations/accounts/enableTOTP.js.map +1 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts +7 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.js +30 -0
- package/lib/resolvers/mutations/accounts/linkOAuthAccount.js.map +1 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts +8 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.js +25 -0
- package/lib/resolvers/mutations/accounts/loginWithOAuth.js.map +1 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts +5 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js +20 -0
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +1 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts +6 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts.map +1 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js +13 -0
- package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js.map +1 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts +6 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts.map +1 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +18 -0
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +1 -0
- package/lib/resolvers/mutations/products/addProductAssignment.d.ts.map +1 -1
- package/lib/resolvers/mutations/products/addProductAssignment.js +3 -1
- package/lib/resolvers/mutations/products/addProductAssignment.js.map +1 -1
- package/lib/resolvers/mutations/products/addProductMedia.d.ts +6 -0
- package/lib/resolvers/mutations/products/addProductMedia.d.ts.map +1 -0
- package/lib/resolvers/mutations/products/addProductMedia.js +18 -0
- package/lib/resolvers/mutations/products/addProductMedia.js.map +1 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.d.ts +6 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.d.ts.map +1 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.js +22 -0
- package/lib/resolvers/mutations/users/updateUserAvatar.js.map +1 -0
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts +7 -0
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +1 -0
- package/lib/resolvers/mutations/utils/getOrderCart.js +13 -0
- package/lib/resolvers/mutations/utils/getOrderCart.js.map +1 -0
- package/lib/resolvers/type/dispatch-types.d.ts +15 -0
- package/lib/resolvers/type/dispatch-types.d.ts.map +1 -0
- package/lib/resolvers/type/dispatch-types.js +16 -0
- package/lib/resolvers/type/dispatch-types.js.map +1 -0
- package/lib/resolvers/type/oauth-account.d.ts +6 -0
- package/lib/resolvers/type/oauth-account.d.ts.map +1 -0
- package/lib/resolvers/type/oauth-account.js +7 -0
- package/lib/resolvers/type/oauth-account.js.map +1 -0
- package/lib/resolvers/type/oauth-provider.d.ts +6 -0
- package/lib/resolvers/type/oauth-provider.d.ts.map +1 -0
- package/lib/resolvers/type/oauth-provider.js +6 -0
- package/lib/resolvers/type/oauth-provider.js.map +1 -0
- package/lib/resolvers/type/stock-types.d.ts +14 -0
- package/lib/resolvers/type/stock-types.d.ts.map +1 -0
- package/lib/resolvers/type/stock-types.js +15 -0
- package/lib/resolvers/type/stock-types.js.map +1 -0
- package/lib/user-context.d.ts +7 -0
- package/lib/user-context.d.ts.map +1 -0
- package/lib/user-context.js +76 -0
- package/lib/user-context.js.map +1 -0
- package/package.json +13 -13
- package/src/errors.ts +5 -0
- package/src/loaders/buildLocaleMap.test.ts +14 -25
- package/src/loaders/buildLocaleMap.ts +1 -1
- package/src/loaders/buildTextMap.test.ts +9 -10
- package/src/loaders/index.ts +0 -1
- package/src/resolvers/mutations/products/addProductAssignment.ts +8 -1
- package/lib/express/mcpHandler.d.ts.map +0 -1
- package/lib/express/mcpHandler.js +0 -68
- package/lib/express/mcpHandler.js.map +0 -1
- package/lib/fastify/createMCPMiddleware.d.ts +0 -2
- package/lib/fastify/createMCPMiddleware.d.ts.map +0 -1
- package/lib/fastify/createMCPMiddleware.js +0 -2
- package/lib/fastify/createMCPMiddleware.js.map +0 -1
- package/lib/fastify/index copy.d.ts.map +0 -1
- package/lib/fastify/index copy.js +0 -157
- package/lib/fastify/index copy.js.map +0 -1
- package/lib/fastify/mcpHandler.d.ts +0 -8
- package/lib/fastify/mcpHandler.d.ts.map +0 -1
- package/lib/fastify/mcpHandler.js +0 -46
- package/lib/fastify/mcpHandler.js.map +0 -1
- package/lib/mcp/server.d.ts +0 -4
- package/lib/mcp/server.d.ts.map +0 -1
- package/lib/mcp/server.js +0 -60
- package/lib/mcp/server.js.map +0 -1
- package/lib/mcp/types.d.ts +0 -27
- package/lib/mcp/types.d.ts.map +0 -1
- package/lib/mcp/types.js +0 -5
- package/lib/mcp/types.js.map +0 -1
- package/lib/mcp/utils/html.d.ts +0 -16
- package/lib/mcp/utils/html.d.ts.map +0 -1
- package/lib/mcp/utils/html.js +0 -102
- package/lib/mcp/utils/html.js.map +0 -1
- package/lib/middleware/accountLockout.d.ts.map +0 -1
- package/lib/middleware/accountLockout.js +0 -84
- package/lib/middleware/accountLockout.js.map +0 -1
- package/lib/middleware/rateLimiter.d.ts.map +0 -1
- package/lib/middleware/rateLimiter.js +0 -91
- package/lib/middleware/rateLimiter.js.map +0 -1
- package/lib/plugins/inputValidation.d.ts.map +0 -1
- package/lib/plugins/inputValidation.js +0 -95
- package/lib/plugins/inputValidation.js.map +0 -1
- package/lib/utils/inputValidation.d.ts.map +0 -1
- package/lib/utils/inputValidation.js +0 -51
- package/lib/utils/inputValidation.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getNormalizedProductDetails } from '../utils/getNormalizedProductDetails.js';
|
|
3
|
+
import { ProductNotFoundError, ProductVariationVectorAlreadySet, ProductVariationVectorInvalid, ProductWrongTypeError, } from '../../errors.js';
|
|
4
|
+
import { ProductTypes } from '@unchainedshop/core-products';
|
|
5
|
+
const extractVariationMatrix = (variations = []) => {
|
|
6
|
+
const cartesianProduct = (arrays) => {
|
|
7
|
+
return arrays.reduce((acc, array) => acc.flatMap((item) => array.map((value) => [...item, value])), [[]]);
|
|
8
|
+
};
|
|
9
|
+
const keys = variations.map((item) => item.key);
|
|
10
|
+
const options = variations.map((item) => item.options);
|
|
11
|
+
const combinations = cartesianProduct(options);
|
|
12
|
+
return combinations.map((combination) => combination.reduce((acc, value, index) => {
|
|
13
|
+
acc[keys[index]] = value;
|
|
14
|
+
return acc;
|
|
15
|
+
}, {}));
|
|
16
|
+
};
|
|
17
|
+
const combinationExists = (matrix, combination) => {
|
|
18
|
+
return matrix.some((variation) => {
|
|
19
|
+
return (Object.keys(variation).length === Object.keys(combination).length && // Ensure both have the same number of keys
|
|
20
|
+
Object.entries(combination).every(([key, value]) => variation[key] === value));
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
// Zod schema for ProductAssignmentVectorInput
|
|
24
|
+
const ProductAssignmentVectorSchema = z.object({
|
|
25
|
+
key: z.string().min(1).describe('Attribute key (e.g., "Color", "Size")'),
|
|
26
|
+
value: z.string().min(1).describe('Attribute value (e.g., "Red", "M")'),
|
|
27
|
+
});
|
|
28
|
+
export const AssignProductVariationSchema = {
|
|
29
|
+
proxyId: z.string().min(1).describe('should be ID of the CONFIGURABLE_PRODUCT (parent) only'),
|
|
30
|
+
productId: z
|
|
31
|
+
.string()
|
|
32
|
+
.min(1)
|
|
33
|
+
.describe('ID of the product being assigned. can not be a CONFIGURABLE_PRODUCT product'),
|
|
34
|
+
vectors: z
|
|
35
|
+
.array(ProductAssignmentVectorSchema)
|
|
36
|
+
.min(1)
|
|
37
|
+
.describe('Combination of attributes uniquely identifying the variant'),
|
|
38
|
+
};
|
|
39
|
+
// Full schema for the mutation
|
|
40
|
+
export const AddProductAssignmentZodSchema = z.object(AssignProductVariationSchema);
|
|
41
|
+
export async function addProductAssignmentHandler(context, params) {
|
|
42
|
+
const { proxyId, productId, vectors } = params;
|
|
43
|
+
const { modules } = context;
|
|
44
|
+
try {
|
|
45
|
+
const proxyProduct = await modules.products.findProduct({
|
|
46
|
+
productId: proxyId,
|
|
47
|
+
});
|
|
48
|
+
if (!proxyProduct)
|
|
49
|
+
throw new ProductNotFoundError({ proxyId });
|
|
50
|
+
if (proxyProduct.type !== ProductTypes.ConfigurableProduct)
|
|
51
|
+
throw new ProductWrongTypeError({
|
|
52
|
+
proxyId,
|
|
53
|
+
received: proxyProduct.type,
|
|
54
|
+
required: ProductTypes.ConfigurableProduct,
|
|
55
|
+
});
|
|
56
|
+
const variations = await modules.products.variations.findProductVariations({
|
|
57
|
+
productId: proxyId,
|
|
58
|
+
});
|
|
59
|
+
const variationMatrix = extractVariationMatrix(variations);
|
|
60
|
+
const normalizedVectors = vectors?.reduce((prev, { key, value }) => {
|
|
61
|
+
return {
|
|
62
|
+
...prev,
|
|
63
|
+
[key]: value,
|
|
64
|
+
};
|
|
65
|
+
}, {});
|
|
66
|
+
if (!combinationExists(variationMatrix, normalizedVectors))
|
|
67
|
+
throw new ProductVariationVectorInvalid({ proxyId, vectors });
|
|
68
|
+
const added = await modules.products.assignments.addProxyAssignment({
|
|
69
|
+
productId,
|
|
70
|
+
proxyId,
|
|
71
|
+
vectors: vectors,
|
|
72
|
+
});
|
|
73
|
+
if (!added)
|
|
74
|
+
throw new ProductVariationVectorAlreadySet({ proxyId, vectors });
|
|
75
|
+
return {
|
|
76
|
+
content: [
|
|
77
|
+
{
|
|
78
|
+
type: 'text',
|
|
79
|
+
text: JSON.stringify({
|
|
80
|
+
product: await getNormalizedProductDetails(proxyId, context),
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
content: [
|
|
89
|
+
{
|
|
90
|
+
type: 'text',
|
|
91
|
+
text: `Error assigning product: ${error.message}`,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=addProductAssignmentHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addProductAssignmentHandler.js","sourceRoot":"","sources":["../../../src/mcp/tools/addProductAssignmentHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EACH,oBAAoB,EACpB,gCAAgC,EAChC,6BAA6B,EAC7B,qBAAqB,GACxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA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I,EAAE,IAAI,CAAC,SAAS,CAAC;wBACjB,OAAO,EAAE,MAAM,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC;qBAC/D,CAAC;iBACL;aACJ;SACJ,CAAC;IACN,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO;YACH,OAAO,EAAE;gBACL;oBACI,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,4BAA6B,KAAe,CAAC,OAAO,EAAE;iBAC/D;aACJ;SACJ,CAAC;IACN,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Context } from '../../context.js';
|
|
3
|
+
export declare const ListCountriesSchema: {
|
|
4
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
5
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
6
|
+
includeInactive: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
queryString: z.ZodOptional<z.ZodString>;
|
|
8
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
9
|
+
key: z.ZodString;
|
|
10
|
+
value: z.ZodEnum<["ASC" | "DESC", ...("ASC" | "DESC")[]]>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
key?: string;
|
|
13
|
+
value?: "ASC" | "DESC";
|
|
14
|
+
}, {
|
|
15
|
+
key?: string;
|
|
16
|
+
value?: "ASC" | "DESC";
|
|
17
|
+
}>, "many">>;
|
|
18
|
+
};
|
|
19
|
+
export declare const ListCountriesZodSchema: z.ZodObject<{
|
|
20
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
21
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
22
|
+
includeInactive: z.ZodDefault<z.ZodBoolean>;
|
|
23
|
+
queryString: z.ZodOptional<z.ZodString>;
|
|
24
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
25
|
+
key: z.ZodString;
|
|
26
|
+
value: z.ZodEnum<["ASC" | "DESC", ...("ASC" | "DESC")[]]>;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
key?: string;
|
|
29
|
+
value?: "ASC" | "DESC";
|
|
30
|
+
}, {
|
|
31
|
+
key?: string;
|
|
32
|
+
value?: "ASC" | "DESC";
|
|
33
|
+
}>, "many">>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
sort?: {
|
|
36
|
+
key?: string;
|
|
37
|
+
value?: "ASC" | "DESC";
|
|
38
|
+
}[];
|
|
39
|
+
includeInactive?: boolean;
|
|
40
|
+
queryString?: string;
|
|
41
|
+
limit?: number;
|
|
42
|
+
offset?: number;
|
|
43
|
+
}, {
|
|
44
|
+
sort?: {
|
|
45
|
+
key?: string;
|
|
46
|
+
value?: "ASC" | "DESC";
|
|
47
|
+
}[];
|
|
48
|
+
includeInactive?: boolean;
|
|
49
|
+
queryString?: string;
|
|
50
|
+
limit?: number;
|
|
51
|
+
offset?: number;
|
|
52
|
+
}>;
|
|
53
|
+
export type ListCountriesParams = z.infer<typeof ListCountriesZodSchema>;
|
|
54
|
+
export declare function countriesHandler(context: Context, params: ListCountriesParams): Promise<{
|
|
55
|
+
content: {
|
|
56
|
+
type: "text";
|
|
57
|
+
text: string;
|
|
58
|
+
}[];
|
|
59
|
+
}>;
|
|
60
|
+
//# sourceMappingURL=countriesHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countriesHandler.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/countriesHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAQ3C,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;CAa/B,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAgC,CAAC;AAEpE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEzE,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB;;;;;GA+BnF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { SortDirection } from '@unchainedshop/utils';
|
|
3
|
+
const sortDirectionKeys = Object.keys(SortDirection);
|
|
4
|
+
export const ListCountriesSchema = {
|
|
5
|
+
limit: z.number().int().min(1).max(100).default(50),
|
|
6
|
+
offset: z.number().int().min(0).default(0),
|
|
7
|
+
includeInactive: z.boolean().default(false),
|
|
8
|
+
queryString: z.string().min(1).optional(),
|
|
9
|
+
sort: z
|
|
10
|
+
.array(z.object({
|
|
11
|
+
key: z.string().min(1),
|
|
12
|
+
value: z.enum(sortDirectionKeys).describe("Sort direction, e.g., 'ASC' or 'DESC'"),
|
|
13
|
+
}))
|
|
14
|
+
.optional(),
|
|
15
|
+
};
|
|
16
|
+
export const ListCountriesZodSchema = z.object(ListCountriesSchema);
|
|
17
|
+
export async function countriesHandler(context, params) {
|
|
18
|
+
const { limit, offset, includeInactive, queryString, sort } = params;
|
|
19
|
+
const { modules } = context;
|
|
20
|
+
try {
|
|
21
|
+
const countries = await modules.countries.findCountries({
|
|
22
|
+
limit,
|
|
23
|
+
offset,
|
|
24
|
+
includeInactive,
|
|
25
|
+
queryString,
|
|
26
|
+
sort: sort,
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: 'text',
|
|
32
|
+
text: JSON.stringify({ countries }),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
content: [
|
|
40
|
+
{
|
|
41
|
+
type: 'text',
|
|
42
|
+
text: `Error retrieving countries: ${error.message}`,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=countriesHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countriesHandler.js","sourceRoot":"","sources":["../../../src/mcp/tools/countriesHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAGlD,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IACnD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1C,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IAC3C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACzC,IAAI,EAAE,CAAC;SACJ,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACtB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,uCAAuC,CAAC;KACnF,CAAC,CACH;SACA,QAAQ,EAAE;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAIpE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAgB,EAAE,MAA2B;IAClF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACrE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC;YACtD,KAAK;YACL,MAAM;YACN,eAAe;YACf,WAAW;YACX,IAAI,EAAE,IAAa;SACpB,CAAC,CAAC;QAEH,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC;iBACpC;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,+BAAgC,KAAe,CAAC,OAAO,EAAE;iBAChE;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Context } from '../../context.js';
|
|
3
|
+
export declare const CountrySchema: {
|
|
4
|
+
countryId: z.ZodString;
|
|
5
|
+
};
|
|
6
|
+
export declare const CountryZodSchema: z.ZodObject<{
|
|
7
|
+
countryId: z.ZodString;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
countryId?: string;
|
|
10
|
+
}, {
|
|
11
|
+
countryId?: string;
|
|
12
|
+
}>;
|
|
13
|
+
export type CountryParams = z.infer<typeof CountryZodSchema>;
|
|
14
|
+
export declare function countryHandler(context: Context, params: CountryParams): Promise<{
|
|
15
|
+
content: {
|
|
16
|
+
type: "text";
|
|
17
|
+
text: string;
|
|
18
|
+
}[];
|
|
19
|
+
}>;
|
|
20
|
+
//# sourceMappingURL=countryHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countryHandler.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/countryHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAG3C,eAAO,MAAM,aAAa;;CAEzB,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;EAA0B,CAAC;AAExD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE7D,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa;;;;;GA2B3E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CountryNotFoundError } from '../../errors.js';
|
|
3
|
+
export const CountrySchema = {
|
|
4
|
+
countryId: z.string().min(1).describe('The ID of the country to fetch'),
|
|
5
|
+
};
|
|
6
|
+
export const CountryZodSchema = z.object(CountrySchema);
|
|
7
|
+
export async function countryHandler(context, params) {
|
|
8
|
+
const { countryId } = params;
|
|
9
|
+
const { modules } = context;
|
|
10
|
+
try {
|
|
11
|
+
const country = await modules.countries.findCountry({ countryId });
|
|
12
|
+
if (!country)
|
|
13
|
+
throw new CountryNotFoundError({ countryId });
|
|
14
|
+
return {
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: 'text',
|
|
18
|
+
text: JSON.stringify({ country }),
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return {
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: 'text',
|
|
28
|
+
text: `Error retrieving country: ${error.message}`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=countryHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countryHandler.js","sourceRoot":"","sources":["../../../src/mcp/tools/countryHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gCAAgC,CAAC;CACxE,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AAIxD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAgB,EAAE,MAAqB;IAC1E,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QAEnE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,oBAAoB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QAE5D,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC;iBAClC;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,6BAA8B,KAAe,CAAC,OAAO,EAAE;iBAC9D;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Context } from '../../context.js';
|
|
3
|
+
export declare const CreateProductSchema: {
|
|
4
|
+
product: z.ZodObject<{
|
|
5
|
+
type: z.ZodEnum<["SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct", ...("SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct")[]]>;
|
|
6
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
tags?: string[];
|
|
9
|
+
type?: "SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct";
|
|
10
|
+
}, {
|
|
11
|
+
tags?: string[];
|
|
12
|
+
type?: "SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct";
|
|
13
|
+
}>;
|
|
14
|
+
texts: z.ZodArray<z.ZodObject<{
|
|
15
|
+
locale: z.ZodString;
|
|
16
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
17
|
+
title: z.ZodOptional<z.ZodString>;
|
|
18
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
19
|
+
description: z.ZodOptional<z.ZodString>;
|
|
20
|
+
vendor: z.ZodOptional<z.ZodString>;
|
|
21
|
+
brand: z.ZodOptional<z.ZodString>;
|
|
22
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
description?: string;
|
|
25
|
+
locale?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
subtitle?: string;
|
|
28
|
+
slug?: string;
|
|
29
|
+
brand?: string;
|
|
30
|
+
vendor?: string;
|
|
31
|
+
labels?: string[];
|
|
32
|
+
}, {
|
|
33
|
+
description?: string;
|
|
34
|
+
locale?: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
subtitle?: string;
|
|
37
|
+
slug?: string;
|
|
38
|
+
brand?: string;
|
|
39
|
+
vendor?: string;
|
|
40
|
+
labels?: string[];
|
|
41
|
+
}>, "atleastone">;
|
|
42
|
+
};
|
|
43
|
+
export declare const CreateProductZodSchema: z.ZodObject<{
|
|
44
|
+
product: z.ZodObject<{
|
|
45
|
+
type: z.ZodEnum<["SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct", ...("SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct")[]]>;
|
|
46
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
tags?: string[];
|
|
49
|
+
type?: "SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct";
|
|
50
|
+
}, {
|
|
51
|
+
tags?: string[];
|
|
52
|
+
type?: "SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct";
|
|
53
|
+
}>;
|
|
54
|
+
texts: z.ZodArray<z.ZodObject<{
|
|
55
|
+
locale: z.ZodString;
|
|
56
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
57
|
+
title: z.ZodOptional<z.ZodString>;
|
|
58
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
59
|
+
description: z.ZodOptional<z.ZodString>;
|
|
60
|
+
vendor: z.ZodOptional<z.ZodString>;
|
|
61
|
+
brand: z.ZodOptional<z.ZodString>;
|
|
62
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
63
|
+
}, "strip", z.ZodTypeAny, {
|
|
64
|
+
description?: string;
|
|
65
|
+
locale?: string;
|
|
66
|
+
title?: string;
|
|
67
|
+
subtitle?: string;
|
|
68
|
+
slug?: string;
|
|
69
|
+
brand?: string;
|
|
70
|
+
vendor?: string;
|
|
71
|
+
labels?: string[];
|
|
72
|
+
}, {
|
|
73
|
+
description?: string;
|
|
74
|
+
locale?: string;
|
|
75
|
+
title?: string;
|
|
76
|
+
subtitle?: string;
|
|
77
|
+
slug?: string;
|
|
78
|
+
brand?: string;
|
|
79
|
+
vendor?: string;
|
|
80
|
+
labels?: string[];
|
|
81
|
+
}>, "atleastone">;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
product?: {
|
|
84
|
+
tags?: string[];
|
|
85
|
+
type?: "SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct";
|
|
86
|
+
};
|
|
87
|
+
texts?: [{
|
|
88
|
+
description?: string;
|
|
89
|
+
locale?: string;
|
|
90
|
+
title?: string;
|
|
91
|
+
subtitle?: string;
|
|
92
|
+
slug?: string;
|
|
93
|
+
brand?: string;
|
|
94
|
+
vendor?: string;
|
|
95
|
+
labels?: string[];
|
|
96
|
+
}, ...{
|
|
97
|
+
description?: string;
|
|
98
|
+
locale?: string;
|
|
99
|
+
title?: string;
|
|
100
|
+
subtitle?: string;
|
|
101
|
+
slug?: string;
|
|
102
|
+
brand?: string;
|
|
103
|
+
vendor?: string;
|
|
104
|
+
labels?: string[];
|
|
105
|
+
}[]];
|
|
106
|
+
}, {
|
|
107
|
+
product?: {
|
|
108
|
+
tags?: string[];
|
|
109
|
+
type?: "SimpleProduct" | "ConfigurableProduct" | "BundleProduct" | "PlanProduct" | "TokenizedProduct";
|
|
110
|
+
};
|
|
111
|
+
texts?: [{
|
|
112
|
+
description?: string;
|
|
113
|
+
locale?: string;
|
|
114
|
+
title?: string;
|
|
115
|
+
subtitle?: string;
|
|
116
|
+
slug?: string;
|
|
117
|
+
brand?: string;
|
|
118
|
+
vendor?: string;
|
|
119
|
+
labels?: string[];
|
|
120
|
+
}, ...{
|
|
121
|
+
description?: string;
|
|
122
|
+
locale?: string;
|
|
123
|
+
title?: string;
|
|
124
|
+
subtitle?: string;
|
|
125
|
+
slug?: string;
|
|
126
|
+
brand?: string;
|
|
127
|
+
vendor?: string;
|
|
128
|
+
labels?: string[];
|
|
129
|
+
}[]];
|
|
130
|
+
}>;
|
|
131
|
+
export type CreateProductParams = z.infer<typeof CreateProductZodSchema>;
|
|
132
|
+
export declare function createProductHandler(context: Context, params: CreateProductParams): Promise<{
|
|
133
|
+
content: {
|
|
134
|
+
type: "text";
|
|
135
|
+
text: string;
|
|
136
|
+
}[];
|
|
137
|
+
}>;
|
|
138
|
+
//# sourceMappingURL=createProduct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createProduct.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/createProduct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAO3C,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyB/B,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAgC,CAAC;AAEpE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEzE,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB;;;;;GAmCvF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ProductTypes } from '@unchainedshop/core-products';
|
|
3
|
+
const productTypeKeys = Object.keys(ProductTypes);
|
|
4
|
+
export const CreateProductSchema = {
|
|
5
|
+
product: z.object({
|
|
6
|
+
type: z.enum(productTypeKeys).describe('Product type (e.g., "SIMPLE_PRODUCT")'),
|
|
7
|
+
tags: z.array(z.string().min(1).toLowerCase()).optional().describe('Tags (lowercased strings)'),
|
|
8
|
+
}),
|
|
9
|
+
texts: z
|
|
10
|
+
.array(z.object({
|
|
11
|
+
locale: z
|
|
12
|
+
.string()
|
|
13
|
+
.min(2)
|
|
14
|
+
.describe('Locale code like "en", "de" always use locales registered in the system languages, if language explicitly provided check if it exists'),
|
|
15
|
+
slug: z.string().optional().describe('URL slug'),
|
|
16
|
+
title: z.string().optional().describe('Product title'),
|
|
17
|
+
subtitle: z.string().optional().describe('Product subtitle'),
|
|
18
|
+
description: z.string().optional().describe('Markdown description'),
|
|
19
|
+
vendor: z.string().optional().describe('Vendor name'),
|
|
20
|
+
brand: z.string().optional().describe('Brand name'),
|
|
21
|
+
labels: z.array(z.string()).optional().describe('Labels or tags'),
|
|
22
|
+
}))
|
|
23
|
+
.nonempty()
|
|
24
|
+
.describe('Localized product text entries'),
|
|
25
|
+
};
|
|
26
|
+
export const CreateProductZodSchema = z.object(CreateProductSchema);
|
|
27
|
+
export async function createProductHandler(context, params) {
|
|
28
|
+
const { product, texts } = params;
|
|
29
|
+
try {
|
|
30
|
+
const newProduct = await context.modules.products.create(product);
|
|
31
|
+
let productTexts = texts;
|
|
32
|
+
if (texts) {
|
|
33
|
+
productTexts = await context.modules.products.texts.updateTexts(newProduct._id, texts);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
content: [
|
|
37
|
+
{
|
|
38
|
+
type: 'text',
|
|
39
|
+
text: JSON.stringify({
|
|
40
|
+
product: {
|
|
41
|
+
...newProduct,
|
|
42
|
+
texts: productTexts,
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `Error creating product: ${error.message}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=createProduct.js.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F;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Context } from '../../context.js';
|
|
3
|
+
export declare const CreateProductVariationSchema: {
|
|
4
|
+
productId: z.ZodString;
|
|
5
|
+
variation: z.ZodObject<{
|
|
6
|
+
key: z.ZodString;
|
|
7
|
+
type: z.ZodEnum<["COLOR" | "TEXT", ...("COLOR" | "TEXT")[]]>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
key?: string;
|
|
10
|
+
type?: "COLOR" | "TEXT";
|
|
11
|
+
}, {
|
|
12
|
+
key?: string;
|
|
13
|
+
type?: "COLOR" | "TEXT";
|
|
14
|
+
}>;
|
|
15
|
+
texts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
16
|
+
locale: z.ZodString;
|
|
17
|
+
title: z.ZodOptional<z.ZodString>;
|
|
18
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
locale?: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
subtitle?: string;
|
|
23
|
+
}, {
|
|
24
|
+
locale?: string;
|
|
25
|
+
title?: string;
|
|
26
|
+
subtitle?: string;
|
|
27
|
+
}>, "many">>;
|
|
28
|
+
};
|
|
29
|
+
export declare const CreateProductVariationZodSchema: z.ZodObject<{
|
|
30
|
+
productId: z.ZodString;
|
|
31
|
+
variation: z.ZodObject<{
|
|
32
|
+
key: z.ZodString;
|
|
33
|
+
type: z.ZodEnum<["COLOR" | "TEXT", ...("COLOR" | "TEXT")[]]>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
key?: string;
|
|
36
|
+
type?: "COLOR" | "TEXT";
|
|
37
|
+
}, {
|
|
38
|
+
key?: string;
|
|
39
|
+
type?: "COLOR" | "TEXT";
|
|
40
|
+
}>;
|
|
41
|
+
texts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
42
|
+
locale: z.ZodString;
|
|
43
|
+
title: z.ZodOptional<z.ZodString>;
|
|
44
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
locale?: string;
|
|
47
|
+
title?: string;
|
|
48
|
+
subtitle?: string;
|
|
49
|
+
}, {
|
|
50
|
+
locale?: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
subtitle?: string;
|
|
53
|
+
}>, "many">>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
productId?: string;
|
|
56
|
+
texts?: {
|
|
57
|
+
locale?: string;
|
|
58
|
+
title?: string;
|
|
59
|
+
subtitle?: string;
|
|
60
|
+
}[];
|
|
61
|
+
variation?: {
|
|
62
|
+
key?: string;
|
|
63
|
+
type?: "COLOR" | "TEXT";
|
|
64
|
+
};
|
|
65
|
+
}, {
|
|
66
|
+
productId?: string;
|
|
67
|
+
texts?: {
|
|
68
|
+
locale?: string;
|
|
69
|
+
title?: string;
|
|
70
|
+
subtitle?: string;
|
|
71
|
+
}[];
|
|
72
|
+
variation?: {
|
|
73
|
+
key?: string;
|
|
74
|
+
type?: "COLOR" | "TEXT";
|
|
75
|
+
};
|
|
76
|
+
}>;
|
|
77
|
+
export type CreateProductVariationParams = z.infer<typeof CreateProductVariationZodSchema>;
|
|
78
|
+
export declare function createProductVariationHandler(context: Context, params: CreateProductVariationParams): Promise<{
|
|
79
|
+
content: {
|
|
80
|
+
type: "text";
|
|
81
|
+
text: string;
|
|
82
|
+
}[];
|
|
83
|
+
}>;
|
|
84
|
+
//# sourceMappingURL=createProductVariationHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createProductVariationHandler.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/createProductVariationHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAU3C,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;CAoBxC,CAAC;AAEF,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAyC,CAAC;AACtF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAE3F,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,4BAA4B;;;;;GA8CrC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ProductTypes, ProductVariationType } from '@unchainedshop/core-products';
|
|
3
|
+
import { ProductNotFoundError, ProductWrongTypeError } from '../../errors.js';
|
|
4
|
+
import { getNormalizedProductDetails } from '../utils/getNormalizedProductDetails.js';
|
|
5
|
+
const productVariationTypeKeys = Object.keys(ProductVariationType);
|
|
6
|
+
export const CreateProductVariationSchema = {
|
|
7
|
+
productId: z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1)
|
|
10
|
+
.describe('Product ID for which to create the variation. it should only be CONFIGURABLE_PRODUCT type product id'),
|
|
11
|
+
variation: z.object({
|
|
12
|
+
key: z.string().min(1),
|
|
13
|
+
type: z.enum(productVariationTypeKeys).describe('Product variation types'),
|
|
14
|
+
}),
|
|
15
|
+
texts: z
|
|
16
|
+
.array(z.object({
|
|
17
|
+
locale: z.string().min(2),
|
|
18
|
+
title: z.string().optional(),
|
|
19
|
+
subtitle: z.string().optional(),
|
|
20
|
+
}))
|
|
21
|
+
.optional(),
|
|
22
|
+
};
|
|
23
|
+
export const CreateProductVariationZodSchema = z.object(CreateProductVariationSchema);
|
|
24
|
+
export async function createProductVariationHandler(context, params) {
|
|
25
|
+
const { productId, variation, texts } = params;
|
|
26
|
+
const { modules } = context;
|
|
27
|
+
try {
|
|
28
|
+
const product = await modules.products.findProduct({ productId });
|
|
29
|
+
if (!product)
|
|
30
|
+
throw new ProductNotFoundError({ productId });
|
|
31
|
+
if (product.type !== ProductTypes.ConfigurableProduct)
|
|
32
|
+
throw new ProductWrongTypeError({
|
|
33
|
+
productId,
|
|
34
|
+
received: product.type,
|
|
35
|
+
required: ProductTypes.ConfigurableProduct,
|
|
36
|
+
});
|
|
37
|
+
const newVariation = await modules.products.variations.create({
|
|
38
|
+
options: [],
|
|
39
|
+
productId,
|
|
40
|
+
...variation,
|
|
41
|
+
});
|
|
42
|
+
if (texts) {
|
|
43
|
+
await modules.products.variations.texts.updateVariationTexts(newVariation._id, texts);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: 'text',
|
|
49
|
+
text: JSON.stringify({
|
|
50
|
+
product: await getNormalizedProductDetails(productId, context),
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: 'text',
|
|
61
|
+
text: `Error creating product variation: ${error.message}`,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=createProductVariationHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createProductVariationHandler.js","sourceRoot":"","sources":["../../../src/mcp/tools/createProductVariationHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAEtF,MAAM,wBAAwB,GAAG,M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