@medusajs/medusa 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (507) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/api/index.d.ts +15 -14
  3. package/dist/api/index.js +15 -14
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/api/middlewares/authenticate-customer.d.ts +2 -1
  6. package/dist/api/middlewares/authenticate-customer.js +1 -2
  7. package/dist/api/middlewares/authenticate-customer.js.map +1 -1
  8. package/dist/api/middlewares/authenticate.d.ts +2 -1
  9. package/dist/api/middlewares/authenticate.js.map +1 -1
  10. package/dist/api/middlewares/await-middleware.d.ts +3 -1
  11. package/dist/api/middlewares/await-middleware.js +2 -31
  12. package/dist/api/middlewares/await-middleware.js.map +1 -1
  13. package/dist/api/middlewares/error-handler.d.ts +3 -1
  14. package/dist/api/middlewares/error-handler.js.map +1 -1
  15. package/dist/api/middlewares/feature-flag-enabled.d.ts +2 -0
  16. package/dist/api/middlewares/feature-flag-enabled.js +57 -0
  17. package/dist/api/middlewares/feature-flag-enabled.js.map +1 -0
  18. package/dist/api/middlewares/index.d.ts +10 -10
  19. package/dist/api/middlewares/index.js +5 -1
  20. package/dist/api/middlewares/index.js.map +1 -1
  21. package/dist/api/middlewares/normalized-query.d.ts +6 -1
  22. package/dist/api/middlewares/normalized-query.js +5 -2
  23. package/dist/api/middlewares/normalized-query.js.map +1 -1
  24. package/dist/api/middlewares/transform-body.d.ts +4 -0
  25. package/dist/api/middlewares/transform-body.js +66 -0
  26. package/dist/api/middlewares/transform-body.js.map +1 -0
  27. package/dist/api/middlewares/transform-query.d.ts +6 -0
  28. package/dist/api/middlewares/transform-query.js +86 -0
  29. package/dist/api/middlewares/transform-query.js.map +1 -0
  30. package/dist/api/routes/admin/batch/cancel-batch-job.d.ts +22 -0
  31. package/dist/api/routes/admin/batch/cancel-batch-job.js +74 -0
  32. package/dist/api/routes/admin/batch/cancel-batch-job.js.map +1 -0
  33. package/dist/api/routes/admin/batch/confirm-batch-job.d.ts +22 -0
  34. package/dist/api/routes/admin/batch/confirm-batch-job.js +74 -0
  35. package/dist/api/routes/admin/batch/confirm-batch-job.js.map +1 -0
  36. package/dist/api/routes/admin/batch/create-batch-job.d.ts +30 -0
  37. package/dist/api/routes/admin/batch/create-batch-job.js +125 -0
  38. package/dist/api/routes/admin/batch/create-batch-job.js.map +1 -0
  39. package/dist/api/routes/admin/batch/get-batch-job.d.ts +22 -0
  40. package/dist/api/routes/admin/batch/get-batch-job.js +67 -0
  41. package/dist/api/routes/admin/batch/get-batch-job.js.map +1 -0
  42. package/dist/api/routes/admin/batch/index.d.ts +4 -0
  43. package/dist/api/routes/admin/batch/index.js +36 -7
  44. package/dist/api/routes/admin/batch/index.js.map +1 -1
  45. package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +15 -7
  46. package/dist/api/routes/admin/batch/list-batch-jobs.js +61 -46
  47. package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -1
  48. package/dist/api/routes/admin/collections/add-products.d.ts +2 -1
  49. package/dist/api/routes/admin/collections/add-products.js +4 -7
  50. package/dist/api/routes/admin/collections/add-products.js.map +1 -1
  51. package/dist/api/routes/admin/collections/create-collection.d.ts +2 -1
  52. package/dist/api/routes/admin/collections/create-collection.js +6 -8
  53. package/dist/api/routes/admin/collections/create-collection.js.map +1 -1
  54. package/dist/api/routes/admin/collections/delete-collection.d.ts +2 -1
  55. package/dist/api/routes/admin/collections/delete-collection.js.map +1 -1
  56. package/dist/api/routes/admin/collections/get-collection.d.ts +2 -1
  57. package/dist/api/routes/admin/collections/get-collection.js +4 -5
  58. package/dist/api/routes/admin/collections/get-collection.js.map +1 -1
  59. package/dist/api/routes/admin/collections/index.js +32 -12
  60. package/dist/api/routes/admin/collections/index.js.map +1 -1
  61. package/dist/api/routes/admin/collections/list-collections.d.ts +2 -1
  62. package/dist/api/routes/admin/collections/list-collections.js +9 -19
  63. package/dist/api/routes/admin/collections/list-collections.js.map +1 -1
  64. package/dist/api/routes/admin/collections/remove-products.d.ts +2 -1
  65. package/dist/api/routes/admin/collections/remove-products.js +5 -8
  66. package/dist/api/routes/admin/collections/remove-products.js.map +1 -1
  67. package/dist/api/routes/admin/collections/update-collection.d.ts +2 -1
  68. package/dist/api/routes/admin/collections/update-collection.js +5 -8
  69. package/dist/api/routes/admin/collections/update-collection.js.map +1 -1
  70. package/dist/api/routes/admin/customer-groups/add-customers-batch.d.ts +2 -1
  71. package/dist/api/routes/admin/customer-groups/add-customers-batch.js.map +1 -1
  72. package/dist/api/routes/admin/customer-groups/create-customer-group.d.ts +2 -1
  73. package/dist/api/routes/admin/customer-groups/create-customer-group.js.map +1 -1
  74. package/dist/api/routes/admin/customer-groups/delete-customer-group.d.ts +2 -1
  75. package/dist/api/routes/admin/customer-groups/delete-customer-group.js.map +1 -1
  76. package/dist/api/routes/admin/customer-groups/delete-customers-batch.d.ts +2 -1
  77. package/dist/api/routes/admin/customer-groups/delete-customers-batch.js.map +1 -1
  78. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.d.ts +2 -1
  79. package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js.map +1 -1
  80. package/dist/api/routes/admin/customer-groups/get-customer-group.d.ts +2 -1
  81. package/dist/api/routes/admin/customer-groups/get-customer-group.js +3 -17
  82. package/dist/api/routes/admin/customer-groups/get-customer-group.js.map +1 -1
  83. package/dist/api/routes/admin/customer-groups/index.js +29 -11
  84. package/dist/api/routes/admin/customer-groups/index.js.map +1 -1
  85. package/dist/api/routes/admin/customer-groups/list-customer-groups.d.ts +2 -1
  86. package/dist/api/routes/admin/customer-groups/list-customer-groups.js +10 -45
  87. package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
  88. package/dist/api/routes/admin/customer-groups/update-customer-group.d.ts +2 -1
  89. package/dist/api/routes/admin/customer-groups/update-customer-group.js.map +1 -1
  90. package/dist/api/routes/admin/customers/create-customer.d.ts +1 -1
  91. package/dist/api/routes/admin/customers/create-customer.js.map +1 -1
  92. package/dist/api/routes/admin/customers/update-customer.d.ts +1 -1
  93. package/dist/api/routes/admin/customers/update-customer.js.map +1 -1
  94. package/dist/api/routes/admin/discounts/add-valid-product.d.ts +23 -0
  95. package/dist/api/routes/admin/discounts/add-valid-product.js +82 -0
  96. package/dist/api/routes/admin/discounts/add-valid-product.js.map +1 -0
  97. package/dist/api/routes/admin/discounts/remove-valid-product.d.ts +23 -0
  98. package/dist/api/routes/admin/discounts/remove-valid-product.js +82 -0
  99. package/dist/api/routes/admin/discounts/remove-valid-product.js.map +1 -0
  100. package/dist/api/routes/admin/draft-orders/index.d.ts +1 -1
  101. package/dist/api/routes/admin/draft-orders/index.js +1 -0
  102. package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
  103. package/dist/api/routes/admin/draft-orders/list-draft-orders.js +7 -6
  104. package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
  105. package/dist/api/routes/admin/gift-cards/create-gift-card.d.ts +2 -2
  106. package/dist/api/routes/admin/gift-cards/create-gift-card.js +0 -1
  107. package/dist/api/routes/admin/gift-cards/create-gift-card.js.map +1 -1
  108. package/dist/api/routes/admin/gift-cards/index.d.ts +1 -1
  109. package/dist/api/routes/admin/gift-cards/index.js +19 -5
  110. package/dist/api/routes/admin/gift-cards/index.js.map +1 -1
  111. package/dist/api/routes/admin/gift-cards/list-gift-cards.js +24 -18
  112. package/dist/api/routes/admin/gift-cards/list-gift-cards.js.map +1 -1
  113. package/dist/api/routes/admin/gift-cards/update-gift-card.d.ts +1 -1
  114. package/dist/api/routes/admin/gift-cards/update-gift-card.js.map +1 -1
  115. package/dist/api/routes/admin/orders/create-claim.d.ts +4 -14
  116. package/dist/api/routes/admin/orders/create-claim.js +3 -14
  117. package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
  118. package/dist/api/routes/admin/orders/fulfill-claim.d.ts +1 -1
  119. package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
  120. package/dist/api/routes/admin/orders/update-claim.d.ts +1 -1
  121. package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
  122. package/dist/api/routes/admin/price-lists/create-price-list.d.ts +2 -1
  123. package/dist/api/routes/admin/price-lists/create-price-list.js +4 -7
  124. package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -1
  125. package/dist/api/routes/admin/price-lists/index.js +26 -7
  126. package/dist/api/routes/admin/price-lists/index.js.map +1 -1
  127. package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +3 -7
  128. package/dist/api/routes/admin/price-lists/list-price-list-products.js +21 -59
  129. package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -1
  130. package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +2 -1
  131. package/dist/api/routes/admin/price-lists/list-price-lists.js +8 -40
  132. package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -1
  133. package/dist/api/routes/admin/products/add-option.js +26 -6
  134. package/dist/api/routes/admin/products/add-option.js.map +1 -1
  135. package/dist/api/routes/admin/products/create-product.d.ts +3 -3
  136. package/dist/api/routes/admin/products/create-product.js +13 -9
  137. package/dist/api/routes/admin/products/create-product.js.map +1 -1
  138. package/dist/api/routes/admin/products/delete-variant.js +26 -6
  139. package/dist/api/routes/admin/products/delete-variant.js.map +1 -1
  140. package/dist/api/routes/admin/products/get-product.js +24 -4
  141. package/dist/api/routes/admin/products/get-product.js.map +1 -1
  142. package/dist/api/routes/admin/products/get-variants.d.ts +24 -0
  143. package/dist/api/routes/admin/products/get-variants.js +76 -0
  144. package/dist/api/routes/admin/products/get-variants.js.map +1 -0
  145. package/dist/api/routes/admin/products/index.d.ts +3 -2
  146. package/dist/api/routes/admin/products/index.js +1 -4
  147. package/dist/api/routes/admin/products/index.js.map +1 -1
  148. package/dist/api/routes/admin/products/list-products.d.ts +1 -6
  149. package/dist/api/routes/admin/products/list-products.js +3 -9
  150. package/dist/api/routes/admin/products/list-products.js.map +1 -1
  151. package/dist/api/routes/admin/products/update-product.d.ts +3 -3
  152. package/dist/api/routes/admin/products/update-product.js +28 -7
  153. package/dist/api/routes/admin/products/update-product.js.map +1 -1
  154. package/dist/api/routes/admin/products/update-variant.js +27 -10
  155. package/dist/api/routes/admin/products/update-variant.js.map +1 -1
  156. package/dist/api/routes/admin/shipping-options/list-shipping-options.js +6 -2
  157. package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
  158. package/dist/api/routes/admin/store/get-store.js +4 -2
  159. package/dist/api/routes/admin/store/get-store.js.map +1 -1
  160. package/dist/api/routes/admin/store/update-store.d.ts +1 -0
  161. package/dist/api/routes/admin/store/update-store.js +5 -0
  162. package/dist/api/routes/admin/store/update-store.js.map +1 -1
  163. package/dist/api/routes/admin/uploads/create-upload.d.ts +1 -1
  164. package/dist/api/routes/admin/uploads/create-upload.js +5 -5
  165. package/dist/api/routes/admin/uploads/create-upload.js.map +1 -1
  166. package/dist/api/routes/admin/uploads/delete-upload.d.ts +4 -1
  167. package/dist/api/routes/admin/uploads/delete-upload.js +29 -11
  168. package/dist/api/routes/admin/uploads/delete-upload.js.map +1 -1
  169. package/dist/api/routes/admin/uploads/get-download-url.d.ts +28 -0
  170. package/dist/api/routes/admin/uploads/get-download-url.js +99 -0
  171. package/dist/api/routes/admin/uploads/get-download-url.js.map +1 -0
  172. package/dist/api/routes/admin/uploads/index.d.ts +10 -3
  173. package/dist/api/routes/admin/uploads/index.js +19 -4
  174. package/dist/api/routes/admin/uploads/index.js.map +1 -1
  175. package/dist/api/routes/store/carts/add-shipping-method.js +6 -2
  176. package/dist/api/routes/store/carts/add-shipping-method.js.map +1 -1
  177. package/dist/api/routes/store/carts/calculate-taxes.js +9 -2
  178. package/dist/api/routes/store/carts/calculate-taxes.js.map +1 -1
  179. package/dist/api/routes/store/carts/create-cart.js +6 -2
  180. package/dist/api/routes/store/carts/create-cart.js.map +1 -1
  181. package/dist/api/routes/store/carts/create-line-item.js +6 -2
  182. package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
  183. package/dist/api/routes/store/carts/create-payment-sessions.js +6 -2
  184. package/dist/api/routes/store/carts/create-payment-sessions.js.map +1 -1
  185. package/dist/api/routes/store/carts/decorate-line-items-with-totals.d.ts +5 -0
  186. package/dist/api/routes/store/carts/decorate-line-items-with-totals.js +71 -0
  187. package/dist/api/routes/store/carts/decorate-line-items-with-totals.js.map +1 -0
  188. package/dist/api/routes/store/carts/delete-discount.js +6 -2
  189. package/dist/api/routes/store/carts/delete-discount.js.map +1 -1
  190. package/dist/api/routes/store/carts/delete-line-item.js +6 -2
  191. package/dist/api/routes/store/carts/delete-line-item.js.map +1 -1
  192. package/dist/api/routes/store/carts/delete-payment-session.js +6 -2
  193. package/dist/api/routes/store/carts/delete-payment-session.js.map +1 -1
  194. package/dist/api/routes/store/carts/get-cart.js +6 -2
  195. package/dist/api/routes/store/carts/get-cart.js.map +1 -1
  196. package/dist/api/routes/store/carts/refresh-payment-session.js +6 -2
  197. package/dist/api/routes/store/carts/refresh-payment-session.js.map +1 -1
  198. package/dist/api/routes/store/carts/set-payment-session.js +6 -2
  199. package/dist/api/routes/store/carts/set-payment-session.js.map +1 -1
  200. package/dist/api/routes/store/carts/update-cart.js +6 -2
  201. package/dist/api/routes/store/carts/update-cart.js.map +1 -1
  202. package/dist/api/routes/store/carts/update-line-item.js +6 -2
  203. package/dist/api/routes/store/carts/update-line-item.js.map +1 -1
  204. package/dist/api/routes/store/carts/update-payment-method.d.ts +38 -0
  205. package/dist/api/routes/store/carts/update-payment-method.js +122 -0
  206. package/dist/api/routes/store/carts/update-payment-method.js.map +1 -0
  207. package/dist/api/routes/store/carts/update-payment-session.js +6 -2
  208. package/dist/api/routes/store/carts/update-payment-session.js.map +1 -1
  209. package/dist/api/routes/store/customers/get-payment-methods.js +6 -7
  210. package/dist/api/routes/store/customers/get-payment-methods.js.map +1 -1
  211. package/dist/api/routes/store/customers/index.d.ts +1 -1
  212. package/dist/api/routes/store/customers/index.js.map +1 -1
  213. package/dist/api/routes/store/customers/update-address.js +1 -1
  214. package/dist/api/routes/store/customers/update-address.js.map +1 -1
  215. package/dist/api/routes/store/customers/update-customer.d.ts +1 -1
  216. package/dist/api/routes/store/customers/update-customer.js.map +1 -1
  217. package/dist/api/routes/store/gift-cards/index.d.ts +1 -1
  218. package/dist/api/routes/store/gift-cards/index.js +6 -1
  219. package/dist/api/routes/store/gift-cards/index.js.map +1 -1
  220. package/dist/api/routes/store/products/get-product.js +51 -12
  221. package/dist/api/routes/store/products/get-product.js.map +1 -1
  222. package/dist/api/routes/store/products/list-products.js +30 -7
  223. package/dist/api/routes/store/products/list-products.js.map +1 -1
  224. package/dist/api/routes/store/shipping-options/list-options.js +6 -2
  225. package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
  226. package/dist/api/routes/store/shipping-options/list-shipping-options.js +8 -2
  227. package/dist/api/routes/store/shipping-options/list-shipping-options.js.map +1 -1
  228. package/dist/api/routes/store/variants/get-variant.js +51 -12
  229. package/dist/api/routes/store/variants/get-variant.js.map +1 -1
  230. package/dist/api/routes/store/variants/list-variants.js +29 -6
  231. package/dist/api/routes/store/variants/list-variants.js.map +1 -1
  232. package/dist/commands/migrate.js +29 -14
  233. package/dist/commands/migrate.js.map +1 -1
  234. package/dist/commands/seed.js +14 -10
  235. package/dist/commands/seed.js.map +1 -1
  236. package/dist/commands/start.js +1 -1
  237. package/dist/commands/utils/get-migrations.d.ts +2 -1
  238. package/dist/commands/utils/get-migrations.js +95 -36
  239. package/dist/commands/utils/get-migrations.js.map +1 -1
  240. package/dist/config/index.d.ts +14 -0
  241. package/dist/config/index.js +40 -0
  242. package/dist/config/index.js.map +1 -0
  243. package/dist/controllers/products/admin-list-products.js +16 -8
  244. package/dist/controllers/products/admin-list-products.js.map +1 -1
  245. package/dist/helpers/test-request.js +21 -15
  246. package/dist/helpers/test-request.js.map +1 -1
  247. package/dist/interfaces/abstract-parser.d.ts +25 -0
  248. package/dist/interfaces/abstract-parser.js +14 -0
  249. package/dist/interfaces/abstract-parser.js.map +1 -0
  250. package/dist/interfaces/base-service.d.ts +66 -0
  251. package/dist/interfaces/base-service.js +377 -0
  252. package/dist/interfaces/base-service.js.map +1 -0
  253. package/dist/interfaces/batch-job-strategy.d.ts +34 -0
  254. package/dist/interfaces/batch-job-strategy.js +182 -0
  255. package/dist/interfaces/batch-job-strategy.js.map +1 -0
  256. package/dist/interfaces/csv-parser.d.ts +46 -0
  257. package/dist/interfaces/csv-parser.js +15 -0
  258. package/dist/interfaces/csv-parser.js.map +1 -0
  259. package/dist/interfaces/file-service.d.ts +66 -0
  260. package/dist/interfaces/file-service.js +32 -0
  261. package/dist/interfaces/file-service.js.map +1 -0
  262. package/dist/interfaces/index.d.ts +2 -0
  263. package/dist/interfaces/index.js +2 -0
  264. package/dist/interfaces/index.js.map +1 -1
  265. package/dist/loaders/config.js +3 -2
  266. package/dist/loaders/config.js.map +1 -1
  267. package/dist/loaders/feature-flags/index.d.ts +6 -0
  268. package/dist/loaders/feature-flags/index.js +71 -0
  269. package/dist/loaders/feature-flags/index.js.map +1 -0
  270. package/dist/loaders/index.d.ts +1 -1
  271. package/dist/loaders/index.js +8 -5
  272. package/dist/loaders/index.js.map +1 -1
  273. package/dist/loaders/plugins.d.ts +4 -3
  274. package/dist/loaders/plugins.js +71 -34
  275. package/dist/loaders/plugins.js.map +1 -1
  276. package/dist/loaders/redis.d.ts +1 -1
  277. package/dist/loaders/redis.js.map +1 -1
  278. package/dist/loaders/search-index.js +1 -0
  279. package/dist/loaders/search-index.js.map +1 -1
  280. package/dist/loaders/strategies.d.ts +2 -2
  281. package/dist/loaders/strategies.js +21 -7
  282. package/dist/loaders/strategies.js.map +1 -1
  283. package/dist/migrations/1649775522087-add_batch_job_model.js +4 -4
  284. package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -1
  285. package/dist/models/batch-job.d.ts +45 -4
  286. package/dist/models/batch-job.js +94 -7
  287. package/dist/models/batch-job.js.map +1 -1
  288. package/dist/models/customer.d.ts +1 -1
  289. package/dist/models/customer.js +1 -1
  290. package/dist/models/customer.js.map +1 -1
  291. package/dist/models/draft-order.d.ts +1 -2
  292. package/dist/models/draft-order.js +2 -2
  293. package/dist/models/draft-order.js.map +1 -1
  294. package/dist/models/line-item.d.ts +9 -2
  295. package/dist/models/line-item.js +2 -2
  296. package/dist/models/line-item.js.map +1 -1
  297. package/dist/models/product.d.ts +17 -17
  298. package/dist/models/product.js +34 -34
  299. package/dist/models/product.js.map +1 -1
  300. package/dist/models/shipping-method.d.ts +1 -1
  301. package/dist/models/shipping-method.js +1 -1
  302. package/dist/models/shipping-method.js.map +1 -1
  303. package/dist/models/shipping-option.d.ts +1 -1
  304. package/dist/models/shipping-option.js +1 -1
  305. package/dist/models/shipping-option.js.map +1 -1
  306. package/dist/repositories/customer.d.ts +2 -1
  307. package/dist/repositories/customer.js +18 -7
  308. package/dist/repositories/customer.js.map +1 -1
  309. package/dist/repositories/gift-card.d.ts +5 -1
  310. package/dist/repositories/gift-card.js +124 -29
  311. package/dist/repositories/gift-card.js.map +1 -1
  312. package/dist/repositories/image.d.ts +1 -0
  313. package/dist/repositories/image.js +100 -0
  314. package/dist/repositories/image.js.map +1 -1
  315. package/dist/repositories/price-list.js.map +1 -1
  316. package/dist/repositories/product-tag.d.ts +6 -0
  317. package/dist/repositories/product-tag.js +113 -0
  318. package/dist/repositories/product-tag.js.map +1 -1
  319. package/dist/repositories/product-type.d.ts +5 -0
  320. package/dist/repositories/product-type.js +64 -0
  321. package/dist/repositories/product-type.js.map +1 -1
  322. package/dist/repositories/product-variant.js +4 -5
  323. package/dist/repositories/product-variant.js.map +1 -1
  324. package/dist/repositories/product.d.ts +14 -17
  325. package/dist/repositories/product.js +64 -2
  326. package/dist/repositories/product.js.map +1 -1
  327. package/dist/repositories/tax-rate.d.ts +1 -1
  328. package/dist/repositories/tax-rate.js +2 -9
  329. package/dist/repositories/tax-rate.js.map +1 -1
  330. package/dist/services/auth.d.ts +16 -7
  331. package/dist/services/auth.js +130 -93
  332. package/dist/services/auth.js.map +1 -1
  333. package/dist/services/batch-job.d.ts +30 -5
  334. package/dist/services/batch-job.js +437 -2
  335. package/dist/services/batch-job.js.map +1 -1
  336. package/dist/services/cart.js +34 -13
  337. package/dist/services/cart.js.map +1 -1
  338. package/dist/services/claim-item.d.ts +23 -27
  339. package/dist/services/claim-item.js +217 -247
  340. package/dist/services/claim-item.js.map +1 -1
  341. package/dist/services/claim.d.ts +89 -71
  342. package/dist/services/claim.js +911 -879
  343. package/dist/services/claim.js.map +1 -1
  344. package/dist/services/csv-parser.d.ts +17 -0
  345. package/dist/services/csv-parser.js +319 -0
  346. package/dist/services/csv-parser.js.map +1 -0
  347. package/dist/services/custom-shipping-option.d.ts +30 -32
  348. package/dist/services/custom-shipping-option.js +78 -74
  349. package/dist/services/custom-shipping-option.js.map +1 -1
  350. package/dist/services/customer.d.ts +48 -50
  351. package/dist/services/customer.js +465 -428
  352. package/dist/services/customer.js.map +1 -1
  353. package/dist/services/discount-condition.d.ts +13 -13
  354. package/dist/services/discount-condition.js +5 -16
  355. package/dist/services/discount-condition.js.map +1 -1
  356. package/dist/services/discount.d.ts +22 -16
  357. package/dist/services/discount.js +530 -484
  358. package/dist/services/discount.js.map +1 -1
  359. package/dist/services/draft-order.d.ts +69 -66
  360. package/dist/services/draft-order.js +375 -353
  361. package/dist/services/draft-order.js.map +1 -1
  362. package/dist/services/event-bus.d.ts +72 -56
  363. package/dist/services/event-bus.js +122 -99
  364. package/dist/services/event-bus.js.map +1 -1
  365. package/dist/services/file.d.ts +14 -0
  366. package/dist/services/file.js +43 -0
  367. package/dist/services/file.js.map +1 -0
  368. package/dist/services/fulfillment.d.ts +63 -64
  369. package/dist/services/fulfillment.js +200 -194
  370. package/dist/services/fulfillment.js.map +1 -1
  371. package/dist/services/gift-card.d.ts +54 -45
  372. package/dist/services/gift-card.js +239 -221
  373. package/dist/services/gift-card.js.map +1 -1
  374. package/dist/services/idempotency-key.d.ts +1 -5
  375. package/dist/services/idempotency-key.js +2 -5
  376. package/dist/services/idempotency-key.js.map +1 -1
  377. package/dist/services/index.d.ts +11 -9
  378. package/dist/services/index.js +23 -19
  379. package/dist/services/index.js.map +1 -1
  380. package/dist/services/line-item.d.ts +3 -2
  381. package/dist/services/line-item.js +9 -7
  382. package/dist/services/line-item.js.map +1 -1
  383. package/dist/services/price-list.d.ts +4 -1
  384. package/dist/services/price-list.js +7 -4
  385. package/dist/services/price-list.js.map +1 -1
  386. package/dist/services/pricing.d.ts +101 -0
  387. package/dist/services/pricing.js +588 -0
  388. package/dist/services/pricing.js.map +1 -0
  389. package/dist/services/product-variant.d.ts +0 -11
  390. package/dist/services/product-variant.js +28 -138
  391. package/dist/services/product-variant.js.map +1 -1
  392. package/dist/services/product.d.ts +107 -145
  393. package/dist/services/product.js +708 -1036
  394. package/dist/services/product.js.map +1 -1
  395. package/dist/services/region.js +4 -4
  396. package/dist/services/region.js.map +1 -1
  397. package/dist/services/shipping-option.d.ts +43 -108
  398. package/dist/services/shipping-option.js +305 -352
  399. package/dist/services/shipping-option.js.map +1 -1
  400. package/dist/services/shipping-profile.d.ts +2 -2
  401. package/dist/services/shipping-profile.js +1 -1
  402. package/dist/services/store.d.ts +36 -45
  403. package/dist/services/store.js +207 -217
  404. package/dist/services/store.js.map +1 -1
  405. package/dist/services/strategy-resolver.d.ts +13 -0
  406. package/dist/services/strategy-resolver.js +40 -0
  407. package/dist/services/strategy-resolver.js.map +1 -0
  408. package/dist/services/tax-provider.d.ts +7 -3
  409. package/dist/services/tax-provider.js +6 -6
  410. package/dist/services/tax-provider.js.map +1 -1
  411. package/dist/services/tax-rate.d.ts +1 -1
  412. package/dist/services/tax-rate.js +2 -2
  413. package/dist/services/tax-rate.js.map +1 -1
  414. package/dist/services/totals.js.map +1 -1
  415. package/dist/services/user.d.ts +8 -9
  416. package/dist/services/user.js +216 -168
  417. package/dist/services/user.js.map +1 -1
  418. package/dist/strategies/__fixtures__/order-export-data.d.ts +3 -0
  419. package/dist/strategies/__fixtures__/order-export-data.js +70 -0
  420. package/dist/strategies/__fixtures__/order-export-data.js.map +1 -0
  421. package/dist/strategies/__fixtures__/product-export-data.d.ts +319 -0
  422. package/dist/strategies/__fixtures__/product-export-data.js +401 -0
  423. package/dist/strategies/__fixtures__/product-export-data.js.map +1 -0
  424. package/dist/strategies/batch-jobs/order/export.d.ts +36 -0
  425. package/dist/strategies/batch-jobs/order/export.js +351 -0
  426. package/dist/strategies/batch-jobs/order/export.js.map +1 -0
  427. package/dist/strategies/batch-jobs/order/index.d.ts +29 -0
  428. package/dist/strategies/batch-jobs/order/index.js +115 -0
  429. package/dist/strategies/batch-jobs/order/index.js.map +1 -0
  430. package/dist/strategies/batch-jobs/product/export.d.ts +36 -0
  431. package/dist/strategies/batch-jobs/product/export.js +546 -0
  432. package/dist/strategies/batch-jobs/product/export.js.map +1 -0
  433. package/dist/strategies/batch-jobs/product/index.d.ts +45 -0
  434. package/dist/strategies/batch-jobs/product/index.js +272 -0
  435. package/dist/strategies/batch-jobs/product/index.js.map +1 -0
  436. package/dist/subscribers/batch-job.d.ts +17 -0
  437. package/dist/subscribers/batch-job.js +96 -0
  438. package/dist/subscribers/batch-job.js.map +1 -0
  439. package/dist/types/batch-job.d.ts +23 -2
  440. package/dist/types/batch-job.js +4 -1
  441. package/dist/types/batch-job.js.map +1 -1
  442. package/dist/types/claim.d.ts +67 -0
  443. package/dist/types/claim.js +3 -0
  444. package/dist/types/claim.js.map +1 -0
  445. package/dist/types/common.d.ts +27 -3
  446. package/dist/types/common.js.map +1 -1
  447. package/dist/types/customers.d.ts +24 -0
  448. package/dist/types/customers.js.map +1 -1
  449. package/dist/types/discount.d.ts +2 -1
  450. package/dist/types/discount.js.map +1 -1
  451. package/dist/types/feature-flags.d.ts +9 -0
  452. package/dist/types/feature-flags.js +3 -0
  453. package/dist/types/feature-flags.js.map +1 -0
  454. package/dist/types/fulfillment.d.ts +27 -0
  455. package/dist/types/fulfillment.js +3 -0
  456. package/dist/types/fulfillment.js.map +1 -0
  457. package/dist/types/gift-card.d.ts +21 -0
  458. package/dist/types/gift-card.js +3 -0
  459. package/dist/types/gift-card.js.map +1 -0
  460. package/dist/types/global.d.ts +12 -1
  461. package/dist/types/price-list.d.ts +9 -0
  462. package/dist/types/pricing.d.ts +30 -0
  463. package/dist/types/pricing.js +3 -0
  464. package/dist/types/pricing.js.map +1 -0
  465. package/dist/types/product-variant.d.ts +4 -3
  466. package/dist/types/product-variant.js.map +1 -1
  467. package/dist/types/product.d.ts +110 -8
  468. package/dist/types/product.js +8 -11
  469. package/dist/types/product.js.map +1 -1
  470. package/dist/types/shipping-options.d.ts +62 -0
  471. package/dist/types/shipping-options.js +3 -0
  472. package/dist/types/shipping-options.js.map +1 -0
  473. package/dist/types/store.d.ts +9 -0
  474. package/dist/types/store.js +3 -0
  475. package/dist/types/store.js.map +1 -0
  476. package/dist/utils/build-query.d.ts +7 -7
  477. package/dist/utils/build-query.js +9 -5
  478. package/dist/utils/build-query.js.map +1 -1
  479. package/dist/utils/countries.d.ts +3 -2
  480. package/dist/utils/countries.js.map +1 -1
  481. package/dist/utils/currencies.d.ts +10 -1899
  482. package/dist/utils/currencies.js.map +1 -1
  483. package/dist/utils/db-aware-column.js +2 -2
  484. package/dist/utils/db-aware-column.js.map +1 -1
  485. package/dist/utils/feature-flag-decorators.d.ts +4 -0
  486. package/dist/utils/feature-flag-decorators.js +52 -0
  487. package/dist/utils/feature-flag-decorators.js.map +1 -0
  488. package/dist/utils/flag-router.d.ts +7 -0
  489. package/dist/utils/flag-router.js +19 -0
  490. package/dist/utils/flag-router.js.map +1 -0
  491. package/dist/utils/format-registration-name.d.ts +4 -4
  492. package/dist/utils/format-registration-name.js +7 -10
  493. package/dist/utils/format-registration-name.js.map +1 -1
  494. package/dist/utils/get-query-config.d.ts +4 -6
  495. package/dist/utils/get-query-config.js +46 -1
  496. package/dist/utils/get-query-config.js.map +1 -1
  497. package/dist/utils/omit-relation-if-exists.d.ts +7 -0
  498. package/dist/utils/omit-relation-if-exists.js +16 -0
  499. package/dist/utils/omit-relation-if-exists.js.map +1 -0
  500. package/dist/utils/set-metadata.d.ts +6 -6
  501. package/dist/utils/set-metadata.js +5 -5
  502. package/dist/utils/set-metadata.js.map +1 -1
  503. package/dist/utils/sleep.d.ts +1 -0
  504. package/dist/utils/sleep.js +50 -0
  505. package/dist/utils/sleep.js.map +1 -0
  506. package/package.json +6 -4
  507. package/yarn-error.log +29038 -0
