@unchainedshop/api 4.0.0-rc.2 → 4.0.0-rc.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.
Files changed (417) hide show
  1. package/lib/api-index.d.ts.map +1 -1
  2. package/lib/api-index.js +4 -1
  3. package/lib/api-index.js.map +1 -1
  4. package/lib/errors.d.ts +1 -1
  5. package/lib/errors.d.ts.map +1 -1
  6. package/lib/errors.js +1 -1
  7. package/lib/errors.js.map +1 -1
  8. package/lib/express/chatRouter.d.ts +3 -0
  9. package/lib/express/chatRouter.d.ts.map +1 -0
  10. package/lib/express/chatRouter.js +86 -0
  11. package/lib/express/chatRouter.js.map +1 -0
  12. package/lib/express/createApolloMiddleware.d.ts +4 -0
  13. package/lib/express/createApolloMiddleware.d.ts.map +1 -0
  14. package/lib/express/createApolloMiddleware.js +36 -0
  15. package/lib/express/createApolloMiddleware.js.map +1 -0
  16. package/lib/express/createBulkImportMiddleware copy.d.ts +6 -0
  17. package/lib/express/createBulkImportMiddleware copy.d.ts.map +1 -0
  18. package/lib/express/createBulkImportMiddleware copy.js +49 -0
  19. package/lib/express/createBulkImportMiddleware copy.js.map +1 -0
  20. package/lib/express/createMCPMiddleware.d.ts +2 -6
  21. package/lib/express/createMCPMiddleware.d.ts.map +1 -1
  22. package/lib/express/createMCPMiddleware.js +73 -42
  23. package/lib/express/createMCPMiddleware.js.map +1 -1
  24. package/lib/express/createSingleSignOnMiddleware.d.ts +5 -0
  25. package/lib/express/createSingleSignOnMiddleware.d.ts.map +1 -0
  26. package/lib/express/createSingleSignOnMiddleware.js +71 -0
  27. package/lib/express/createSingleSignOnMiddleware.js.map +1 -0
  28. package/lib/express/createTempUploadMiddleware.d.ts +7 -0
  29. package/lib/express/createTempUploadMiddleware.d.ts.map +1 -0
  30. package/lib/express/createTempUploadMiddleware.js +48 -0
  31. package/lib/express/createTempUploadMiddleware.js.map +1 -0
  32. package/lib/express/index.d.ts.map +1 -1
  33. package/lib/express/index.js +17 -4
  34. package/lib/express/index.js.map +1 -1
  35. package/lib/express/setupMCPChatHandler.d.ts +3 -0
  36. package/lib/express/setupMCPChatHandler.d.ts.map +1 -0
  37. package/lib/express/setupMCPChatHandler.js +57 -0
  38. package/lib/express/setupMCPChatHandler.js.map +1 -0
  39. package/lib/fastify/index.d.ts.map +1 -1
  40. package/lib/fastify/index.js +24 -2
  41. package/lib/fastify/index.js.map +1 -1
  42. package/lib/fastify/mcpChatHandler.d.ts +3 -0
  43. package/lib/fastify/mcpChatHandler.d.ts.map +1 -0
  44. package/lib/fastify/mcpChatHandler.js +60 -0
  45. package/lib/fastify/mcpChatHandler.js.map +1 -0
  46. package/lib/fastify/mcpHandler copy.d.ts +4 -0
  47. package/lib/fastify/mcpHandler copy.d.ts.map +1 -0
  48. package/lib/fastify/mcpHandler copy.js +72 -0
  49. package/lib/fastify/mcpHandler copy.js.map +1 -0
  50. package/lib/fastify/mcpHandler.d.ts +3 -7
  51. package/lib/fastify/mcpHandler.d.ts.map +1 -1
  52. package/lib/fastify/mcpHandler.js +71 -39
  53. package/lib/fastify/mcpHandler.js.map +1 -1
  54. package/lib/fastify/tempUploadHandler.d.ts +4 -0
  55. package/lib/fastify/tempUploadHandler.d.ts.map +1 -0
  56. package/lib/fastify/tempUploadHandler.js +41 -0
  57. package/lib/fastify/tempUploadHandler.js.map +1 -0
  58. package/lib/hashPassword.d.ts +2 -0
  59. package/lib/hashPassword.d.ts.map +1 -0
  60. package/lib/hashPassword.js +5 -0
  61. package/lib/hashPassword.js.map +1 -0
  62. package/lib/loaders/assortmentMediaTextLoader.js +1 -1
  63. package/lib/loaders/assortmentMediaTextLoader.js.map +1 -1
  64. package/lib/loaders/assortmentTextLoader.js +1 -1
  65. package/lib/loaders/assortmentTextLoader.js.map +1 -1
  66. package/lib/loaders/buildLocaleMap.d.ts +6 -0
  67. package/lib/loaders/buildLocaleMap.d.ts.map +1 -0
  68. package/lib/loaders/buildLocaleMap.js +67 -0
  69. package/lib/loaders/buildLocaleMap.js.map +1 -0
  70. package/lib/loaders/buildTextMap.d.ts +1 -1
  71. package/lib/loaders/buildTextMap.d.ts.map +1 -1
  72. package/lib/loaders/buildTextMap.js +19 -6
  73. package/lib/loaders/buildTextMap.js.map +1 -1
  74. package/lib/loaders/filterTextLoader.js +1 -1
  75. package/lib/loaders/filterTextLoader.js.map +1 -1
  76. package/lib/loaders/productMediaTextLoader.d.ts.map +1 -1
  77. package/lib/loaders/productMediaTextLoader.js +1 -1
  78. package/lib/loaders/productMediaTextLoader.js.map +1 -1
  79. package/lib/loaders/productTextLoader.d.ts.map +1 -1
  80. package/lib/loaders/productTextLoader.js +1 -1
  81. package/lib/loaders/productTextLoader.js.map +1 -1
  82. package/lib/mcp/index.d.ts +3 -94
  83. package/lib/mcp/index.d.ts.map +1 -1
  84. package/lib/mcp/index.js +45 -135
  85. package/lib/mcp/index.js.map +1 -1
  86. package/lib/mcp/tools/addProductAssignmentHandler.d.ts +52 -0
  87. package/lib/mcp/tools/addProductAssignmentHandler.d.ts.map +1 -0
  88. package/lib/mcp/tools/addProductAssignmentHandler.js +97 -0
  89. package/lib/mcp/tools/addProductAssignmentHandler.js.map +1 -0
  90. package/lib/mcp/tools/addProductMediaUploadHandler.d.ts +28 -0
  91. package/lib/mcp/tools/addProductMediaUploadHandler.d.ts.map +1 -0
  92. package/lib/mcp/tools/addProductMediaUploadHandler.js +62 -0
  93. package/lib/mcp/tools/addProductMediaUploadHandler.js.map +1 -0
  94. package/lib/mcp/tools/countriesHandler.d.ts +60 -0
  95. package/lib/mcp/tools/countriesHandler.d.ts.map +1 -0
  96. package/lib/mcp/tools/countriesHandler.js +48 -0
  97. package/lib/mcp/tools/countriesHandler.js.map +1 -0
  98. package/lib/mcp/tools/countryHandler.d.ts +20 -0
  99. package/lib/mcp/tools/countryHandler.d.ts.map +1 -0
  100. package/lib/mcp/tools/countryHandler.js +34 -0
  101. package/lib/mcp/tools/countryHandler.js.map +1 -0
  102. package/lib/mcp/tools/createLanguageHandler.d.ts +36 -0
  103. package/lib/mcp/tools/createLanguageHandler.d.ts.map +1 -0
  104. package/lib/mcp/tools/createLanguageHandler.js +39 -0
  105. package/lib/mcp/tools/createLanguageHandler.js.map +1 -0
  106. package/lib/mcp/tools/createProduct.d.ts +138 -0
  107. package/lib/mcp/tools/createProduct.d.ts.map +1 -0
  108. package/lib/mcp/tools/createProduct.js +60 -0
  109. package/lib/mcp/tools/createProduct.js.map +1 -0
  110. package/lib/mcp/tools/createProductVariationHandler.d.ts +84 -0
  111. package/lib/mcp/tools/createProductVariationHandler.d.ts.map +1 -0
  112. package/lib/mcp/tools/createProductVariationHandler.js +73 -0
  113. package/lib/mcp/tools/createProductVariationHandler.js.map +1 -0
  114. package/lib/mcp/tools/createProductVariationOptionHandler.d.ts +60 -0
  115. package/lib/mcp/tools/createProductVariationOptionHandler.d.ts.map +1 -0
  116. package/lib/mcp/tools/createProductVariationOptionHandler.js +59 -0
  117. package/lib/mcp/tools/createProductVariationOptionHandler.js.map +1 -0
  118. package/lib/mcp/tools/currenciesHandler.d.ts +60 -0
  119. package/lib/mcp/tools/currenciesHandler.d.ts.map +1 -0
  120. package/lib/mcp/tools/currenciesHandler.js +50 -0
  121. package/lib/mcp/tools/currenciesHandler.js.map +1 -0
  122. package/lib/mcp/tools/currencyHandler.d.ts +20 -0
  123. package/lib/mcp/tools/currencyHandler.d.ts.map +1 -0
  124. package/lib/mcp/tools/currencyHandler.js +34 -0
  125. package/lib/mcp/tools/currencyHandler.js.map +1 -0
  126. package/lib/mcp/tools/getProduct.d.ts +48 -0
  127. package/lib/mcp/tools/getProduct.d.ts.map +1 -0
  128. package/lib/mcp/tools/getProduct.js +61 -0
  129. package/lib/mcp/tools/getProduct.js.map +1 -0
  130. package/lib/mcp/tools/index.d.ts +39 -0
  131. package/lib/mcp/tools/index.d.ts.map +1 -0
  132. package/lib/mcp/tools/index.js +39 -0
  133. package/lib/mcp/tools/index.js.map +1 -0
  134. package/lib/mcp/tools/languageHandler.d.ts +20 -0
  135. package/lib/mcp/tools/languageHandler.d.ts.map +1 -0
  136. package/lib/mcp/tools/languageHandler.js +31 -0
  137. package/lib/mcp/tools/languageHandler.js.map +1 -0
  138. package/lib/mcp/tools/languagesHandler.d.ts +60 -0
  139. package/lib/mcp/tools/languagesHandler.d.ts.map +1 -0
  140. package/lib/mcp/tools/languagesHandler.js +42 -0
  141. package/lib/mcp/tools/languagesHandler.js.map +1 -0
  142. package/lib/mcp/tools/listProducts.d.ts +112 -0
  143. package/lib/mcp/tools/listProducts.d.ts.map +1 -0
  144. package/lib/mcp/tools/listProducts.js +110 -0
  145. package/lib/mcp/tools/listProducts.js.map +1 -0
  146. package/lib/mcp/tools/normalizeMediaUrl.d.ts +3 -0
  147. package/lib/mcp/tools/normalizeMediaUrl.d.ts.map +1 -0
  148. package/lib/mcp/tools/normalizeMediaUrl.js +21 -0
  149. package/lib/mcp/tools/normalizeMediaUrl.js.map +1 -0
  150. package/lib/mcp/tools/productReviewsCountHandler.d.ts +20 -0
  151. package/lib/mcp/tools/productReviewsCountHandler.d.ts.map +1 -0
  152. package/lib/mcp/tools/productReviewsCountHandler.js +30 -0
  153. package/lib/mcp/tools/productReviewsCountHandler.js.map +1 -0
  154. package/lib/mcp/tools/productReviewsHandler.d.ts +56 -0
  155. package/lib/mcp/tools/productReviewsHandler.d.ts.map +1 -0
  156. package/lib/mcp/tools/productReviewsHandler.js +45 -0
  157. package/lib/mcp/tools/productReviewsHandler.js.map +1 -0
  158. package/lib/mcp/tools/productsCountHandler.d.ts +32 -0
  159. package/lib/mcp/tools/productsCountHandler.d.ts.map +1 -0
  160. package/lib/mcp/tools/productsCountHandler.js +33 -0
  161. package/lib/mcp/tools/productsCountHandler.js.map +1 -0
  162. package/lib/mcp/tools/publishProduct.d.ts +20 -0
  163. package/lib/mcp/tools/publishProduct.d.ts.map +1 -0
  164. package/lib/mcp/tools/publishProduct.js +40 -0
  165. package/lib/mcp/tools/publishProduct.js.map +1 -0
  166. package/lib/mcp/tools/removeLanguageHandler.d.ts +20 -0
  167. package/lib/mcp/tools/removeLanguageHandler.d.ts.map +1 -0
  168. package/lib/mcp/tools/removeLanguageHandler.js +35 -0
  169. package/lib/mcp/tools/removeLanguageHandler.js.map +1 -0
  170. package/lib/mcp/tools/removeProduct.d.ts +20 -0
  171. package/lib/mcp/tools/removeProduct.d.ts.map +1 -0
  172. package/lib/mcp/tools/removeProduct.js +34 -0
  173. package/lib/mcp/tools/removeProduct.js.map +1 -0
  174. package/lib/mcp/tools/removeProductAssignmentHandler.d.ts +48 -0
  175. package/lib/mcp/tools/removeProductAssignmentHandler.d.ts.map +1 -0
  176. package/lib/mcp/tools/removeProductAssignmentHandler.js +51 -0
  177. package/lib/mcp/tools/removeProductAssignmentHandler.js.map +1 -0
  178. package/lib/mcp/tools/removeProductHandler.d.ts +20 -0
  179. package/lib/mcp/tools/removeProductHandler.d.ts.map +1 -0
  180. package/lib/mcp/tools/removeProductHandler.js +34 -0
  181. package/lib/mcp/tools/removeProductHandler.js.map +1 -0
  182. package/lib/mcp/tools/removeProductMediaHandler.d.ts +20 -0
  183. package/lib/mcp/tools/removeProductMediaHandler.d.ts.map +1 -0
  184. package/lib/mcp/tools/removeProductMediaHandler.js +42 -0
  185. package/lib/mcp/tools/removeProductMediaHandler.js.map +1 -0
  186. package/lib/mcp/tools/removeProductVariationHandler.d.ts +20 -0
  187. package/lib/mcp/tools/removeProductVariationHandler.d.ts.map +1 -0
  188. package/lib/mcp/tools/removeProductVariationHandler.js +43 -0
  189. package/lib/mcp/tools/removeProductVariationHandler.js.map +1 -0
  190. package/lib/mcp/tools/removeProductVariationOptionHandler.d.ts +24 -0
  191. package/lib/mcp/tools/removeProductVariationOptionHandler.d.ts.map +1 -0
  192. package/lib/mcp/tools/removeProductVariationOptionHandler.js +47 -0
  193. package/lib/mcp/tools/removeProductVariationOptionHandler.js.map +1 -0
  194. package/lib/mcp/tools/reorderProductMediaHandler.d.ts +44 -0
  195. package/lib/mcp/tools/reorderProductMediaHandler.d.ts.map +1 -0
  196. package/lib/mcp/tools/reorderProductMediaHandler.js +39 -0
  197. package/lib/mcp/tools/reorderProductMediaHandler.js.map +1 -0
  198. package/lib/mcp/tools/unPublishProduct.d.ts +20 -0
  199. package/lib/mcp/tools/unPublishProduct.d.ts.map +1 -0
  200. package/lib/mcp/tools/unPublishProduct.js +40 -0
  201. package/lib/mcp/tools/unPublishProduct.js.map +1 -0
  202. package/lib/mcp/tools/updateLanguageHandler.d.ts +48 -0
  203. package/lib/mcp/tools/updateLanguageHandler.d.ts.map +1 -0
  204. package/lib/mcp/tools/updateLanguageHandler.js +40 -0
  205. package/lib/mcp/tools/updateLanguageHandler.js.map +1 -0
  206. package/lib/mcp/tools/updateProduct.d.ts +56 -0
  207. package/lib/mcp/tools/updateProduct.d.ts.map +1 -0
  208. package/lib/mcp/tools/updateProduct.js +44 -0
  209. package/lib/mcp/tools/updateProduct.js.map +1 -0
  210. package/lib/mcp/tools/updateProductCommerceHandler.d.ts +166 -0
  211. package/lib/mcp/tools/updateProductCommerceHandler.d.ts.map +1 -0
  212. package/lib/mcp/tools/updateProductCommerceHandler.js +64 -0
  213. package/lib/mcp/tools/updateProductCommerceHandler.js.map +1 -0
  214. package/lib/mcp/tools/updateProductMediaTextsHandler.d.ts +56 -0
  215. package/lib/mcp/tools/updateProductMediaTextsHandler.d.ts.map +1 -0
  216. package/lib/mcp/tools/updateProductMediaTextsHandler.js +45 -0
  217. package/lib/mcp/tools/updateProductMediaTextsHandler.js.map +1 -0
  218. package/lib/mcp/tools/updateProductPlanHandler.d.ts +72 -0
  219. package/lib/mcp/tools/updateProductPlanHandler.d.ts.map +1 -0
  220. package/lib/mcp/tools/updateProductPlanHandler.js +51 -0
  221. package/lib/mcp/tools/updateProductPlanHandler.js.map +1 -0
  222. package/lib/mcp/tools/updateProductSupplyHandler.d.ts +64 -0
  223. package/lib/mcp/tools/updateProductSupplyHandler.d.ts.map +1 -0
  224. package/lib/mcp/tools/updateProductSupplyHandler.js +52 -0
  225. package/lib/mcp/tools/updateProductSupplyHandler.js.map +1 -0
  226. package/lib/mcp/tools/updateProductTextsHandler.d.ts +114 -0
  227. package/lib/mcp/tools/updateProductTextsHandler.d.ts.map +1 -0
  228. package/lib/mcp/tools/updateProductTextsHandler.js +50 -0
  229. package/lib/mcp/tools/updateProductTextsHandler.js.map +1 -0
  230. package/lib/mcp/tools/updateProductTokenizationHandler.d.ts +72 -0
  231. package/lib/mcp/tools/updateProductTokenizationHandler.d.ts.map +1 -0
  232. package/lib/mcp/tools/updateProductTokenizationHandler.js +49 -0
  233. package/lib/mcp/tools/updateProductTokenizationHandler.js.map +1 -0
  234. package/lib/mcp/tools/updateProductWarehousingHandler.d.ts +48 -0
  235. package/lib/mcp/tools/updateProductWarehousingHandler.d.ts.map +1 -0
  236. package/lib/mcp/tools/updateProductWarehousingHandler.js +45 -0
  237. package/lib/mcp/tools/updateProductWarehousingHandler.js.map +1 -0
  238. package/lib/mcp/utils/getNormalizedProductDetails.d.ts +26 -0
  239. package/lib/mcp/utils/getNormalizedProductDetails.d.ts.map +1 -0
  240. package/lib/mcp/utils/getNormalizedProductDetails.js +38 -0
  241. package/lib/mcp/utils/getNormalizedProductDetails.js.map +1 -0
  242. package/lib/mcp/utils/normalizeMediaUrl.d.ts +3 -0
  243. package/lib/mcp/utils/normalizeMediaUrl.d.ts.map +1 -0
  244. package/lib/mcp/utils/normalizeMediaUrl.js +21 -0
  245. package/lib/mcp/utils/normalizeMediaUrl.js.map +1 -0
  246. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts +3 -0
  247. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.d.ts.map +1 -0
  248. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js +6 -0
  249. package/lib/resolvers/mutations/accounts/buildSecretTOTPAuthURL.js.map +1 -0
  250. package/lib/resolvers/mutations/accounts/disableTOTP.d.ts +6 -0
  251. package/lib/resolvers/mutations/accounts/disableTOTP.d.ts.map +1 -0
  252. package/lib/resolvers/mutations/accounts/disableTOTP.js +27 -0
  253. package/lib/resolvers/mutations/accounts/disableTOTP.js.map +1 -0
  254. package/lib/resolvers/mutations/accounts/enableTOTP.d.ts +6 -0
  255. package/lib/resolvers/mutations/accounts/enableTOTP.d.ts.map +1 -0
  256. package/lib/resolvers/mutations/accounts/enableTOTP.js +20 -0
  257. package/lib/resolvers/mutations/accounts/enableTOTP.js.map +1 -0
  258. package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts +7 -0
  259. package/lib/resolvers/mutations/accounts/linkOAuthAccount.d.ts.map +1 -0
  260. package/lib/resolvers/mutations/accounts/linkOAuthAccount.js +30 -0
  261. package/lib/resolvers/mutations/accounts/linkOAuthAccount.js.map +1 -0
  262. package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts +8 -0
  263. package/lib/resolvers/mutations/accounts/loginWithOAuth.d.ts.map +1 -0
  264. package/lib/resolvers/mutations/accounts/loginWithOAuth.js +25 -0
  265. package/lib/resolvers/mutations/accounts/loginWithOAuth.js.map +1 -0
  266. package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts +5 -0
  267. package/lib/resolvers/mutations/accounts/logoutAllSessions.d.ts.map +1 -0
  268. package/lib/resolvers/mutations/accounts/logoutAllSessions.js +20 -0
  269. package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +1 -0
  270. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts +6 -0
  271. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.d.ts.map +1 -0
  272. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js +13 -0
  273. package/lib/resolvers/mutations/accounts/unlinkOAuthAccount.js.map +1 -0
  274. package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts +6 -0
  275. package/lib/resolvers/mutations/assortments/addAssortmentMedia.d.ts.map +1 -0
  276. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +18 -0
  277. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +1 -0
  278. package/lib/resolvers/mutations/products/addProductAssignment.d.ts.map +1 -1
  279. package/lib/resolvers/mutations/products/addProductAssignment.js +3 -1
  280. package/lib/resolvers/mutations/products/addProductAssignment.js.map +1 -1
  281. package/lib/resolvers/mutations/products/addProductMedia.d.ts +6 -0
  282. package/lib/resolvers/mutations/products/addProductMedia.d.ts.map +1 -0
  283. package/lib/resolvers/mutations/products/addProductMedia.js +18 -0
  284. package/lib/resolvers/mutations/products/addProductMedia.js.map +1 -0
  285. package/lib/resolvers/mutations/users/updateUserAvatar.d.ts +6 -0
  286. package/lib/resolvers/mutations/users/updateUserAvatar.d.ts.map +1 -0
  287. package/lib/resolvers/mutations/users/updateUserAvatar.js +22 -0
  288. package/lib/resolvers/mutations/users/updateUserAvatar.js.map +1 -0
  289. package/lib/resolvers/mutations/utils/getOrderCart.d.ts +7 -0
  290. package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +1 -0
  291. package/lib/resolvers/mutations/utils/getOrderCart.js +13 -0
  292. package/lib/resolvers/mutations/utils/getOrderCart.js.map +1 -0
  293. package/lib/resolvers/queries/filters/searchAssortments.d.ts.map +1 -1
  294. package/lib/resolvers/queries/filters/searchAssortments.js +0 -5
  295. package/lib/resolvers/queries/filters/searchAssortments.js.map +1 -1
  296. package/lib/resolvers/queries/filters/searchProducts.d.ts.map +1 -1
  297. package/lib/resolvers/queries/filters/searchProducts.js +2 -7
  298. package/lib/resolvers/queries/filters/searchProducts.js.map +1 -1
  299. package/lib/resolvers/type/dispatch-types.d.ts +15 -0
  300. package/lib/resolvers/type/dispatch-types.d.ts.map +1 -0
  301. package/lib/resolvers/type/dispatch-types.js +16 -0
  302. package/lib/resolvers/type/dispatch-types.js.map +1 -0
  303. package/lib/resolvers/type/oauth-account.d.ts +6 -0
  304. package/lib/resolvers/type/oauth-account.d.ts.map +1 -0
  305. package/lib/resolvers/type/oauth-account.js +7 -0
  306. package/lib/resolvers/type/oauth-account.js.map +1 -0
  307. package/lib/resolvers/type/oauth-provider.d.ts +6 -0
  308. package/lib/resolvers/type/oauth-provider.d.ts.map +1 -0
  309. package/lib/resolvers/type/oauth-provider.js +6 -0
  310. package/lib/resolvers/type/oauth-provider.js.map +1 -0
  311. package/lib/resolvers/type/stock-types.d.ts +14 -0
  312. package/lib/resolvers/type/stock-types.d.ts.map +1 -0
  313. package/lib/resolvers/type/stock-types.js +15 -0
  314. package/lib/resolvers/type/stock-types.js.map +1 -0
  315. package/lib/roles/all.d.ts.map +1 -1
  316. package/lib/roles/all.js +1 -0
  317. package/lib/roles/all.js.map +1 -1
  318. package/lib/roles/index.d.ts.map +1 -1
  319. package/lib/roles/index.js +1 -0
  320. package/lib/roles/index.js.map +1 -1
  321. package/lib/roles/loggedIn.d.ts.map +1 -1
  322. package/lib/roles/loggedIn.js +1 -0
  323. package/lib/roles/loggedIn.js.map +1 -1
  324. package/lib/user-context.d.ts +7 -0
  325. package/lib/user-context.d.ts.map +1 -0
  326. package/lib/user-context.js +76 -0
  327. package/lib/user-context.js.map +1 -0
  328. package/package.json +34 -18
  329. package/src/api-index.ts +4 -1
  330. package/src/errors.ts +5 -4
  331. package/src/express/createMCPMiddleware.ts +91 -0
  332. package/src/express/createTempUploadMiddleware.ts +60 -0
  333. package/src/express/index.ts +35 -6
  334. package/src/fastify/index.ts +32 -2
  335. package/src/fastify/mcpHandler.ts +97 -0
  336. package/src/fastify/tempUploadHandler.ts +52 -0
  337. package/src/loaders/assortmentMediaTextLoader.ts +1 -1
  338. package/src/loaders/assortmentTextLoader.ts +1 -1
  339. package/src/loaders/buildLocaleMap.test.ts +65 -0
  340. package/src/loaders/buildLocaleMap.ts +73 -0
  341. package/src/loaders/buildTextMap.test.ts +54 -0
  342. package/src/loaders/buildTextMap.ts +25 -6
  343. package/src/loaders/filterTextLoader.ts +1 -1
  344. package/src/loaders/productMediaTextLoader.ts +1 -1
  345. package/src/loaders/productTextLoader.ts +1 -1
  346. package/src/mcp/README.md +25 -0
  347. package/src/mcp/index.ts +313 -0
  348. package/src/mcp/tools/addProductAssignmentHandler.ts +118 -0
  349. package/src/mcp/tools/addProductMediaUploadHandler.ts +79 -0
  350. package/src/mcp/tools/countriesHandler.ts +60 -0
  351. package/src/mcp/tools/countryHandler.ts +40 -0
  352. package/src/mcp/tools/createLanguageHandler.ts +46 -0
  353. package/src/mcp/tools/createProduct.ts +75 -0
  354. package/src/mcp/tools/createProductVariationHandler.ts +93 -0
  355. package/src/mcp/tools/createProductVariationOptionHandler.ts +73 -0
  356. package/src/mcp/tools/currenciesHandler.ts +63 -0
  357. package/src/mcp/tools/currencyHandler.ts +40 -0
  358. package/src/mcp/tools/getProduct.ts +74 -0
  359. package/src/mcp/tools/index.ts +39 -0
  360. package/src/mcp/tools/languageHandler.ts +37 -0
  361. package/src/mcp/tools/languagesHandler.ts +54 -0
  362. package/src/mcp/tools/listProducts.ts +148 -0
  363. package/src/mcp/tools/productReviewsCountHandler.ts +36 -0
  364. package/src/mcp/tools/productReviewsHandler.ts +54 -0
  365. package/src/mcp/tools/productsCountHandler.ts +38 -0
  366. package/src/mcp/tools/publishProduct.ts +45 -0
  367. package/src/mcp/tools/removeLanguageHandler.ts +42 -0
  368. package/src/mcp/tools/removeProductAssignmentHandler.ts +61 -0
  369. package/src/mcp/tools/removeProductHandler.ts +40 -0
  370. package/src/mcp/tools/removeProductMediaHandler.ts +49 -0
  371. package/src/mcp/tools/removeProductVariationHandler.ts +51 -0
  372. package/src/mcp/tools/removeProductVariationOptionHandler.ts +58 -0
  373. package/src/mcp/tools/reorderProductMediaHandler.ts +48 -0
  374. package/src/mcp/tools/unPublishProduct.ts +46 -0
  375. package/src/mcp/tools/updateLanguageHandler.ts +47 -0
  376. package/src/mcp/tools/updateProduct.ts +51 -0
  377. package/src/mcp/tools/updateProductCommerceHandler.ts +79 -0
  378. package/src/mcp/tools/updateProductMediaTextsHandler.ts +56 -0
  379. package/src/mcp/tools/updateProductPlanHandler.ts +58 -0
  380. package/src/mcp/tools/updateProductSupplyHandler.ts +59 -0
  381. package/src/mcp/tools/updateProductTextsHandler.ts +59 -0
  382. package/src/mcp/tools/updateProductTokenizationHandler.ts +58 -0
  383. package/src/mcp/tools/updateProductWarehousingHandler.ts +54 -0
  384. package/src/mcp/utils/getNormalizedProductDetails.ts +42 -0
  385. package/src/mcp/utils/normalizeMediaUrl.ts +26 -0
  386. package/src/resolvers/mutations/products/addProductAssignment.ts +3 -0
  387. package/src/resolvers/queries/filters/searchAssortments.ts +0 -5
  388. package/src/resolvers/queries/filters/searchProducts.ts +2 -7
  389. package/src/roles/all.ts +1 -0
  390. package/src/roles/index.ts +1 -0
  391. package/src/roles/loggedIn.ts +1 -0
  392. package/lib/express/mcpHandler.d.ts.map +0 -1
  393. package/lib/express/mcpHandler.js +0 -68
  394. package/lib/express/mcpHandler.js.map +0 -1
  395. package/lib/fastify/index copy.d.ts.map +0 -1
  396. package/lib/fastify/index copy.js +0 -157
  397. package/lib/fastify/index copy.js.map +0 -1
  398. package/lib/mcp/server.d.ts +0 -4
  399. package/lib/mcp/server.d.ts.map +0 -1
  400. package/lib/mcp/server.js +0 -60
  401. package/lib/mcp/server.js.map +0 -1
  402. package/lib/mcp/types.d.ts +0 -28
  403. package/lib/mcp/types.d.ts.map +0 -1
  404. package/lib/mcp/types.js +0 -2
  405. package/lib/mcp/types.js.map +0 -1
  406. package/lib/middleware/accountLockout.d.ts.map +0 -1
  407. package/lib/middleware/accountLockout.js +0 -84
  408. package/lib/middleware/accountLockout.js.map +0 -1
  409. package/lib/middleware/rateLimiter.d.ts.map +0 -1
  410. package/lib/middleware/rateLimiter.js +0 -91
  411. package/lib/middleware/rateLimiter.js.map +0 -1
  412. package/lib/plugins/inputValidation.d.ts.map +0 -1
  413. package/lib/plugins/inputValidation.js +0 -95
  414. package/lib/plugins/inputValidation.js.map +0 -1
  415. package/lib/utils/inputValidation.d.ts.map +0 -1
  416. package/lib/utils/inputValidation.js +0 -51
  417. package/lib/utils/inputValidation.js.map +0 -1
