@shophost/rest-api 2.0.31 → 2.0.33

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 (348) hide show
  1. package/package.json +13 -14
  2. package/src/app.js +53 -1
  3. package/src/app.js.map +1 -0
  4. package/src/core/auth/auth.schema.js +41 -1
  5. package/src/core/auth/auth.schema.js.map +1 -0
  6. package/src/core/auth/auth.util.js +44 -1
  7. package/src/core/auth/auth.util.js.map +1 -0
  8. package/src/core/auth/better-auth.lib.js +100 -1
  9. package/src/core/auth/better-auth.lib.js.map +1 -0
  10. package/src/core/auth/generate-password-hash.util.d.ts +3 -0
  11. package/src/core/auth/generate-password-hash.util.js +30 -1
  12. package/src/core/auth/generate-password-hash.util.js.map +1 -0
  13. package/src/core/auth/headers.schema.js +22 -1
  14. package/src/core/auth/headers.schema.js.map +1 -0
  15. package/src/core/auth/user.schema.js +30 -1
  16. package/src/core/auth/user.schema.js.map +1 -0
  17. package/src/core/db/__generated__/client/browser.d.ts +128 -0
  18. package/src/core/db/__generated__/client/browser.js +18 -1
  19. package/src/core/db/__generated__/client/browser.js.map +1 -0
  20. package/src/core/db/__generated__/client/client.d.ts +143 -0
  21. package/src/core/db/__generated__/client/client.js +35 -1
  22. package/src/core/db/__generated__/client/client.js.map +1 -0
  23. package/src/core/db/__generated__/client/commonInputTypes.js +11 -1
  24. package/src/core/db/__generated__/client/commonInputTypes.js.map +1 -0
  25. package/src/core/db/__generated__/client/enums.js +200 -1
  26. package/src/core/db/__generated__/client/enums.js.map +1 -0
  27. package/src/core/db/__generated__/client/internal/class.d.ts +343 -0
  28. package/src/core/db/__generated__/client/internal/class.js +55 -1
  29. package/src/core/db/__generated__/client/internal/class.js.map +1 -0
  30. package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +234 -0
  31. package/src/core/db/__generated__/client/internal/prismaNamespace.js +541 -1
  32. package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +1 -0
  33. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +15 -0
  34. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +512 -1
  35. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +1 -0
  36. package/src/core/db/__generated__/client/models/Account.d.ts +633 -0
  37. package/src/core/db/__generated__/client/models/Account.js +2 -1
  38. package/src/core/db/__generated__/client/models/Account.js.map +1 -0
  39. package/src/core/db/__generated__/client/models/Address.d.ts +706 -0
  40. package/src/core/db/__generated__/client/models/Address.js +2 -1
  41. package/src/core/db/__generated__/client/models/Address.js.map +1 -0
  42. package/src/core/db/__generated__/client/models/Campaign.d.ts +643 -0
  43. package/src/core/db/__generated__/client/models/Campaign.js +2 -1
  44. package/src/core/db/__generated__/client/models/Campaign.js.map +1 -0
  45. package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +639 -0
  46. package/src/core/db/__generated__/client/models/ClosingTimes.js +2 -1
  47. package/src/core/db/__generated__/client/models/ClosingTimes.js.map +1 -0
  48. package/src/core/db/__generated__/client/models/File.d.ts +757 -0
  49. package/src/core/db/__generated__/client/models/File.js +2 -1
  50. package/src/core/db/__generated__/client/models/File.js.map +1 -0
  51. package/src/core/db/__generated__/client/models/Invitation.d.ts +633 -0
  52. package/src/core/db/__generated__/client/models/Invitation.js +2 -1
  53. package/src/core/db/__generated__/client/models/Invitation.js.map +1 -0
  54. package/src/core/db/__generated__/client/models/LegalEntity.d.ts +657 -0
  55. package/src/core/db/__generated__/client/models/LegalEntity.js +2 -1
  56. package/src/core/db/__generated__/client/models/LegalEntity.js.map +1 -0
  57. package/src/core/db/__generated__/client/models/Manufacturer.d.ts +684 -0
  58. package/src/core/db/__generated__/client/models/Manufacturer.js +2 -1
  59. package/src/core/db/__generated__/client/models/Manufacturer.js.map +1 -0
  60. package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +633 -0
  61. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +2 -1
  62. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js.map +1 -0
  63. package/src/core/db/__generated__/client/models/Member.d.ts +633 -0
  64. package/src/core/db/__generated__/client/models/Member.js +2 -1
  65. package/src/core/db/__generated__/client/models/Member.js.map +1 -0
  66. package/src/core/db/__generated__/client/models/Modifier.d.ts +667 -0
  67. package/src/core/db/__generated__/client/models/Modifier.js +2 -1
  68. package/src/core/db/__generated__/client/models/Modifier.js.map +1 -0
  69. package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +691 -0
  70. package/src/core/db/__generated__/client/models/ModifierGroup.js +2 -1
  71. package/src/core/db/__generated__/client/models/ModifierGroup.js.map +1 -0
  72. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +633 -0
  73. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +2 -1
  74. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js.map +1 -0
  75. package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +639 -0
  76. package/src/core/db/__generated__/client/models/OpeningTimes.js +2 -1
  77. package/src/core/db/__generated__/client/models/OpeningTimes.js.map +1 -0
  78. package/src/core/db/__generated__/client/models/Order.d.ts +705 -0
  79. package/src/core/db/__generated__/client/models/Order.js +2 -1
  80. package/src/core/db/__generated__/client/models/Order.js.map +1 -0
  81. package/src/core/db/__generated__/client/models/OrderItem.d.ts +691 -0
  82. package/src/core/db/__generated__/client/models/OrderItem.js +2 -1
  83. package/src/core/db/__generated__/client/models/OrderItem.js.map +1 -0
  84. package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +633 -0
  85. package/src/core/db/__generated__/client/models/OrderItemTranslation.js +2 -1
  86. package/src/core/db/__generated__/client/models/OrderItemTranslation.js.map +1 -0
  87. package/src/core/db/__generated__/client/models/Organization.d.ts +816 -0
  88. package/src/core/db/__generated__/client/models/Organization.js +2 -1
  89. package/src/core/db/__generated__/client/models/Organization.js.map +1 -0
  90. package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +681 -0
  91. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +2 -1
  92. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js.map +1 -0
  93. package/src/core/db/__generated__/client/models/Payment.d.ts +673 -0
  94. package/src/core/db/__generated__/client/models/Payment.js +2 -1
  95. package/src/core/db/__generated__/client/models/Payment.js.map +1 -0
  96. package/src/core/db/__generated__/client/models/PaymentSession.d.ts +643 -0
  97. package/src/core/db/__generated__/client/models/PaymentSession.js +2 -1
  98. package/src/core/db/__generated__/client/models/PaymentSession.js.map +1 -0
  99. package/src/core/db/__generated__/client/models/Product.d.ts +751 -0
  100. package/src/core/db/__generated__/client/models/Product.js +2 -1
  101. package/src/core/db/__generated__/client/models/Product.js.map +1 -0
  102. package/src/core/db/__generated__/client/models/ProductCategory.d.ts +694 -0
  103. package/src/core/db/__generated__/client/models/ProductCategory.js +2 -1
  104. package/src/core/db/__generated__/client/models/ProductCategory.js.map +1 -0
  105. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +633 -0
  106. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +2 -1
  107. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js.map +1 -0
  108. package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +669 -0
  109. package/src/core/db/__generated__/client/models/ProductSnapshot.js +2 -1
  110. package/src/core/db/__generated__/client/models/ProductSnapshot.js.map +1 -0
  111. package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +633 -0
  112. package/src/core/db/__generated__/client/models/ProductTranslation.js +2 -1
  113. package/src/core/db/__generated__/client/models/ProductTranslation.js.map +1 -0
  114. package/src/core/db/__generated__/client/models/Reservation.d.ts +655 -0
  115. package/src/core/db/__generated__/client/models/Reservation.js +2 -1
  116. package/src/core/db/__generated__/client/models/Reservation.js.map +1 -0
  117. package/src/core/db/__generated__/client/models/Session.d.ts +633 -0
  118. package/src/core/db/__generated__/client/models/Session.js +2 -1
  119. package/src/core/db/__generated__/client/models/Session.js.map +1 -0
  120. package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +684 -0
  121. package/src/core/db/__generated__/client/models/ShippingMethod.js +2 -1
  122. package/src/core/db/__generated__/client/models/ShippingMethod.js.map +1 -0
  123. package/src/core/db/__generated__/client/models/ShippingZone.d.ts +643 -0
  124. package/src/core/db/__generated__/client/models/ShippingZone.js +2 -1
  125. package/src/core/db/__generated__/client/models/ShippingZone.js.map +1 -0
  126. package/src/core/db/__generated__/client/models/User.d.ts +741 -0
  127. package/src/core/db/__generated__/client/models/User.js +2 -1
  128. package/src/core/db/__generated__/client/models/User.js.map +1 -0
  129. package/src/core/db/__generated__/client/models/Verification.d.ts +597 -0
  130. package/src/core/db/__generated__/client/models/Verification.js +2 -1
  131. package/src/core/db/__generated__/client/models/Verification.js.map +1 -0
  132. package/src/core/db/__generated__/client/models.js +2 -1
  133. package/src/core/db/__generated__/client/models.js.map +1 -0
  134. package/src/core/db/index.js +2 -1
  135. package/src/core/db/index.js.map +1 -0
  136. package/src/core/exceptions/http-exception.js +9 -1
  137. package/src/core/exceptions/http-exception.js.map +1 -0
  138. package/src/core/hono/hono.js +123 -1
  139. package/src/core/hono/hono.js.map +1 -0
  140. package/src/core/lib/prisma.js +11 -1
  141. package/src/core/lib/prisma.js.map +1 -0
  142. package/src/core/logging/pino.js +5 -1
  143. package/src/core/logging/pino.js.map +1 -0
  144. package/src/core/notifications/email.service.d.ts +15 -0
  145. package/src/core/notifications/email.service.js +116 -1
  146. package/src/core/notifications/email.service.js.map +1 -0
  147. package/src/core/openapi/openapi.lib.js +26 -1
  148. package/src/core/openapi/openapi.lib.js.map +1 -0
  149. package/src/core/types/google-maps.types.js +2 -1
  150. package/src/core/types/google-maps.types.js.map +1 -0
  151. package/src/core/utils/currency.util.js +11 -1
  152. package/src/core/utils/currency.util.js.map +1 -0
  153. package/src/core/utils/env.util.js +8 -1
  154. package/src/core/utils/env.util.js.map +1 -0
  155. package/src/core/utils/object.util.d.ts +10 -0
  156. package/src/core/utils/object.util.js +39 -1
  157. package/src/core/utils/object.util.js.map +1 -0
  158. package/src/core/utils/translations.util.js +2 -0
  159. package/src/core/utils/translations.util.js.map +1 -0
  160. package/src/core/utils/zod.util.d.ts +12 -0
  161. package/src/core/utils/zod.util.js +85 -1
  162. package/src/core/utils/zod.util.js.map +1 -0
  163. package/src/db.js +3 -1
  164. package/src/db.js.map +1 -0
  165. package/src/features/access/access.handler.js +91 -1
  166. package/src/features/access/access.handler.js.map +1 -0
  167. package/src/features/access/access.route.js +220 -1
  168. package/src/features/access/access.route.js.map +1 -0
  169. package/src/features/access/access.schema.js +108 -1
  170. package/src/features/access/access.schema.js.map +1 -0
  171. package/src/features/access/access.service.js +294 -1
  172. package/src/features/access/access.service.js.map +1 -0
  173. package/src/features/cart/cart.handler.js +17 -1
  174. package/src/features/cart/cart.handler.js.map +1 -0
  175. package/src/features/cart/cart.route.js +32 -1
  176. package/src/features/cart/cart.route.js.map +1 -0
  177. package/src/features/cart/cart.schema.js +39 -1
  178. package/src/features/cart/cart.schema.js.map +1 -0
  179. package/src/features/cart/cart.service.d.ts +7 -0
  180. package/src/features/cart/cart.service.js +97 -1
  181. package/src/features/cart/cart.service.js.map +1 -0
  182. package/src/features/cart/cart.util.js +76 -1
  183. package/src/features/cart/cart.util.js.map +1 -0
  184. package/src/features/file/file.handler.js +23 -1
  185. package/src/features/file/file.handler.js.map +1 -0
  186. package/src/features/file/file.route.js +34 -1
  187. package/src/features/file/file.route.js.map +1 -0
  188. package/src/features/file/file.schema.js +77 -1
  189. package/src/features/file/file.schema.js.map +1 -0
  190. package/src/features/file/file.service.d.ts +6 -0
  191. package/src/features/file/file.service.js +66 -1
  192. package/src/features/file/file.service.js.map +1 -0
  193. package/src/features/health/health.handler.js +10 -1
  194. package/src/features/health/health.handler.js.map +1 -0
  195. package/src/features/health/health.route.js +25 -1
  196. package/src/features/health/health.route.js.map +1 -0
  197. package/src/features/index.js +16 -1
  198. package/src/features/index.js.map +1 -0
  199. package/src/features/location/location.handler.js +25 -1
  200. package/src/features/location/location.handler.js.map +1 -0
  201. package/src/features/location/location.route.js +56 -1
  202. package/src/features/location/location.route.js.map +1 -0
  203. package/src/features/location/location.schema.js +50 -1
  204. package/src/features/location/location.schema.js.map +1 -0
  205. package/src/features/location/location.service.d.ts +3 -0
  206. package/src/features/location/location.service.js +141 -1
  207. package/src/features/location/location.service.js.map +1 -0
  208. package/src/features/manufacturer/manufacturer.handler.js +53 -1
  209. package/src/features/manufacturer/manufacturer.handler.js.map +1 -0
  210. package/src/features/manufacturer/manufacturer.route.js +97 -1
  211. package/src/features/manufacturer/manufacturer.route.js.map +1 -0
  212. package/src/features/manufacturer/manufacturer.schema.js +125 -1
  213. package/src/features/manufacturer/manufacturer.schema.js.map +1 -0
  214. package/src/features/manufacturer/manufacturer.service.d.ts +19 -0
  215. package/src/features/manufacturer/manufacturer.service.js +190 -1
  216. package/src/features/manufacturer/manufacturer.service.js.map +1 -0
  217. package/src/features/order/emails/order-confirmation.email.js +229 -1
  218. package/src/features/order/emails/order-confirmation.email.js.map +1 -0
  219. package/src/features/order/emails/order-notification.email.js +229 -1
  220. package/src/features/order/emails/order-notification.email.js.map +1 -0
  221. package/src/features/order/fulfilment.schema.js +3 -1
  222. package/src/features/order/fulfilment.schema.js.map +1 -0
  223. package/src/features/order/order.handler.js +54 -1
  224. package/src/features/order/order.handler.js.map +1 -0
  225. package/src/features/order/order.route.js +111 -1
  226. package/src/features/order/order.route.js.map +1 -0
  227. package/src/features/order/order.schema.js +158 -1
  228. package/src/features/order/order.schema.js.map +1 -0
  229. package/src/features/order/order.service.d.ts +15 -0
  230. package/src/features/order/order.service.js +306 -1
  231. package/src/features/order/order.service.js.map +1 -0
  232. package/src/features/order/recipient.schema.js +38 -1
  233. package/src/features/order/recipient.schema.js.map +1 -0
  234. package/src/features/organization/legal-entity.schema.js +83 -1
  235. package/src/features/organization/legal-entity.schema.js.map +1 -0
  236. package/src/features/organization/organization-configuration.schema.js +115 -1
  237. package/src/features/organization/organization-configuration.schema.js.map +1 -0
  238. package/src/features/organization/organization.handler.js +48 -1
  239. package/src/features/organization/organization.handler.js.map +1 -0
  240. package/src/features/organization/organization.route.js +84 -1
  241. package/src/features/organization/organization.route.js.map +1 -0
  242. package/src/features/organization/organization.schema.js +64 -1
  243. package/src/features/organization/organization.schema.js.map +1 -0
  244. package/src/features/organization/organization.service.d.ts +15 -0
  245. package/src/features/organization/organization.service.js +334 -1
  246. package/src/features/organization/organization.service.js.map +1 -0
  247. package/src/features/payment/payment.handler.js +16 -1
  248. package/src/features/payment/payment.handler.js.map +1 -0
  249. package/src/features/payment/payment.route.js +22 -1
  250. package/src/features/payment/payment.route.js.map +1 -0
  251. package/src/features/payment/payment.schema.js +46 -1
  252. package/src/features/payment/payment.schema.js.map +1 -0
  253. package/src/features/payment/payment.service.js +100 -1
  254. package/src/features/payment/payment.service.js.map +1 -0
  255. package/src/features/payment/stripe.service.js +164 -1
  256. package/src/features/payment/stripe.service.js.map +1 -0
  257. package/src/features/product/product-modifier.schema.js +84 -1
  258. package/src/features/product/product-modifier.schema.js.map +1 -0
  259. package/src/features/product/product.handler.js +87 -1
  260. package/src/features/product/product.handler.js.map +1 -0
  261. package/src/features/product/product.route.js +179 -1
  262. package/src/features/product/product.route.js.map +1 -0
  263. package/src/features/product/product.schema.js +143 -1
  264. package/src/features/product/product.schema.js.map +1 -0
  265. package/src/features/product/product.service.d.ts +25 -0
  266. package/src/features/product/product.service.js +440 -1
  267. package/src/features/product/product.service.js.map +1 -0
  268. package/src/features/product-category/product-category.handler.js +59 -1
  269. package/src/features/product-category/product-category.handler.js.map +1 -0
  270. package/src/features/product-category/product-category.route.js +139 -1
  271. package/src/features/product-category/product-category.route.js.map +1 -0
  272. package/src/features/product-category/product-category.schema.js +86 -1
  273. package/src/features/product-category/product-category.schema.js.map +1 -0
  274. package/src/features/product-category/product-category.service.d.ts +22 -0
  275. package/src/features/product-category/product-category.service.js +220 -1
  276. package/src/features/product-category/product-category.service.js.map +1 -0
  277. package/src/features/reservation/emails/reservation-cancellation.email.js +82 -1
  278. package/src/features/reservation/emails/reservation-cancellation.email.js.map +1 -0
  279. package/src/features/reservation/emails/reservation-confirmation.email.js +82 -1
  280. package/src/features/reservation/emails/reservation-confirmation.email.js.map +1 -0
  281. package/src/features/reservation/emails/reservation-notification.email.js +93 -1
  282. package/src/features/reservation/emails/reservation-notification.email.js.map +1 -0
  283. package/src/features/reservation/reservation.handler.js +65 -1
  284. package/src/features/reservation/reservation.handler.js.map +1 -0
  285. package/src/features/reservation/reservation.route.js +167 -1
  286. package/src/features/reservation/reservation.route.js.map +1 -0
  287. package/src/features/reservation/reservation.schema.js +51 -1
  288. package/src/features/reservation/reservation.schema.js.map +1 -0
  289. package/src/features/reservation/reservation.service.d.ts +18 -0
  290. package/src/features/reservation/reservation.service.js +231 -1
  291. package/src/features/reservation/reservation.service.js.map +1 -0
  292. package/src/features/shipping/shipping.handler.js +32 -1
  293. package/src/features/shipping/shipping.handler.js.map +1 -0
  294. package/src/features/shipping/shipping.route.js +51 -1
  295. package/src/features/shipping/shipping.route.js.map +1 -0
  296. package/src/features/shipping/shipping.service.d.ts +7 -0
  297. package/src/features/shipping/shipping.service.js +96 -1
  298. package/src/features/shipping/shipping.service.js.map +1 -0
  299. package/src/features/shipping-method/shipping-method.handler.js +60 -1
  300. package/src/features/shipping-method/shipping-method.handler.js.map +1 -0
  301. package/src/features/shipping-method/shipping-method.route.js +144 -1
  302. package/src/features/shipping-method/shipping-method.route.js.map +1 -0
  303. package/src/features/shipping-method/shipping-method.schema.js +48 -1
  304. package/src/features/shipping-method/shipping-method.schema.js.map +1 -0
  305. package/src/features/shipping-method/shipping-method.service.d.ts +25 -0
  306. package/src/features/shipping-method/shipping-method.service.js +229 -1
  307. package/src/features/shipping-method/shipping-method.service.js.map +1 -0
  308. package/src/features/shipping-method/shipping-zone.schema.js +31 -1
  309. package/src/features/shipping-method/shipping-zone.schema.js.map +1 -0
  310. package/src/features/webhook/webhook.handler.js +50 -1
  311. package/src/features/webhook/webhook.handler.js.map +1 -0
  312. package/src/features/webhook/webhook.route.js +33 -1
  313. package/src/features/webhook/webhook.route.js.map +1 -0
  314. package/src/index.js +6 -1
  315. package/src/index.js.map +1 -0
  316. package/src/integrations/next.js +82 -1
  317. package/src/integrations/next.js.map +1 -0
  318. package/src/schemas/address.schema.d.ts +8 -0
  319. package/src/schemas/address.schema.js +112 -1
  320. package/src/schemas/address.schema.js.map +1 -0
  321. package/src/schemas/currency.schema.d.ts +42 -0
  322. package/src/schemas/currency.schema.js +118 -1
  323. package/src/schemas/currency.schema.js.map +1 -0
  324. package/src/schemas/error.schema.js +12 -1
  325. package/src/schemas/error.schema.js.map +1 -0
  326. package/src/schemas/index.js +29 -1
  327. package/src/schemas/index.js.map +1 -0
  328. package/src/schemas/locales.schema.js +238 -1
  329. package/src/schemas/locales.schema.js.map +1 -0
  330. package/src/schemas/number.schema.js +29 -1
  331. package/src/schemas/number.schema.js.map +1 -0
  332. package/src/schemas/pagination.schema.js +54 -1
  333. package/src/schemas/pagination.schema.js.map +1 -0
  334. package/src/schemas/params.schema.js +20 -1
  335. package/src/schemas/params.schema.js.map +1 -0
  336. package/src/schemas/queries.schema.js +6 -1
  337. package/src/schemas/queries.schema.js.map +1 -0
  338. package/src/test/global-setup.js +37 -1
  339. package/src/test/global-setup.js.map +1 -0
  340. package/src/test/integration/api-fixtures.js +160 -1
  341. package/src/test/integration/api-fixtures.js.map +1 -0
  342. package/src/test/integration/seed.js +368 -1
  343. package/src/test/integration/seed.js.map +1 -0
  344. package/src/test/integration/test-helpers.js +154 -1
  345. package/src/test/integration/test-helpers.js.map +1 -0
  346. package/src/test/setup-test-env.js +7 -1
  347. package/src/test/setup-test-env.js.map +1 -0
  348. package/scripts/minify.mjs +0 -110
