@shophost/rest-api 2.0.30 → 2.0.31

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 (352) hide show
  1. package/package.json +18 -13
  2. package/scripts/minify.mjs +110 -0
  3. package/src/app.js +1 -53
  4. package/src/core/auth/auth.schema.js +1 -41
  5. package/src/core/auth/auth.util.js +1 -44
  6. package/src/core/auth/better-auth.lib.js +1 -100
  7. package/src/core/auth/generate-password-hash.util.d.ts +0 -3
  8. package/src/core/auth/generate-password-hash.util.js +1 -30
  9. package/src/core/auth/headers.schema.js +1 -22
  10. package/src/core/auth/user.schema.js +1 -30
  11. package/src/core/db/__generated__/client/browser.d.ts +0 -128
  12. package/src/core/db/__generated__/client/browser.js +1 -18
  13. package/src/core/db/__generated__/client/client.d.ts +0 -143
  14. package/src/core/db/__generated__/client/client.js +1 -35
  15. package/src/core/db/__generated__/client/commonInputTypes.js +1 -11
  16. package/src/core/db/__generated__/client/enums.js +1 -200
  17. package/src/core/db/__generated__/client/internal/class.d.ts +0 -343
  18. package/src/core/db/__generated__/client/internal/class.js +1 -55
  19. package/src/core/db/__generated__/client/internal/prismaNamespace.d.ts +0 -234
  20. package/src/core/db/__generated__/client/internal/prismaNamespace.js +1 -541
  21. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.d.ts +0 -15
  22. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js +1 -512
  23. package/src/core/db/__generated__/client/models/Account.d.ts +0 -628
  24. package/src/core/db/__generated__/client/models/Account.js +1 -2
  25. package/src/core/db/__generated__/client/models/Address.d.ts +0 -701
  26. package/src/core/db/__generated__/client/models/Address.js +1 -2
  27. package/src/core/db/__generated__/client/models/Campaign.d.ts +0 -638
  28. package/src/core/db/__generated__/client/models/Campaign.js +1 -2
  29. package/src/core/db/__generated__/client/models/ClosingTimes.d.ts +0 -634
  30. package/src/core/db/__generated__/client/models/ClosingTimes.js +1 -2
  31. package/src/core/db/__generated__/client/models/File.d.ts +0 -752
  32. package/src/core/db/__generated__/client/models/File.js +1 -2
  33. package/src/core/db/__generated__/client/models/Invitation.d.ts +0 -628
  34. package/src/core/db/__generated__/client/models/Invitation.js +1 -2
  35. package/src/core/db/__generated__/client/models/LegalEntity.d.ts +0 -652
  36. package/src/core/db/__generated__/client/models/LegalEntity.js +1 -2
  37. package/src/core/db/__generated__/client/models/Manufacturer.d.ts +0 -679
  38. package/src/core/db/__generated__/client/models/Manufacturer.js +1 -2
  39. package/src/core/db/__generated__/client/models/ManufacturerTranslation.d.ts +0 -628
  40. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js +1 -2
  41. package/src/core/db/__generated__/client/models/Member.d.ts +0 -628
  42. package/src/core/db/__generated__/client/models/Member.js +1 -2
  43. package/src/core/db/__generated__/client/models/Modifier.d.ts +0 -662
  44. package/src/core/db/__generated__/client/models/Modifier.js +1 -2
  45. package/src/core/db/__generated__/client/models/ModifierGroup.d.ts +0 -686
  46. package/src/core/db/__generated__/client/models/ModifierGroup.js +1 -2
  47. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.d.ts +0 -628
  48. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js +1 -2
  49. package/src/core/db/__generated__/client/models/OpeningTimes.d.ts +0 -634
  50. package/src/core/db/__generated__/client/models/OpeningTimes.js +1 -2
  51. package/src/core/db/__generated__/client/models/Order.d.ts +0 -700
  52. package/src/core/db/__generated__/client/models/Order.js +1 -2
  53. package/src/core/db/__generated__/client/models/OrderItem.d.ts +0 -686
  54. package/src/core/db/__generated__/client/models/OrderItem.js +1 -2
  55. package/src/core/db/__generated__/client/models/OrderItemTranslation.d.ts +0 -628
  56. package/src/core/db/__generated__/client/models/OrderItemTranslation.js +1 -2
  57. package/src/core/db/__generated__/client/models/Organization.d.ts +0 -811
  58. package/src/core/db/__generated__/client/models/Organization.js +1 -2
  59. package/src/core/db/__generated__/client/models/OrganizationConfiguration.d.ts +0 -676
  60. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js +1 -2
  61. package/src/core/db/__generated__/client/models/Payment.d.ts +0 -668
  62. package/src/core/db/__generated__/client/models/Payment.js +1 -2
  63. package/src/core/db/__generated__/client/models/PaymentSession.d.ts +0 -638
  64. package/src/core/db/__generated__/client/models/PaymentSession.js +1 -2
  65. package/src/core/db/__generated__/client/models/Product.d.ts +0 -746
  66. package/src/core/db/__generated__/client/models/Product.js +1 -2
  67. package/src/core/db/__generated__/client/models/ProductCategory.d.ts +0 -689
  68. package/src/core/db/__generated__/client/models/ProductCategory.js +1 -2
  69. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.d.ts +0 -628
  70. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js +1 -2
  71. package/src/core/db/__generated__/client/models/ProductSnapshot.d.ts +0 -664
  72. package/src/core/db/__generated__/client/models/ProductSnapshot.js +1 -2
  73. package/src/core/db/__generated__/client/models/ProductTranslation.d.ts +0 -628
  74. package/src/core/db/__generated__/client/models/ProductTranslation.js +1 -2
  75. package/src/core/db/__generated__/client/models/Reservation.d.ts +0 -650
  76. package/src/core/db/__generated__/client/models/Reservation.js +1 -2
  77. package/src/core/db/__generated__/client/models/Session.d.ts +0 -628
  78. package/src/core/db/__generated__/client/models/Session.js +1 -2
  79. package/src/core/db/__generated__/client/models/ShippingMethod.d.ts +0 -679
  80. package/src/core/db/__generated__/client/models/ShippingMethod.js +1 -2
  81. package/src/core/db/__generated__/client/models/ShippingZone.d.ts +0 -638
  82. package/src/core/db/__generated__/client/models/ShippingZone.js +1 -2
  83. package/src/core/db/__generated__/client/models/User.d.ts +0 -736
  84. package/src/core/db/__generated__/client/models/User.js +1 -2
  85. package/src/core/db/__generated__/client/models/Verification.d.ts +0 -592
  86. package/src/core/db/__generated__/client/models/Verification.js +1 -2
  87. package/src/core/db/__generated__/client/models.js +1 -2
  88. package/src/core/db/index.js +1 -2
  89. package/src/core/exceptions/http-exception.js +1 -9
  90. package/src/core/hono/hono.js +1 -123
  91. package/src/core/lib/prisma.d.ts +9 -1
  92. package/src/core/lib/prisma.js +1 -11
  93. package/src/core/logging/pino.js +1 -5
  94. package/src/core/notifications/email.service.d.ts +0 -15
  95. package/src/core/notifications/email.service.js +1 -116
  96. package/src/core/openapi/openapi.lib.js +1 -26
  97. package/src/core/types/google-maps.types.js +1 -2
  98. package/src/core/utils/currency.util.js +1 -11
  99. package/src/core/utils/env.util.js +1 -8
  100. package/src/core/utils/object.util.d.ts +0 -10
  101. package/src/core/utils/object.util.js +1 -39
  102. package/src/core/utils/translations.util.js +0 -2
  103. package/src/core/utils/zod.util.d.ts +0 -12
  104. package/src/core/utils/zod.util.js +1 -85
  105. package/src/db.js +1 -3
  106. package/src/features/access/access.handler.js +1 -91
  107. package/src/features/access/access.route.js +1 -220
  108. package/src/features/access/access.schema.js +1 -108
  109. package/src/features/access/access.service.js +1 -294
  110. package/src/features/cart/cart.handler.js +1 -17
  111. package/src/features/cart/cart.route.js +1 -32
  112. package/src/features/cart/cart.schema.js +1 -39
  113. package/src/features/cart/cart.service.d.ts +0 -7
  114. package/src/features/cart/cart.service.js +1 -97
  115. package/src/features/cart/cart.util.js +1 -76
  116. package/src/features/file/file.handler.js +1 -23
  117. package/src/features/file/file.route.js +1 -34
  118. package/src/features/file/file.schema.js +1 -77
  119. package/src/features/file/file.service.d.ts +0 -6
  120. package/src/features/file/file.service.js +1 -66
  121. package/src/features/health/health.handler.js +1 -10
  122. package/src/features/health/health.route.js +1 -25
  123. package/src/features/index.js +1 -16
  124. package/src/features/location/location.handler.js +1 -25
  125. package/src/features/location/location.route.js +1 -56
  126. package/src/features/location/location.schema.js +1 -50
  127. package/src/features/location/location.service.d.ts +0 -3
  128. package/src/features/location/location.service.js +1 -141
  129. package/src/features/manufacturer/manufacturer.handler.js +1 -53
  130. package/src/features/manufacturer/manufacturer.route.js +1 -97
  131. package/src/features/manufacturer/manufacturer.schema.js +1 -125
  132. package/src/features/manufacturer/manufacturer.service.d.ts +0 -19
  133. package/src/features/manufacturer/manufacturer.service.js +1 -190
  134. package/src/features/order/emails/order-confirmation.email.js +1 -229
  135. package/src/features/order/emails/order-notification.email.js +1 -229
  136. package/src/features/order/fulfilment.schema.js +1 -3
  137. package/src/features/order/order.handler.js +1 -54
  138. package/src/features/order/order.route.js +1 -111
  139. package/src/features/order/order.schema.js +1 -158
  140. package/src/features/order/order.service.d.ts +0 -15
  141. package/src/features/order/order.service.js +1 -306
  142. package/src/features/order/recipient.schema.js +1 -38
  143. package/src/features/organization/legal-entity.schema.js +1 -83
  144. package/src/features/organization/organization-configuration.schema.js +1 -115
  145. package/src/features/organization/organization.handler.js +1 -48
  146. package/src/features/organization/organization.route.js +1 -84
  147. package/src/features/organization/organization.schema.js +1 -64
  148. package/src/features/organization/organization.service.d.ts +0 -15
  149. package/src/features/organization/organization.service.js +1 -334
  150. package/src/features/payment/payment.handler.js +1 -16
  151. package/src/features/payment/payment.route.js +1 -22
  152. package/src/features/payment/payment.schema.js +1 -46
  153. package/src/features/payment/payment.service.js +1 -100
  154. package/src/features/payment/stripe.service.js +1 -164
  155. package/src/features/product/product-modifier.schema.js +1 -84
  156. package/src/features/product/product.handler.js +1 -87
  157. package/src/features/product/product.route.js +1 -179
  158. package/src/features/product/product.schema.js +1 -143
  159. package/src/features/product/product.service.d.ts +0 -25
  160. package/src/features/product/product.service.js +1 -440
  161. package/src/features/product-category/product-category.handler.js +1 -59
  162. package/src/features/product-category/product-category.route.js +1 -139
  163. package/src/features/product-category/product-category.schema.js +1 -86
  164. package/src/features/product-category/product-category.service.d.ts +0 -22
  165. package/src/features/product-category/product-category.service.js +1 -220
  166. package/src/features/reservation/emails/reservation-cancellation.email.js +1 -82
  167. package/src/features/reservation/emails/reservation-confirmation.email.js +1 -82
  168. package/src/features/reservation/emails/reservation-notification.email.js +1 -93
  169. package/src/features/reservation/reservation.handler.js +1 -65
  170. package/src/features/reservation/reservation.route.js +1 -167
  171. package/src/features/reservation/reservation.schema.js +1 -51
  172. package/src/features/reservation/reservation.service.d.ts +0 -18
  173. package/src/features/reservation/reservation.service.js +1 -231
  174. package/src/features/shipping/shipping.handler.js +1 -32
  175. package/src/features/shipping/shipping.route.js +1 -51
  176. package/src/features/shipping/shipping.service.d.ts +0 -7
  177. package/src/features/shipping/shipping.service.js +1 -96
  178. package/src/features/shipping-method/shipping-method.handler.js +1 -60
  179. package/src/features/shipping-method/shipping-method.route.js +1 -144
  180. package/src/features/shipping-method/shipping-method.schema.js +1 -48
  181. package/src/features/shipping-method/shipping-method.service.d.ts +0 -25
  182. package/src/features/shipping-method/shipping-method.service.js +1 -229
  183. package/src/features/shipping-method/shipping-zone.schema.js +1 -31
  184. package/src/features/webhook/webhook.handler.js +1 -50
  185. package/src/features/webhook/webhook.route.js +1 -33
  186. package/src/index.js +1 -6
  187. package/src/integrations/next.js +1 -82
  188. package/src/schemas/address.schema.d.ts +0 -8
  189. package/src/schemas/address.schema.js +1 -112
  190. package/src/schemas/currency.schema.d.ts +0 -42
  191. package/src/schemas/currency.schema.js +1 -118
  192. package/src/schemas/error.schema.js +1 -12
  193. package/src/schemas/index.js +1 -29
  194. package/src/schemas/locales.schema.js +1 -238
  195. package/src/schemas/number.schema.js +1 -29
  196. package/src/schemas/pagination.schema.js +1 -54
  197. package/src/schemas/params.schema.js +1 -20
  198. package/src/schemas/queries.schema.js +1 -6
  199. package/src/test/global-setup.d.ts +1 -0
  200. package/src/test/global-setup.js +1 -0
  201. package/src/test/integration/api-fixtures.d.ts +4 -16
  202. package/src/test/integration/api-fixtures.js +1 -225
  203. package/src/test/integration/seed.d.ts +81 -0
  204. package/src/test/integration/seed.js +1 -0
  205. package/src/test/integration/test-helpers.d.ts +107 -924
  206. package/src/test/integration/test-helpers.js +1 -1100
  207. package/src/test/setup-test-env.d.ts +1 -1
  208. package/src/test/setup-test-env.js +1 -29
  209. package/src/app.js.map +0 -1
  210. package/src/core/auth/auth.schema.js.map +0 -1
  211. package/src/core/auth/auth.util.js.map +0 -1
  212. package/src/core/auth/better-auth.lib.js.map +0 -1
  213. package/src/core/auth/generate-password-hash.util.js.map +0 -1
  214. package/src/core/auth/headers.schema.js.map +0 -1
  215. package/src/core/auth/user.schema.js.map +0 -1
  216. package/src/core/db/__generated__/client/browser.js.map +0 -1
  217. package/src/core/db/__generated__/client/client.js.map +0 -1
  218. package/src/core/db/__generated__/client/commonInputTypes.js.map +0 -1
  219. package/src/core/db/__generated__/client/enums.js.map +0 -1
  220. package/src/core/db/__generated__/client/internal/class.js.map +0 -1
  221. package/src/core/db/__generated__/client/internal/prismaNamespace.js.map +0 -1
  222. package/src/core/db/__generated__/client/internal/prismaNamespaceBrowser.js.map +0 -1
  223. package/src/core/db/__generated__/client/models/Account.js.map +0 -1
  224. package/src/core/db/__generated__/client/models/Address.js.map +0 -1
  225. package/src/core/db/__generated__/client/models/Campaign.js.map +0 -1
  226. package/src/core/db/__generated__/client/models/ClosingTimes.js.map +0 -1
  227. package/src/core/db/__generated__/client/models/File.js.map +0 -1
  228. package/src/core/db/__generated__/client/models/Invitation.js.map +0 -1
  229. package/src/core/db/__generated__/client/models/LegalEntity.js.map +0 -1
  230. package/src/core/db/__generated__/client/models/Manufacturer.js.map +0 -1
  231. package/src/core/db/__generated__/client/models/ManufacturerTranslation.js.map +0 -1
  232. package/src/core/db/__generated__/client/models/Member.js.map +0 -1
  233. package/src/core/db/__generated__/client/models/Modifier.js.map +0 -1
  234. package/src/core/db/__generated__/client/models/ModifierGroup.js.map +0 -1
  235. package/src/core/db/__generated__/client/models/ModifierGroupTranslation.js.map +0 -1
  236. package/src/core/db/__generated__/client/models/OpeningTimes.js.map +0 -1
  237. package/src/core/db/__generated__/client/models/Order.js.map +0 -1
  238. package/src/core/db/__generated__/client/models/OrderItem.js.map +0 -1
  239. package/src/core/db/__generated__/client/models/OrderItemTranslation.js.map +0 -1
  240. package/src/core/db/__generated__/client/models/Organization.js.map +0 -1
  241. package/src/core/db/__generated__/client/models/OrganizationConfiguration.js.map +0 -1
  242. package/src/core/db/__generated__/client/models/Payment.js.map +0 -1
  243. package/src/core/db/__generated__/client/models/PaymentSession.js.map +0 -1
  244. package/src/core/db/__generated__/client/models/Product.js.map +0 -1
  245. package/src/core/db/__generated__/client/models/ProductCategory.js.map +0 -1
  246. package/src/core/db/__generated__/client/models/ProductCategoryTranslation.js.map +0 -1
  247. package/src/core/db/__generated__/client/models/ProductSnapshot.js.map +0 -1
  248. package/src/core/db/__generated__/client/models/ProductTranslation.js.map +0 -1
  249. package/src/core/db/__generated__/client/models/Reservation.js.map +0 -1
  250. package/src/core/db/__generated__/client/models/Session.js.map +0 -1
  251. package/src/core/db/__generated__/client/models/ShippingMethod.js.map +0 -1
  252. package/src/core/db/__generated__/client/models/ShippingZone.js.map +0 -1
  253. package/src/core/db/__generated__/client/models/User.js.map +0 -1
  254. package/src/core/db/__generated__/client/models/Verification.js.map +0 -1
  255. package/src/core/db/__generated__/client/models.js.map +0 -1
  256. package/src/core/db/index.js.map +0 -1
  257. package/src/core/exceptions/http-exception.js.map +0 -1
  258. package/src/core/hono/hono.js.map +0 -1
  259. package/src/core/lib/prisma.js.map +0 -1
  260. package/src/core/logging/pino.js.map +0 -1
  261. package/src/core/notifications/email.service.js.map +0 -1
  262. package/src/core/openapi/openapi.lib.js.map +0 -1
  263. package/src/core/types/google-maps.types.js.map +0 -1
  264. package/src/core/utils/currency.util.js.map +0 -1
  265. package/src/core/utils/env.util.js.map +0 -1
  266. package/src/core/utils/object.util.js.map +0 -1
  267. package/src/core/utils/translations.util.js.map +0 -1
  268. package/src/core/utils/zod.util.js.map +0 -1
  269. package/src/db.js.map +0 -1
  270. package/src/features/access/access.handler.js.map +0 -1
  271. package/src/features/access/access.route.js.map +0 -1
  272. package/src/features/access/access.schema.js.map +0 -1
  273. package/src/features/access/access.service.js.map +0 -1
  274. package/src/features/cart/cart.handler.js.map +0 -1
  275. package/src/features/cart/cart.route.js.map +0 -1
  276. package/src/features/cart/cart.schema.js.map +0 -1
  277. package/src/features/cart/cart.service.js.map +0 -1
  278. package/src/features/cart/cart.util.js.map +0 -1
  279. package/src/features/file/file.handler.js.map +0 -1
  280. package/src/features/file/file.route.js.map +0 -1
  281. package/src/features/file/file.schema.js.map +0 -1
  282. package/src/features/file/file.service.js.map +0 -1
  283. package/src/features/health/health.handler.js.map +0 -1
  284. package/src/features/health/health.route.js.map +0 -1
  285. package/src/features/index.js.map +0 -1
  286. package/src/features/location/location.handler.js.map +0 -1
  287. package/src/features/location/location.route.js.map +0 -1
  288. package/src/features/location/location.schema.js.map +0 -1
  289. package/src/features/location/location.service.js.map +0 -1
  290. package/src/features/manufacturer/manufacturer.handler.js.map +0 -1
  291. package/src/features/manufacturer/manufacturer.route.js.map +0 -1
  292. package/src/features/manufacturer/manufacturer.schema.js.map +0 -1
  293. package/src/features/manufacturer/manufacturer.service.js.map +0 -1
  294. package/src/features/order/emails/order-confirmation.email.js.map +0 -1
  295. package/src/features/order/emails/order-notification.email.js.map +0 -1
  296. package/src/features/order/fulfilment.schema.js.map +0 -1
  297. package/src/features/order/order.handler.js.map +0 -1
  298. package/src/features/order/order.route.js.map +0 -1
  299. package/src/features/order/order.schema.js.map +0 -1
  300. package/src/features/order/order.service.js.map +0 -1
  301. package/src/features/order/recipient.schema.js.map +0 -1
  302. package/src/features/organization/legal-entity.schema.js.map +0 -1
  303. package/src/features/organization/organization-configuration.schema.js.map +0 -1
  304. package/src/features/organization/organization.handler.js.map +0 -1
  305. package/src/features/organization/organization.route.js.map +0 -1
  306. package/src/features/organization/organization.schema.js.map +0 -1
  307. package/src/features/organization/organization.service.js.map +0 -1
  308. package/src/features/payment/payment.handler.js.map +0 -1
  309. package/src/features/payment/payment.route.js.map +0 -1
  310. package/src/features/payment/payment.schema.js.map +0 -1
  311. package/src/features/payment/payment.service.js.map +0 -1
  312. package/src/features/payment/stripe.service.js.map +0 -1
  313. package/src/features/product/product-modifier.schema.js.map +0 -1
  314. package/src/features/product/product.handler.js.map +0 -1
  315. package/src/features/product/product.route.js.map +0 -1
  316. package/src/features/product/product.schema.js.map +0 -1
  317. package/src/features/product/product.service.js.map +0 -1
  318. package/src/features/product-category/product-category.handler.js.map +0 -1
  319. package/src/features/product-category/product-category.route.js.map +0 -1
  320. package/src/features/product-category/product-category.schema.js.map +0 -1
  321. package/src/features/product-category/product-category.service.js.map +0 -1
  322. package/src/features/reservation/emails/reservation-cancellation.email.js.map +0 -1
  323. package/src/features/reservation/emails/reservation-confirmation.email.js.map +0 -1
  324. package/src/features/reservation/emails/reservation-notification.email.js.map +0 -1
  325. package/src/features/reservation/reservation.handler.js.map +0 -1
  326. package/src/features/reservation/reservation.route.js.map +0 -1
  327. package/src/features/reservation/reservation.schema.js.map +0 -1
  328. package/src/features/reservation/reservation.service.js.map +0 -1
  329. package/src/features/shipping/shipping.handler.js.map +0 -1
  330. package/src/features/shipping/shipping.route.js.map +0 -1
  331. package/src/features/shipping/shipping.service.js.map +0 -1
  332. package/src/features/shipping-method/shipping-method.handler.js.map +0 -1
  333. package/src/features/shipping-method/shipping-method.route.js.map +0 -1
  334. package/src/features/shipping-method/shipping-method.schema.js.map +0 -1
  335. package/src/features/shipping-method/shipping-method.service.js.map +0 -1
  336. package/src/features/shipping-method/shipping-zone.schema.js.map +0 -1
  337. package/src/features/webhook/webhook.handler.js.map +0 -1
  338. package/src/features/webhook/webhook.route.js.map +0 -1
  339. package/src/index.js.map +0 -1
  340. package/src/integrations/next.js.map +0 -1
  341. package/src/schemas/address.schema.js.map +0 -1
  342. package/src/schemas/currency.schema.js.map +0 -1
  343. package/src/schemas/error.schema.js.map +0 -1
  344. package/src/schemas/index.js.map +0 -1
  345. package/src/schemas/locales.schema.js.map +0 -1
  346. package/src/schemas/number.schema.js.map +0 -1
  347. package/src/schemas/pagination.schema.js.map +0 -1
  348. package/src/schemas/params.schema.js.map +0 -1
  349. package/src/schemas/queries.schema.js.map +0 -1
  350. package/src/test/integration/api-fixtures.js.map +0 -1
  351. package/src/test/integration/test-helpers.js.map +0 -1
  352. package/src/test/setup-test-env.js.map +0 -1