@@ -72,17 +72,6 @@ var __rest = (this && this.__rest) || function (s, e) {
72
72
  }
73
73
  return t;
74
74
  };
75
- var __values = (this && this.__values) || function(o) {
76
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
77
- if (m) return m.call(o);
78
- if (o && typeof o.length === "number") return {
79
- next: function () {
80
- if (o && i >= o.length) o = void 0;
81
- return { value: o && o[i++], done: !o };
82
- }
83
- };
84
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
85
- };
86
75
  var __read = (this && this.__read) || function (o, n) {
87
76
  var m = typeof Symbol === "function" && o[Symbol.iterator];
88
77
  if (!m) return o;
@@ -99,49 +88,43 @@ var __read = (this && this.__read) || function (o, n) {
99
88
  }
100
89
  return ar;
101
90
  };
91
+ var __values = (this && this.__values) || function(o) {
92
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
93
+ if (m) return m.call(o);
94
+ if (o && typeof o.length === "number") return {
95
+ next: function () {
96
+ if (o && i >= o.length) o = void 0;
97
+ return { value: o && o[i++], done: !o };
98
+ }
99
+ };
100
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
101
+ };
102
102
  var __importDefault = (this && this.__importDefault) || function (mod) {
103
103
  return (mod && mod.__esModule) ? mod : { "default": mod };
104
104
  };