@@ -1 +1,164 @@
1
- import{__awaiter as e}from"tslib";import i from"stripe";import{HttpException as t}from"../../core/exceptions/http-exception";import{EmailService as r}from"../../core/notifications/email.service";import{OrderSchema as o,OrganizationSchema as n,UserSchema as s}from"../../schemas";class a{constructor(e,t){this.prisma=e,this.options=t,(null==t?void 0:t.secretKey)&&(this.stripe=new i(t.secretKey)),(null==t?void 0:t.resendApiKey)&&(this.emailService=new r(t.resendApiKey))}handleCheckoutSessionCompleted(i){return e(this,void 0,void 0,function*(){var e,r,a;const d=i.data.object,p=yield this.prisma.paymentSession.findFirst({where:{referenceId:d.id}});if(!p)throw new t(404,"Payment session not found");if(yield this.prisma.paymentSession.update({where:{id:p.id},data:{capturedAt:new Date,payment:{update:{status:"succeeded"}}}}),!(null===(e=d.metadata)||void 0===e?void 0:e.orderId)||!this.emailService)return;const c=yield this.prisma.order.findFirst({where:{id:null===(r=d.metadata)||void 0===r?void 0:r.orderId},include:{items:{include:{translations:!0,image:!0}},payment:!0,organization:{include:{address:!0,configuration:!0,logoFile:!0,members:{include:{user:!0}}}},shippingAddress:!0,shippingMethod:{include:{shippingZones:!0}}}}),l=yield this.prisma.user.findFirst({where:{id:null===(a=d.metadata)||void 0===a?void 0:a.userId}});if(c&&l){yield this.emailService.sendOrderConfirmationEmail(s.parse(l),n.parse(c.organization),o.parse(c));for(const e of c.organization.members)yield this.emailService.sendOrderNotificationEmail(s.parse(l),s.parse(e.user),n.parse(c.organization),o.parse(c))}})}createCheckoutSession(i,t,r){return e(this,arguments,void 0,function*(e,i,{locale:t,successUrl:r,cancelUrl:o}){var n;if(!this.stripe)throw new Error("Stripe is not configured");if("card"!==i.payment.method&&"blik"!==i.payment.method)throw new Error("Payment method not supported");const s={payment_method_types:[i.payment.method],customer_email:e.email,line_items:i.items.map(({translations:e,unitPrice:i,quantity:r,image:o})=>{var n;const s=e.find(e=>e.locale===t);return{quantity:r,price_data:{currency:"pln",product_data:{name:null!==(n=null==s?void 0:s.title)&&void 0!==n?n:"N/A",description:(null==s?void 0:s.subtitle)||void 0,images:(null==o?void 0:o.url)?[null==o?void 0:o.url]:void 0},unit_amount:100*i}}}),shipping_options:(null===(n=i.shippingMethod)||void 0===n?void 0:n.shippingZones[0].price)?[{shipping_rate_data:{type:"fixed_amount",fixed_amount:{amount:100*i.payment.shipping,currency:i.currency.toLowerCase()},display_name:"Delivery fee"}}]:void 0,mode:"payment",success_url:r,cancel_url:o,metadata:{userId:e.id,orderId:i.id}};return this.stripe.checkout.sessions.create(s)})}handleWebhookEvent(i,t){return e(this,void 0,void 0,function*(){var e;if(!this.stripe)throw new Error("Stripe is not configured");if(!(null===(e=this.options)||void 0===e?void 0:e.webhookSecret))throw new Error("Stripe webhook secret is not configured");const r=this.stripe.webhooks.constructEvent(t,i,this.options.webhookSecret);if("checkout.session.completed"===r.type)return this.handleCheckoutSessionCompleted(r);throw new Error(`Unhandled event type ${r.type}`)})}}export{a as StripeService};
1
+ import { __awaiter } from "tslib";
2
+ import Stripe from "stripe";
3
+ import { HttpException } from "../../core/exceptions/http-exception";
4
+ import { EmailService } from "../../core/notifications/email.service";
5
+ import { OrderSchema, OrganizationSchema, UserSchema, } from "../../schemas";
6
+ class StripeService {
7
+ constructor(prisma, options) {
8
+ this.prisma = prisma;
9
+ this.options = options;
10
+ if (options === null || options === void 0 ? void 0 : options.secretKey) {
11
+ this.stripe = new Stripe(options.secretKey);
12
+ }
13
+ if (options === null || options === void 0 ? void 0 : options.resendApiKey) {
14
+ this.emailService = new EmailService(options.resendApiKey);
15
+ }
16
+ }
17
+ handleCheckoutSessionCompleted(event) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ var _a, _b, _c;
20
+ const session = event.data.object;
21
+ const paymentSession = yield this.prisma.paymentSession.findFirst({
22
+ where: {
23
+ referenceId: session.id,
24
+ },
25
+ });
26
+ if (!paymentSession) {
27
+ throw new HttpException(404, "Payment session not found");
28
+ }
29
+ yield this.prisma.paymentSession.update({
30
+ where: {
31
+ id: paymentSession.id,
32
+ },
33
+ data: {
34
+ capturedAt: new Date(),
35
+ payment: {
36
+ update: {
37
+ status: "succeeded",
38
+ },
39
+ },
40
+ },
41
+ });
42
+ if (!((_a = session.metadata) === null || _a === void 0 ? void 0 : _a.orderId) || !this.emailService) {
43
+ return;
44
+ }
45
+ const order = yield this.prisma.order.findFirst({
46
+ where: {
47
+ id: (_b = session.metadata) === null || _b === void 0 ? void 0 : _b.orderId,
48
+ },
49
+ include: {
50
+ items: {
51
+ include: {
52
+ translations: true,
53
+ image: true,
54
+ },
55
+ },
56
+ payment: true,
57
+ organization: {
58
+ include: {
59
+ address: true,
60
+ configuration: true,
61
+ logoFile: true,
62
+ members: {
63
+ include: {
64
+ user: true,
65
+ },
66
+ },
67
+ },
68
+ },
69
+ shippingAddress: true,
70
+ shippingMethod: {
71
+ include: {
72
+ shippingZones: true,
73
+ },
74
+ },
75
+ },
76
+ });
77
+ const user = yield this.prisma.user.findFirst({
78
+ where: {
79
+ id: (_c = session.metadata) === null || _c === void 0 ? void 0 : _c.userId,
80
+ },
81
+ });
82
+ if (!order || !user) {
83
+ return;
84
+ }
85
+ yield this.emailService.sendOrderConfirmationEmail(UserSchema.parse(user), OrganizationSchema.parse(order.organization), OrderSchema.parse(order));
86
+ for (const member of order.organization.members) {
87
+ yield this.emailService.sendOrderNotificationEmail(UserSchema.parse(user), UserSchema.parse(member.user), OrganizationSchema.parse(order.organization), OrderSchema.parse(order));
88
+ }
89
+ });
90
+ }
91
+ createCheckoutSession(user_1, order_1, _a) {
92
+ return __awaiter(this, arguments, void 0, function* (user, order, { locale, successUrl, cancelUrl }) {
93
+ var _b;
94
+ if (!this.stripe) {
95
+ throw new Error("Stripe is not configured");
96
+ }
97
+ if (order.payment.method !== "card" && order.payment.method !== "blik") {
98
+ throw new Error("Payment method not supported");
99
+ }
100
+ const params = {
101
+ payment_method_types: [order.payment.method],
102
+ customer_email: user.email,
103
+ line_items: order.items.map(({ translations, unitPrice, quantity, image }) => {
104
+ var _a;
105
+ const translation = translations.find((t) => t.locale === locale);
106
+ return {
107
+ quantity,
108
+ price_data: {
109
+ currency: "pln",
110
+ product_data: {
111
+ name: (_a = translation === null || translation === void 0 ? void 0 : translation.title) !== null && _a !== void 0 ? _a : "N/A",
112
+ description: (translation === null || translation === void 0 ? void 0 : translation.subtitle) || undefined,
113
+ images: (image === null || image === void 0 ? void 0 : image.url) ? [image === null || image === void 0 ? void 0 : image.url] : undefined,
114
+ },
115
+ unit_amount: unitPrice * 100,
116
+ },
117
+ };
118
+ }),
119
+ shipping_options: ((_b = order.shippingMethod) === null || _b === void 0 ? void 0 : _b.shippingZones[0].price)
120
+ ? [
121
+ {
122
+ shipping_rate_data: {
123
+ type: "fixed_amount",
124
+ fixed_amount: {
125
+ amount: order.payment.shipping * 100,
126
+ currency: order.currency.toLowerCase(),
127
+ },
128
+ display_name: "Delivery fee",
129
+ },
130
+ },
131
+ ]
132
+ : undefined,
133
+ mode: "payment",
134
+ success_url: successUrl,
135
+ cancel_url: cancelUrl,
136
+ metadata: {
137
+ userId: user.id,
138
+ orderId: order.id,
139
+ },
140
+ };
141
+ return this.stripe.checkout.sessions.create(params);
142
+ });
143
+ }
144
+ handleWebhookEvent(signature, body) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ var _a;
147
+ if (!this.stripe) {
148
+ throw new Error("Stripe is not configured");
149
+ }
150
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.webhookSecret)) {
151
+ throw new Error("Stripe webhook secret is not configured");
152
+ }
153
+ const event = this.stripe.webhooks.constructEvent(body, signature, this.options.webhookSecret);
154
+ switch (event.type) {
155
+ case "checkout.session.completed":
156
+ return this.handleCheckoutSessionCompleted(event);
157
+ default:
158
+ throw new Error(`Unhandled event type ${event.type}`);
159
+ }
160
+ });
161
+ }
162
+ }
163
+ export { StripeService };
164
+ //# sourceMappingURL=stripe.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe.service.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/payment/stripe.service.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAAE,YA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jC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;YAC7D,CAAC;YAED,MAAM,KAAK,GAAiB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAC7D,IAAI,EACJ,SAAS,EACT,IAAI,CAAC,OAAO,CAAC,aAAa,CAC3B,CAAC;YAEF,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;gBACnB,KAAK,4BAA4B;oBAC/B,OAAO,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC,CAAC;gBACpD;oBACE,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;KAAA;CACF;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1 +1,84 @@
1
- import{z as e}from"@hono/zod-openapi";import{validateRequiredForDefaultLocale as i}from"../../core/utils/zod.util";import{locale as o}from"../../schemas/locales.schema";export const ModifierSchema=e.object({id:e.string().cuid().optional(),title:e.string().min(1,"This field is required").openapi({example:"Large",description:"Title of the modifier"}),sku:e.coerce.string().optional().openapi({example:"csd9876543210abcdef",description:"Stock Keeping Unit identifier"}),price:e.coerce.number().optional().default(0).openapi({example:2.5,description:"Price of the modifier"})}).openapi("Modifier");export const ModifierGroupSchema=e.object({id:e.string().cuid(),selectMin:e.coerce.number().min(0).openapi({example:1,description:"Minimum number of modifiers that can be selected"}),selectMax:e.coerce.number().min(0).openapi({example:1,description:"Maximum number of modifiers that can be selected"}),defaultLocale:o.optional(),modifiers:e.array(ModifierSchema).optional().openapi({}),translations:e.array(e.object({locale:o,title:e.string().optional().openapi({example:"Size",description:"Title of the modifier group"})}))}).openapi("ModifierGroup");export const LocalizedModifierGroupSchema=ModifierGroupSchema.extend({title:e.string().default("").nullable()}).omit({translations:!0}).openapi("LocalizedModifierGroup");export const CreateOrUpdateModifierGroupSchema=e.object({selectMin:e.coerce.number().min(0).openapi({example:1,description:"Minimum number of modifiers that can be selected"}),selectMax:e.coerce.number().min(0).openapi({example:1,description:"Maximum number of modifiers that can be selected"}),defaultLocale:o.optional(),modifiers:e.array(ModifierSchema).optional().openapi({}),translations:e.array(e.object({locale:o,title:e.string().optional().openapi({example:"Size",description:"Title of the modifier group"})}))}).refine(e=>e.selectMax>=e.selectMin,{message:"Maximum selections must be greater than or equal to minimum selections",path:["selectMax"]}).refine(e=>{var i;const o=(null===(i=e.modifiers)||void 0===i?void 0:i.length)||0;return e.selectMax<=o},{message:"Maximum selections cannot exceed the total number of modifiers",path:["selectMax"]}).superRefine(i("title")).openapi("ModifierGroup");
1
+ import { z } from "@hono/zod-openapi";
2
+ import { validateRequiredForDefaultLocale } from "../../core/utils/zod.util";
3
+ import { locale } from "../../schemas/locales.schema";
4
+ export const ModifierSchema = z
5
+ .object({
6
+ id: z.string().cuid().optional(),
7
+ title: z.string().min(1, "This field is required").openapi({
8
+ example: "Large",
9
+ description: "Title of the modifier",
10
+ }),
11
+ sku: z.coerce.string().optional().openapi({
12
+ example: "csd9876543210abcdef",
13
+ description: "Stock Keeping Unit identifier",
14
+ }),
15
+ price: z.coerce.number().optional().default(0).openapi({
16
+ example: 2.5,
17
+ description: "Price of the modifier",
18
+ }),
19
+ })
20
+ .openapi("Modifier");
21
+ export const ModifierGroupSchema = z
22
+ .object({
23
+ id: z.string().cuid(),
24
+ selectMin: z.coerce.number().min(0).openapi({
25
+ example: 1,
26
+ description: "Minimum number of modifiers that can be selected",
27
+ }),
28
+ selectMax: z.coerce.number().min(0).openapi({
29
+ example: 1,
30
+ description: "Maximum number of modifiers that can be selected",
31
+ }),
32
+ defaultLocale: locale.optional(),
33
+ modifiers: z.array(ModifierSchema).optional().openapi({}),
34
+ translations: z.array(z.object({
35
+ locale,
36
+ title: z.string().optional().openapi({
37
+ example: "Size",
38
+ description: "Title of the modifier group",
39
+ }),
40
+ })),
41
+ })
42
+ .openapi("ModifierGroup");
43
+ export const LocalizedModifierGroupSchema = ModifierGroupSchema.extend({
44
+ title: z.string().default("").nullable(),
45
+ })
46
+ .omit({
47
+ translations: true,
48
+ })
49
+ .openapi("LocalizedModifierGroup");
50
+ export const CreateOrUpdateModifierGroupSchema = z
51
+ .object({
52
+ selectMin: z.coerce.number().min(0).openapi({
53
+ example: 1,
54
+ description: "Minimum number of modifiers that can be selected",
55
+ }),
56
+ selectMax: z.coerce.number().min(0).openapi({
57
+ example: 1,
58
+ description: "Maximum number of modifiers that can be selected",
59
+ }),
60
+ defaultLocale: locale.optional(),
61
+ modifiers: z.array(ModifierSchema).optional().openapi({}),
62
+ translations: z.array(z.object({
63
+ locale,
64
+ title: z.string().optional().openapi({
65
+ example: "Size",
66
+ description: "Title of the modifier group",
67
+ }),
68
+ })),
69
+ })
70
+ .refine((data) => data.selectMax >= data.selectMin, {
71
+ message: "Maximum selections must be greater than or equal to minimum selections",
72
+ path: ["selectMax"],
73
+ })
74
+ .refine((data) => {
75
+ var _a;
76
+ const modifierCount = ((_a = data.modifiers) === null || _a === void 0 ? void 0 : _a.length) || 0;
77
+ return data.selectMax <= modifierCount;
78
+ }, {
79
+ message: "Maximum selections cannot exceed the total number of modifiers",
80
+ path: ["selectMax"],
81
+ })
82
+ .superRefine(validateRequiredForDefaultLocale("title"))
83
+ .openapi("ModifierGroup");
84
+ //# sourceMappingURL=product-modifier.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-modifier.schema.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/product/product-modifier.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEtC,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC;KAC5B,MAAM,CAAC;IACN,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IAChC,K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ACD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE;IAClD,OAAO,EACL,wEAAwE;IAC1E,IAAI,EAAE,CAAC,WAAW,CAAC;CACpB,CAAC;KACD,MAAM,CACL,CAAC,IAAI,EAAE,EAAE;;IACP,MAAM,aAAa,GAAG,CAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,MAAM,KAAI,CAAC,CAAC;IAClD,OAAO,IAAI,CAAC,SAAS,IAAI,aAAa,CAAC;AACzC,CAAC,EACD;IACE,OAAO,EAAE,gEAAgE;IACzE,IAAI,EAAE,CAAC,WAAW,CAAC;CACpB,CACF;KACA,WAAW,CAAC,gCAAgC,CAAC,OAAO,CAAC,CAAC;KACtD,OAAO,CAAC,eAAe,CAAC,CAAC"}
@@ -1 +1,87 @@
1
- import{__awaiter as e}from"tslib";import{createApiRouter as o}from"../../core/hono/hono";import{productRoute as t}from"./product.route";import{ProductService as i}from"./product.service";export const buildProductHandler=d=>{const a=o();return a.openapi(t.createProduct,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),a=o.req.valid("json"),r=yield e.isGranted("create"),n=new i(d),c=yield n.createProduct(t.organizationId,r.id,a);return o.json(c,201)})),a.openapi(t.getProduct,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),a=o.req.valid("query");let r=!1;try{yield e.isGranted("read"),r=!0}catch(e){console.log("User only has public access")}const n=new i(d),c=yield n.getProduct(t.organizationId,t.id,{locale:a.locale||null,published:!r});return o.json(c,200)})),a.openapi(t.getProducts,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),a=o.req.valid("query");let r=!1;try{yield e.isGranted("read"),r=!0}catch(e){console.log("User only has public access")}const n=new i(d),c=yield n.getProducts(t.organizationId,Object.assign(Object.assign({},a),{locale:a.locale||null,published:!r}));return o.json(c,200)})),a.openapi(t.updateProduct,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),a=o.req.valid("json"),r=yield e.isGranted("update"),n=new i(d),c=yield n.updateProduct(t.organizationId,t.id,r.id,a);return o.json(c,200)})),a.openapi(t.updateProductStatus,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),a=yield e.isGranted("update"),r=new i(d),n=yield r.updateProductStatus(t.organizationId,t.id,t.operation,a.id);return o.json(n,200)})),a.openapi(t.deleteProduct,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),a=yield e.isGranted("delete"),r=new i(d);return yield r.deleteProduct(t.organizationId,t.id,a.id),o.body(null,204)})),a.openapi(t.getProductsByCategory,o=>e(void 0,void 0,void 0,function*(){const e=o.get("auth"),t=o.req.valid("param"),a=o.req.valid("query");yield e.isGranted("read");const r=new i(d),n=yield r.getProductsByCategory(t.organizationId,t.categoryId,Object.assign(Object.assign({},a),{locale:a.locale||null}));return o.json(n,200)})),a};
1
+ import { __awaiter } from "tslib";
2
+ import { createApiRouter } from "../../core/hono/hono";
3
+ import { productRoute } from "./product.route";
4
+ import { ProductService } from "./product.service";
5
+ export const buildProductHandler = (prisma) => {
6
+ const app = createApiRouter();
7
+ app.openapi(productRoute.createProduct, (c) => __awaiter(void 0, void 0, void 0, function* () {
8
+ const auth = c.get("auth");
9
+ const params = c.req.valid("param");
10
+ const body = c.req.valid("json");
11
+ const user = yield auth.isGranted("create");
12
+ const service = new ProductService(prisma);
13
+ const product = yield service.createProduct(params.organizationId, user.id, body);
14
+ return c.json(product, 201);
15
+ }));
16
+ app.openapi(productRoute.getProduct, (c) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const auth = c.get("auth");
18
+ const params = c.req.valid("param");
19
+ const query = c.req.valid("query");
20
+ let hasPrivateAccess = false;
21
+ try {
22
+ yield auth.isGranted("read");
23
+ hasPrivateAccess = true;
24
+ }
25
+ catch (error) {
26
+ console.log("User only has public access");
27
+ }
28
+ const service = new ProductService(prisma);
29
+ const product = yield service.getProduct(params.organizationId, params.id, {
30
+ locale: query.locale || null,
31
+ published: !hasPrivateAccess,
32
+ });
33
+ return c.json(product, 200);
34
+ }));
35
+ app.openapi(productRoute.getProducts, (c) => __awaiter(void 0, void 0, void 0, function* () {
36
+ const auth = c.get("auth");
37
+ const params = c.req.valid("param");
38
+ const query = c.req.valid("query");
39
+ let hasPrivateAccess = false;
40
+ try {
41
+ yield auth.isGranted("read");
42
+ hasPrivateAccess = true;
43
+ }
44
+ catch (error) {
45
+ console.log("User only has public access");
46
+ }
47
+ const service = new ProductService(prisma);
48
+ const result = yield service.getProducts(params.organizationId, Object.assign(Object.assign({}, query), { locale: query.locale || null, published: !hasPrivateAccess }));
49
+ return c.json(result, 200);
50
+ }));
51
+ app.openapi(productRoute.updateProduct, (c) => __awaiter(void 0, void 0, void 0, function* () {
52
+ const auth = c.get("auth");
53
+ const params = c.req.valid("param");
54
+ const body = c.req.valid("json");
55
+ const user = yield auth.isGranted("update");
56
+ const service = new ProductService(prisma);
57
+ const updatedProduct = yield service.updateProduct(params.organizationId, params.id, user.id, body);
58
+ return c.json(updatedProduct, 200);
59
+ }));
60
+ app.openapi(productRoute.updateProductStatus, (c) => __awaiter(void 0, void 0, void 0, function* () {
61
+ const auth = c.get("auth");
62
+ const params = c.req.valid("param");
63
+ const user = yield auth.isGranted("update");
64
+ const service = new ProductService(prisma);
65
+ const updatedProduct = yield service.updateProductStatus(params.organizationId, params.id, params.operation, user.id);
66
+ return c.json(updatedProduct, 200);
67
+ }));
68
+ app.openapi(productRoute.deleteProduct, (c) => __awaiter(void 0, void 0, void 0, function* () {
69
+ const auth = c.get("auth");
70
+ const params = c.req.valid("param");
71
+ const user = yield auth.isGranted("delete");
72
+ const service = new ProductService(prisma);
73
+ yield service.deleteProduct(params.organizationId, params.id, user.id);
74
+ return c.body(null, 204);
75
+ }));
76
+ app.openapi(productRoute.getProductsByCategory, (c) => __awaiter(void 0, void 0, void 0, function* () {
77
+ const auth = c.get("auth");
78
+ const params = c.req.valid("param");
79
+ const query = c.req.valid("query");
80
+ yield auth.isGranted("read");
81
+ const service = new ProductService(prisma);
82
+ const result = yield service.getProductsByCategory(params.organizationId, params.categoryId, Object.assign(Object.assign({}, query), { locale: query.locale || null }));
83
+ return c.json(result, 200);
84
+ }));
85
+ return app;
86
+ };
87
+ //# sourceMappingURL=product.handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.handler.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/product/product.handler.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAwB,EAAE,EAAE;IAC9D,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;IAE9B,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,aAAa,EAAE,CAAO,CAAM,EAAE,EAAE;QACvD,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAE5C,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,aAAa,CACzC,MAAM,CAAC,cAAc,EACrB,IAAI,CAAC,EAAE,EACP,IAAI,CACL,CAAC;QAEF,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CA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,CAAC,CAAC;IAEH,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAO,CAAM,EAAE,EAAE;QAC/D,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEnC,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAE7B,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAChD,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,UAAU,kCACZ,KAAK,KAAE,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,IAAI,IACzC,CAAC;QAEF,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAA,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
@@ -1 +1,179 @@
1
- import{z as t}from"@hono/zod-openapi";import{createApiRoute as e}from"../../core/hono/hono";import{CreateProductSchema as o,ErrorSchema as a,HeaderSchema as r,LocalizedProductSchema as p,OrganizationParams as s,OrganizationWithIdParams as i,PaginationMetaSchema as d,PaginationQuerySchema as n,ProductSchema as c,UpdateProductSchema as u}from"../../schemas";import{GetResourceQuerySchema as m}from"../../schemas/queries.schema";const h=t.object({categoryId:t.string().openapi({description:"The category ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"categoryId"}}),organizationId:t.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}).openapi("OrganizationWithCategoryParams"),g=e({description:"Fetches paginated list of products",headers:r,method:"GET",operationId:"getProducts",path:"/:organizationId/products",pathParams:s,query:n,responses:{200:t.object({list:t.array(t.union([c,p])),meta:d}),400:a,401:a},summary:"Get Products",tags:["Product"]}),P=e({description:"Fetches a specific product by ID",headers:r,method:"GET",operationId:"getProduct",path:"/:organizationId/products/:id",pathParams:i,query:m,responses:{200:t.union([c,p]),401:a,404:a},summary:"Get Product",tags:["Product"]}),y=e({body:u,description:"Updates a specific product by ID",headers:r,method:"PATCH",operationId:"updateProduct",path:"/:organizationId/products/:id",pathParams:i,responses:{200:c,400:a,401:a,404:a},summary:"Update Product",tags:["Product"]}),I=e({body:o,description:"Creates a new product",headers:r,method:"POST",operationId:"createProduct",path:"/:organizationId/products",pathParams:s,responses:{201:c,400:a,401:a,404:a},summary:"Create Product",tags:["Product"]}),l=e({description:"Sets the published status of an existing product based on the operation (publish or unpublish)",headers:r,method:"POST",operationId:"updateProductStatus",path:"/:organizationId/products/:id/status/:operation",pathParams:t.object({id:t.string().openapi({description:"The product ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"id"}}),operation:t.enum(["publish","unpublish"]).openapi({description:"The operation to perform on the product",example:"publish",param:{in:"path",name:"operation"}}),organizationId:t.string().openapi({description:"The organization ID",example:"ckel0e8qw00004n5p5w6fznym",param:{in:"path",name:"organizationId"}})}),responses:{200:c,400:a,401:a,404:a},summary:"Publish or Unpublish Product",tags:["Product"]}),b=e({description:"Deletes a specific product by ID",headers:r,method:"DELETE",operationId:"deleteProduct",path:"/:organizationId/products/:id",pathParams:i,responses:{204:null,400:a,401:a,404:a},summary:"Delete Product",tags:["Product"]}),z=e({description:"Fetches a paginated list of products for a specific category",headers:r,method:"GET",operationId:"getProductsByCategory",path:"/:organizationId/products/by-category/:categoryId",pathParams:h,query:n,responses:{200:t.object({list:t.array(c),meta:d}),400:a,401:a},summary:"Get Products by Category",tags:["Product"]});export const productRoute={getProducts:g,getProduct:P,updateProduct:y,createProduct:I,updateProductStatus:l,deleteProduct:b,getProductsByCategory:z};
1
+ import { z } from "@hono/zod-openapi";
2
+ import { createApiRoute } from "../../core/hono/hono";
3
+ import { CreateProductSchema, ErrorSchema, HeaderSchema, LocalizedProductSchema, OrganizationParams, OrganizationWithIdParams, PaginationMetaSchema, PaginationQuerySchema, ProductSchema, UpdateProductSchema, } from "../../schemas";
4
+ import { GetResourceQuerySchema } from "../../schemas/queries.schema";
5
+ const OrganizationWithCategoryParams = z
6
+ .object({
7
+ categoryId: z.string().openapi({
8
+ description: "The category ID",
9
+ example: "ckel0e8qw00004n5p5w6fznym",
10
+ param: {
11
+ in: "path",
12
+ name: "categoryId",
13
+ },
14
+ }),
15
+ organizationId: z.string().openapi({
16
+ description: "The organization ID",
17
+ example: "ckel0e8qw00004n5p5w6fznym",
18
+ param: {
19
+ in: "path",
20
+ name: "organizationId",
21
+ },
22
+ }),
23
+ })
24
+ .openapi("OrganizationWithCategoryParams");
25
+ const getProductsRoute = createApiRoute({
26
+ description: "Fetches paginated list of products",
27
+ headers: HeaderSchema,
28
+ method: "GET",
29
+ operationId: "getProducts",
30
+ path: "/:organizationId/products",
31
+ pathParams: OrganizationParams,
32
+ query: PaginationQuerySchema,
33
+ responses: {
34
+ 200: z.object({
35
+ list: z.array(z.union([ProductSchema, LocalizedProductSchema])),
36
+ meta: PaginationMetaSchema,
37
+ }),
38
+ 400: ErrorSchema,
39
+ 401: ErrorSchema,
40
+ },
41
+ summary: "Get Products",
42
+ tags: ["Product"],
43
+ });
44
+ const getProductRoute = createApiRoute({
45
+ description: "Fetches a specific product by ID",
46
+ headers: HeaderSchema,
47
+ method: "GET",
48
+ operationId: "getProduct",
49
+ path: "/:organizationId/products/:id",
50
+ pathParams: OrganizationWithIdParams,
51
+ query: GetResourceQuerySchema,
52
+ responses: {
53
+ 200: z.union([ProductSchema, LocalizedProductSchema]),
54
+ 401: ErrorSchema,
55
+ 404: ErrorSchema,
56
+ },
57
+ summary: "Get Product",
58
+ tags: ["Product"],
59
+ });
60
+ const updateProductRoute = createApiRoute({
61
+ body: UpdateProductSchema,
62
+ description: "Updates a specific product by ID",
63
+ headers: HeaderSchema,
64
+ method: "PATCH",
65
+ operationId: "updateProduct",
66
+ path: "/:organizationId/products/:id",
67
+ pathParams: OrganizationWithIdParams,
68
+ responses: {
69
+ 200: ProductSchema,
70
+ 400: ErrorSchema,
71
+ 401: ErrorSchema,
72
+ 404: ErrorSchema,
73
+ },
74
+ summary: "Update Product",
75
+ tags: ["Product"],
76
+ });
77
+ const createProductRoute = createApiRoute({
78
+ body: CreateProductSchema,
79
+ description: "Creates a new product",
80
+ headers: HeaderSchema,
81
+ method: "POST",
82
+ operationId: "createProduct",
83
+ path: "/:organizationId/products",
84
+ pathParams: OrganizationParams,
85
+ responses: {
86
+ 201: ProductSchema,
87
+ 400: ErrorSchema,
88
+ 401: ErrorSchema,
89
+ 404: ErrorSchema,
90
+ },
91
+ summary: "Create Product",
92
+ tags: ["Product"],
93
+ });
94
+ const updateProductStatusRoute = createApiRoute({
95
+ description: "Sets the published status of an existing product based on the operation (publish or unpublish)",
96
+ headers: HeaderSchema,
97
+ method: "POST",
98
+ operationId: "updateProductStatus",
99
+ path: "/:organizationId/products/:id/status/:operation",
100
+ pathParams: z.object({
101
+ id: z.string().openapi({
102
+ description: "The product ID",
103
+ example: "ckel0e8qw00004n5p5w6fznym",
104
+ param: {
105
+ in: "path",
106
+ name: "id",
107
+ },
108
+ }),
109
+ operation: z.enum(["publish", "unpublish"]).openapi({
110
+ description: "The operation to perform on the product",
111
+ example: "publish",
112
+ param: {
113
+ in: "path",
114
+ name: "operation",
115
+ },
116
+ }),
117
+ organizationId: z.string().openapi({
118
+ description: "The organization ID",
119
+ example: "ckel0e8qw00004n5p5w6fznym",
120
+ param: {
121
+ in: "path",
122
+ name: "organizationId",
123
+ },
124
+ }),
125
+ }),
126
+ responses: {
127
+ 200: ProductSchema,
128
+ 400: ErrorSchema,
129
+ 401: ErrorSchema,
130
+ 404: ErrorSchema,
131
+ },
132
+ summary: "Publish or Unpublish Product",
133
+ tags: ["Product"],
134
+ });
135
+ const deleteProductRoute = createApiRoute({
136
+ description: "Deletes a specific product by ID",
137
+ headers: HeaderSchema,
138
+ method: "DELETE",
139
+ operationId: "deleteProduct",
140
+ path: "/:organizationId/products/:id",
141
+ pathParams: OrganizationWithIdParams,
142
+ responses: {
143
+ 204: null,
144
+ 400: ErrorSchema,
145
+ 401: ErrorSchema,
146
+ 404: ErrorSchema,
147
+ },
148
+ summary: "Delete Product",
149
+ tags: ["Product"],
150
+ });
151
+ const getProductsByCategoryRoute = createApiRoute({
152
+ description: "Fetches a paginated list of products for a specific category",
153
+ headers: HeaderSchema,
154
+ method: "GET",
155
+ operationId: "getProductsByCategory",
156
+ path: "/:organizationId/products/by-category/:categoryId",
157
+ pathParams: OrganizationWithCategoryParams,
158
+ query: PaginationQuerySchema,
159
+ responses: {
160
+ 200: z.object({
161
+ list: z.array(ProductSchema),
162
+ meta: PaginationMetaSchema,
163
+ }),
164
+ 400: ErrorSchema,
165
+ 401: ErrorSchema,
166
+ },
167
+ summary: "Get Products by Category",
168
+ tags: ["Product"],
169
+ });
170
+ export const productRoute = {
171
+ getProducts: getProductsRoute,
172
+ getProduct: getProductRoute,
173
+ updateProduct: updateProductRoute,
174
+ createProduct: createProductRoute,
175
+ updateProductStatus: updateProductStatusRoute,
176
+ deleteProduct: deleteProductRoute,
177
+ getProductsByCategory: getProductsByCategoryRoute,
178
+ };
179
+ //# sourceMappingURL=product.route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product.route.js","sourceRoot":"","sources":["../../../../../../packages/rest-api/src/features/product/product.route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,EACrB,aAA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