@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.
- package/CHANGELOG.md +43 -0
- package/dist/api/index.d.ts +15 -14
- package/dist/api/index.js +15 -14
- package/dist/api/index.js.map +1 -1
- package/dist/api/middlewares/authenticate-customer.d.ts +2 -1
- package/dist/api/middlewares/authenticate-customer.js +1 -2
- package/dist/api/middlewares/authenticate-customer.js.map +1 -1
- package/dist/api/middlewares/authenticate.d.ts +2 -1
- package/dist/api/middlewares/authenticate.js.map +1 -1
- package/dist/api/middlewares/await-middleware.d.ts +3 -1
- package/dist/api/middlewares/await-middleware.js +2 -31
- package/dist/api/middlewares/await-middleware.js.map +1 -1
- package/dist/api/middlewares/error-handler.d.ts +3 -1
- package/dist/api/middlewares/error-handler.js.map +1 -1
- package/dist/api/middlewares/feature-flag-enabled.d.ts +2 -0
- package/dist/api/middlewares/feature-flag-enabled.js +57 -0
- package/dist/api/middlewares/feature-flag-enabled.js.map +1 -0
- package/dist/api/middlewares/index.d.ts +10 -10
- package/dist/api/middlewares/index.js +5 -1
- package/dist/api/middlewares/index.js.map +1 -1
- package/dist/api/middlewares/normalized-query.d.ts +6 -1
- package/dist/api/middlewares/normalized-query.js +5 -2
- package/dist/api/middlewares/normalized-query.js.map +1 -1
- package/dist/api/middlewares/transform-body.d.ts +4 -0
- package/dist/api/middlewares/transform-body.js +66 -0
- package/dist/api/middlewares/transform-body.js.map +1 -0
- package/dist/api/middlewares/transform-query.d.ts +6 -0
- package/dist/api/middlewares/transform-query.js +86 -0
- package/dist/api/middlewares/transform-query.js.map +1 -0
- package/dist/api/routes/admin/batch/cancel-batch-job.d.ts +22 -0
- package/dist/api/routes/admin/batch/cancel-batch-job.js +74 -0
- package/dist/api/routes/admin/batch/cancel-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/confirm-batch-job.d.ts +22 -0
- package/dist/api/routes/admin/batch/confirm-batch-job.js +74 -0
- package/dist/api/routes/admin/batch/confirm-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/create-batch-job.d.ts +30 -0
- package/dist/api/routes/admin/batch/create-batch-job.js +125 -0
- package/dist/api/routes/admin/batch/create-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/get-batch-job.d.ts +22 -0
- package/dist/api/routes/admin/batch/get-batch-job.js +67 -0
- package/dist/api/routes/admin/batch/get-batch-job.js.map +1 -0
- package/dist/api/routes/admin/batch/index.d.ts +4 -0
- package/dist/api/routes/admin/batch/index.js +36 -7
- package/dist/api/routes/admin/batch/index.js.map +1 -1
- package/dist/api/routes/admin/batch/list-batch-jobs.d.ts +15 -7
- package/dist/api/routes/admin/batch/list-batch-jobs.js +61 -46
- package/dist/api/routes/admin/batch/list-batch-jobs.js.map +1 -1
- package/dist/api/routes/admin/collections/add-products.d.ts +2 -1
- package/dist/api/routes/admin/collections/add-products.js +4 -7
- package/dist/api/routes/admin/collections/add-products.js.map +1 -1
- package/dist/api/routes/admin/collections/create-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/create-collection.js +6 -8
- package/dist/api/routes/admin/collections/create-collection.js.map +1 -1
- package/dist/api/routes/admin/collections/delete-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/delete-collection.js.map +1 -1
- package/dist/api/routes/admin/collections/get-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/get-collection.js +4 -5
- package/dist/api/routes/admin/collections/get-collection.js.map +1 -1
- package/dist/api/routes/admin/collections/index.js +32 -12
- package/dist/api/routes/admin/collections/index.js.map +1 -1
- package/dist/api/routes/admin/collections/list-collections.d.ts +2 -1
- package/dist/api/routes/admin/collections/list-collections.js +9 -19
- package/dist/api/routes/admin/collections/list-collections.js.map +1 -1
- package/dist/api/routes/admin/collections/remove-products.d.ts +2 -1
- package/dist/api/routes/admin/collections/remove-products.js +5 -8
- package/dist/api/routes/admin/collections/remove-products.js.map +1 -1
- package/dist/api/routes/admin/collections/update-collection.d.ts +2 -1
- package/dist/api/routes/admin/collections/update-collection.js +5 -8
- package/dist/api/routes/admin/collections/update-collection.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/add-customers-batch.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/add-customers-batch.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/create-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/create-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/delete-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/delete-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/delete-customers-batch.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/delete-customers-batch.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group-customers.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group-customers.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/get-customer-group.js +3 -17
- package/dist/api/routes/admin/customer-groups/get-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/index.js +29 -11
- package/dist/api/routes/admin/customer-groups/index.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/list-customer-groups.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js +10 -45
- package/dist/api/routes/admin/customer-groups/list-customer-groups.js.map +1 -1
- package/dist/api/routes/admin/customer-groups/update-customer-group.d.ts +2 -1
- package/dist/api/routes/admin/customer-groups/update-customer-group.js.map +1 -1
- package/dist/api/routes/admin/customers/create-customer.d.ts +1 -1
- package/dist/api/routes/admin/customers/create-customer.js.map +1 -1
- package/dist/api/routes/admin/customers/update-customer.d.ts +1 -1
- package/dist/api/routes/admin/customers/update-customer.js.map +1 -1
- package/dist/api/routes/admin/discounts/add-valid-product.d.ts +23 -0
- package/dist/api/routes/admin/discounts/add-valid-product.js +82 -0
- package/dist/api/routes/admin/discounts/add-valid-product.js.map +1 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.d.ts +23 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.js +82 -0
- package/dist/api/routes/admin/discounts/remove-valid-product.js.map +1 -0
- package/dist/api/routes/admin/draft-orders/index.d.ts +1 -1
- package/dist/api/routes/admin/draft-orders/index.js +1 -0
- package/dist/api/routes/admin/draft-orders/index.js.map +1 -1
- package/dist/api/routes/admin/draft-orders/list-draft-orders.js +7 -6
- package/dist/api/routes/admin/draft-orders/list-draft-orders.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/create-gift-card.d.ts +2 -2
- package/dist/api/routes/admin/gift-cards/create-gift-card.js +0 -1
- package/dist/api/routes/admin/gift-cards/create-gift-card.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/index.d.ts +1 -1
- package/dist/api/routes/admin/gift-cards/index.js +19 -5
- package/dist/api/routes/admin/gift-cards/index.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/list-gift-cards.js +24 -18
- package/dist/api/routes/admin/gift-cards/list-gift-cards.js.map +1 -1
- package/dist/api/routes/admin/gift-cards/update-gift-card.d.ts +1 -1
- package/dist/api/routes/admin/gift-cards/update-gift-card.js.map +1 -1
- package/dist/api/routes/admin/orders/create-claim.d.ts +4 -14
- package/dist/api/routes/admin/orders/create-claim.js +3 -14
- package/dist/api/routes/admin/orders/create-claim.js.map +1 -1
- package/dist/api/routes/admin/orders/fulfill-claim.d.ts +1 -1
- package/dist/api/routes/admin/orders/fulfill-claim.js.map +1 -1
- package/dist/api/routes/admin/orders/update-claim.d.ts +1 -1
- package/dist/api/routes/admin/orders/update-claim.js.map +1 -1
- package/dist/api/routes/admin/price-lists/create-price-list.d.ts +2 -1
- package/dist/api/routes/admin/price-lists/create-price-list.js +4 -7
- package/dist/api/routes/admin/price-lists/create-price-list.js.map +1 -1
- package/dist/api/routes/admin/price-lists/index.js +26 -7
- package/dist/api/routes/admin/price-lists/index.js.map +1 -1
- package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +3 -7
- package/dist/api/routes/admin/price-lists/list-price-list-products.js +21 -59
- package/dist/api/routes/admin/price-lists/list-price-list-products.js.map +1 -1
- package/dist/api/routes/admin/price-lists/list-price-lists.d.ts +2 -1
- package/dist/api/routes/admin/price-lists/list-price-lists.js +8 -40
- package/dist/api/routes/admin/price-lists/list-price-lists.js.map +1 -1
- package/dist/api/routes/admin/products/add-option.js +26 -6
- package/dist/api/routes/admin/products/add-option.js.map +1 -1
- package/dist/api/routes/admin/products/create-product.d.ts +3 -3
- package/dist/api/routes/admin/products/create-product.js +13 -9
- package/dist/api/routes/admin/products/create-product.js.map +1 -1
- package/dist/api/routes/admin/products/delete-variant.js +26 -6
- package/dist/api/routes/admin/products/delete-variant.js.map +1 -1
- package/dist/api/routes/admin/products/get-product.js +24 -4
- package/dist/api/routes/admin/products/get-product.js.map +1 -1
- package/dist/api/routes/admin/products/get-variants.d.ts +24 -0
- package/dist/api/routes/admin/products/get-variants.js +76 -0
- package/dist/api/routes/admin/products/get-variants.js.map +1 -0
- package/dist/api/routes/admin/products/index.d.ts +3 -2
- package/dist/api/routes/admin/products/index.js +1 -4
- package/dist/api/routes/admin/products/index.js.map +1 -1
- package/dist/api/routes/admin/products/list-products.d.ts +1 -6
- package/dist/api/routes/admin/products/list-products.js +3 -9
- package/dist/api/routes/admin/products/list-products.js.map +1 -1
- package/dist/api/routes/admin/products/update-product.d.ts +3 -3
- package/dist/api/routes/admin/products/update-product.js +28 -7
- package/dist/api/routes/admin/products/update-product.js.map +1 -1
- package/dist/api/routes/admin/products/update-variant.js +27 -10
- package/dist/api/routes/admin/products/update-variant.js.map +1 -1
- package/dist/api/routes/admin/shipping-options/list-shipping-options.js +6 -2
- package/dist/api/routes/admin/shipping-options/list-shipping-options.js.map +1 -1
- package/dist/api/routes/admin/store/get-store.js +4 -2
- package/dist/api/routes/admin/store/get-store.js.map +1 -1
- package/dist/api/routes/admin/store/update-store.d.ts +1 -0
- package/dist/api/routes/admin/store/update-store.js +5 -0
- package/dist/api/routes/admin/store/update-store.js.map +1 -1
- package/dist/api/routes/admin/uploads/create-upload.d.ts +1 -1
- package/dist/api/routes/admin/uploads/create-upload.js +5 -5
- package/dist/api/routes/admin/uploads/create-upload.js.map +1 -1
- package/dist/api/routes/admin/uploads/delete-upload.d.ts +4 -1
- package/dist/api/routes/admin/uploads/delete-upload.js +29 -11
- package/dist/api/routes/admin/uploads/delete-upload.js.map +1 -1
- package/dist/api/routes/admin/uploads/get-download-url.d.ts +28 -0
- package/dist/api/routes/admin/uploads/get-download-url.js +99 -0
- package/dist/api/routes/admin/uploads/get-download-url.js.map +1 -0
- package/dist/api/routes/admin/uploads/index.d.ts +10 -3
- package/dist/api/routes/admin/uploads/index.js +19 -4
- package/dist/api/routes/admin/uploads/index.js.map +1 -1
- package/dist/api/routes/store/carts/add-shipping-method.js +6 -2
- package/dist/api/routes/store/carts/add-shipping-method.js.map +1 -1
- package/dist/api/routes/store/carts/calculate-taxes.js +9 -2
- package/dist/api/routes/store/carts/calculate-taxes.js.map +1 -1
- package/dist/api/routes/store/carts/create-cart.js +6 -2
- package/dist/api/routes/store/carts/create-cart.js.map +1 -1
- package/dist/api/routes/store/carts/create-line-item.js +6 -2
- package/dist/api/routes/store/carts/create-line-item.js.map +1 -1
- package/dist/api/routes/store/carts/create-payment-sessions.js +6 -2
- package/dist/api/routes/store/carts/create-payment-sessions.js.map +1 -1
- package/dist/api/routes/store/carts/decorate-line-items-with-totals.d.ts +5 -0
- package/dist/api/routes/store/carts/decorate-line-items-with-totals.js +71 -0
- package/dist/api/routes/store/carts/decorate-line-items-with-totals.js.map +1 -0
- package/dist/api/routes/store/carts/delete-discount.js +6 -2
- package/dist/api/routes/store/carts/delete-discount.js.map +1 -1
- package/dist/api/routes/store/carts/delete-line-item.js +6 -2
- package/dist/api/routes/store/carts/delete-line-item.js.map +1 -1
- package/dist/api/routes/store/carts/delete-payment-session.js +6 -2
- package/dist/api/routes/store/carts/delete-payment-session.js.map +1 -1
- package/dist/api/routes/store/carts/get-cart.js +6 -2
- package/dist/api/routes/store/carts/get-cart.js.map +1 -1
- package/dist/api/routes/store/carts/refresh-payment-session.js +6 -2
- package/dist/api/routes/store/carts/refresh-payment-session.js.map +1 -1
- package/dist/api/routes/store/carts/set-payment-session.js +6 -2
- package/dist/api/routes/store/carts/set-payment-session.js.map +1 -1
- package/dist/api/routes/store/carts/update-cart.js +6 -2
- package/dist/api/routes/store/carts/update-cart.js.map +1 -1
- package/dist/api/routes/store/carts/update-line-item.js +6 -2
- package/dist/api/routes/store/carts/update-line-item.js.map +1 -1
- package/dist/api/routes/store/carts/update-payment-method.d.ts +38 -0
- package/dist/api/routes/store/carts/update-payment-method.js +122 -0
- package/dist/api/routes/store/carts/update-payment-method.js.map +1 -0
- package/dist/api/routes/store/carts/update-payment-session.js +6 -2
- package/dist/api/routes/store/carts/update-payment-session.js.map +1 -1
- package/dist/api/routes/store/customers/get-payment-methods.js +6 -7
- package/dist/api/routes/store/customers/get-payment-methods.js.map +1 -1
- package/dist/api/routes/store/customers/index.d.ts +1 -1
- package/dist/api/routes/store/customers/index.js.map +1 -1
- package/dist/api/routes/store/customers/update-address.js +1 -1
- package/dist/api/routes/store/customers/update-address.js.map +1 -1
- package/dist/api/routes/store/customers/update-customer.d.ts +1 -1
- package/dist/api/routes/store/customers/update-customer.js.map +1 -1
- package/dist/api/routes/store/gift-cards/index.d.ts +1 -1
- package/dist/api/routes/store/gift-cards/index.js +6 -1
- package/dist/api/routes/store/gift-cards/index.js.map +1 -1
- package/dist/api/routes/store/products/get-product.js +51 -12
- package/dist/api/routes/store/products/get-product.js.map +1 -1
- package/dist/api/routes/store/products/list-products.js +30 -7
- package/dist/api/routes/store/products/list-products.js.map +1 -1
- package/dist/api/routes/store/shipping-options/list-options.js +6 -2
- package/dist/api/routes/store/shipping-options/list-options.js.map +1 -1
- package/dist/api/routes/store/shipping-options/list-shipping-options.js +8 -2
- package/dist/api/routes/store/shipping-options/list-shipping-options.js.map +1 -1
- package/dist/api/routes/store/variants/get-variant.js +51 -12
- package/dist/api/routes/store/variants/get-variant.js.map +1 -1
- package/dist/api/routes/store/variants/list-variants.js +29 -6
- package/dist/api/routes/store/variants/list-variants.js.map +1 -1
- package/dist/commands/migrate.js +29 -14
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/seed.js +14 -10
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/start.js +1 -1
- package/dist/commands/utils/get-migrations.d.ts +2 -1
- package/dist/commands/utils/get-migrations.js +95 -36
- package/dist/commands/utils/get-migrations.js.map +1 -1
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.js +40 -0
- package/dist/config/index.js.map +1 -0
- package/dist/controllers/products/admin-list-products.js +16 -8
- package/dist/controllers/products/admin-list-products.js.map +1 -1
- package/dist/helpers/test-request.js +21 -15
- package/dist/helpers/test-request.js.map +1 -1
- package/dist/interfaces/abstract-parser.d.ts +25 -0
- package/dist/interfaces/abstract-parser.js +14 -0
- package/dist/interfaces/abstract-parser.js.map +1 -0
- package/dist/interfaces/base-service.d.ts +66 -0
- package/dist/interfaces/base-service.js +377 -0
- package/dist/interfaces/base-service.js.map +1 -0
- package/dist/interfaces/batch-job-strategy.d.ts +34 -0
- package/dist/interfaces/batch-job-strategy.js +182 -0
- package/dist/interfaces/batch-job-strategy.js.map +1 -0
- package/dist/interfaces/csv-parser.d.ts +46 -0
- package/dist/interfaces/csv-parser.js +15 -0
- package/dist/interfaces/csv-parser.js.map +1 -0
- package/dist/interfaces/file-service.d.ts +66 -0
- package/dist/interfaces/file-service.js +32 -0
- package/dist/interfaces/file-service.js.map +1 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/index.js.map +1 -1
- package/dist/loaders/config.js +3 -2
- package/dist/loaders/config.js.map +1 -1
- package/dist/loaders/feature-flags/index.d.ts +6 -0
- package/dist/loaders/feature-flags/index.js +71 -0
- package/dist/loaders/feature-flags/index.js.map +1 -0
- package/dist/loaders/index.d.ts +1 -1
- package/dist/loaders/index.js +8 -5
- package/dist/loaders/index.js.map +1 -1
- package/dist/loaders/plugins.d.ts +4 -3
- package/dist/loaders/plugins.js +71 -34
- package/dist/loaders/plugins.js.map +1 -1
- package/dist/loaders/redis.d.ts +1 -1
- package/dist/loaders/redis.js.map +1 -1
- package/dist/loaders/search-index.js +1 -0
- package/dist/loaders/search-index.js.map +1 -1
- package/dist/loaders/strategies.d.ts +2 -2
- package/dist/loaders/strategies.js +21 -7
- package/dist/loaders/strategies.js.map +1 -1
- package/dist/migrations/1649775522087-add_batch_job_model.js +4 -4
- package/dist/migrations/1649775522087-add_batch_job_model.js.map +1 -1
- package/dist/models/batch-job.d.ts +45 -4
- package/dist/models/batch-job.js +94 -7
- package/dist/models/batch-job.js.map +1 -1
- package/dist/models/customer.d.ts +1 -1
- package/dist/models/customer.js +1 -1
- package/dist/models/customer.js.map +1 -1
- package/dist/models/draft-order.d.ts +1 -2
- package/dist/models/draft-order.js +2 -2
- package/dist/models/draft-order.js.map +1 -1
- package/dist/models/line-item.d.ts +9 -2
- package/dist/models/line-item.js +2 -2
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/product.d.ts +17 -17
- package/dist/models/product.js +34 -34
- package/dist/models/product.js.map +1 -1
- package/dist/models/shipping-method.d.ts +1 -1
- package/dist/models/shipping-method.js +1 -1
- package/dist/models/shipping-method.js.map +1 -1
- package/dist/models/shipping-option.d.ts +1 -1
- package/dist/models/shipping-option.js +1 -1
- package/dist/models/shipping-option.js.map +1 -1
- package/dist/repositories/customer.d.ts +2 -1
- package/dist/repositories/customer.js +18 -7
- package/dist/repositories/customer.js.map +1 -1
- package/dist/repositories/gift-card.d.ts +5 -1
- package/dist/repositories/gift-card.js +124 -29
- package/dist/repositories/gift-card.js.map +1 -1
- package/dist/repositories/image.d.ts +1 -0
- package/dist/repositories/image.js +100 -0
- package/dist/repositories/image.js.map +1 -1
- package/dist/repositories/price-list.js.map +1 -1
- package/dist/repositories/product-tag.d.ts +6 -0
- package/dist/repositories/product-tag.js +113 -0
- package/dist/repositories/product-tag.js.map +1 -1
- package/dist/repositories/product-type.d.ts +5 -0
- package/dist/repositories/product-type.js +64 -0
- package/dist/repositories/product-type.js.map +1 -1
- package/dist/repositories/product-variant.js +4 -5
- package/dist/repositories/product-variant.js.map +1 -1
- package/dist/repositories/product.d.ts +14 -17
- package/dist/repositories/product.js +64 -2
- package/dist/repositories/product.js.map +1 -1
- package/dist/repositories/tax-rate.d.ts +1 -1
- package/dist/repositories/tax-rate.js +2 -9
- package/dist/repositories/tax-rate.js.map +1 -1
- package/dist/services/auth.d.ts +16 -7
- package/dist/services/auth.js +130 -93
- package/dist/services/auth.js.map +1 -1
- package/dist/services/batch-job.d.ts +30 -5
- package/dist/services/batch-job.js +437 -2
- package/dist/services/batch-job.js.map +1 -1
- package/dist/services/cart.js +34 -13
- package/dist/services/cart.js.map +1 -1
- package/dist/services/claim-item.d.ts +23 -27
- package/dist/services/claim-item.js +217 -247
- package/dist/services/claim-item.js.map +1 -1
- package/dist/services/claim.d.ts +89 -71
- package/dist/services/claim.js +911 -879
- package/dist/services/claim.js.map +1 -1
- package/dist/services/csv-parser.d.ts +17 -0
- package/dist/services/csv-parser.js +319 -0
- package/dist/services/csv-parser.js.map +1 -0
- package/dist/services/custom-shipping-option.d.ts +30 -32
- package/dist/services/custom-shipping-option.js +78 -74
- package/dist/services/custom-shipping-option.js.map +1 -1
- package/dist/services/customer.d.ts +48 -50
- package/dist/services/customer.js +465 -428
- package/dist/services/customer.js.map +1 -1
- package/dist/services/discount-condition.d.ts +13 -13
- package/dist/services/discount-condition.js +5 -16
- package/dist/services/discount-condition.js.map +1 -1
- package/dist/services/discount.d.ts +22 -16
- package/dist/services/discount.js +530 -484
- package/dist/services/discount.js.map +1 -1
- package/dist/services/draft-order.d.ts +69 -66
- package/dist/services/draft-order.js +375 -353
- package/dist/services/draft-order.js.map +1 -1
- package/dist/services/event-bus.d.ts +72 -56
- package/dist/services/event-bus.js +122 -99
- package/dist/services/event-bus.js.map +1 -1
- package/dist/services/file.d.ts +14 -0
- package/dist/services/file.js +43 -0
- package/dist/services/file.js.map +1 -0
- package/dist/services/fulfillment.d.ts +63 -64
- package/dist/services/fulfillment.js +200 -194
- package/dist/services/fulfillment.js.map +1 -1
- package/dist/services/gift-card.d.ts +54 -45
- package/dist/services/gift-card.js +239 -221
- package/dist/services/gift-card.js.map +1 -1
- package/dist/services/idempotency-key.d.ts +1 -5
- package/dist/services/idempotency-key.js +2 -5
- package/dist/services/idempotency-key.js.map +1 -1
- package/dist/services/index.d.ts +11 -9
- package/dist/services/index.js +23 -19
- package/dist/services/index.js.map +1 -1
- package/dist/services/line-item.d.ts +3 -2
- package/dist/services/line-item.js +9 -7
- package/dist/services/line-item.js.map +1 -1
- package/dist/services/price-list.d.ts +4 -1
- package/dist/services/price-list.js +7 -4
- package/dist/services/price-list.js.map +1 -1
- package/dist/services/pricing.d.ts +101 -0
- package/dist/services/pricing.js +588 -0
- package/dist/services/pricing.js.map +1 -0
- package/dist/services/product-variant.d.ts +0 -11
- package/dist/services/product-variant.js +28 -138
- package/dist/services/product-variant.js.map +1 -1
- package/dist/services/product.d.ts +107 -145
- package/dist/services/product.js +708 -1036
- package/dist/services/product.js.map +1 -1
- package/dist/services/region.js +4 -4
- package/dist/services/region.js.map +1 -1
- package/dist/services/shipping-option.d.ts +43 -108
- package/dist/services/shipping-option.js +305 -352
- package/dist/services/shipping-option.js.map +1 -1
- package/dist/services/shipping-profile.d.ts +2 -2
- package/dist/services/shipping-profile.js +1 -1
- package/dist/services/store.d.ts +36 -45
- package/dist/services/store.js +207 -217
- package/dist/services/store.js.map +1 -1
- package/dist/services/strategy-resolver.d.ts +13 -0
- package/dist/services/strategy-resolver.js +40 -0
- package/dist/services/strategy-resolver.js.map +1 -0
- package/dist/services/tax-provider.d.ts +7 -3
- package/dist/services/tax-provider.js +6 -6
- package/dist/services/tax-provider.js.map +1 -1
- package/dist/services/tax-rate.d.ts +1 -1
- package/dist/services/tax-rate.js +2 -2
- package/dist/services/tax-rate.js.map +1 -1
- package/dist/services/totals.js.map +1 -1
- package/dist/services/user.d.ts +8 -9
- package/dist/services/user.js +216 -168
- package/dist/services/user.js.map +1 -1
- package/dist/strategies/__fixtures__/order-export-data.d.ts +3 -0
- package/dist/strategies/__fixtures__/order-export-data.js +70 -0
- package/dist/strategies/__fixtures__/order-export-data.js.map +1 -0
- package/dist/strategies/__fixtures__/product-export-data.d.ts +319 -0
- package/dist/strategies/__fixtures__/product-export-data.js +401 -0
- package/dist/strategies/__fixtures__/product-export-data.js.map +1 -0
- package/dist/strategies/batch-jobs/order/export.d.ts +36 -0
- package/dist/strategies/batch-jobs/order/export.js +351 -0
- package/dist/strategies/batch-jobs/order/export.js.map +1 -0
- package/dist/strategies/batch-jobs/order/index.d.ts +29 -0
- package/dist/strategies/batch-jobs/order/index.js +115 -0
- package/dist/strategies/batch-jobs/order/index.js.map +1 -0
- package/dist/strategies/batch-jobs/product/export.d.ts +36 -0
- package/dist/strategies/batch-jobs/product/export.js +546 -0
- package/dist/strategies/batch-jobs/product/export.js.map +1 -0
- package/dist/strategies/batch-jobs/product/index.d.ts +45 -0
- package/dist/strategies/batch-jobs/product/index.js +272 -0
- package/dist/strategies/batch-jobs/product/index.js.map +1 -0
- package/dist/subscribers/batch-job.d.ts +17 -0
- package/dist/subscribers/batch-job.js +96 -0
- package/dist/subscribers/batch-job.js.map +1 -0
- package/dist/types/batch-job.d.ts +23 -2
- package/dist/types/batch-job.js +4 -1
- package/dist/types/batch-job.js.map +1 -1
- package/dist/types/claim.d.ts +67 -0
- package/dist/types/claim.js +3 -0
- package/dist/types/claim.js.map +1 -0
- package/dist/types/common.d.ts +27 -3
- package/dist/types/common.js.map +1 -1
- package/dist/types/customers.d.ts +24 -0
- package/dist/types/customers.js.map +1 -1
- package/dist/types/discount.d.ts +2 -1
- package/dist/types/discount.js.map +1 -1
- package/dist/types/feature-flags.d.ts +9 -0
- package/dist/types/feature-flags.js +3 -0
- package/dist/types/feature-flags.js.map +1 -0
- package/dist/types/fulfillment.d.ts +27 -0
- package/dist/types/fulfillment.js +3 -0
- package/dist/types/fulfillment.js.map +1 -0
- package/dist/types/gift-card.d.ts +21 -0
- package/dist/types/gift-card.js +3 -0
- package/dist/types/gift-card.js.map +1 -0
- package/dist/types/global.d.ts +12 -1
- package/dist/types/price-list.d.ts +9 -0
- package/dist/types/pricing.d.ts +30 -0
- package/dist/types/pricing.js +3 -0
- package/dist/types/pricing.js.map +1 -0
- package/dist/types/product-variant.d.ts +4 -3
- package/dist/types/product-variant.js.map +1 -1
- package/dist/types/product.d.ts +110 -8
- package/dist/types/product.js +8 -11
- package/dist/types/product.js.map +1 -1
- package/dist/types/shipping-options.d.ts +62 -0
- package/dist/types/shipping-options.js +3 -0
- package/dist/types/shipping-options.js.map +1 -0
- package/dist/types/store.d.ts +9 -0
- package/dist/types/store.js +3 -0
- package/dist/types/store.js.map +1 -0
- package/dist/utils/build-query.d.ts +7 -7
- package/dist/utils/build-query.js +9 -5
- package/dist/utils/build-query.js.map +1 -1
- package/dist/utils/countries.d.ts +3 -2
- package/dist/utils/countries.js.map +1 -1
- package/dist/utils/currencies.d.ts +10 -1899
- package/dist/utils/currencies.js.map +1 -1
- package/dist/utils/db-aware-column.js +2 -2
- package/dist/utils/db-aware-column.js.map +1 -1
- package/dist/utils/feature-flag-decorators.d.ts +4 -0
- package/dist/utils/feature-flag-decorators.js +52 -0
- package/dist/utils/feature-flag-decorators.js.map +1 -0
- package/dist/utils/flag-router.d.ts +7 -0
- package/dist/utils/flag-router.js +19 -0
- package/dist/utils/flag-router.js.map +1 -0
- package/dist/utils/format-registration-name.d.ts +4 -4
- package/dist/utils/format-registration-name.js +7 -10
- package/dist/utils/format-registration-name.js.map +1 -1
- package/dist/utils/get-query-config.d.ts +4 -6
- package/dist/utils/get-query-config.js +46 -1
- package/dist/utils/get-query-config.js.map +1 -1
- package/dist/utils/omit-relation-if-exists.d.ts +7 -0
- package/dist/utils/omit-relation-if-exists.js +16 -0
- package/dist/utils/omit-relation-if-exists.js.map +1 -0
- package/dist/utils/set-metadata.d.ts +6 -6
- package/dist/utils/set-metadata.js +5 -5
- package/dist/utils/set-metadata.js.map +1 -1
- package/dist/utils/sleep.d.ts +1 -0
- package/dist/utils/sleep.js +50 -0
- package/dist/utils/sleep.js.map +1 -0
- package/package.json +6 -4
- 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
|
|
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 =
|
|
122
|
-
|
|
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
|
-
|
|
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
|
|
139
|
+
var _this = this;
|
|
157
140
|
return __generator(this, function (_a) {
|
|
158
141
|
switch (_a.label) {
|
|
159
|
-
case 0: return [4 /*yield*/, this.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
|
194
|
+
var _this = this;
|
|
202
195
|
return __generator(this, function (_a) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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 = {
|
|
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
|
|
233
|
+
var _this = this;
|
|
236
234
|
return __generator(this, function (_a) {
|
|
237
235
|
switch (_a.label) {
|
|
238
|
-
case 0:
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
query =
|
|
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 =
|
|
295
|
+
customer = _b.sent();
|
|
294
296
|
if (!customer) {
|
|
295
|
-
|
|
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
|
|
316
|
+
var _this = this;
|
|
312
317
|
return __generator(this, function (_a) {
|
|
313
318
|
switch (_a.label) {
|
|
314
|
-
case 0:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
-
|
|
482
|
-
|
|
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
|
-
|
|
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
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
|
554
|
+
CustomerService.prototype.updateBillingAddress_ = function (customer, addressOrId) {
|
|
525
555
|
return __awaiter(this, void 0, void 0, function () {
|
|
526
|
-
var
|
|
556
|
+
var _this = this;
|
|
527
557
|
return __generator(this, function (_a) {
|
|
528
558
|
switch (_a.label) {
|
|
529
|
-
case 0:
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
return
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
|
|
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
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
a.
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
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
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
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
|
-
}(
|
|
777
|
+
}(interfaces_1.TransactionBaseService));
|
|
741
778
|
exports.default = CustomerService;
|
|
742
779
|
//# sourceMappingURL=customer.js.map
|