105
105
  Object.defineProperty(exports, "__esModule", { value: true });
106
106
  var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
107
- var lodash_1 = __importDefault(require("lodash"));
108
107
  var medusa_core_utils_1 = require("medusa-core-utils");
109
- var medusa_interfaces_1 = require("medusa-interfaces");
110
108
  var scrypt_kdf_1 = __importDefault(require("scrypt-kdf"));
111
- var typeorm_1 = require("typeorm");
109
+ var interfaces_1 = require("../interfaces");
110
+ var utils_1 = require("../utils");
112
111
  var exception_formatter_1 = require("../utils/exception-formatter");
113
112
  /**
114
113
  * Provides layer to manipulate customers.
115
- * @implements {BaseService}
116
114
  */
117
115
  var CustomerService = /** @class */ (function (_super) {
118
116
  __extends(CustomerService, _super);
119
117
  function CustomerService(_a) {
120
118
  var manager = _a.manager, customerRepository = _a.customerRepository, eventBusService = _a.eventBusService, addressRepository = _a.addressRepository;
121
- var _this = _super.call(this) || this;
122
- /** @private @const {EntityManager} */
119
+ var _this =
120
+ // eslint-disable-next-line prefer-rest-params
121
+ _super.call(this, arguments[0]) || this;
123
122
  _this.manager_ = manager;
124
- /** @private @const {CustomerRepository} */
125
123
  _this.customerRepository_ = customerRepository;
126
- /** @private @const {EventBus} */
127
- _this.eventBus_ = eventBusService;
128
- /** @private @const {AddressRepository} */
124
+ _this.eventBusService_ = eventBusService;
129
125
  _this.addressRepository_ = addressRepository;
130
126
  return _this;
131
127
  }
132
- CustomerService.prototype.withTransaction = function (transactionManager) {
133
- if (!transactionManager) {
134
- return this;
135
- }
136
- var cloned = new CustomerService({
137
- manager: transactionManager,
138
- customerRepository: this.customerRepository_,
139
- eventBusService: this.eventBus_,
140
- addressRepository: this.addressRepository_,
141
- });
142
- cloned.transactionManager_ = transactionManager;
143
- return cloned;
144
- };
145
128
  /**
146
129
  * Generate a JSON Web token, that will be sent to a customer, that wishes to
147
130
  * reset password.
@@ -153,38 +136,48 @@ var CustomerService = /** @class */ (function (_super) {
153
136
  */
154
137
  CustomerService.prototype.generateResetPasswordToken = function (customerId) {
155
138
  return __awaiter(this, void 0, void 0, function () {
156
- var customer, secret, expiry, payload, token;
139
+ var _this = this;
157
140
  return __generator(this, function (_a) {
158
141
  switch (_a.label) {
159
- case 0: return [4 /*yield*/, this.retrieve(customerId, {
160
- select: [
161
- "id",
162
- "has_account",
163
- "password_hash",
164
- "email",
165
- "first_name",
166
- "last_name",
167
- ],
168
- })];
169
- case 1:
170
- customer = _a.sent();
171
- if (!customer.has_account) {
172
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "You must have an account to reset the password. Create an account first");
173
- }
174
- secret = customer.password_hash;
175
- expiry = Math.floor(Date.now() / 1000) + 60 * 15 // 15 minutes ahead
176
- ;
177
- payload = { customer_id: customer.id, exp: expiry };
178
- token = jsonwebtoken_1.default.sign(payload, secret);
179
- // Notify subscribers
180
- this.eventBus_.emit(CustomerService.Events.PASSWORD_RESET, {
181
- id: customerId,
182
- email: customer.email,
183
- first_name: customer.first_name,
184
- last_name: customer.last_name,
185
- token: token,
186
- });
187
- return [2 /*return*/, token];
142
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
143
+ var customer, secret, expiry, payload, token;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0: return [4 /*yield*/, this.retrieve(customerId, {
147
+ select: [
148
+ "id",
149
+ "has_account",
150
+ "password_hash",
151
+ "email",
152
+ "first_name",
153
+ "last_name",
154
+ ],
155
+ })];
156
+ case 1:
157
+ customer = _a.sent();
158
+ if (!customer.has_account) {
159
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "You must have an account to reset the password. Create an account first");
160
+ }
161
+ secret = customer.password_hash;
162
+ expiry = Math.floor(Date.now() / 1000) + 60 * 15 // 15 minutes ahead
163
+ ;
164
+ payload = { customer_id: customer.id, exp: expiry };
165
+ token = jsonwebtoken_1.default.sign(payload, secret);
166
+ // Notify subscribers
167
+ this.eventBusService_
168
+ .withTransaction(manager)
169
+ .emit(CustomerService.Events.PASSWORD_RESET, {
170
+ id: customerId,
171
+ email: customer.email,
172
+ first_name: customer.first_name,
173
+ last_name: customer.last_name,
174
+ token: token,
175
+ });
176
+ return [2 /*return*/, token];
177
+ }
178
+ });
179
+ }); })];
180
+ case 1: return [2 /*return*/, _a.sent()];
188
181
  }