@@ -0,0 +1,25 @@
1
+ # MCP Server
2
+
3
+ This directory contains the Model Context Protocol (MCP) server implementation for Unchained Commerce.
4
+
5
+ ## Structure
6
+
7
+ ```
8
+ mcp/
9
+ ├── index.ts # Main MCP server setup
10
+ ├── types.ts # Shared type definitions
11
+ ├── tools/ # Individual tool implementations
12
+ │ ├── index.ts # Re-exports for all tools
13
+ │ └── listProducts.ts # List products tool
14
+ └── utils/ # Shared utilities
15
+ └── html.ts # HTML generation utilities
16
+ ```
17
+
18
+ ## Adding New Tools
19
+
20
+ To add a new tool:
21
+
22
+ 1. Create a new file in the `tools/` directory
23
+ 2. Export the schema and handler from the file
24
+ 3. Add the exports to `tools/index.ts`
25
+ 4. Register the tool in the main `index.ts` file
@@ -0,0 +1,313 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { Context } from '../context.js';
3
+ import {
4
+ listProductsHandler,
5
+ ListProductsSchema,
6
+ getProductHandler,
7
+ GetProductSchema,
8
+ createProductHandler,
9
+ CreateProductSchema,
10
+ RemoveProductSchema,
11
+ removeProductHandler,
12
+ PublishProductSchema,
13
+ publishProductHandler,
14
+ UnpublishProductSchema,
15
+ unpublishProductHandler,
16
+ UpdateProductSchema,
17
+ updateProductHandler,
18
+ UpdateProductTextsSchema,
19
+ updateProductTextsHandler,
20
+ UpdateProductCommerceSchema,
21
+ updateProductCommerceHandler,
22
+ ListCurrenciesSchema,
23
+ currenciesHandler,
24
+ CurrencySchema,
25
+ currencyHandler,
26
+ ListCountriesSchema,
27
+ countriesHandler,
28
+ CountrySchema,
29
+ countryHandler,
30
+ ListLanguagesSchema,
31
+ languagesHandler,
32
+ LanguageSchema,
33
+ languageHandler,
34
+ UpdateProductSupplySchema,
35
+ updateProductSupplyHandler,
36
+ UpdateProductPlanSchema,
37
+ updateProductPlanHandler,
38
+ UpdateProductTokenizationSchema,
39
+ updateProductTokenizationHandler,
40
+ ProductsCountSchema,
41
+ productsCountHandler,
42
+ CreateProductVariationSchema,
43
+ createProductVariationHandler,
44
+ RemoveProductVariationSchema,
45
+ removeProductVariationHandler,
46
+ AssignProductVariationSchema,
47
+ addProductAssignmentHandler,
48
+ CreateProductVariationOptionSchema,
49
+ createProductVariationOptionHandler,
50
+ removeProductAssignmentHandler,
51
+ RemoveProductVariationOptionSchema,
52
+ removeProductVariationOptionHandler,
53
+ RemoveProductAssignmentSchema,
54
+ CreateLanguageSchema,
55
+ createLanguageHandler,
56
+ UpdateLanguageSchema,
57
+ updateLanguageHandler,
58
+ RemoveLanguageSchema,
59
+ removeLanguageHandler,
60
+ AddProductMediaUploadSchema,
61
+ addProductMediaUploadHandler,
62
+ RemoveProductMediaSchema,
63
+ removeProductMediaHandler,
64
+ UpdateProductMediaTextsSchema,
65
+ updateProductMediaTextsHandler,
66
+ ReorderProductMediaSchema,
67
+ reorderProductMediaHandler,
68
+ ProductReviewsCountSchema,
69
+ productReviewsCountHandler,
70
+ ProductReviewsSchema,
71
+ productReviewsHandler,
72
+ } from './tools/index.js';
73
+
74
+ export default function createMcpServer(context: Context, roles) {
75
+ const server = new McpServer({
76
+ name: 'Unchained MCP Server',
77
+ version: '1.0.0',
78
+ });
79
+
80
+ if (!roles?.includes('admin')) {
81
+ return server;
82
+ }
83
+
84
+ server.tool(
85
+ 'list_products',
86
+ 'Search and list products with comprehensive filtering and pagination support',
87
+ ListProductsSchema,
88
+ async (params) => listProductsHandler(context, params),
89
+ );
90
+
91
+ server.tool(
92
+ 'products_count',
93
+ 'Search and returns total number of products registered in the system with comprehensive filtering if provided',
94
+ ProductsCountSchema,
95
+ async (params) => productsCountHandler(context, params),
96
+ );
97
+ server.tool('get_product', 'Get detailed product information', GetProductSchema, async (params) =>
98
+ getProductHandler(context, params),
99
+ );
100
+
101
+ server.tool(
102
+ 'create_product',
103
+ 'Adds or create new product the product will be in DRAFT/unpublish status',
104
+ CreateProductSchema,
105
+ async (params) => createProductHandler(context, params),
106
+ );
107
+ server.tool(
108
+ 'remove_product',
109
+ 'Removed or deletes a product by its id changing its status to DELETED and removing it from sale',
110
+ RemoveProductSchema,
111
+ async (params) => removeProductHandler(context, params),
112
+ );
113
+
114
+ server.tool(
115
+ 'publish_product',
116
+ 'Publish a product by its id changing it to active and available for sale',
117
+ PublishProductSchema,
118
+ async (params) => publishProductHandler(context, params),
119
+ );
120
+
121
+ server.tool(
122
+ 'unpublish_product',
123
+ 'Deactivates or Unpublishes product by its id changing it to DRAFT and not available for sale',
124
+ UnpublishProductSchema,
125
+ async (params) => unpublishProductHandler(context, params),
126
+ );
127
+ server.tool(
128
+ 'update_product',
129
+ 'Modify/Update generic infos of a product (tags for ex.)',
130
+ UpdateProductSchema,
131
+ async (params) => updateProductHandler(context, params),
132
+ );
133
+
134
+ server.tool(
135
+ 'update_product_texts',
136
+ 'Modify/update localized texts of a product',
137
+ UpdateProductTextsSchema,
138
+ async (params) => updateProductTextsHandler(context, params),
139
+ );
140
+
141
+ server.tool(
142
+ 'update_product_commerce',
143
+ 'Modify/update products commerce info like prices, taxes, etc. for all product types except CONFIGURABLE_PRODUCT. for currency value always use registered currency in the system and not a custom one, it should not be called for CONFIGURABLE_PRODUCT type products',
144
+ UpdateProductCommerceSchema,
145
+ async (params) => updateProductCommerceHandler(context, params),
146
+ );
147
+
148
+ server.tool(
149
+ 'update_product_warehousing',
150
+ 'Modify/update products commerce info like prices, taxes, etc. for SIMPLE_PRODUCT product type only. it is only available for SIMPLE_PRODUCT type products',
151
+ UpdateProductCommerceSchema,
152
+ async (params) => updateProductCommerceHandler(context, params),
153
+ );
154
+
155
+ server.tool(
156
+ 'update_product_supply',
157
+ 'Modify/update products supply of SIMPLE_PRODUCT type info like prices, taxes, etc. it is only available for SIMPLE_PRODUCT type products',
158
+ UpdateProductSupplySchema,
159
+ async (params) => updateProductSupplyHandler(context, params),
160
+ );
161
+ server.tool(
162
+ 'update_tokenized_product',
163
+ 'Modify/update products supply of TOKENIZED_PRODUCT type info like contractAddress, contractStandard, tokenId, supply, ercMetadataProperties etc. it is only available for TOKENIZED_PRODUCT type products',
164
+ UpdateProductTokenizationSchema,
165
+ async (params) => updateProductTokenizationHandler(context, params),
166
+ );
167
+ server.tool(
168
+ 'update_product_plan',
169
+ 'Modify/update products subscription/plan information of PLAN_PRODUCT type info like billing period, trial period and usage calculation, etc. it is only available for PLAN_PRODUCT type products',
170
+ UpdateProductPlanSchema,
171
+ async (params) => updateProductPlanHandler(context, params),
172
+ );
173
+
174
+ server.tool(
175
+ 'list_currencies',
176
+ 'List all available currencies in the system, when currency is required and not implicitly provided use this tool to get the list of available currencies also if non existing currency is provided to you by a user inform them it does not exist and to create it first before they can use it',
177
+ ListCurrenciesSchema,
178
+ async (params) => currenciesHandler(context, params),
179
+ );
180
+
181
+ server.tool(
182
+ 'get_currency',
183
+ 'Gets a single currency registered in the system',
184
+ CurrencySchema,
185
+ async (params) => currencyHandler(context, params),
186
+ );
187
+
188
+ server.tool(
189
+ 'list_countries',
190
+ 'List all available countries in the system, when country is required and not implicitly provided use this tool to get the list of available countries also if non existing country is provided to you by a user inform them it does not exist and to create it first before they can use it',
191
+ ListCountriesSchema,
192
+ async (params) => countriesHandler(context, params),
193
+ );
194
+
195
+ server.tool(
196
+ 'get_country',
197
+ 'Gets a single country registered in the system',
198
+ CountrySchema,
199
+ async (params) => countryHandler(context, params),
200
+ );
201
+
202
+ server.tool(
203
+ 'list_languages',
204
+ 'List all available languages in the system, when language is required and not implicitly provided use this tool to get the list of available languages also if non existing language is provided to you by a user inform them it does not exist and to create it first before they can use it',
205
+ ListLanguagesSchema,
206
+ async (params) => languagesHandler(context, params),
207
+ );
208
+
209
+ server.tool(
210
+ 'get_language',
211
+ 'Gets a single language registered in the system',
212
+ LanguageSchema,
213
+ async (params) => languageHandler(context, params),
214
+ );
215
+
216
+ server.tool(
217
+ 'create_product_variation',
218
+ 'Adds/create a variation of a product, it is only available for CONFIGURABLE_PRODUCT type products',
219
+ CreateProductVariationSchema,
220
+ async (params) => createProductVariationHandler(context, params),
221
+ );
222
+
223
+ server.tool(
224
+ 'remove_product_variation',
225
+ 'removes a variation of a product',
226
+ RemoveProductVariationSchema,
227
+ async (params) => removeProductVariationHandler(context, params),
228
+ );
229
+
230
+ server.tool(
231
+ 'assign_product_variation',
232
+ 'Link a product to a ConfigurableProduct variation option by providing a vector combination that uniquely identifies the variation option',
233
+ AssignProductVariationSchema,
234
+ async (params) => addProductAssignmentHandler(context, params),
235
+ );
236
+
237
+ server.tool(
238
+ 'add_variation_options',
239
+ 'Adds variation option to an existing product variations',
240
+ CreateProductVariationOptionSchema,
241
+ async (params) => createProductVariationOptionHandler(context, params),
242
+ );
243
+
244
+ server.tool(
245
+ 'remove_variation_options',
246
+ 'Removes product option value for product variation with the provided variation option value',
247
+ RemoveProductVariationOptionSchema,
248
+ async (params) => removeProductVariationOptionHandler(context, params),
249
+ );
250
+
251
+ server.tool(
252
+ 'remove_product_variation_assignment',
253
+ 'Unlinks a product from a ConfigurableProduct by providing a configuration combination that uniquely identifies a row in the assignment matrix',
254
+ RemoveProductAssignmentSchema,
255
+ async (params) => removeProductAssignmentHandler(context, params),
256
+ );
257
+
258
+ server.tool('add_language', 'Adds new language', CreateLanguageSchema, async (params) =>
259
+ createLanguageHandler(context, params),
260
+ );
261
+
262
+ server.tool('update_language', 'Updates language', UpdateLanguageSchema, async (params) =>
263
+ updateLanguageHandler(context, params),
264
+ );
265
+
266
+ server.tool('remove_language', 'Deletes a language', RemoveLanguageSchema, async (params) =>
267
+ removeLanguageHandler(context, params),
268
+ );
269
+
270
+ server.tool(
271
+ 'add_product_media',
272
+ 'Adds media to a product',
273
+ AddProductMediaUploadSchema,
274
+ async (params) => addProductMediaUploadHandler(context, params),
275
+ );
276
+
277
+ server.tool(
278
+ 'remove_product_media',
279
+ "Remove a media asset from a product's visualization",
280
+ RemoveProductMediaSchema,
281
+ async (params) => removeProductMediaHandler(context, params),
282
+ );
283
+
284
+ server.tool(
285
+ 'update_product_media_texts',
286
+ "Modify localized texts part of a product's media asset",
287
+ UpdateProductMediaTextsSchema,
288
+ async (params) => updateProductMediaTextsHandler(context, params),
289
+ );
290
+
291
+ server.tool(
292
+ 'reorder_product_media',
293
+ 'Reorder a media asset (first is primary)',
294
+ ReorderProductMediaSchema,
295
+ async (params) => reorderProductMediaHandler(context, params),
296
+ );
297
+
298
+ server.tool(
299
+ 'product_review_count',
300
+ 'Returns total number of product reviews',
301
+ ProductReviewsCountSchema,
302
+ async (params) => productReviewsCountHandler(context, params),
303
+ );
304
+
305
+ server.tool(
306
+ 'product_reviews',
307
+ ' Get all product reviews, by default sorted by creation date (descending)',
308
+ ProductReviewsSchema,
309
+ async (params) => productReviewsHandler(context, params),
310
+ );
311
+
312
+ return server;
313
+ }
@@ -0,0 +1,118 @@
1
+ import { z } from 'zod';
2
+ import { Context } from '../../context.js';
3
+ import { getNormalizedProductDetails } from '../utils/getNormalizedProductDetails.js';
4
+ import {
5
+ ProductNotFoundError,
6
+ ProductVariationVectorAlreadySet,
7
+ ProductVariationVectorInvalid,
8
+ ProductWrongTypeError,
9
+ } from '../../errors.js';
10
+ import { ProductConfiguration, ProductTypes } from '@unchainedshop/core-products';
11
+
12
+ const extractVariationMatrix = (variations = []) => {
13
+ const cartesianProduct = (arrays) => {
14
+ return arrays.reduce(
15
+ (acc, array) => acc.flatMap((item) => array.map((value) => [...item, value])),
16
+ [[]],
17
+ );
18
+ };
19
+ const keys = variations.map((item) => item.key);
20
+ const options = variations.map((item) => item.options);
21
+ const combinations = cartesianProduct(options);
22
+ return combinations.map((combination) =>
23
+ combination.reduce((acc, value, index) => {
24
+ acc[keys[index]] = value;
25
+ return acc;
26
+ }, {}),
27
+ );
28
+ };
29
+
30
+ const combinationExists = (matrix, combination) => {
31
+ return matrix.some((variation) => {
32
+ return (
33
+ Object.keys(variation).length === Object.keys(combination).length && // Ensure both have the same number of keys
34
+ Object.entries(combination).every(([key, value]) => variation[key] === value)
35
+ );
36
+ });
37
+ };
38
+
39
+ // Zod schema for ProductAssignmentVectorInput
40
+ const ProductAssignmentVectorSchema = z.object({
41
+ key: z.string().min(1).describe('Attribute key (e.g., "Color", "Size")'),
42
+ value: z.string().min(1).describe('Attribute value (e.g., "Red", "M")'),
43
+ });
44
+
45
+ export const AssignProductVariationSchema = {
46
+ proxyId: z.string().min(1).describe('should be ID of the CONFIGURABLE_PRODUCT (parent) only'),
47
+ productId: z
48
+ .string()
49
+ .min(1)
50
+ .describe('ID of the product being assigned. can not be a CONFIGURABLE_PRODUCT product'),
51
+ vectors: z
52
+ .array(ProductAssignmentVectorSchema)
53
+ .min(1)
54
+ .describe('Combination of attributes uniquely identifying the variant'),
55
+ };
56
+ // Full schema for the mutation
57
+ export const AddProductAssignmentZodSchema = z.object(AssignProductVariationSchema);
58
+
59
+ export type AddProductAssignmentParams = z.infer<typeof AddProductAssignmentZodSchema>;
60
+
61
+ export async function addProductAssignmentHandler(context: Context, params: AddProductAssignmentParams) {
62
+ const { proxyId, productId, vectors } = params;
63
+ const { modules } = context;
64
+
65
+ try {
66
+ const proxyProduct = await modules.products.findProduct({
67
+ productId: proxyId,
68
+ });
69
+ if (!proxyProduct) throw new ProductNotFoundError({ proxyId });
70
+
71
+ if (proxyProduct.type !== ProductTypes.ConfigurableProduct)
72
+ throw new ProductWrongTypeError({
73
+ proxyId,
74
+ received: proxyProduct.type,
75
+ required: ProductTypes.ConfigurableProduct,
76
+ });
77
+ const variations = await modules.products.variations.findProductVariations({
78
+ productId: proxyId,
79
+ });
80
+ const variationMatrix = extractVariationMatrix(variations);
81
+ const normalizedVectors = vectors?.reduce((prev, { key, value }) => {
82
+ return {
83
+ ...prev,
84
+ [key]: value,
85
+ };
86
+ }, {});
87
+ if (!combinationExists(variationMatrix, normalizedVectors))
88
+ throw new ProductVariationVectorInvalid({ proxyId, vectors });
89
+
90
+ const added = await modules.products.assignments.addProxyAssignment({
91
+ productId,
92
+ proxyId,
93
+ vectors: vectors as ProductConfiguration[],
94
+ });
95
+
96
+ if (!added) throw new ProductVariationVectorAlreadySet({ proxyId, vectors });
97
+
98
+ return {
99
+ content: [
100
+ {
101
+ type: 'text' as const,
102
+ text: JSON.stringify({
103
+ product: await getNormalizedProductDetails(proxyId, context),
104
+ }),
105
+ },
106
+ ],
107
+ };
108
+ } catch (error) {
109
+ return {
110
+ content: [
111
+ {
112
+ type: 'text' as const,
113
+ text: `Error assigning product: ${(error as Error).message}`,
114
+ },
115
+ ],
116
+ };
117
+ }
118
+ }
@@ -0,0 +1,79 @@
1
+ import { z } from 'zod';
2
+ import { Context } from '../../context.js';
3
+ import { log } from '@unchainedshop/logger';
4
+ import { FileNotFoundError, FileUploadExpiredError } from '../../errors.js';
5
+
6
+ export const AddProductMediaUploadSchema = {
7
+ mediaName: z
8
+ .string()
9
+ .min(1)
10
+ .describe('Name of the media file (e.g. "image.png") use random name if not provided'),
11
+ productId: z.string().min(1).describe('ID of the product to link media to'),
12
+ url: z.string().describe('Anonymously fetchable URL of the source media, can be a data URL too'),
13
+ };
14
+
15
+ export const AddProductMediaUploadZodSchema = z.object(AddProductMediaUploadSchema);
16
+
17
+ export type AddProductMediaUploadParams = z.infer<typeof AddProductMediaUploadZodSchema>;
18
+
19
+ export async function addProductMediaUploadHandler(
20
+ context: Context,
21
+ params: AddProductMediaUploadParams,
22
+ ) {
23
+ const { mediaName, productId, url } = params;
24
+ const { modules, services, userId } = context;
25
+
26
+ try {
27
+ log('addProductMediaUploadHandler', { mediaName, productId, userId, url });
28
+ const {
29
+ _id: fileId,
30
+ putURL,
31
+ type,
32
+ size,
33
+ } = await services.files.createSignedURL({
34
+ directoryName: 'product-media',
35
+ fileName: mediaName,
36
+ meta: { productId },
37
+ });
38
+
39
+ const sourceResponse = await fetch(url);
40
+ const uploadUrl = new URL(putURL, process.env.ROOT_URL || 'http://localhost:4010');
41
+ const uploadResponse = await fetch(uploadUrl, {
42
+ method: 'PUT',
43
+ body: sourceResponse.body,
44
+ duplex: 'half',
45
+ } as RequestInit);
46
+
47
+ if (!uploadResponse.ok) {
48
+ throw new Error(`Upload failed: ${uploadResponse.status} ${uploadResponse.statusText}`);
49
+ }
50
+
51
+ const file = await modules.files.findFile({ fileId });
52
+ if (!file) throw new FileNotFoundError({ fileId });
53
+
54
+ if (file.expires && new Date(file.expires).getTime() < Date.now()) {
55
+ throw new FileUploadExpiredError({ fileId });
56
+ }
57
+ const linked = await services.files.linkFile({ fileId, size, type });
58
+
59
+ return {
60
+ content: [
61
+ {
62
+ type: 'text' as const,
63
+ text: JSON.stringify({
64
+ file: linked,
65
+ }),
66
+ },
67
+ ],
68
+ };
69
+ } catch (error) {
70
+ return {
71
+ content: [
72
+ {
73
+ type: 'text' as const,
74
+ text: `Error uploading product media: ${(error as Error).message}`,
75
+ },
76
+ ],
77
+ };
78
+ }
79
+ }
@@ -0,0 +1,60 @@
1
+ import { z } from 'zod';
2
+ import { Context } from '../../context.js';
3
+ import { SortDirection } from '@unchainedshop/utils';
4
+
5
+ const sortDirectionKeys = Object.keys(SortDirection) as [
6
+ keyof typeof SortDirection,
7
+ ...(keyof typeof SortDirection)[],
8
+ ];
9
+
10
+ export const ListCountriesSchema = {
11
+ limit: z.number().int().min(1).max(100).default(50),
12
+ offset: z.number().int().min(0).default(0),
13
+ includeInactive: z.boolean().default(false),
14
+ queryString: z.string().min(1).optional(),
15
+ sort: z
16
+ .array(
17
+ z.object({
18
+ key: z.string().min(1),
19
+ value: z.enum(sortDirectionKeys).describe("Sort direction, e.g., 'ASC' or 'DESC'"),
20
+ }),
21
+ )
22
+ .optional(),
23
+ };
24
+
25
+ export const ListCountriesZodSchema = z.object(ListCountriesSchema);
26
+
27
+ export type ListCountriesParams = z.infer<typeof ListCountriesZodSchema>;
28
+
29
+ export async function countriesHandler(context: Context, params: ListCountriesParams) {
30
+ const { limit, offset, includeInactive, queryString, sort } = params;
31
+ const { modules } = context;
32
+
33
+ try {
34
+ const countries = await modules.countries.findCountries({
35
+ limit,
36
+ offset,
37
+ includeInactive,
38
+ queryString,
39
+ sort: sort as any[],
40
+ });
41
+
42
+ return {
43
+ content: [
44
+ {
45
+ type: 'text' as const,
46
+ text: JSON.stringify({ countries }),
47
+ },
48
+ ],
49
+ };
50
+ } catch (error) {
51
+ return {
52
+ content: [
53
+ {
54
+ type: 'text' as const,
55
+ text: `Error retrieving countries: ${(error as Error).message}`,
56
+ },
57
+ ],
58
+ };
59
+ }
60
+ }
@@ -0,0 +1,40 @@
1
+ import { z } from 'zod';
2
+ import { Context } from '../../context.js';
3
+ import { CountryNotFoundError } from '../../errors.js';
4
+
5
+ export const CountrySchema = {
6
+ countryId: z.string().min(1).describe('The ID of the country to fetch'),
7
+ };
8
+
9
+ export const CountryZodSchema = z.object(CountrySchema);
10
+
11
+ export type CountryParams = z.infer<typeof CountryZodSchema>;
12
+
13
+ export async function countryHandler(context: Context, params: CountryParams) {
14
+ const { countryId } = params;
15
+ const { modules } = context;
16
+
17
+ try {
18
+ const country = await modules.countries.findCountry({ countryId });
19
+
20
+ if (!country) throw new CountryNotFoundError({ countryId });
21
+
22
+ return {
23
+ content: [
24
+ {
25
+ type: 'text' as const,
26
+ text: JSON.stringify({ country }),
27
+ },
28
+ ],
29
+ };
30
+ } catch (error) {
31
+ return {
32
+ content: [
33
+ {
34
+ type: 'text' as const,
35
+ text: `Error retrieving country: ${(error as Error).message}`,
36
+ },
37
+ ],
38
+ };
39
+ }
40
+ }
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { Context } from '../../context.js';
3
+
4
+ const CreateLanguageInputSchema = z.object({
5
+ isoCode: z
6
+ .string()
7
+ .min(2)
8
+ .max(10)
9
+ .describe('Language ISO code, e.g. "en" or "de-CH, accept only valid ISO code"'),
10
+ });
11
+
12
+ export const CreateLanguageSchema = {
13
+ language: CreateLanguageInputSchema,
14
+ };
15
+
16
+ export const CreateLanguageZodSchema = z.object(CreateLanguageSchema);
17
+ export type CreateLanguageParams = z.infer<typeof CreateLanguageZodSchema>;
18
+
19
+ export async function createLanguageHandler(context: Context, params: CreateLanguageParams) {
20
+ const { language } = params;
21
+ const { modules } = context;
22
+
23
+ try {
24
+ const languageId = await modules.languages.create(language as any);
25
+
26
+ const newLanguage = await modules.languages.findLanguage({ languageId });
27
+
28
+ return {
29
+ content: [
30
+ {
31
+ type: 'text' as const,
32
+ text: JSON.stringify({ language: newLanguage }),
33
+ },
34
+ ],
35
+ };
36
+ } catch (error) {
37
+ return {
38
+ content: [
39
+ {
40
+ type: 'text' as const,
41
+ text: `Error creating language: ${(error as Error).message}`,
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ }