@shophost/rest-api 2.0.29 → 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,1100 +1 @@
1
- import { __awaiter } from "tslib";
2
- import { PrismaNeon } from "@prisma/adapter-neon";
3
- import { randomUUID } from "node:crypto";
4
- import { buildApiApp } from "../../app";
5
- import { HttpException } from "../../core/exceptions/http-exception";
6
- import { createPrismaClient, } from "../../core/lib/prisma";
7
- const GOOGLE_MAPS_TEST_KEY = "test-google-maps-key";
8
- const getOrganizationIdFromPath = (path) => {
9
- var _a;
10
- const match = path.match(/^\/organizations\/([^/]+)/);
11
- return (_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : null;
12
- };
13
- const toAuthUser = (user) => ({
14
- id: user.id,
15
- email: user.email,
16
- firstname: user.firstname,
17
- lastname: user.lastname,
18
- image: user.image,
19
- name: user.name,
20
- });
21
- export const createIntegrationPrismaClient = () => {
22
- const adapter = new PrismaNeon({
23
- connectionString: process.env.DATABASE_URL,
24
- });
25
- return createPrismaClient({
26
- adapter,
27
- log: ["warn", "error"],
28
- });
29
- };
30
- export const createTestUser = (prisma_1, ...args_1) => __awaiter(void 0, [prisma_1, ...args_1], void 0, function* (prisma, overrides = {}) {
31
- var _a, _b, _c, _d;
32
- const id = randomUUID();
33
- const firstname = (_a = overrides.firstname) !== null && _a !== void 0 ? _a : "Integration";
34
- const lastname = (_b = overrides.lastname) !== null && _b !== void 0 ? _b : "Tester";
35
- const name = (_c = overrides.name) !== null && _c !== void 0 ? _c : `${firstname} ${lastname}`;
36
- return prisma.user.create({
37
- data: {
38
- id,
39
- email: (_d = overrides.email) !== null && _d !== void 0 ? _d : `integration-${id}@shophost.test`,
40
- emailVerified: false,
41
- firstname,
42
- image: null,
43
- lastname,
44
- name,
45
- createdAt: new Date(),
46
- updatedAt: new Date(),
47
- },
48
- });
49
- });
50
- const ensureMembership = (prisma, organizationId, userId) => __awaiter(void 0, void 0, void 0, function* () {
51
- const existingMembership = yield prisma.member.findFirst({
52
- where: {
53
- organizationId,
54
- userId,
55
- },
56
- select: {
57
- id: true,
58
- },
59
- });
60
- if (existingMembership) {
61
- return existingMembership;
62
- }
63
- return prisma.member.create({
64
- data: {
65
- organizationId,
66
- role: "owner",
67
- userId,
68
- },
69
- select: {
70
- id: true,
71
- },
72
- });
73
- });
74
- const ensureSeededUser = (prisma, fixtureKey) => __awaiter(void 0, void 0, void 0, function* () {
75
- const now = new Date();
76
- const email = `fixture.${fixtureKey}@shophost.test`;
77
- const displayName = fixtureKey
78
- .split("-")
79
- .map((value) => value.charAt(0).toUpperCase() + value.slice(1))
80
- .join(" ");
81
- return prisma.user.upsert({
82
- where: {
83
- email,
84
- },
85
- update: {
86
- emailVerified: false,
87
- firstname: "Fixture",
88
- image: null,
89
- lastname: displayName,
90
- name: `Fixture ${displayName}`,
91
- updatedAt: now,
92
- },
93
- create: {
94
- id: randomUUID(),
95
- email,
96
- emailVerified: false,
97
- firstname: "Fixture",
98
- image: null,
99
- lastname: displayName,
100
- name: `Fixture ${displayName}`,
101
- createdAt: now,
102
- updatedAt: now,
103
- },
104
- });
105
- });
106
- const ensureSeededOrganization = (prisma, fixtureKey, variant, userId) => __awaiter(void 0, void 0, void 0, function* () {
107
- const slug = `it-${fixtureKey}-${variant}`;
108
- const name = `Integration ${fixtureKey} ${variant}`;
109
- const addressData = variant === "primary"
110
- ? {
111
- addressLineOne: "123 Main Street",
112
- addressLineTwo: "Suite 10",
113
- city: "New York",
114
- country: "US",
115
- doorNumber: "10A",
116
- latitude: 40.7128,
117
- longitude: -74.006,
118
- zipCode: "10001",
119
- }
120
- : {
121
- addressLineOne: "500 Lake Shore Drive",
122
- addressLineTwo: "Floor 4",
123
- city: "Chicago",
124
- country: "US",
125
- doorNumber: "4B",
126
- latitude: 41.8781,
127
- longitude: -87.6298,
128
- zipCode: "60601",
129
- };
130
- const existingOrganization = yield prisma.organization.findUnique({
131
- where: {
132
- slug,
133
- },
134
- select: {
135
- addressId: true,
136
- configurationId: true,
137
- id: true,
138
- slug: true,
139
- },
140
- });
141
- if (existingOrganization) {
142
- yield prisma.address.update({
143
- where: {
144
- id: existingOrganization.addressId,
145
- },
146
- data: Object.assign(Object.assign({}, addressData), { deletedAt: null, deletedBy: null, updatedBy: userId }),
147
- });
148
- yield prisma.organizationConfiguration.update({
149
- where: {
150
- id: existingOrganization.configurationId,
151
- },
152
- data: {
153
- countriesShipping: ["US"],
154
- defaultCurrency: "USD",
155
- defaultLocale: "en",
156
- enableHostCheckout: true,
157
- enableHostTracking: true,
158
- hostname: `${slug}.shophost.test`,
159
- isAcceptingOrders: true,
160
- supportedLocales: ["en", "pl"],
161
- updatedBy: userId,
162
- },
163
- });
164
- yield prisma.organization.update({
165
- where: {
166
- id: existingOrganization.id,
167
- },
168
- data: {
169
- deletedAt: null,
170
- deletedBy: null,
171
- email: `${slug}@shophost.test`,
172
- name,
173
- phone: "+15550001111",
174
- slug,
175
- updatedBy: userId,
176
- },
177
- });
178
- yield ensureMembership(prisma, existingOrganization.id, userId);
179
- return Object.assign(Object.assign({}, existingOrganization), { slug });
180
- }
181
- const address = yield prisma.address.create({
182
- data: Object.assign(Object.assign({}, addressData), { createdBy: userId, isDefault: false }),
183
- select: {
184
- id: true,
185
- },
186
- });
187
- const configuration = yield prisma.organizationConfiguration.create({
188
- data: {
189
- countriesShipping: ["US"],
190
- defaultCurrency: "USD",
191
- defaultLocale: "en",
192
- enableHostCheckout: true,
193
- enableHostTracking: true,
194
- hostname: `${slug}.shophost.test`,
195
- isAcceptingOrders: true,
196
- supportedLocales: ["en", "pl"],
197
- createdBy: userId,
198
- updatedBy: userId,
199
- },
200
- select: {
201
- id: true,
202
- },
203
- });
204
- const organization = yield prisma.organization.create({
205
- data: {
206
- addressId: address.id,
207
- configurationId: configuration.id,
208
- createdBy: userId,
209
- email: `${slug}@shophost.test`,
210
- name,
211
- phone: "+15550001111",
212
- slug,
213
- },
214
- select: {
215
- addressId: true,
216
- configurationId: true,
217
- id: true,
218
- slug: true,
219
- },
220
- });
221
- yield ensureMembership(prisma, organization.id, userId);
222
- return Object.assign(Object.assign({}, organization), { slug });
223
- });
224
- const deleteOrganizationResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
225
- const [productCategories, manufacturers, products, modifierGroups, shippingMethods, orders,] = yield Promise.all([
226
- prisma.productCategory.findMany({
227
- where: {
228
- organizationId,
229
- },
230
- select: {
231
- id: true,
232
- },
233
- }),
234
- prisma.manufacturer.findMany({
235
- where: {
236
- organizationId,
237
- },
238
- select: {
239
- id: true,
240
- },
241
- }),
242
- prisma.product.findMany({
243
- where: {
244
- organizationId,
245
- },
246
- select: {
247
- id: true,
248
- },
249
- }),
250
- prisma.modifierGroup.findMany({
251
- where: {
252
- products: {
253
- some: {
254
- organizationId,
255
- },
256
- },
257
- },
258
- select: {
259
- id: true,
260
- },
261
- }),
262
- prisma.shippingMethod.findMany({
263
- where: {
264
- organizationId,
265
- },
266
- select: {
267
- id: true,
268
- },
269
- }),
270
- prisma.order.findMany({
271
- where: {
272
- organizationId,
273
- },
274
- select: {
275
- id: true,
276
- paymentId: true,
277
- shippingAddressId: true,
278
- },
279
- }),
280
- ]);
281
- const productCategoryIds = productCategories.map(({ id }) => id);
282
- const manufacturerIds = manufacturers.map(({ id }) => id);
283
- const productIds = products.map(({ id }) => id);
284
- const modifierGroupIds = modifierGroups.map(({ id }) => id);
285
- const shippingMethodIds = shippingMethods.map(({ id }) => id);
286
- const orderIds = orders.map(({ id }) => id);
287
- const paymentIds = orders
288
- .map(({ paymentId }) => paymentId)
289
- .filter((paymentId) => Boolean(paymentId));
290
- const orderShippingAddressIds = orders
291
- .map(({ shippingAddressId }) => shippingAddressId)
292
- .filter((shippingAddressId) => Boolean(shippingAddressId));
293
- if (orderIds.length > 0) {
294
- yield prisma.orderItemTranslation.deleteMany({
295
- where: {
296
- orderItem: {
297
- orderId: {
298
- in: orderIds,
299
- },
300
- },
301
- },
302
- });
303
- yield prisma.orderItem.deleteMany({
304
- where: {
305
- orderId: {
306
- in: orderIds,
307
- },
308
- },
309
- });
310
- }
311
- yield prisma.order.deleteMany({
312
- where: {
313
- organizationId,
314
- },
315
- });
316
- if (paymentIds.length > 0) {
317
- yield prisma.paymentSession.deleteMany({
318
- where: {
319
- paymentId: {
320
- in: paymentIds,
321
- },
322
- },
323
- });
324
- yield prisma.payment.deleteMany({
325
- where: {
326
- id: {
327
- in: paymentIds,
328
- },
329
- },
330
- });
331
- }
332
- if (orderShippingAddressIds.length > 0) {
333
- yield prisma.address.deleteMany({
334
- where: {
335
- id: {
336
- in: orderShippingAddressIds,
337
- },
338
- },
339
- });
340
- }
341
- yield prisma.reservation.deleteMany({
342
- where: {
343
- organizationId,
344
- },
345
- });
346
- if (shippingMethodIds.length > 0) {
347
- yield prisma.shippingZone.deleteMany({
348
- where: {
349
- shippingMethodId: {
350
- in: shippingMethodIds,
351
- },
352
- },
353
- });
354
- }
355
- yield prisma.shippingMethod.deleteMany({
356
- where: {
357
- organizationId,
358
- },
359
- });
360
- yield prisma.product.updateMany({
361
- where: {
362
- organizationId,
363
- },
364
- data: {
365
- latestSnapshotId: null,
366
- },
367
- });
368
- if (productIds.length > 0) {
369
- yield prisma.productSnapshot.deleteMany({
370
- where: {
371
- productId: {
372
- in: productIds,
373
- },
374
- },
375
- });
376
- yield prisma.productTranslation.deleteMany({
377
- where: {
378
- productId: {
379
- in: productIds,
380
- },
381
- },
382
- });
383
- }
384
- yield prisma.product.deleteMany({
385
- where: {
386
- organizationId,
387
- },
388
- });
389
- if (modifierGroupIds.length > 0) {
390
- yield prisma.modifier.deleteMany({
391
- where: {
392
- modifierGroupId: {
393
- in: modifierGroupIds,
394
- },
395
- },
396
- });
397
- yield prisma.modifierGroupTranslation.deleteMany({
398
- where: {
399
- modifierGroupId: {
400
- in: modifierGroupIds,
401
- },
402
- },
403
- });
404
- yield prisma.modifierGroup.deleteMany({
405
- where: {
406
- id: {
407
- in: modifierGroupIds,
408
- },
409
- },
410
- });
411
- }
412
- if (productCategoryIds.length > 0) {
413
- yield prisma.productCategoryTranslation.deleteMany({
414
- where: {
415
- productCategoryId: {
416
- in: productCategoryIds,
417
- },
418
- },
419
- });
420
- }
421
- yield prisma.productCategory.deleteMany({
422
- where: {
423
- organizationId,
424
- },
425
- });
426
- if (manufacturerIds.length > 0) {
427
- yield prisma.manufacturerTranslation.deleteMany({
428
- where: {
429
- manufacturerId: {
430
- in: manufacturerIds,
431
- },
432
- },
433
- });
434
- }
435
- yield prisma.manufacturer.deleteMany({
436
- where: {
437
- organizationId,
438
- },
439
- });
440
- });
441
- export const resetManufacturerResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
442
- const manufacturers = yield prisma.manufacturer.findMany({
443
- where: {
444
- organizationId,
445
- },
446
- select: {
447
- id: true,
448
- },
449
- });
450
- const manufacturerIds = manufacturers.map(({ id }) => id);
451
- if (manufacturerIds.length > 0) {
452
- yield prisma.manufacturerTranslation.deleteMany({
453
- where: {
454
- manufacturerId: {
455
- in: manufacturerIds,
456
- },
457
- },
458
- });
459
- }
460
- yield prisma.manufacturer.deleteMany({
461
- where: {
462
- organizationId,
463
- },
464
- });
465
- });
466
- export const resetProductCategoryResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
467
- const productCategories = yield prisma.productCategory.findMany({
468
- where: {
469
- organizationId,
470
- },
471
- select: {
472
- id: true,
473
- },
474
- });
475
- const productCategoryIds = productCategories.map(({ id }) => id);
476
- if (productCategoryIds.length > 0) {
477
- yield prisma.productCategoryTranslation.deleteMany({
478
- where: {
479
- productCategoryId: {
480
- in: productCategoryIds,
481
- },
482
- },
483
- });
484
- }
485
- yield prisma.productCategory.deleteMany({
486
- where: {
487
- organizationId,
488
- },
489
- });
490
- });
491
- export const resetProductResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
492
- const [products, modifierGroups] = yield Promise.all([
493
- prisma.product.findMany({
494
- where: {
495
- organizationId,
496
- },
497
- select: {
498
- id: true,
499
- },
500
- }),
501
- prisma.modifierGroup.findMany({
502
- where: {
503
- products: {
504
- some: {
505
- organizationId,
506
- },
507
- },
508
- },
509
- select: {
510
- id: true,
511
- },
512
- }),
513
- ]);
514
- const productIds = products.map(({ id }) => id);
515
- const modifierGroupIds = modifierGroups.map(({ id }) => id);
516
- yield prisma.product.updateMany({
517
- where: {
518
- organizationId,
519
- },
520
- data: {
521
- latestSnapshotId: null,
522
- },
523
- });
524
- if (productIds.length > 0) {
525
- yield prisma.productSnapshot.deleteMany({
526
- where: {
527
- productId: {
528
- in: productIds,
529
- },
530
- },
531
- });
532
- yield prisma.productTranslation.deleteMany({
533
- where: {
534
- productId: {
535
- in: productIds,
536
- },
537
- },
538
- });
539
- }
540
- yield prisma.product.deleteMany({
541
- where: {
542
- organizationId,
543
- },
544
- });
545
- if (modifierGroupIds.length > 0) {
546
- yield prisma.modifier.deleteMany({
547
- where: {
548
- modifierGroupId: {
549
- in: modifierGroupIds,
550
- },
551
- },
552
- });
553
- yield prisma.modifierGroupTranslation.deleteMany({
554
- where: {
555
- modifierGroupId: {
556
- in: modifierGroupIds,
557
- },
558
- },
559
- });
560
- yield prisma.modifierGroup.deleteMany({
561
- where: {
562
- id: {
563
- in: modifierGroupIds,
564
- },
565
- },
566
- });
567
- }
568
- });
569
- export const resetOrganizationResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
570
- yield prisma.$transaction((tx) => __awaiter(void 0, void 0, void 0, function* () {
571
- yield deleteOrganizationResources(tx, organizationId);
572
- }));
573
- });
574
- export const hardDeleteOrganization = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
575
- const organization = yield prisma.organization.findUnique({
576
- where: {
577
- id: organizationId,
578
- },
579
- select: {
580
- addressId: true,
581
- configurationId: true,
582
- },
583
- });
584
- if (!organization) {
585
- return;
586
- }
587
- const configuration = yield prisma.organizationConfiguration.findUnique({
588
- where: {
589
- id: organization.configurationId,
590
- },
591
- select: {
592
- closingTimesId: true,
593
- openingTimesId: true,
594
- },
595
- });
596
- yield prisma.$transaction((tx) => __awaiter(void 0, void 0, void 0, function* () {
597
- yield deleteOrganizationResources(tx, organizationId);
598
- yield tx.organization.deleteMany({
599
- where: {
600
- id: organizationId,
601
- },
602
- });
603
- yield tx.organizationConfiguration.deleteMany({
604
- where: {
605
- id: organization.configurationId,
606
- },
607
- });
608
- if (configuration === null || configuration === void 0 ? void 0 : configuration.openingTimesId) {
609
- yield tx.openingTimes.deleteMany({
610
- where: {
611
- id: configuration.openingTimesId,
612
- },
613
- });
614
- }
615
- if (configuration === null || configuration === void 0 ? void 0 : configuration.closingTimesId) {
616
- yield tx.closingTimes.deleteMany({
617
- where: {
618
- id: configuration.closingTimesId,
619
- },
620
- });
621
- }
622
- yield tx.address.deleteMany({
623
- where: {
624
- id: organization.addressId,
625
- },
626
- });
627
- }));
628
- });
629
- const deleteUserShippingAddresses = (prisma, userId) => __awaiter(void 0, void 0, void 0, function* () {
630
- const shippingAddresses = yield prisma.address.findMany({
631
- where: {
632
- users: {
633
- some: {
634
- id: userId,
635
- },
636
- },
637
- },
638
- select: {
639
- id: true,
640
- },
641
- });
642
- if (shippingAddresses.length === 0) {
643
- return;
644
- }
645
- yield prisma.address.deleteMany({
646
- where: {
647
- id: {
648
- in: shippingAddresses.map(({ id }) => id),
649
- },
650
- },
651
- });
652
- });
653
- export const resetUserShippingAddresses = deleteUserShippingAddresses;
654
- export const resetFileResources = (prisma, userId) => __awaiter(void 0, void 0, void 0, function* () {
655
- yield prisma.file.deleteMany({
656
- where: {
657
- createdBy: userId,
658
- },
659
- });
660
- });
661
- export const resetReservationResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
662
- yield prisma.reservation.deleteMany({
663
- where: {
664
- organizationId,
665
- },
666
- });
667
- });
668
- export const resetShippingMethodResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
669
- const shippingMethods = yield prisma.shippingMethod.findMany({
670
- where: {
671
- organizationId,
672
- },
673
- select: {
674
- id: true,
675
- },
676
- });
677
- const shippingMethodIds = shippingMethods.map(({ id }) => id);
678
- if (shippingMethodIds.length > 0) {
679
- yield prisma.shippingZone.deleteMany({
680
- where: {
681
- shippingMethodId: {
682
- in: shippingMethodIds,
683
- },
684
- },
685
- });
686
- }
687
- yield prisma.shippingMethod.deleteMany({
688
- where: {
689
- organizationId,
690
- },
691
- });
692
- });
693
- export const resetOrderResources = (prisma, organizationId) => __awaiter(void 0, void 0, void 0, function* () {
694
- const orders = yield prisma.order.findMany({
695
- where: {
696
- organizationId,
697
- },
698
- select: {
699
- id: true,
700
- paymentId: true,
701
- shippingAddressId: true,
702
- },
703
- });
704
- const orderIds = orders.map(({ id }) => id);
705
- const paymentIds = orders
706
- .map(({ paymentId }) => paymentId)
707
- .filter((paymentId) => Boolean(paymentId));
708
- const orderShippingAddressIds = orders
709
- .map(({ shippingAddressId }) => shippingAddressId)
710
- .filter((shippingAddressId) => Boolean(shippingAddressId));
711
- if (orderIds.length > 0) {
712
- yield prisma.orderItemTranslation.deleteMany({
713
- where: {
714
- orderItem: {
715
- orderId: {
716
- in: orderIds,
717
- },
718
- },
719
- },
720
- });
721
- yield prisma.orderItem.deleteMany({
722
- where: {
723
- orderId: {
724
- in: orderIds,
725
- },
726
- },
727
- });
728
- }
729
- yield prisma.order.deleteMany({
730
- where: {
731
- organizationId,
732
- },
733
- });
734
- if (paymentIds.length > 0) {
735
- yield prisma.paymentSession.deleteMany({
736
- where: {
737
- paymentId: {
738
- in: paymentIds,
739
- },
740
- },
741
- });
742
- yield prisma.payment.deleteMany({
743
- where: {
744
- id: {
745
- in: paymentIds,
746
- },
747
- },
748
- });
749
- }
750
- if (orderShippingAddressIds.length > 0) {
751
- yield prisma.address.deleteMany({
752
- where: {
753
- id: {
754
- in: orderShippingAddressIds,
755
- },
756
- },
757
- });
758
- }
759
- });
760
- const seedShippingAddress = (prisma, fixtureKey, userId) => __awaiter(void 0, void 0, void 0, function* () {
761
- const shippingAddress = yield prisma.address.create({
762
- data: {
763
- firstname: "Fixture",
764
- lastname: "Recipient",
765
- phone: "+15550009999",
766
- addressLineOne: "500 Market Street",
767
- addressLineTwo: `Suite ${fixtureKey}`,
768
- city: "New York",
769
- country: "US",
770
- createdBy: userId,
771
- deliveryInstructions: "Leave at reception",
772
- doorNumber: "10A",
773
- isDefault: true,
774
- latitude: 40.713,
775
- longitude: -74.0055,
776
- placeId: `fixture-shipping-${fixtureKey}`,
777
- users: {
778
- connect: {
779
- id: userId,
780
- },
781
- },
782
- zipCode: "10001",
783
- },
784
- select: {
785
- id: true,
786
- },
787
- });
788
- return shippingAddress;
789
- });
790
- const seedCatalog = (prisma, fixtureKey, organizationId, suffix, userId) => __awaiter(void 0, void 0, void 0, function* () {
791
- const manufacturer = yield prisma.manufacturer.create({
792
- data: {
793
- createdBy: userId,
794
- name: `Fixture Manufacturer ${fixtureKey} ${suffix}`,
795
- organizationId,
796
- translations: {
797
- create: [
798
- {
799
- about: `About fixture manufacturer ${suffix} in English`,
800
- createdBy: userId,
801
- locale: "en",
802
- },
803
- {
804
- about: `O producencie testowym ${suffix} po polsku`,
805
- createdBy: userId,
806
- locale: "pl",
807
- },
808
- ],
809
- },
810
- },
811
- select: {
812
- id: true,
813
- },
814
- });
815
- const category = yield prisma.productCategory.create({
816
- data: {
817
- createdBy: userId,
818
- organizationId,
819
- slug: `fixture-category-${fixtureKey}-${suffix}`,
820
- translations: {
821
- create: [
822
- {
823
- createdBy: userId,
824
- description: `Fixture category ${suffix} in English`,
825
- locale: "en",
826
- title: `Fixture Category ${suffix}`,
827
- },
828
- {
829
- createdBy: userId,
830
- description: `Kategoria testowa ${suffix} po polsku`,
831
- locale: "pl",
832
- title: `Kategoria Testowa ${suffix}`,
833
- },
834
- ],
835
- },
836
- },
837
- select: {
838
- id: true,
839
- },
840
- });
841
- const product = yield prisma.product.create({
842
- data: {
843
- basePrice: 24.99,
844
- categories: {
845
- connect: {
846
- id: category.id,
847
- },
848
- },
849
- createdBy: userId,
850
- currency: "USD",
851
- discountedBasePrice: 19.99,
852
- manufacturerId: manufacturer.id,
853
- metadata: {
854
- fixtureKey,
855
- suffix,
856
- },
857
- modifierGroups: {
858
- create: [],
859
- },
860
- organizationId,
861
- sku: `fixture-sku-${fixtureKey}-${suffix}`,
862
- slug: `fixture-product-${fixtureKey}-${suffix}`,
863
- tags: [],
864
- translations: {
865
- create: [
866
- {
867
- createdBy: userId,
868
- description: `Fixture product ${suffix} in English`,
869
- locale: "en",
870
- title: `Fixture Product ${suffix}`,
871
- },
872
- {
873
- createdBy: userId,
874
- description: `Produkt testowy ${suffix} po polsku`,
875
- locale: "pl",
876
- title: `Produkt Testowy ${suffix}`,
877
- },
878
- ],
879
- },
880
- },
881
- select: {
882
- id: true,
883
- },
884
- });
885
- const snapshot = yield prisma.productSnapshot.create({
886
- data: {
887
- createdBy: userId,
888
- data: {
889
- id: product.id,
890
- sku: `fixture-sku-${fixtureKey}-${suffix}`,
891
- title: `Fixture Product ${suffix}`,
892
- },
893
- productId: product.id,
894
- },
895
- select: {
896
- id: true,
897
- },
898
- });
899
- yield prisma.product.update({
900
- where: {
901
- id: product.id,
902
- },
903
- data: {
904
- latestSnapshotId: snapshot.id,
905
- },
906
- });
907
- return {
908
- categoryId: category.id,
909
- manufacturerId: manufacturer.id,
910
- productId: product.id,
911
- productSnapshotId: snapshot.id,
912
- };
913
- });
914
- const seedShippingMethod = (prisma, fixtureKey, organizationId, suffix, userId) => __awaiter(void 0, void 0, void 0, function* () {
915
- const shippingMethod = yield prisma.shippingMethod.create({
916
- data: {
917
- createdBy: userId,
918
- organizationId,
919
- providerName: `Fixture Provider ${suffix}`,
920
- requireDateOfDelivery: false,
921
- shippingZones: {
922
- create: [
923
- {
924
- distanceUpto: 10,
925
- eta: "30-45 min",
926
- minimumOrderAmount: 0,
927
- price: 4.99,
928
- title: `Fixture Zone ${suffix}`,
929
- },
930
- ],
931
- },
932
- title: `Fixture Shipping ${fixtureKey} ${suffix}`,
933
- },
934
- select: {
935
- id: true,
936
- },
937
- });
938
- return shippingMethod;
939
- });
940
- const seedFixtureGraph = (prisma, fixtureKey, userId, options, organizations) => __awaiter(void 0, void 0, void 0, function* () {
941
- const fixture = {
942
- primaryOrganization: organizations.primaryOrganization,
943
- secondaryOrganization: organizations.secondaryOrganization,
944
- };
945
- if (options.includeDefaultShippingAddress) {
946
- fixture.defaultShippingAddress = yield seedShippingAddress(prisma, fixtureKey, userId);
947
- }
948
- if (options.includePrimaryCatalog) {
949
- fixture.primaryCatalog = yield seedCatalog(prisma, fixtureKey, organizations.primaryOrganization.id, "primary", userId);
950
- }
951
- if (options.includeSecondaryCatalog) {
952
- fixture.secondaryCatalog = yield seedCatalog(prisma, fixtureKey, organizations.secondaryOrganization.id, "secondary", userId);
953
- }
954
- if (options.includePrimaryShippingMethod) {
955
- fixture.primaryShippingMethod = yield seedShippingMethod(prisma, fixtureKey, organizations.primaryOrganization.id, "primary", userId);
956
- }
957
- if (options.includeSecondaryShippingMethod) {
958
- fixture.secondaryShippingMethod = yield seedShippingMethod(prisma, fixtureKey, organizations.secondaryOrganization.id, "secondary", userId);
959
- }
960
- return fixture;
961
- });
962
- export const ensureSeededTestFixture = (prisma_1, fixtureKey_1, ...args_1) => __awaiter(void 0, [prisma_1, fixtureKey_1, ...args_1], void 0, function* (prisma, fixtureKey, graph = {}) {
963
- const dbUser = yield ensureSeededUser(prisma, fixtureKey);
964
- const authUser = toAuthUser(dbUser);
965
- const primaryOrganization = yield ensureSeededOrganization(prisma, fixtureKey, "primary", dbUser.id);
966
- const secondaryOrganization = yield ensureSeededOrganization(prisma, fixtureKey, "secondary", dbUser.id);
967
- yield resetOrganizationResources(prisma, primaryOrganization.id);
968
- yield resetOrganizationResources(prisma, secondaryOrganization.id);
969
- yield deleteUserShippingAddresses(prisma, dbUser.id);
970
- const fixture = yield seedFixtureGraph(prisma, fixtureKey, dbUser.id, graph, {
971
- primaryOrganization,
972
- secondaryOrganization,
973
- });
974
- return {
975
- authUser,
976
- dbUser,
977
- fixture,
978
- };
979
- });
980
- export const createSeededApiContext = (prisma, context, appOptions = {}) => {
981
- return {
982
- app: createAuthenticatedApiApp(prisma, context.authUser, appOptions),
983
- authUser: context.authUser,
984
- dbUser: context.dbUser,
985
- fixture: context.fixture,
986
- };
987
- };
988
- export const createSeededTestContext = (prisma_1, fixtureKey_1, ...args_1) => __awaiter(void 0, [prisma_1, fixtureKey_1, ...args_1], void 0, function* (prisma, fixtureKey, options = {}) {
989
- const seededFixture = yield ensureSeededTestFixture(prisma, fixtureKey, options.graph);
990
- const appContext = createSeededApiContext(prisma, seededFixture, options.appOptions);
991
- return Object.assign(Object.assign({}, appContext), { cleanup: () => __awaiter(void 0, void 0, void 0, function* () {
992
- yield resetOrganizationResources(prisma, seededFixture.fixture.primaryOrganization.id);
993
- yield resetOrganizationResources(prisma, seededFixture.fixture.secondaryOrganization.id);
994
- yield deleteUserShippingAddresses(prisma, seededFixture.dbUser.id);
995
- }) });
996
- });
997
- export const cleanupTestUser = (prisma, userId) => __awaiter(void 0, void 0, void 0, function* () {
998
- const [memberships, shippingAddresses] = yield Promise.all([
999
- prisma.member.findMany({
1000
- where: {
1001
- userId,
1002
- },
1003
- select: {
1004
- organizationId: true,
1005
- },
1006
- }),
1007
- prisma.address.findMany({
1008
- where: {
1009
- users: {
1010
- some: {
1011
- id: userId,
1012
- },
1013
- },
1014
- },
1015
- select: {
1016
- id: true,
1017
- },
1018
- }),
1019
- ]);
1020
- const organizationIds = [
1021
- ...new Set(memberships.map(({ organizationId }) => organizationId)),
1022
- ];
1023
- const shippingAddressIds = shippingAddresses.map(({ id }) => id);
1024
- for (const organizationId of organizationIds) {
1025
- yield hardDeleteOrganization(prisma, organizationId);
1026
- }
1027
- yield prisma.$transaction((tx) => __awaiter(void 0, void 0, void 0, function* () {
1028
- yield tx.session.deleteMany({
1029
- where: {
1030
- userId,
1031
- },
1032
- });
1033
- yield tx.account.deleteMany({
1034
- where: {
1035
- userId,
1036
- },
1037
- });
1038
- yield tx.invitation.deleteMany({
1039
- where: {
1040
- inviterId: userId,
1041
- },
1042
- });
1043
- yield tx.member.deleteMany({
1044
- where: {
1045
- userId,
1046
- },
1047
- });
1048
- yield tx.user.deleteMany({
1049
- where: {
1050
- id: userId,
1051
- },
1052
- });
1053
- if (shippingAddressIds.length > 0) {
1054
- yield tx.address.deleteMany({
1055
- where: {
1056
- id: {
1057
- in: shippingAddressIds,
1058
- },
1059
- },
1060
- });
1061
- }
1062
- }));
1063
- });
1064
- export const createAuthenticatedApiApp = (prisma, authUser, options = {}) => {
1065
- return buildApiApp(Object.assign(Object.assign({}, options), { maps: Object.assign({ google: {
1066
- key: GOOGLE_MAPS_TEST_KEY,
1067
- } }, options.maps), prisma, resolveAuth: (_request, path) => ({
1068
- getCurrentUser: () => __awaiter(void 0, void 0, void 0, function* () { return authUser; }),
1069
- isGranted: () => __awaiter(void 0, void 0, void 0, function* () {
1070
- const organizationId = getOrganizationIdFromPath(path);
1071
- if (!organizationId) {
1072
- return authUser;
1073
- }
1074
- const membership = yield prisma.member.findFirst({
1075
- where: {
1076
- organizationId,
1077
- userId: authUser.id,
1078
- },
1079
- });
1080
- if (!membership) {
1081
- throw new HttpException(403, "Forbidden");
1082
- }
1083
- return authUser;
1084
- }),
1085
- }) }));
1086
- };
1087
- export const createAuthenticatedTestContext = (prisma_1, ...args_1) => __awaiter(void 0, [prisma_1, ...args_1], void 0, function* (prisma, options = {}) {
1088
- const dbUser = yield createTestUser(prisma);
1089
- const authUser = toAuthUser(dbUser);
1090
- const app = createAuthenticatedApiApp(prisma, authUser, options);
1091
- return {
1092
- app,
1093
- authUser,
1094
- dbUser,
1095
- cleanup: () => __awaiter(void 0, void 0, void 0, function* () {
1096
- yield cleanupTestUser(prisma, dbUser.id);
1097
- }),
1098
- };
1099
- });
1100
- //# sourceMappingURL=test-helpers.js.map
1
+ import{__awaiter as e}from"tslib";import{randomUUID as r}from"node:crypto";import{PrismaPg as t}from"@prisma/adapter-pg";import{buildApiApp as o}from"../../app";import{HttpException as i}from"../../core/exceptions/http-exception";import{createPrismaClient as a}from"../../core/lib/prisma";import{SEED as n,resetToSeed as s}from"./seed";export{SEED}from"./seed";let d=null;const p=()=>(d||(d=a({adapter:new t({connectionString:"postgresql://shophost:shophost@localhost:5555/shophost_test"}),log:["warn","error"]})),d);export const resetToSeed=()=>s(p());export const createTestApp=(r=n.users.owner,t={})=>{const a=p(),s={id:(d=r).id,email:d.email,firstname:d.firstname,lastname:d.lastname,name:d.name,image:d.image};var d;return o(Object.assign(Object.assign({},t),{maps:Object.assign({google:{key:"test-google-maps-key"}},t.maps),prisma:a,resolveAuth:(r,t)=>({getCurrentUser:()=>e(void 0,void 0,void 0,function*(){return s}),isGranted:()=>e(void 0,void 0,void 0,function*(){const e=(e=>{var r,t;const o=e.split("/").filter(Boolean);return"organizations"===o[0]?null!==(r=o[1])&&void 0!==r?r:"":null!==(t=o[0])&&void 0!==t?t:""})(t);if(!e)return s;if(!(yield a.member.findFirst({where:{organizationId:e,userId:s.id}})))throw new i(403,"Forbidden");return s})})}))};export const primaryContext=e=>({app:createTestApp(n.users.owner,e),user:n.users.owner,org:n.organizations.primary,catalog:n.catalog.primary,shipping:n.shipping.primary});export const secondaryContext=e=>({app:createTestApp(n.users.owner,e),user:n.users.owner,org:n.organizations.secondary,catalog:n.catalog.secondary,shipping:n.shipping.secondary});export const outsiderContext=e=>({app:createTestApp(n.users.outsider,e),user:n.users.outsider});export const createAdditionalUser=(...t)=>e(void 0,[...t],void 0,function*(e={}){var t,o,i,a;const n=p(),s=r(),d=null!==(t=e.firstname)&&void 0!==t?t:"Extra",m=null!==(o=e.lastname)&&void 0!==o?o:"User",l=null!==(i=e.name)&&void 0!==i?i:`${d} ${m}`,u=null!==(a=e.email)&&void 0!==a?a:`extra-${s}@shophost.test`,c=yield n.user.create({data:{id:s,email:u,emailVerified:!1,firstname:d,image:null,lastname:m,name:l,createdAt:new Date,updatedAt:new Date}}),g={id:c.id,email:c.email,firstname:c.firstname,lastname:c.lastname,name:c.name,image:c.image};return{app:createTestApp(g),user:g,dbUser:c}});export const seedMember=r=>e(void 0,void 0,void 0,function*(){var e;return p().member.create({data:{organizationId:r.organizationId,role:null!==(e=r.role)&&void 0!==e?e:"member",userId:r.userId},include:{user:{select:{id:!0,firstname:!0,lastname:!0,email:!0,image:!0}}}})});export const seedInvitation=t=>e(void 0,void 0,void 0,function*(){var e,o,i;return p().invitation.create({data:{id:r(),organizationId:t.organizationId,email:t.email,role:null!==(e=t.role)&&void 0!==e?e:"member",status:null!==(o=t.status)&&void 0!==o?o:"pending",expiresAt:null!==(i=t.expiresAt)&&void 0!==i?i:new Date(Date.now()+6048e5),inviterId:n.users.owner.id}})});