189
182
  });
190
183
  });
@@ -198,29 +191,29 @@ var CustomerService = /** @class */ (function (_super) {
198
191
  if (selector === void 0) { selector = {}; }
199
192
  if (config === void 0) { config = { relations: [], skip: 0, take: 50 }; }
200
193
  return __awaiter(this, void 0, void 0, function () {
201
- var customerRepo, q, query, where_1;
194
+ var _this = this;
202
195
  return __generator(this, function (_a) {
203
- customerRepo = this.manager_.getCustomRepository(this.customerRepository_);
204
- if ("q" in selector) {
205
- q = selector.q;
206
- delete selector.q;
207
- }
208
- query = this.buildQuery_(selector, config);
209
- if (q) {
210
- where_1 = query.where;
211
- delete where_1.email;
212
- delete where_1.first_name;
213
- delete where_1.last_name;
214
- query.where = function (qb) {
215
- qb.where(where_1);
216
- qb.andWhere(new typeorm_1.Brackets(function (qb) {
217
- qb.where({ email: (0, typeorm_1.ILike)("%".concat(q, "%")) })
218
- .orWhere({ first_name: (0, typeorm_1.ILike)("%".concat(q, "%")) })
219
- .orWhere({ last_name: (0, typeorm_1.ILike)("%".concat(q, "%")) });
220
- }));
221
- };
196
+ switch (_a.label) {
197
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
198
+ var customerRepo, q, query, _a, customers;
199
+ return __generator(this, function (_b) {
200
+ switch (_b.label) {
201
+ case 0:
202
+ customerRepo = manager.getCustomRepository(this.customerRepository_);
203
+ if ("q" in selector) {
204
+ q = selector.q;
205
+ delete selector.q;
206
+ }
207
+ query = (0, utils_1.buildQuery)(selector, config);
208
+ return [4 /*yield*/, customerRepo.listAndCount(query, q)];
209
+ case 1:
210
+ _a = __read.apply(void 0, [_b.sent(), 1]), customers = _a[0];
211
+ return [2 /*return*/, customers];
212
+ }
213
+ });
214
+ }); })];
215
+ case 1: return [2 /*return*/, _a.sent()];
222
216
  }
223
- return [2 /*return*/, customerRepo.find(query)];
224
217
  });