@@ -1,294 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { z } from "@hono/zod-openapi";
3
- import { HttpException } from "../../core/exceptions/http-exception";
4
- import { PaginationMetaSchema } from "../../schemas";
5
- import { InvitationSchema, MemberSchema, UserInvitationSchema, } from "./access.schema";
6
- class AccessService {
7
- constructor(prisma) {
8
- this.prisma = prisma;
9
- }
10
- getMembers(organizationId, query) {
11
- return __awaiter(this, void 0, void 0, function* () {
12
- const { page = 1, limit = 10, search } = query;
13
- const [list, meta] = yield this.prisma.member
14
- .paginate({
15
- orderBy: { createdAt: "desc" },
16
- where: Object.assign({ organizationId }, (search && {
17
- user: {
18
- OR: [
19
- { firstname: { contains: search, mode: "insensitive" } },
20
- { lastname: { contains: search, mode: "insensitive" } },
21
- { email: { contains: search, mode: "insensitive" } },
22
- ],
23
- },
24
- })),
25
- include: {
26
- user: {
27
- select: {
28
- id: true,
29
- firstname: true,
30
- lastname: true,
31
- email: true,
32
- image: true,
33
- },
34
- },
35
- },
36
- })
37
- .withPages({ page, limit });
38
- return z
39
- .object({
40
- meta: PaginationMetaSchema,
41
- list: z.array(MemberSchema),
42
- })
43
- .parse({ meta, list });
44
- });
45
- }
46
- getMember(organizationId, memberId) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const member = yield this.prisma.member.findUnique({
49
- where: { id: memberId, organizationId },
50
- include: {
51
- user: {
52
- select: {
53
- id: true,
54
- firstname: true,
55
- lastname: true,
56
- email: true,
57
- image: true,
58
- },
59
- },
60
- },
61
- });
62
- if (!member) {
63
- throw new HttpException(404, "Member not found");
64
- }
65
- return MemberSchema.parse(member);
66
- });
67
- }
68
- updateMemberRole(organizationId, memberId, currentUserId, body) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const member = yield this.prisma.member.findUnique({
71
- where: { id: memberId, organizationId },
72
- include: { user: { select: { id: true, firstname: true, lastname: true, email: true, image: true } } },
73
- });
74
- if (!member) {
75
- throw new HttpException(404, "Member not found");
76
- }
77
- // Prevent demotion of the last owner
78
- if (member.role === "owner" && body.role !== "owner") {
79
- const ownerCount = yield this.prisma.member.count({
80
- where: { organizationId, role: "owner" },
81
- });
82
- if (ownerCount <= 1) {
83
- throw new HttpException(400, "Cannot change the role of the last owner. Promote another member to owner first.");
84
- }
85
- }
86
- const updated = yield this.prisma.member.update({
87
- where: { id: memberId, organizationId },
88
- data: { role: body.role },
89
- include: {
90
- user: {
91
- select: {
92
- id: true,
93
- firstname: true,
94
- lastname: true,
95
- email: true,
96
- image: true,
97
- },
98
- },
99
- },
100
- });
101
- return MemberSchema.parse(updated);
102
- });
103
- }
104
- deleteMember(organizationId, memberId, currentUserId) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const member = yield this.prisma.member.findUnique({
107
- where: { id: memberId, organizationId },
108
- });
109
- if (!member) {
110
- throw new HttpException(404, "Member not found");
111
- }
112
- // Prevent self-removal
113
- if (member.userId === currentUserId) {
114
- throw new HttpException(400, "You cannot remove yourself from the organization");
115
- }
116
- // Prevent removal of the last owner
117
- if (member.role === "owner") {
118
- const ownerCount = yield this.prisma.member.count({
119
- where: { organizationId, role: "owner" },
120
- });
121
- if (ownerCount <= 1) {
122
- throw new HttpException(400, "Cannot remove the last owner. Transfer ownership first.");
123
- }
124
- }
125
- yield this.prisma.member.delete({
126
- where: { id: memberId, organizationId },
127
- });
128
- });
129
- }
130
- leaveOrganization(organizationId, userId) {
131
- return __awaiter(this, void 0, void 0, function* () {
132
- const member = yield this.prisma.member.findFirst({
133
- where: { organizationId, userId },
134
- });
135
- if (!member) {
136
- throw new HttpException(404, "You are not a member of this organization");
137
- }
138
- if (member.role === "owner") {
139
- const ownerCount = yield this.prisma.member.count({
140
- where: { organizationId, role: "owner" },
141
- });
142
- if (ownerCount <= 1) {
143
- throw new HttpException(400, "Cannot leave as the last owner. Transfer ownership first.");
144
- }
145
- }
146
- yield this.prisma.member.delete({
147
- where: { id: member.id, organizationId },
148
- });
149
- });
150
- }
151
- createInvitation(organizationId, inviterId, body) {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- // Check for duplicate active invitation
154
- const existing = yield this.prisma.invitation.findFirst({
155
- where: {
156
- organizationId,
157
- email: body.email,
158
- status: "pending",
159
- expiresAt: { gt: new Date() },
160
- },
161
- });
162
- if (existing) {
163
- throw new HttpException(400, "An active invitation already exists for this email address");
164
- }
165
- // Check if user is already a member
166
- const existingMember = yield this.prisma.member.findFirst({
167
- where: {
168
- organizationId,
169
- user: { email: body.email },
170
- },
171
- });
172
- if (existingMember) {
173
- throw new HttpException(400, "This user is already a member of the organization");
174
- }
175
- const invitation = yield this.prisma.invitation.create({
176
- data: {
177
- id: crypto.randomUUID(),
178
- organizationId,
179
- email: body.email,
180
- role: body.role,
181
- status: "pending",
182
- inviterId,
183
- expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days
184
- },
185
- });
186
- return InvitationSchema.parse(invitation);
187
- });
188
- }
189
- getInvitations(organizationId) {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- const invitations = yield this.prisma.invitation.findMany({
192
- where: {
193
- organizationId,
194
- status: "pending",
195
- },
196
- orderBy: { expiresAt: "desc" },
197
- });
198
- return z.array(InvitationSchema).parse(invitations);
199
- });
200
- }
201
- deleteInvitation(organizationId, invitationId) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- const invitation = yield this.prisma.invitation.findUnique({
204
- where: { id: invitationId, organizationId },
205
- });
206
- if (!invitation) {
207
- throw new HttpException(404, "Invitation not found");
208
- }
209
- if (invitation.status !== "pending") {
210
- throw new HttpException(400, "Only pending invitations can be revoked");
211
- }
212
- yield this.prisma.invitation.delete({
213
- where: { id: invitationId },
214
- });
215
- });
216
- }
217
- getUserInvitations(email) {
218
- return __awaiter(this, void 0, void 0, function* () {
219
- const invitations = yield this.prisma.invitation.findMany({
220
- where: {
221
- email,
222
- status: "pending",
223
- expiresAt: { gt: new Date() },
224
- },
225
- include: {
226
- organization: {
227
- select: { id: true, name: true },
228
- },
229
- },
230
- orderBy: { expiresAt: "desc" },
231
- });
232
- return z.array(UserInvitationSchema).parse(invitations);
233
- });
234
- }
235
- acceptInvitation(invitationId, userId) {
236
- return __awaiter(this, void 0, void 0, function* () {
237
- var _a;
238
- const invitation = yield this.prisma.invitation.findUnique({
239
- where: { id: invitationId },
240
- });
241
- if (!invitation) {
242
- throw new HttpException(404, "Invitation not found");
243
- }
244
- if (invitation.status !== "pending") {
245
- throw new HttpException(400, "Invitation is no longer pending");
246
- }
247
- if (invitation.expiresAt < new Date()) {
248
- throw new HttpException(400, "Invitation has expired");
249
- }
250
- const user = yield this.prisma.user.findUnique({
251
- where: { id: userId },
252
- });
253
- if (!user || user.email !== invitation.email) {
254
- throw new HttpException(400, "Invitation does not belong to this user");
255
- }
256
- const existingMember = yield this.prisma.member.findFirst({
257
- where: {
258
- organizationId: invitation.organizationId,
259
- userId,
260
- },
261
- });
262
- if (existingMember) {
263
- throw new HttpException(400, "You are already a member of this organization");
264
- }
265
- const [member] = yield this.prisma.$transaction([
266
- this.prisma.member.create({
267
- data: {
268
- organizationId: invitation.organizationId,
269
- userId,
270
- role: (_a = invitation.role) !== null && _a !== void 0 ? _a : "member",
271
- },
272
- include: {
273
- user: {
274
- select: {
275
- id: true,
276
- firstname: true,
277
- lastname: true,
278
- email: true,
279
- image: true,
280
- },
281
- },
282
- },
283
- }),
284
- this.prisma.invitation.update({
285
- where: { id: invitationId },
286
- data: { status: "accepted" },
287
- }),
288
- ]);
289
- return MemberSchema.parse(member);
290
- });
291
- }
292
- }
293
- export { AccessService };
294
- //# sourceMappingURL=access.service.js.map
1
+ import{__awaiter as e}from"tslib";import{z as i}from"@hono/zod-openapi";import{HttpException as t}from"../../core/exceptions/http-exception";import{PaginationMetaSchema as n}from"../../schemas";import{InvitationSchema as r,MemberSchema as o,UserInvitationSchema as a}from"./access.schema";class s{constructor(e){this.prisma=e}getMembers(t,r){return e(this,void 0,void 0,function*(){const{page:e=1,limit:a=10,search:s}=r,[d,m]=yield this.prisma.member.paginate({orderBy:{createdAt:"desc"},where:Object.assign({organizationId:t},s&&{user:{OR:[{firstname:{contains:s,mode:"insensitive"}},{lastname:{contains:s,mode:"insensitive"}},{email:{contains:s,mode:"insensitive"}}]}}),include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}}).withPages({page:e,limit:a});return i.object({meta:n,list:i.array(o)}).parse({meta:m,list:d})})}getMember(i,n){return e(this,void 0,void 0,function*(){const e=yield this.prisma.member.findUnique({where:{id:n,organizationId:i},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}});if(!e)throw new t(404,"Member not found");return o.parse(e)})}updateMemberRole(i,n,r,a){return e(this,void 0,void 0,function*(){const e=yield this.prisma.member.findUnique({where:{id:n,organizationId:i},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}});if(!e)throw new t(404,"Member not found");if("owner"===e.role&&"owner"!==a.role&&(yield this.prisma.member.count({where:{organizationId:i,role:"owner"}}))<=1)throw new t(400,"Cannot change the role of the last owner. Promote another member to owner first.");const r=yield this.prisma.member.update({where:{id:n,organizationId:i},data:{role:a.role},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}});return o.parse(r)})}deleteMember(i,n,r){return e(this,void 0,void 0,function*(){const e=yield this.prisma.member.findUnique({where:{id:n,organizationId:i}});if(!e)throw new t(404,"Member not found");if(e.userId===r)throw new t(400,"You cannot remove yourself from the organization");if("owner"===e.role&&(yield this.prisma.member.count({where:{organizationId:i,role:"owner"}}))<=1)throw new t(400,"Cannot remove the last owner. Transfer ownership first.");yield this.prisma.member.delete({where:{id:n,organizationId:i}})})}leaveOrganization(i,n){return e(this,void 0,void 0,function*(){const e=yield this.prisma.member.findFirst({where:{organizationId:i,userId:n}});if(!e)throw new t(404,"You are not a member of this organization");if("owner"===e.role&&(yield this.prisma.member.count({where:{organizationId:i,role:"owner"}}))<=1)throw new t(400,"Cannot leave as the last owner. Transfer ownership first.");yield this.prisma.member.delete({where:{id:e.id,organizationId:i}})})}createInvitation(i,n,o){return e(this,void 0,void 0,function*(){if(yield this.prisma.invitation.findFirst({where:{organizationId:i,email:o.email,status:"pending",expiresAt:{gt:new Date}}}))throw new t(400,"An active invitation already exists for this email address");if(yield this.prisma.member.findFirst({where:{organizationId:i,user:{email:o.email}}}))throw new t(400,"This user is already a member of the organization");const e=yield this.prisma.invitation.create({data:{id:crypto.randomUUID(),organizationId:i,email:o.email,role:o.role,status:"pending",inviterId:n,expiresAt:new Date(Date.now()+6048e5)}});return r.parse(e)})}getInvitations(t){return e(this,void 0,void 0,function*(){const e=yield this.prisma.invitation.findMany({where:{organizationId:t,status:"pending"},orderBy:{expiresAt:"desc"}});return i.array(r).parse(e)})}deleteInvitation(i,n){return e(this,void 0,void 0,function*(){const e=yield this.prisma.invitation.findUnique({where:{id:n,organizationId:i}});if(!e)throw new t(404,"Invitation not found");if("pending"!==e.status)throw new t(400,"Only pending invitations can be revoked");yield this.prisma.invitation.delete({where:{id:n}})})}getUserInvitations(t){return e(this,void 0,void 0,function*(){const e=yield this.prisma.invitation.findMany({where:{email:t,status:"pending",expiresAt:{gt:new Date}},include:{organization:{select:{id:!0,name:!0}}},orderBy:{expiresAt:"desc"}});return i.array(a).parse(e)})}acceptInvitation(i,n){return e(this,void 0,void 0,function*(){var e;const r=yield this.prisma.invitation.findUnique({where:{id:i}});if(!r)throw new t(404,"Invitation not found");if("pending"!==r.status)throw new t(400,"Invitation is no longer pending");if(r.expiresAt<new Date)throw new t(400,"Invitation has expired");const a=yield this.prisma.user.findUnique({where:{id:n}});if(!a||a.email!==r.email)throw new t(400,"Invitation does not belong to this user");if(yield this.prisma.member.findFirst({where:{organizationId:r.organizationId,userId:n}}))throw new t(400,"You are already a member of this organization");const[s]=yield this.prisma.$transaction([this.prisma.member.create({data:{organizationId:r.organizationId,userId:n,role:null!==(e=r.role)&&void 0!==e?e:"member"},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}}),this.prisma.invitation.update({where:{id:i},data:{status:"accepted"}})]);return o.parse(s)})}}export{s as AccessService};
@@ -1,17 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { createApiRouter } from "../../core/hono/hono";
3
- import { cartRoute } from "./cart.route";
4
- import { CartService } from "./cart.service";
5
- export const buildCartHandler = (prisma) => {
6
- const app = createApiRouter();
7
- app.openapi(cartRoute.getCartData, (c) => __awaiter(void 0, void 0, void 0, function* () {
8
- const params = c.req.valid("param");
9
- const body = c.req.valid("json");
10
- const query = c.req.valid("query");
11
- const service = new CartService(prisma);
12
- const productMapping = yield service.getCartData(params.organizationId, body, query);
13
- return c.json(productMapping, 200);
14
- }));
15
- return app;
16
- };
17
- //# sourceMappingURL=cart.handler.js.map
1
+ import{__awaiter as r}from"tslib";import{createApiRouter as o}from"../../core/hono/hono";import{cartRoute as t}from"./cart.route";import{CartService as a}from"./cart.service";export const buildCartHandler=i=>{const e=o();return e.openapi(t.getCartData,o=>r(void 0,void 0,void 0,function*(){const r=o.req.valid("param"),t=o.req.valid("json"),e=o.req.valid("query"),n=new a(i),d=yield n.getCartData(r.organizationId,t,e);return o.json(d,200)})),e};
@@ -1,32 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- import { createApiRoute } from "../../core/hono/hono";
3
- import { CartProductsMappingSchema, CartSchema, ErrorSchema, HeaderSchema, locale, OrganizationParams, } from "../../schemas";
4
- const getCartDataRoute = createApiRoute({
5
- body: CartSchema,
6
- description: "Fetches formatted cart data",
7
- headers: HeaderSchema,
8
- method: "POST",
9
- operationId: "getCartData",
10
- path: "/:organizationId/cart",
11
- pathParams: OrganizationParams,
12
- query: z.object({
13
- locale: locale.default("en"),
14
- }),
15
- responses: {
16
- 200: z.object({
17
- invalidProductIds: z.array(z.string()),
18
- products: CartProductsMappingSchema,
19
- shipping: z.number().optional(),
20
- subtotal: z.number(),
21
- total: z.number(),
22
- }),
23
- 400: ErrorSchema,
24
- 401: ErrorSchema,
25
- },
26
- summary: "Get Formatted Cart",
27
- tags: ["Cart"],
28
- });
29
- export const cartRoute = {
30
- getCartData: getCartDataRoute,
31
- };
32
- //# sourceMappingURL=cart.route.js.map
1
+ import{z as t}from"@hono/zod-openapi";import{createApiRoute as o}from"../../core/hono/hono";import{CartProductsMappingSchema as a,CartSchema as r,ErrorSchema as e,HeaderSchema as n,locale as s,OrganizationParams as m}from"../../schemas";const d=o({body:r,description:"Fetches formatted cart data",headers:n,method:"POST",operationId:"getCartData",path:"/:organizationId/cart",pathParams:m,query:t.object({locale:s.default("en")}),responses:{200:t.object({invalidProductIds:t.array(t.string()),products:a,shipping:t.number().optional(),subtotal:t.number(),total:t.number()}),400:e,401:e},summary:"Get Formatted Cart",tags:["Cart"]});export const cartRoute={getCartData:d};
@@ -1,39 +1 @@
1
- import { z } from "@hono/zod-openapi";
2
- import { LocalizedProductSchema } from "../product/product.schema";
3
- export const CartProductsMappingSchema = z.record(z.string().openapi({
4
- example: "clf9876543210abcdef",
5
- description: "ID of the product in the cart",
6
- }), LocalizedProductSchema);
7
- export const CartItemSchema = z
8
- .object({
9
- productId: z.string().cuid().openapi({
10
- example: "clf9876543210abcdef",
11
- description: "ID of the product in the cart",
12
- }),
13
- quantity: z.number().default(1).optional().openapi({
14
- example: 2,
15
- description: "Quantity of this item in the cart",
16
- }),
17
- modifierGroups: z.array(z.object({
18
- id: z.string().cuid().openapi({
19
- example: "clg1234567890abcdef",
20
- description: "ID of the modifier group",
21
- }),
22
- modifiers: z.array(z.object({
23
- id: z.string().cuid().openapi({
24
- example: "clh9876543210abcdef",
25
- description: "ID of the selected modifier",
26
- }),
27
- quantity: z.number().default(1).openapi({
28
- example: 1,
29
- description: "Quantity of this modifier",
30
- }),
31
- })),
32
- })),
33
- })
34
- .openapi("CartItem");
35
- export const CartSchema = z.object({
36
- items: z.array(CartItemSchema),
37
- shippingMethodId: z.string().cuid().optional(),
38
- });
39
- //# sourceMappingURL=cart.schema.js.map
1
+ import{z as e}from"@hono/zod-openapi";import{LocalizedProductSchema as t}from"../product/product.schema";export const CartProductsMappingSchema=e.record(e.string().openapi({example:"clf9876543210abcdef",description:"ID of the product in the cart"}),t);export const CartItemSchema=e.object({productId:e.string().cuid().openapi({example:"clf9876543210abcdef",description:"ID of the product in the cart"}),quantity:e.number().default(1).optional().openapi({example:2,description:"Quantity of this item in the cart"}),modifierGroups:e.array(e.object({id:e.string().cuid().openapi({example:"clg1234567890abcdef",description:"ID of the modifier group"}),modifiers:e.array(e.object({id:e.string().cuid().openapi({example:"clh9876543210abcdef",description:"ID of the selected modifier"}),quantity:e.number().default(1).openapi({example:1,description:"Quantity of this modifier"})}))}))}).openapi("CartItem");export const CartSchema=e.object({items:e.array(CartItemSchema),shippingMethodId:e.string().cuid().optional()});
@@ -4,14 +4,7 @@ import { CartSchema } from "../../schemas";
4
4
  declare class CartService {
5
5
  private readonly prisma;
6
6
  constructor(prisma: PrismaClientType);
7
- /**
8
- * Calculate price breakdown for cart items
9
- */
10
7
  private calculatePriceBreakdown;
11
- /**
12
- * Get product mapping for cart items
13
- * This method takes cart items and returns a mapping of product IDs to localized product data
14
- */
15
8
  getCartData(organizationId: string, body: z.infer<typeof CartSchema>, query: {
16
9
  locale?: string;
17
10
  }): Promise<{
@@ -1,97 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { flattenTranslationData } from "../../core/utils/zod.util";
3
- import { LocalizedProductSchema, } from "../../schemas";
4
- class CartService {
5
- constructor(prisma) {
6
- this.prisma = prisma;
7
- }
8
- /**
9
- * Calculate price breakdown for cart items
10
- */
11
- calculatePriceBreakdown(items, products, shippingMethodId) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- var _a, _b;
14
- const shippingMethod = shippingMethodId
15
- ? yield this.prisma.shippingMethod.findUnique({
16
- where: {
17
- id: shippingMethodId,
18
- },
19
- include: {
20
- shippingZones: true,
21
- },
22
- })
23
- : null;
24
- const subtotal = items.reduce((total, item) => {
25
- var _a, _b;
26
- const product = products.find((p) => p.id === item.productId);
27
- if (!product)
28
- return total;
29
- const price = (_b = (_a = product.discountedBasePrice) !== null && _a !== void 0 ? _a : product.basePrice) !== null && _b !== void 0 ? _b : 0;
30
- return total + price * (item.quantity || 1);
31
- }, 0);
32
- const shipping = (_a = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _a === void 0 ? void 0 : _a.price;
33
- const total = subtotal + (shipping !== null && shipping !== void 0 ? shipping : 0);
34
- return {
35
- total,
36
- subtotal,
37
- shipping: (_b = shippingMethod === null || shippingMethod === void 0 ? void 0 : shippingMethod.shippingZones[0]) === null || _b === void 0 ? void 0 : _b.price,
38
- };
39
- });
40
- }
41
- /**
42
- * Get product mapping for cart items
43
- * This method takes cart items and returns a mapping of product IDs to localized product data
44
- */
45
- getCartData(organizationId, body, query) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const { locale } = query;
48
- const productIds = new Set(body.items.map((item) => item.productId));
49
- const products = yield this.prisma.product.findMany({
50
- where: {
51
- id: { in: Array.from(productIds) },
52
- organizationId,
53
- deletedAt: null,
54
- publishedAt: {
55
- not: null,
56
- },
57
- },
58
- include: {
59
- translations: true,
60
- images: true,
61
- categories: {
62
- include: {
63
- translations: {
64
- where: {
65
- locale,
66
- },
67
- },
68
- },
69
- },
70
- modifierGroups: {
71
- include: {
72
- translations: {
73
- where: {
74
- locale,
75
- },
76
- },
77
- modifiers: true,
78
- },
79
- },
80
- },
81
- });
82
- const invalidProductIds = body.items
83
- .filter((item) => {
84
- const product = products.find((p) => p.id === item.productId);
85
- return !product;
86
- })
87
- .map((item) => item.productId);
88
- const paymentBreakdown = yield this.calculatePriceBreakdown(body.items, products, body.shippingMethodId);
89
- return Object.assign(Object.assign({}, paymentBreakdown), { invalidProductIds, products: products.reduce((acc, product) => {
90
- acc[product.id] = LocalizedProductSchema.parse(flattenTranslationData(product));
91
- return acc;
92
- }, {}) });
93
- });
94
- }
95
- }
96
- export { CartService };
97
- //# sourceMappingURL=cart.service.js.map
1
+ import{__awaiter as i}from"tslib";import{flattenTranslationData as e}from"../../core/utils/zod.util";import{LocalizedProductSchema as t}from"../../schemas";class n{constructor(i){this.prisma=i}calculatePriceBreakdown(e,t,n){return i(this,void 0,void 0,function*(){var i,r;const o=n?yield this.prisma.shippingMethod.findUnique({where:{id:n},include:{shippingZones:!0}}):null,d=e.reduce((i,e)=>{var n,r;const o=t.find(i=>i.id===e.productId);return o?i+(null!==(r=null!==(n=o.discountedBasePrice)&&void 0!==n?n:o.basePrice)&&void 0!==r?r:0)*(e.quantity||1):i},0),s=null===(i=null==o?void 0:o.shippingZones[0])||void 0===i?void 0:i.price;return{total:d+(null!=s?s:0),subtotal:d,shipping:null===(r=null==o?void 0:o.shippingZones[0])||void 0===r?void 0:r.price}})}getCartData(n,r,o){return i(this,void 0,void 0,function*(){const{locale:i}=o,d=new Set(r.items.map(i=>i.productId)),s=yield this.prisma.product.findMany({where:{id:{in:Array.from(d)},organizationId:n,deletedAt:null,publishedAt:{not:null}},include:{translations:!0,images:!0,categories:{include:{translations:{where:{locale:i}}}},modifierGroups:{include:{translations:{where:{locale:i}},modifiers:!0}}}}),l=r.items.filter(i=>!s.find(e=>e.id===i.productId)).map(i=>i.productId),a=yield this.calculatePriceBreakdown(r.items,s,r.shippingMethodId);return Object.assign(Object.assign({},a),{invalidProductIds:l,products:s.reduce((i,n)=>(i[n.id]=t.parse(e(n)),i),{})})})}}export{n as CartService};
@@ -1,76 +1 @@
1
- import { __awaiter } from "tslib";
2
- export const transformCartItemToOrderItem = (prisma) => (item) => __awaiter(void 0, void 0, void 0, function* () {
3
- // Fetch the product with all necessary relations
4
- const product = yield prisma.product.findUnique({
5
- where: { id: item.productId },
6
- include: {
7
- translations: true,
8
- modifierGroups: {
9
- include: {
10
- translations: true,
11
- modifiers: true,
12
- },
13
- },
14
- images: true,
15
- },
16
- });
17
- if (!product) {
18
- throw new Error(`Product with ID ${item.productId} not found`);
19
- }
20
- const image = product.images[0];
21
- // Calculate the unit price (base price + modifiers)
22
- let unitPrice = product.basePrice;
23
- // Generate translations with title from product and subtitle from modifiers
24
- const translations = product.translations.map((translation) => {
25
- // Find all selected modifiers for this product
26
- const modifierSelections = [];
27
- // Process each modifier group
28
- item.modifierGroups.forEach((cartModifierGroup) => {
29
- var _a;
30
- // Find the corresponding product modifier group
31
- const productModifierGroup = product.modifierGroups.find((group) => group.id === cartModifierGroup.id);
32
- if (productModifierGroup) {
33
- // Get the translation for this modifier group
34
- const groupTranslation = productModifierGroup.translations.find((t) => t.locale === translation.locale);
35
- // Process each selected modifier
36
- const modifierTexts = [];
37
- cartModifierGroup.modifiers.forEach((cartModifier) => {
38
- // Find the corresponding product modifier
39
- const productModifier = productModifierGroup.modifiers.find((mod) => mod.id === cartModifier.id);
40
- if (productModifier) {
41
- // Add the modifier price to the unit price
42
- unitPrice += productModifier.price * cartModifier.quantity;
43
- // Add the modifier text
44
- modifierTexts.push(`${productModifier.title}${cartModifier.quantity > 1 ? ` (${cartModifier.quantity}x)` : ""}`);
45
- }
46
- });
47
- // Add the group and its modifiers to the selections
48
- if (modifierTexts.length > 0) {
49
- modifierSelections.push(`${(groupTranslation === null || groupTranslation === void 0 ? void 0 : groupTranslation.title) || ((_a = productModifierGroup.translations[0]) === null || _a === void 0 ? void 0 : _a.title) || ""}: ${modifierTexts.join(", ")}`);
50
- }
51
- }
52
- });
53
- // Create the subtitle from modifier selections
54
- const subtitle = modifierSelections.join(", ");
55
- return {
56
- locale: translation.locale,
57
- title: translation.title || "",
58
- subtitle: subtitle || "",
59
- };
60
- });
61
- // Calculate the total price based on quantity
62
- const quantity = item.quantity || 1;
63
- const totalPrice = unitPrice * quantity;
64
- return {
65
- translations: {
66
- create: translations,
67
- },
68
- unitPrice,
69
- totalPrice,
70
- quantity,
71
- rawData: item,
72
- imageId: image === null || image === void 0 ? void 0 : image.id,
73
- productSnapshotId: product.latestSnapshotId,
74
- };
75
- });
76
- //# sourceMappingURL=cart.util.js.map
1
+ import{__awaiter as t}from"tslib";export const transformCartItemToOrderItem=i=>o=>t(void 0,void 0,void 0,function*(){const t=yield i.product.findUnique({where:{id:o.productId},include:{translations:!0,modifierGroups:{include:{translations:!0,modifiers:!0}},images:!0}});if(!t)throw new Error(`Product with ID ${o.productId} not found`);const n=t.images[0];let r=t.basePrice;const e=t.translations.map(i=>{const n=[];o.modifierGroups.forEach(o=>{var e;const a=t.modifierGroups.find(t=>t.id===o.id);if(a){const t=a.translations.find(t=>t.locale===i.locale),d=[];o.modifiers.forEach(t=>{const i=a.modifiers.find(i=>i.id===t.id);i&&(r+=i.price*t.quantity,d.push(`${i.title}${t.quantity>1?` (${t.quantity}x)`:""}`))}),d.length>0&&n.push(`${(null==t?void 0:t.title)||(null===(e=a.translations[0])||void 0===e?void 0:e.title)||""}: ${d.join(", ")}`)}});const e=n.join(", ");return{locale:i.locale,title:i.title||"",subtitle:e||""}}),a=o.quantity||1;return{translations:{create:e},unitPrice:r,totalPrice:r*a,quantity:a,rawData:o,imageId:null==n?void 0:n.id,productSnapshotId:t.latestSnapshotId}});
@@ -1,23 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { createApiRouter } from "../../core/hono/hono";
3
- import { fileRoute } from "./file.route";
4
- import { FileService } from "./file.service";
5
- export const buildFileHandler = (prisma) => {
6
- const app = createApiRouter();
7
- app.openapi(fileRoute.getVercelToken, (c) => __awaiter(void 0, void 0, void 0, function* () {
8
- const body = c.req.valid("json");
9
- const service = new FileService(prisma);
10
- const tokenResponse = yield service.getVercelToken(body, c.req.raw);
11
- return c.json(tokenResponse, 200);
12
- }));
13
- app.openapi(fileRoute.createTemporaryFile, (c) => __awaiter(void 0, void 0, void 0, function* () {
14
- const body = c.req.valid("json");
15
- const auth = c.get("auth");
16
- const user = yield auth.getCurrentUser();
17
- const service = new FileService(prisma);
18
- const file = yield service.createTemporaryFile(user.id, body);
19
- return c.json(file, 201);
20
- }));
21
- return app;
22
- };
23
- //# sourceMappingURL=file.handler.js.map
1
+ import{__awaiter as e}from"tslib";import{createApiRouter as o}from"../../core/hono/hono";import{fileRoute as r}from"./file.route";import{FileService as i}from"./file.service";export const buildFileHandler=n=>{const t=o();return t.openapi(r.getVercelToken,o=>e(void 0,void 0,void 0,function*(){const e=o.req.valid("json"),r=new i(n),t=yield r.getVercelToken(e,o.req.raw);return o.json(t,200)})),t.openapi(r.createTemporaryFile,o=>e(void 0,void 0,void 0,function*(){const e=o.req.valid("json"),r=o.get("auth"),t=yield r.getCurrentUser(),l=new i(n),d=yield l.createTemporaryFile(t.id,e);return o.json(d,201)})),t};
@@ -1,34 +1 @@
1
- import { createApiRoute } from "../../core/hono/hono";
2
- import { CreateTemporaryFileSchema, FileSchema, GetVercelTokenBody, GetVercelTokenResponse, HeaderSchema, } from "../../schemas";
3
- const createTemporaryFileRoute = createApiRoute({
4
- body: CreateTemporaryFileSchema,
5
- description: "Creates a temporary file record and returns its ID",
6
- headers: HeaderSchema,
7
- method: "POST",
8
- operationId: "createTemporaryFile",
9
- path: "/files",
10
- responses: {
11
- 201: FileSchema,
12
- },
13
- summary: "Create Temporary File",
14
- tags: ["File"],
15
- });
16
- const getVercelTokenRoute = createApiRoute({
17
- body: GetVercelTokenBody,
18
- description: "Returns a Vercel token",
19
- headers: HeaderSchema,
20
- method: "POST",
21
- operationId: "getVercelToken",
22
- path: "/files/token/vercel",
23
- responses: {
24
- 200: GetVercelTokenResponse,
25
- 204: null,
26
- },
27
- summary: "Get Vercel Token",
28
- tags: ["File"],
29
- });
30
- export const fileRoute = {
31
- createTemporaryFile: createTemporaryFileRoute,
32
- getVercelToken: getVercelTokenRoute,
33
- };
34
- //# sourceMappingURL=file.route.js.map
1
+ import{createApiRoute as e}from"../../core/hono/hono";import{CreateTemporaryFileSchema as r,FileSchema as o,GetVercelTokenBody as t,GetVercelTokenResponse as s,HeaderSchema as a}from"../../schemas";const n=e({body:r,description:"Creates a temporary file record and returns its ID",headers:a,method:"POST",operationId:"createTemporaryFile",path:"/files",responses:{201:o},summary:"Create Temporary File",tags:["File"]}),i=e({body:t,description:"Returns a Vercel token",headers:a,method:"POST",operationId:"getVercelToken",path:"/files/token/vercel",responses:{200:s,204:null},summary:"Get Vercel Token",tags:["File"]});export const fileRoute={createTemporaryFile:n,getVercelToken:i};