225
218
  });
226
219
  };
@@ -230,35 +223,32 @@ var CustomerService = /** @class */ (function (_super) {
230
223
  * @return {Promise} the result of the find operation
231
224
  */
232
225
  CustomerService.prototype.listAndCount = function (selector, config) {
233
- if (config === void 0) { config = { relations: [], skip: 0, take: 50, order: { created_at: "DESC" } }; }
226
+ if (config === void 0) { config = {
227
+ relations: [],
228
+ skip: 0,
229
+ take: 50,
230
+ order: { created_at: "DESC" },
231
+ }; }
234
232
  return __awaiter(this, void 0, void 0, function () {
235
- var customerRepo, q, query, groups, where_2;
233
+ var _this = this;
236
234
  return __generator(this, function (_a) {
237
235
  switch (_a.label) {
238
- case 0:
239
- customerRepo = this.manager_.getCustomRepository(this.customerRepository_);
240
- if ("q" in selector) {
241
- q = selector.q;
242
- delete selector.q;
243
- }
244
- query = this.buildQuery_(selector, config);
245
- groups = query.where.groups;
246
- delete query.where.groups;
247
- if (q) {
248
- where_2 = query.where;
249
- delete where_2.email;
250
- delete where_2.first_name;
251
- delete where_2.last_name;
252
- query.where = function (qb) {
253
- qb.where(where_2);
254
- qb.andWhere(new typeorm_1.Brackets(function (qb) {
255
- qb.where({ email: (0, typeorm_1.ILike)("%".concat(q, "%")) })
256
- .orWhere({ first_name: (0, typeorm_1.ILike)("%".concat(q, "%")) })
257
- .orWhere({ last_name: (0, typeorm_1.ILike)("%".concat(q, "%")) });
258
- }));
259
- };
260
- }
261
- return [4 /*yield*/, customerRepo.listAndCount(query, groups)];
236
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
237
+ var customerRepo, q, query;
238
+ return __generator(this, function (_a) {
239
+ switch (_a.label) {
240
+ case 0:
241
+ customerRepo = manager.getCustomRepository(this.customerRepository_);
242
+ if ("q" in selector) {
243
+ q = selector.q;
244
+ delete selector.q;
245
+ }
246
+ query = (0, utils_1.buildQuery)(selector, config);
247
+ return [4 /*yield*/, customerRepo.listAndCount(query, q)];
248
+ case 1: return [2 /*return*/, _a.sent()];
249
+ }
250
+ });
251
+ }); })];
262
252
  case 1: return [2 /*return*/, _a.sent()];
263
253
  }
264
254
  });
@@ -269,30 +259,45 @@ var CustomerService = /** @class */ (function (_super) {
269
259
  * @return {Promise} the result of the count operation
270
260
  */
271
261
  CustomerService.prototype.count = function () {
272
- var customerRepo = this.manager_.getCustomRepository(this.customerRepository_);
273
- return customerRepo.count({});
274
- };
275
- /**
276
- * Gets a customer by id.
277
- * @param {string} customerId - the id of the customer to get.
278
- * @param {Object} config - the config object containing query settings
279
- * @return {Promise<Customer>} the customer document.
280
- */
281
- CustomerService.prototype.retrieve = function (customerId, config) {
282
- if (config === void 0) { config = {}; }
283
262
  return __awaiter(this, void 0, void 0, function () {
284
- var customerRepo, validatedId, query, customer;
263
+ var _this = this;
285
264
  return __generator(this, function (_a) {
286
265
  switch (_a.label) {
266
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
267
+ var customerRepo;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0:
271
+ customerRepo = manager.getCustomRepository(this.customerRepository_);
272
+ return [4 /*yield*/, customerRepo.count({})];
273
+ case 1: return [2 /*return*/, _a.sent()];
274
+ }
275
+ });
276
+ }); })];
277
+ case 1: return [2 /*return*/, _a.sent()];
278
+ }
279
+ });
280
+ });
281
+ };
282
+ CustomerService.prototype.retrieve_ = function (selector, config) {
283
+ var _a;
284
+ if (config === void 0) { config = {}; }
285
+ return __awaiter(this, void 0, void 0, function () {
286
+ var manager, customerRepo, query, customer, selectorConstraints;
287
+ return __generator(this, function (_b) {
288
+ switch (_b.label) {
287
289
  case 0:
288
- customerRepo = this.manager_.getCustomRepository(this.customerRepository_);
289
- validatedId = this.validateId_(customerId);
290
- query = this.buildQuery_({ id: validatedId }, config);
290
+ manager = (_a = this.transactionManager_) !== null && _a !== void 0 ? _a : this.manager_;
291
+ customerRepo = manager.getCustomRepository(this.customerRepository_);
292
+ query = (0, utils_1.buildQuery)(selector, config);
291
293
  return [4 /*yield*/, customerRepo.findOne(query)];
292
294
  case 1:
293
- customer = _a.sent();
295
+ customer = _b.sent();
294
296
  if (!customer) {
295
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Customer with ".concat(customerId, " was not found"));
297
+ selectorConstraints = Object.entries(selector)
298
+ .map(function (key, value) { return "".concat(key, ": ").concat(value); })
299
+ .join(", ");
300
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Customer with ".concat(selectorConstraints, " was not found"));
296
301
  }
297
302
  return [2 /*return*/, customer];
298
303
  }
@@ -308,19 +313,18 @@ var CustomerService = /** @class */ (function (_super) {
308
313
  CustomerService.prototype.retrieveByEmail = function (email, config) {
309
314
  if (config === void 0) { config = {}; }
310
315
  return __awaiter(this, void 0, void 0, function () {
311
- var customerRepo, query, customer;
316
+ var _this = this;
312
317
  return __generator(this, function (_a) {
313
318
  switch (_a.label) {
314
- case 0:
315
- customerRepo = this.manager_.getCustomRepository(this.customerRepository_);
316
- query = this.buildQuery_({ email: email.toLowerCase() }, config);
317
- return [4 /*yield*/, customerRepo.findOne(query)];
318
- case 1:
319
- customer = _a.sent();
320
- if (!customer) {
321
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Customer with email ".concat(email, " was not found"));
322
- }
323
- return [2 /*return*/, customer];
319
+ case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
320
+ return __generator(this, function (_a) {
321
+ switch (_a.label) {
322
+ case 0: return [4 /*yield*/, this.retrieve_({ email: email.toLowerCase() }, config)];
323
+ case 1: return [2 /*return*/, _a.sent()];
324
+ }
325
+ });
326
+ }); })];
327
+ case 1: return [2 /*return*/, _a.sent()];
324
328
  }
325
329
  });
326
330
  });
@@ -334,19 +338,40 @@ var CustomerService = /** @class */ (function (_super) {
334
338
  CustomerService.prototype.retrieveByPhone = function (phone, config) {
335
339
  if (config === void 0) { config = {}; }
336
340
  return __awaiter(this, void 0, void 0, function () {
337
- var customerRepo, query, customer;
341
+ var _this = this;
342
+ return __generator(this, function (_a) {
343
+ switch (_a.label) {
344
+ case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
345
+ return __generator(this, function (_a) {
346
+ switch (_a.label) {
347
+ case 0: return [4 /*yield*/, this.retrieve_({ phone: phone }, config)];
348
+ case 1: return [2 /*return*/, _a.sent()];
349
+ }
350
+ });
351
+ }); })];
352
+ case 1: return [2 /*return*/, _a.sent()];
353
+ }
354
+ });
355
+ });
356
+ };
357
+ /**
358
+ * Gets a customer by id.
359
+ * @param {string} customerId - the id of the customer to get.
360
+ * @param {Object} config - the config object containing query settings
361
+ * @return {Promise<Customer>} the customer document.
362
+ */
363
+ CustomerService.prototype.retrieve = function (customerId, config) {
364
+ if (config === void 0) { config = {}; }
365
+ return __awaiter(this, void 0, void 0, function () {
366
+ var _this = this;
338
367
  return __generator(this, function (_a) {
339
368
  switch (_a.label) {
340
- case 0:
341
- customerRepo = this.manager_.getCustomRepository(this.customerRepository_);
342
- query = this.buildQuery_({ phone: phone }, config);
343
- return [4 /*yield*/, customerRepo.findOne(query)];
344
- case 1:
345
- customer = _a.sent();
346
- if (!customer) {
347
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Customer with phone ".concat(phone, " was not found"));
348
- }
349
- return [2 /*return*/, customer];
369
+ case 0: return [4 /*yield*/, this.atomicPhase_(function () { return __awaiter(_this, void 0, void 0, function () {
370
+ return __generator(this, function (_a) {
371
+ return [2 /*return*/, this.retrieve_({ id: customerId }, config)];
372
+ });
373
+ }); })];
374
+ case 1: return [2 /*return*/, _a.sent()];
350
375
  }
351
376
  });
352
377
  });
@@ -381,60 +406,63 @@ var CustomerService = /** @class */ (function (_super) {
381
406
  return __awaiter(this, void 0, void 0, function () {
382
407
  var _this = this;
383
408
  return __generator(this, function (_a) {
384
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
385
- var customerRepository, email, password, existing, hashedPassword, toUpdate, updated, hashedPassword, created, result;
386
- return __generator(this, function (_a) {
387
- switch (_a.label) {
388
- case 0:
389
- customerRepository = manager.getCustomRepository(this.customerRepository_);
390
- email = customer.email, password = customer.password;
391
- return [4 /*yield*/, this.retrieveByEmail(email).catch(function (err) { return undefined; })];
392
- case 1:
393
- existing = _a.sent();
394
- if (existing && existing.has_account) {
395
- throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DUPLICATE_ERROR, "A customer with the given email already has an account. Log in instead");
396
- }
397
- if (!(existing && password && !existing.has_account)) return [3 /*break*/, 5];
398
- return [4 /*yield*/, this.hashPassword_(password)];
399
- case 2:
400
- hashedPassword = _a.sent();
401
- customer.password_hash = hashedPassword;
402
- customer.has_account = true;
403
- delete customer.password;
404
- toUpdate = __assign(__assign({}, existing), customer);
405
- return [4 /*yield*/, customerRepository.save(toUpdate)];
406
- case 3:
407
- updated = _a.sent();
408
- return [4 /*yield*/, this.eventBus_
409
- .withTransaction(manager)
410
- .emit(CustomerService.Events.UPDATED, updated)];
411
- case 4:
412
- _a.sent();
413
- return [2 /*return*/, updated];
414
- case 5:
415
- if (!password) return [3 /*break*/, 7];
416
- return [4 /*yield*/, this.hashPassword_(password)];
417
- case 6:
418
- hashedPassword = _a.sent();
419
- customer.password_hash = hashedPassword;
420
- customer.has_account = true;
421
- delete customer.password;
422
- _a.label = 7;
423
- case 7: return [4 /*yield*/, customerRepository.create(customer)];
424
- case 8:
425
- created = _a.sent();
426
- return [4 /*yield*/, customerRepository.save(created)];
427
- case 9:
428
- result = _a.sent();
429
- return [4 /*yield*/, this.eventBus_
430
- .withTransaction(manager)
431
- .emit(CustomerService.Events.CREATED, result)];
432
- case 10:
433
- _a.sent();
434
- return [2 /*return*/, result];
435
- }
436
- });
437
- }); })];
409
+ switch (_a.label) {
410
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
411
+ var customerRepository, email, password, existing, hashedPassword, toUpdate, updated, hashedPassword, created, result;
412
+ return __generator(this, function (_a) {
413
+ switch (_a.label) {
414
+ case 0:
415
+ customerRepository = manager.getCustomRepository(this.customerRepository_);
416
+ customer.email = customer.email.toLowerCase();
417
+ email = customer.email, password = customer.password;
418
+ return [4 /*yield*/, this.retrieveByEmail(email).catch(function () { return undefined; })];
419
+ case 1:
420
+ existing = _a.sent();
421
+ if (existing && existing.has_account) {
422
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.DUPLICATE_ERROR, "A customer with the given email already has an account. Log in instead");
423
+ }
424
+ if (!(existing && password && !existing.has_account)) return [3 /*break*/, 5];
425
+ return [4 /*yield*/, this.hashPassword_(password)];
426
+ case 2:
427
+ hashedPassword = _a.sent();
428
+ customer.password_hash = hashedPassword;
429
+ customer.has_account = true;
430
+ delete customer.password;
431
+ toUpdate = __assign(__assign({}, existing), customer);
432
+ return [4 /*yield*/, customerRepository.save(toUpdate)];
433
+ case 3:
434
+ updated = _a.sent();
435
+ return [4 /*yield*/, this.eventBusService_
436
+ .withTransaction(manager)
437
+ .emit(CustomerService.Events.UPDATED, updated)];
438
+ case 4:
439
+ _a.sent();
440
+ return [2 /*return*/, updated];
441
+ case 5:
442
+ if (!password) return [3 /*break*/, 7];
443
+ return [4 /*yield*/, this.hashPassword_(password)];
444
+ case 6:
445
+ hashedPassword = _a.sent();
446
+ customer.password_hash = hashedPassword;
447
+ customer.has_account = true;
448
+ delete customer.password;
449
+ _a.label = 7;
450
+ case 7:
451
+ created = customerRepository.create(customer);
452
+ return [4 /*yield*/, customerRepository.save(created)];
453
+ case 8:
454
+ result = _a.sent();
455
+ return [4 /*yield*/, this.eventBusService_
456
+ .withTransaction(manager)
457
+ .emit(CustomerService.Events.CREATED, result)];
458
+ case 9:
459
+ _a.sent();
460
+ return [2 /*return*/, result];
461
+ }
462
+ });
463
+ }); })];
464
+ case 1: return [2 /*return*/, _a.sent()];
465
+ }
438
466
  });
439
467
  });
440
468
  };
@@ -449,68 +477,70 @@ var CustomerService = /** @class */ (function (_super) {
449
477
  return __awaiter(this, void 0, void 0, function () {
450
478
  var _this = this;
451
479
  return __generator(this, function (_a) {
452
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
453
- var customerRepository, addrRepo, customer, password, metadata, billing_address, billing_address_id, groups, rest, address, _a, _b, _c, key, value, _d, updated;
454
- var e_1, _e;
455
- return __generator(this, function (_f) {
456
- switch (_f.label) {
457
- case 0:
458
- customerRepository = manager.getCustomRepository(this.customerRepository_);
459
- addrRepo = manager.getCustomRepository(this.addressRepository_);
460
- return [4 /*yield*/, this.retrieve(customerId)];
461
- case 1:
462
- customer = _f.sent();
463
- password = update.password, metadata = update.metadata, billing_address = update.billing_address, billing_address_id = update.billing_address_id, groups = update.groups, rest = __rest(update, ["password", "metadata", "billing_address", "billing_address_id", "groups"]);
464
- if (metadata) {
465
- customer.metadata = this.setMetadata_(customer, metadata);
466
- }
467
- if (!("billing_address_id" in update || "billing_address" in update)) return [3 /*break*/, 3];
468
- address = billing_address_id || billing_address;
469
- if (!(typeof address !== "undefined")) return [3 /*break*/, 3];
470
- return [4 /*yield*/, this.updateBillingAddress_(customer, address, addrRepo)];
471
- case 2:
472
- _f.sent();
473
- _f.label = 3;
474
- case 3:
475
- try {
476
- for (_a = __values(Object.entries(rest)), _b = _a.next(); !_b.done; _b = _a.next()) {
477
- _c = __read(_b.value, 2), key = _c[0], value = _c[1];
478
- customer[key] = value;
480
+ switch (_a.label) {
481
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
482
+ var customerRepository, customer, password, metadata, billing_address, billing_address_id, groups, rest, address, _a, _b, _c, key, value, _d, updated;
483
+ var e_1, _e;
484
+ return __generator(this, function (_f) {
485
+ switch (_f.label) {
486
+ case 0:
487
+ customerRepository = manager.getCustomRepository(this.customerRepository_);
488
+ return [4 /*yield*/, this.retrieve(customerId)];
489
+ case 1:
490
+ customer = _f.sent();
491
+ password = update.password, metadata = update.metadata, billing_address = update.billing_address, billing_address_id = update.billing_address_id, groups = update.groups, rest = __rest(update, ["password", "metadata", "billing_address", "billing_address_id", "groups"]);
492
+ if (metadata) {
493
+ customer.metadata = (0, utils_1.setMetadata)(customer, metadata);
479
494
  }
480
- }
481
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
482
- finally {
495
+ if (!("billing_address_id" in update || "billing_address" in update)) return [3 /*break*/, 3];
496
+ address = billing_address_id || billing_address;
497
+ if (!(typeof address !== "undefined")) return [3 /*break*/, 3];
498
+ return [4 /*yield*/, this.updateBillingAddress_(customer, address)];
499
+ case 2:
500
+ _f.sent();
501
+ _f.label = 3;
502
+ case 3:
483
503
  try {
484
- if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
504
+ for (_a = __values(Object.entries(rest)), _b = _a.next(); !_b.done; _b = _a.next()) {
505
+ _c = __read(_b.value, 2), key = _c[0], value = _c[1];
506
+ customer[key] = value;
507
+ }
485
508
  }
486
- finally { if (e_1) throw e_1.error; }
487
- }
488
- if (!password) return [3 /*break*/, 5];
489
- _d = customer;
490
- return [4 /*yield*/, this.hashPassword_(password)];
491
- case 4:
492
- _d.password_hash = _f.sent();
493
- _f.label = 5;
494
- case 5:
495
- if (groups) {
496
- customer.groups = groups;
497
- }
498
- return [4 /*yield*/, customerRepository.save(customer)];
499
- case 6:
500
- updated = _f.sent();
501
- return [4 /*yield*/, this.eventBus_
502
- .withTransaction(manager)
503
- .emit(CustomerService.Events.UPDATED, updated)];
504
- case 7:
505
- _f.sent();
506
- return [2 /*return*/, updated];
507
- }
508
- });
509
- }); }, function (error) { return __awaiter(_this, void 0, void 0, function () {
510
- return __generator(this, function (_a) {
511
- throw (0, exception_formatter_1.formatException)(error);
512
- });
513
- }); })];
509
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
510
+ finally {
511
+ try {
512
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
513
+ }
514
+ finally { if (e_1) throw e_1.error; }
515
+ }
516
+ if (!password) return [3 /*break*/, 5];
517
+ _d = customer;
518
+ return [4 /*yield*/, this.hashPassword_(password)];
519
+ case 4:
520
+ _d.password_hash = _f.sent();
521
+ _f.label = 5;
522
+ case 5:
523
+ if (groups) {
524
+ customer.groups = groups;
525
+ }
526
+ return [4 /*yield*/, customerRepository.save(customer)];
527
+ case 6:
528
+ updated = _f.sent();
529
+ return [4 /*yield*/, this.eventBusService_
530
+ .withTransaction(manager)
531
+ .emit(CustomerService.Events.UPDATED, updated)];
532
+ case 7:
533
+ _f.sent();
534
+ return [2 /*return*/, updated];
535
+ }
536
+ });
537
+ }); }, function (error) { return __awaiter(_this, void 0, void 0, function () {
538
+ return __generator(this, function (_a) {
539
+ throw (0, exception_formatter_1.formatException)(error);
540
+ });
541
+ }); })];
542
+ case 1: return [2 /*return*/, _a.sent()];
543
+ }
514
544
  });
515
545
  });
516
546
  };
@@ -521,47 +551,64 @@ var CustomerService = /** @class */ (function (_super) {
521
551
  * @param {Object} addrRepo - address repository
522
552
  * @return {Promise} the result of the update operation
523
553
  */
524
- CustomerService.prototype.updateBillingAddress_ = function (customer, addressOrId, addrRepo) {
554
+ CustomerService.prototype.updateBillingAddress_ = function (customer, addressOrId) {
525
555
  return __awaiter(this, void 0, void 0, function () {
526
- var addr, created, saved;
556
+ var _this = this;
527
557
  return __generator(this, function (_a) {
528
558
  switch (_a.label) {
529
- case 0:
530
- if (addressOrId === null) {
531
- customer.billing_address_id = null;
532
- return [2 /*return*/];
533
- }
534
- if (!(typeof addressOrId === "string")) return [3 /*break*/, 2];
535
- return [4 /*yield*/, addrRepo.findOne({
536
- where: { id: addressOrId },
537
- })];
538
- case 1:
539
- addressOrId = _a.sent();
540
- _a.label = 2;
541
- case 2:
542
- addressOrId.country_code = addressOrId.country_code.toLowerCase();
543
- if (!addressOrId.id) return [3 /*break*/, 3];
544
- customer.billing_address_id = addressOrId.id;
545
- return [3 /*break*/, 8];
546
- case 3:
547
- if (!customer.billing_address_id) return [3 /*break*/, 6];
548
- return [4 /*yield*/, addrRepo.findOne({
549
- where: { id: customer.billing_address_id },
550
- })];
551
- case 4:
552
- addr = _a.sent();
553
- return [4 /*yield*/, addrRepo.save(__assign(__assign({}, addr), addressOrId))];
554
- case 5:
555
- _a.sent();
556
- return [3 /*break*/, 8];
557
- case 6:
558
- created = addrRepo.create(__assign({}, addressOrId));
559
- return [4 /*yield*/, addrRepo.save(created)];
560
- case 7:
561
- saved = _a.sent();
562
- customer.billing_address = saved;
563
- _a.label = 8;
564
- case 8: return [2 /*return*/];
559
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
560
+ var addrRepo, address, fetchedAddress, addr, created, saved;
561
+ var _a;
562
+ return __generator(this, function (_b) {
563
+ switch (_b.label) {
564
+ case 0:
565
+ addrRepo = manager.getCustomRepository(this.addressRepository_);
566
+ if (addressOrId === null || addressOrId === undefined) {
567
+ customer.billing_address_id = null;
568
+ return [2 /*return*/];
569
+ }
570
+ if (!(typeof addressOrId === "string")) return [3 /*break*/, 2];
571
+ return [4 /*yield*/, addrRepo.findOne({
572
+ where: { id: addressOrId },
573
+ })];
574
+ case 1:
575
+ fetchedAddress = _b.sent();
576
+ if (!fetchedAddress) {
577
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Address with id ".concat(addressOrId, " was not found"));
578
+ }
579
+ address = fetchedAddress;
580
+ return [3 /*break*/, 3];
581
+ case 2:
582
+ address = addressOrId;
583
+ _b.label = 3;
584
+ case 3:
585
+ address.country_code = (_a = address.country_code) === null || _a === void 0 ? void 0 : _a.toLowerCase();
586
+ if (!(typeof (address === null || address === void 0 ? void 0 : address.id) !== "undefined")) return [3 /*break*/, 4];
587
+ customer.billing_address_id = address.id;
588
+ return [3 /*break*/, 9];
589
+ case 4:
590
+ if (!customer.billing_address_id) return [3 /*break*/, 7];
591
+ return [4 /*yield*/, addrRepo.findOne({
592
+ where: { id: customer.billing_address_id },
593
+ })];
594
+ case 5:
595
+ addr = _b.sent();
596
+ return [4 /*yield*/, addrRepo.save(__assign(__assign({}, addr), address))];
597
+ case 6:
598
+ _b.sent();
599
+ return [3 /*break*/, 9];
600
+ case 7:
601
+ created = addrRepo.create(address);
602
+ return [4 /*yield*/, addrRepo.save(created)];
603
+ case 8:
604
+ saved = _b.sent();
605
+ customer.billing_address = saved;
606
+ _b.label = 9;
607
+ case 9: return [2 /*return*/];
608
+ }
609
+ });
610
+ }); })];
611
+ case 1: return [2 /*return*/, _a.sent()];
565
612
  }
566
613
  });
567
614
  });
@@ -570,37 +617,43 @@ var CustomerService = /** @class */ (function (_super) {
570
617
  return __awaiter(this, void 0, void 0, function () {
571
618
  var _this = this;
572
619
  return __generator(this, function (_a) {
573
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
574
- var addressRepo, toUpdate, _a, _b, _c, key, value, result;
575
- var e_2, _d;
576
- return __generator(this, function (_e) {
577
- switch (_e.label) {
578
- case 0:
579
- addressRepo = manager.getCustomRepository(this.addressRepository_);
580
- address.country_code = address.country_code.toLowerCase();
581
- return [4 /*yield*/, addressRepo.findOne({
582
- where: { id: addressId, customer_id: customerId },
583
- })];
584
- case 1:
585
- toUpdate = _e.sent();
586
- try {
587
- for (_a = __values(Object.entries(address)), _b = _a.next(); !_b.done; _b = _a.next()) {
588
- _c = __read(_b.value, 2), key = _c[0], value = _c[1];
589
- toUpdate[key] = value;
620
+ switch (_a.label) {
621
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
622
+ var addressRepo, toUpdate, _a, _b, _c, key, value;
623
+ var e_2, _d;
624
+ var _e;
625
+ return __generator(this, function (_f) {
626
+ switch (_f.label) {
627
+ case 0:
628
+ addressRepo = manager.getCustomRepository(this.addressRepository_);
629
+ address.country_code = (_e = address.country_code) === null || _e === void 0 ? void 0 : _e.toLowerCase();
630
+ return [4 /*yield*/, addressRepo.findOne({
631
+ where: { id: addressId, customer_id: customerId },
632
+ })];
633
+ case 1:
634
+ toUpdate = _f.sent();
635
+ if (!toUpdate) {
636
+ throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Could not find address for customer");
590
637
  }
591
- }
592
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
593
- finally {
594
638
  try {
595
- if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
639
+ for (_a = __values(Object.entries(address)), _b = _a.next(); !_b.done; _b = _a.next()) {
640
+ _c = __read(_b.value, 2), key = _c[0], value = _c[1];
641
+ toUpdate[key] = value;
642
+ }
596
643
  }
597
- finally { if (e_2) throw e_2.error; }
598
- }
599
- result = addressRepo.save(toUpdate);
600
- return [2 /*return*/, result];
601
- }
602
- });
603
- }); })];
644
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
645
+ finally {
646
+ try {
647
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
648
+ }
649
+ finally { if (e_2) throw e_2.error; }
650
+ }
651
+ return [2 /*return*/, addressRepo.save(toUpdate)];
652
+ }
653
+ });
654
+ }); })];
655
+ case 1: return [2 /*return*/, _a.sent()];
656
+ }
604
657
  });
605
658
  });
606
659
  };
@@ -608,27 +661,30 @@ var CustomerService = /** @class */ (function (_super) {
608
661
  return __awaiter(this, void 0, void 0, function () {
609
662
  var _this = this;
610
663
  return __generator(this, function (_a) {
611
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
612
- var addressRepo, address;
613
- return __generator(this, function (_a) {
614
- switch (_a.label) {
615
- case 0:
616
- addressRepo = manager.getCustomRepository(this.addressRepository_);
617
- return [4 /*yield*/, addressRepo.findOne({
618
- where: { id: addressId, customer_id: customerId },
619
- })];
620
- case 1:
621
- address = _a.sent();
622
- if (!address) {
623
- return [2 /*return*/, Promise.resolve()];
624
- }
625
- return [4 /*yield*/, addressRepo.softRemove(address)];
626
- case 2:
627
- _a.sent();
628
- return [2 /*return*/, Promise.resolve()];
629
- }
630
- });
631
- }); })];
664
+ switch (_a.label) {
665
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
666
+ var addressRepo, address;
667
+ return __generator(this, function (_a) {
668
+ switch (_a.label) {
669
+ case 0:
670
+ addressRepo = manager.getCustomRepository(this.addressRepository_);
671
+ return [4 /*yield*/, addressRepo.findOne({
672
+ where: { id: addressId, customer_id: customerId },
673
+ })];
674
+ case 1:
675
+ address = _a.sent();
676
+ if (!address) {
677
+ return [2 /*return*/];
678
+ }
679
+ return [4 /*yield*/, addressRepo.softRemove(address)];
680
+ case 2:
681
+ _a.sent();
682
+ return [2 /*return*/];
683
+ }
684
+ });
685
+ }); })];
686
+ case 1: return [2 /*return*/, _a.sent()];
687
+ }
632
688
  });
633
689
  });
634
690
  };
@@ -636,41 +692,46 @@ var CustomerService = /** @class */ (function (_super) {
636
692
  return __awaiter(this, void 0, void 0, function () {
637
693
  var _this = this;
638
694
  return __generator(this, function (_a) {
639
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
640
- var addressRepository, customer, shouldAdd, created, result;
641
- return __generator(this, function (_a) {
642
- switch (_a.label) {
643
- case 0:
644
- addressRepository = manager.getCustomRepository(this.addressRepository_);
645
- address.country_code = address.country_code.toLowerCase();
646
- return [4 /*yield*/, this.retrieve(customerId, {
647
- relations: ["shipping_addresses"],
648
- })];
649
- case 1:
650
- customer = _a.sent();
651
- shouldAdd = !customer.shipping_addresses.find(function (a) {
652
- return a.country_code.toLowerCase() === address.country_code.toLowerCase() &&
653
- a.address_1 === address.address_1 &&
654
- a.address_2 === address.address_2 &&
655
- a.city === address.city &&
656
- a.phone === address.phone &&
657
- a.postal_code === address.postal_code &&
658
- a.province === address.province &&
659
- a.first_name === address.first_name &&
660
- a.last_name === address.last_name;
661
- });
662
- if (!shouldAdd) return [3 /*break*/, 4];
663
- return [4 /*yield*/, addressRepository.create(__assign({ customer_id: customerId }, address))];
664
- case 2:
665
- created = _a.sent();
666
- return [4 /*yield*/, addressRepository.save(created)];
667
- case 3:
668
- result = _a.sent();
669
- return [2 /*return*/, result];
670
- case 4: return [2 /*return*/, customer];
671
- }
672
- });
673
- }); })];
695
+ switch (_a.label) {
696
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
697
+ var addressRepository, customer, shouldAdd, created, result;
698
+ return __generator(this, function (_a) {
699
+ switch (_a.label) {
700
+ case 0:
701
+ addressRepository = manager.getCustomRepository(this.addressRepository_);
702
+ address.country_code = address.country_code.toLowerCase();
703
+ return [4 /*yield*/, this.retrieve(customerId, {
704
+ relations: ["shipping_addresses"],
705
+ })];
706
+ case 1:
707
+ customer = _a.sent();
708
+ shouldAdd = !customer.shipping_addresses.find(function (a) {
709
+ var _a;
710
+ return ((_a = a.country_code) === null || _a === void 0 ? void 0 : _a.toLowerCase()) ===
711
+ address.country_code.toLowerCase() &&
712
+ a.address_1 === address.address_1 &&
713
+ a.address_2 === address.address_2 &&
714
+ a.city === address.city &&
715
+ a.phone === address.phone &&
716
+ a.postal_code === address.postal_code &&
717
+ a.province === address.province &&
718
+ a.first_name === address.first_name &&
719
+ a.last_name === address.last_name;
720
+ });
721
+ if (!shouldAdd) return [3 /*break*/, 4];
722
+ return [4 /*yield*/, addressRepository.create(__assign(__assign({}, address), { customer_id: customerId }))];
723
+ case 2:
724
+ created = _a.sent();
725
+ return [4 /*yield*/, addressRepository.save(created)];
726
+ case 3:
727
+ result = _a.sent();
728
+ return [2 /*return*/, result];
729
+ case 4: return [2 /*return*/, customer];
730
+ }
731
+ });
732
+ }); })];
733
+ case 1: return [2 /*return*/, _a.sent()];
734
+ }
674
735
  });
675
736
  });
676
737
  };
@@ -683,50 +744,26 @@ var CustomerService = /** @class */ (function (_super) {
683
744
  CustomerService.prototype.delete = function (customerId) {
684
745
  return __awaiter(this, void 0, void 0, function () {
685
746
  var _this = this;
686
- return __generator(this, function (_a) {
687
- return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
688
- var customerRepo, customer;
689
- return __generator(this, function (_a) {
690
- switch (_a.label) {
691
- case 0:
692
- customerRepo = manager.getCustomRepository(this.customerRepository_);
693
- return [4 /*yield*/, customerRepo.findOne({ where: { id: customerId } })];
694
- case 1:
695
- customer = _a.sent();
696
- if (!customer) {
697
- return [2 /*return*/, Promise.resolve()];
698
- }
699
- return [4 /*yield*/, customerRepo.softRemove(customer)];
700
- case 2:
701
- _a.sent();
702
- return [2 /*return*/, Promise.resolve()];
703
- }
704
- });
705
- }); })];
706
- });
707
- });
708
- };
709
- /**
710
- * Decorates a customer.
711
- * @param {Customer} customer - the cart to decorate.
712
- * @param {string[]} fields - the fields to include.
713
- * @param {string[]} expandFields - fields to expand.
714
- * @return {Customer} return the decorated customer.
715
- */
716
- CustomerService.prototype.decorate = function (customer, fields, expandFields) {
717
- if (fields === void 0) { fields = []; }
718
- if (expandFields === void 0) { expandFields = []; }
719
- return __awaiter(this, void 0, void 0, function () {
720
- var requiredFields, decorated, final;
721
747
  return __generator(this, function (_a) {
722
748
  switch (_a.label) {
723
- case 0:
724
- requiredFields = ["_id", "metadata"];
725
- decorated = lodash_1.default.pick(customer, fields.concat(requiredFields));
726
- return [4 /*yield*/, this.runDecorators_(decorated)];
727
- case 1:
728
- final = _a.sent();
729
- return [2 /*return*/, final];
749
+ case 0: return [4 /*yield*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
750
+ var customerRepo, customer;
751
+ return __generator(this, function (_a) {
752
+ switch (_a.label) {
753
+ case 0:
754
+ customerRepo = manager.getCustomRepository(this.customerRepository_);
755
+ return [4 /*yield*/, customerRepo.findOne({ where: { id: customerId } })];
756
+ case 1:
757
+ customer = _a.sent();
758
+ if (!customer) {
759
+ return [2 /*return*/];
760
+ }
761
+ return [4 /*yield*/, customerRepo.softRemove(customer)];
762
+ case 2: return [2 /*return*/, _a.sent()];
763
+ }
764
+ });
765
+ }); })];
766
+ case 1: return [2 /*return*/, _a.sent()];
730
767
  }
731
768
  });
732
769
  });
@@ -737,6 +774,6 @@ var CustomerService = /** @class */ (function (_super) {
737
774
  UPDATED: "customer.updated",
738
775
  };
739
776
  return CustomerService;
740
- }(medusa_interfaces_1.BaseService));
777
+ }(interfaces_1.TransactionBaseService));
741
778
  exports.default = CustomerService;
742
779
  //# sourceMappingURL=customer.js.map