@daffodil/cart 0.39.8 → 0.39.12

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 (147) hide show
  1. package/bundles/daffodil-cart-driver-in-memory.umd.js +4 -1
  2. package/bundles/daffodil-cart-driver-in-memory.umd.js.map +1 -1
  3. package/bundles/daffodil-cart-driver-in-memory.umd.min.js +1 -1
  4. package/bundles/daffodil-cart-driver-in-memory.umd.min.js.map +1 -1
  5. package/bundles/daffodil-cart-driver-magento-testing.umd.js +12 -2
  6. package/bundles/daffodil-cart-driver-magento-testing.umd.js.map +1 -1
  7. package/bundles/daffodil-cart-driver-magento-testing.umd.min.js +2 -2
  8. package/bundles/daffodil-cart-driver-magento-testing.umd.min.js.map +1 -1
  9. package/bundles/daffodil-cart-driver-magento.umd.js +119 -39
  10. package/bundles/daffodil-cart-driver-magento.umd.js.map +1 -1
  11. package/bundles/daffodil-cart-driver-magento.umd.min.js +1 -1
  12. package/bundles/daffodil-cart-driver-magento.umd.min.js.map +1 -1
  13. package/bundles/daffodil-cart-driver-testing.umd.js +6 -3
  14. package/bundles/daffodil-cart-driver-testing.umd.js.map +1 -1
  15. package/bundles/daffodil-cart-driver-testing.umd.min.js +1 -1
  16. package/bundles/daffodil-cart-driver-testing.umd.min.js.map +1 -1
  17. package/bundles/daffodil-cart-driver.umd.js.map +1 -1
  18. package/bundles/daffodil-cart-driver.umd.min.js.map +1 -1
  19. package/bundles/daffodil-cart-routing.umd.js +43 -0
  20. package/bundles/daffodil-cart-routing.umd.js.map +1 -1
  21. package/bundles/daffodil-cart-routing.umd.min.js +1 -1
  22. package/bundles/daffodil-cart-routing.umd.min.js.map +1 -1
  23. package/bundles/daffodil-cart-state-testing.umd.js +13 -2
  24. package/bundles/daffodil-cart-state-testing.umd.js.map +1 -1
  25. package/bundles/daffodil-cart-state-testing.umd.min.js +2 -2
  26. package/bundles/daffodil-cart-state-testing.umd.min.js.map +1 -1
  27. package/bundles/daffodil-cart-state.umd.js +169 -28
  28. package/bundles/daffodil-cart-state.umd.js.map +1 -1
  29. package/bundles/daffodil-cart-state.umd.min.js +1 -1
  30. package/bundles/daffodil-cart-state.umd.min.js.map +1 -1
  31. package/bundles/daffodil-cart-testing.umd.js +3 -3
  32. package/bundles/daffodil-cart-testing.umd.js.map +1 -1
  33. package/bundles/daffodil-cart-testing.umd.min.js +2 -2
  34. package/bundles/daffodil-cart-testing.umd.min.js.map +1 -1
  35. package/driver/daffodil-cart-driver.metadata.json +1 -1
  36. package/driver/in-memory/daffodil-cart-driver-in-memory.metadata.json +1 -1
  37. package/driver/in-memory/drivers/cart/cart.service.d.ts +3 -2
  38. package/driver/interfaces/cart-service.interface.d.ts +2 -1
  39. package/driver/magento/cart-item.service.d.ts +3 -1
  40. package/driver/magento/cart.service.d.ts +2 -1
  41. package/driver/magento/daffodil-cart-driver-magento.metadata.json +1 -1
  42. package/driver/magento/errors/transform.d.ts +13 -1
  43. package/driver/magento/injection-tokens/public_api.d.ts +1 -0
  44. package/driver/magento/injection-tokens/transforms/cart-item/token.d.ts +22 -0
  45. package/driver/magento/interfaces/cart-item-transform.type.d.ts +3 -0
  46. package/driver/magento/interfaces/public_api.d.ts +1 -0
  47. package/driver/magento/public_api.d.ts +1 -0
  48. package/driver/magento/testing/daffodil-cart-driver-magento-testing.metadata.json +1 -1
  49. package/driver/magento/testing/factories/public_api.d.ts +10 -10
  50. package/driver/magento/transforms/outputs/cart-coupon-response.service.d.ts +3 -0
  51. package/driver/magento/transforms/outputs/cart-item/cart-item-transformer.d.ts +7 -4
  52. package/driver/magento/transforms/outputs/cart.service.d.ts +3 -1
  53. package/driver/testing/daffodil-cart-driver-testing.metadata.json +1 -1
  54. package/driver/testing/drivers/cart/cart.service.d.ts +2 -1
  55. package/esm2015/driver/in-memory/drivers/cart/cart.service.js +5 -2
  56. package/esm2015/driver/interfaces/cart-service.interface.js +1 -1
  57. package/esm2015/driver/magento/cart-item.service.js +11 -8
  58. package/esm2015/driver/magento/cart.service.js +20 -7
  59. package/esm2015/driver/magento/errors/map.js +2 -2
  60. package/esm2015/driver/magento/errors/transform.js +15 -6
  61. package/esm2015/driver/magento/injection-tokens/public_api.js +2 -1
  62. package/esm2015/driver/magento/injection-tokens/transforms/cart-item/token.js +27 -0
  63. package/esm2015/driver/magento/interfaces/cart-item-transform.type.js +2 -0
  64. package/esm2015/driver/magento/interfaces/public_api.js +2 -0
  65. package/esm2015/driver/magento/public_api.js +2 -1
  66. package/esm2015/driver/magento/testing/factories/cart-address-input.factory.js +2 -2
  67. package/esm2015/driver/magento/testing/factories/cart-address.factory.js +2 -2
  68. package/esm2015/driver/magento/testing/factories/cart-coupon.factory.js +2 -2
  69. package/esm2015/driver/magento/testing/factories/cart-item/bundle-cart-item.factory.js +2 -2
  70. package/esm2015/driver/magento/testing/factories/cart-item/cart-item.factory.js +2 -2
  71. package/esm2015/driver/magento/testing/factories/cart-item/configurable-cart-item.factory.js +1 -1
  72. package/esm2015/driver/magento/testing/factories/cart-payment-method.factory.js +2 -2
  73. package/esm2015/driver/magento/testing/factories/cart-shipping-method.factory.js +2 -2
  74. package/esm2015/driver/magento/testing/factories/cart.factory.js +2 -2
  75. package/esm2015/driver/magento/testing/factories/public_api.js +11 -11
  76. package/esm2015/driver/magento/transforms/outputs/cart-coupon-response.service.js +15 -5
  77. package/esm2015/driver/magento/transforms/outputs/cart-item/bundle-cart-item-transformer.js +2 -2
  78. package/esm2015/driver/magento/transforms/outputs/cart-item/cart-item-transformer.js +9 -6
  79. package/esm2015/driver/magento/transforms/outputs/cart-item/configurable-cart-item-transformer.js +2 -2
  80. package/esm2015/driver/magento/transforms/outputs/cart-item/simple-cart-item-transformer.js +3 -3
  81. package/esm2015/driver/magento/transforms/outputs/cart.service.js +12 -7
  82. package/esm2015/driver/testing/drivers/cart/cart.service.js +5 -2
  83. package/esm2015/driver/testing/drivers/cart-order/cart-order.service.js +2 -2
  84. package/esm2015/routing/guards/in-stock-items/in-stock-items-guard-redirect.token.js +6 -0
  85. package/esm2015/routing/guards/in-stock-items/in-stock-items.guard.js +43 -0
  86. package/esm2015/routing/guards/public_api.js +3 -1
  87. package/esm2015/state/actions/cart-item.actions.js +30 -1
  88. package/esm2015/state/actions/cart.actions.js +29 -1
  89. package/esm2015/state/effects/cart-item.effects.js +17 -6
  90. package/esm2015/state/effects/cart-resolver.effects.js +24 -8
  91. package/esm2015/state/effects/cart.effects.js +13 -4
  92. package/esm2015/state/facades/cart/cart-facade.interface.js +1 -1
  93. package/esm2015/state/facades/cart/cart.facade.js +10 -2
  94. package/esm2015/state/models/stateful-cart-item.js +1 -1
  95. package/esm2015/state/reducers/cart/cart.reducer.js +7 -4
  96. package/esm2015/state/reducers/cart-item/cart-item.reducer.js +11 -1
  97. package/esm2015/state/reducers/cart-item-entities/cart-item-entities.reducer.js +11 -7
  98. package/esm2015/state/reducers/errors/error-state-helpers.js +3 -3
  99. package/esm2015/state/selectors/cart-item-entities/cart-item-entities.selectors.js +7 -1
  100. package/esm2015/state/testing/factories/stateful-cart-item.factory.js +2 -1
  101. package/esm2015/state/testing/factories/stateful-composite-cart-item.factory.js +5 -1
  102. package/esm2015/state/testing/factories/stateful-configurable-cart-item.factory.js +5 -1
  103. package/esm2015/state/testing/mock-cart-facade.js +7 -1
  104. package/esm2015/testing/factories/cart-address.factory.js +2 -2
  105. package/esm2015/testing/factories/cart-coupon.factory.js +2 -2
  106. package/esm2015/testing/factories/cart-item/cart-item.factory.js +3 -3
  107. package/esm2015/testing/factories/cart-item/composite-cart-item.factory.js +2 -2
  108. package/esm2015/testing/factories/cart-item/configurable-cart-item.factory.js +1 -1
  109. package/esm2015/testing/factories/cart-shipping-rate.factory.js +2 -2
  110. package/esm2015/testing/factories/cart.factory.js +2 -2
  111. package/fesm2015/daffodil-cart-driver-in-memory.js +4 -1
  112. package/fesm2015/daffodil-cart-driver-in-memory.js.map +1 -1
  113. package/fesm2015/daffodil-cart-driver-magento-testing.js +2 -2
  114. package/fesm2015/daffodil-cart-driver-magento-testing.js.map +1 -1
  115. package/fesm2015/daffodil-cart-driver-magento.js +108 -44
  116. package/fesm2015/daffodil-cart-driver-magento.js.map +1 -1
  117. package/fesm2015/daffodil-cart-driver-testing.js +5 -2
  118. package/fesm2015/daffodil-cart-driver-testing.js.map +1 -1
  119. package/fesm2015/daffodil-cart-driver.js.map +1 -1
  120. package/fesm2015/daffodil-cart-routing.js +40 -1
  121. package/fesm2015/daffodil-cart-routing.js.map +1 -1
  122. package/fesm2015/daffodil-cart-state-testing.js +15 -0
  123. package/fesm2015/daffodil-cart-state-testing.js.map +1 -1
  124. package/fesm2015/daffodil-cart-state.js +149 -28
  125. package/fesm2015/daffodil-cart-state.js.map +1 -1
  126. package/fesm2015/daffodil-cart-testing.js +2 -2
  127. package/fesm2015/daffodil-cart-testing.js.map +1 -1
  128. package/package.json +6 -6
  129. package/routing/daffodil-cart-routing.metadata.json +1 -1
  130. package/routing/guards/in-stock-items/in-stock-items-guard-redirect.token.d.ts +5 -0
  131. package/routing/guards/in-stock-items/in-stock-items.guard.d.ts +17 -0
  132. package/routing/guards/public_api.d.ts +2 -0
  133. package/state/actions/cart-item.actions.d.ts +26 -1
  134. package/state/actions/cart.actions.d.ts +31 -5
  135. package/state/daffodil-cart-state.metadata.json +1 -1
  136. package/state/effects/cart-item.effects.d.ts +5 -2
  137. package/state/effects/cart.effects.d.ts +2 -2
  138. package/state/facades/cart/cart-facade.interface.d.ts +19 -0
  139. package/state/facades/cart/cart.facade.d.ts +5 -0
  140. package/state/models/stateful-cart-item.d.ts +5 -0
  141. package/state/reducers/errors/error-state-helpers.d.ts +1 -1
  142. package/state/selectors/cart-item-entities/cart-item-entities.selectors.d.ts +13 -0
  143. package/state/testing/daffodil-cart-state-testing.metadata.json +1 -1
  144. package/state/testing/factories/stateful-cart-item.factory.d.ts +1 -0
  145. package/state/testing/factories/stateful-composite-cart-item.factory.d.ts +1 -0
  146. package/state/testing/factories/stateful-configurable-cart-item.factory.d.ts +1 -0
  147. package/state/testing/mock-cart-facade.d.ts +4 -0
@@ -1,16 +1,56 @@
1
- import { ɵɵdefineInjectable, Injectable, ɵɵinject, InjectionToken, inject, Inject, NgModule } from '@angular/core';
1
+ import { InjectionToken, ɵɵdefineInjectable, Injectable, ɵɵinject, Inject, inject, NgModule } from '@angular/core';
2
2
  import { DaffCartItemInputType, DaffCartTotalTypeEnum } from '@daffodil/cart';
3
3
  import { MagentoProductStockStatusEnum } from '@daffodil/product/driver/magento';
4
4
  import { daffAdd } from '@daffodil/core';
5
5
  import { gql, Apollo } from 'apollo-angular';
6
6
  import { daffBuildFragmentNameSpread, daffBuildFragmentDefinition, DaffQueuedApollo } from '@daffodil/core/graphql';
7
- import { throwError, forkJoin } from 'rxjs';
8
- import { catchError, map, switchMap, mapTo } from 'rxjs/operators';
9
- import { DaffCartNotFoundError, DaffCartDriverErrorCodes, DaffCartDriverErrorMap, DaffInvalidCouponCodeError, DaffCartItemDriver, DaffCartDriver, DaffCartAddressDriver, DaffCartBillingAddressDriver, DaffCartShippingAddressDriver, DaffCartShippingMethodsDriver, DaffCartShippingInformationDriver, DaffCartPaymentDriver, DaffCartPaymentMethodsDriver, DaffCartOrderDriver, DaffCartCouponDriver } from '@daffodil/cart/driver';
10
- import { daffTransformMagentoError } from '@daffodil/driver/magento';
7
+ import { forkJoin, throwError } from 'rxjs';
8
+ import { map, switchMap, catchError, mapTo } from 'rxjs/operators';
9
+ import { DaffCartNotFoundError, DaffCartDriverErrorCodes, DaffCartDriverErrorMap, DaffInvalidCouponCodeError, DaffProductOutOfStockError, DaffCartItemDriver, DaffCartDriver, DaffCartAddressDriver, DaffCartBillingAddressDriver, DaffCartShippingAddressDriver, DaffCartShippingMethodsDriver, DaffCartShippingInformationDriver, DaffCartPaymentDriver, DaffCartPaymentMethodsDriver, DaffCartOrderDriver, DaffCartCouponDriver } from '@daffodil/cart/driver';
10
+ import { daffMagentoTransformGraphQlError, daffTransformMagentoError } from '@daffodil/driver/magento';
11
11
  import { DaffBadInputError } from '@daffodil/driver';
12
12
  import { CommonModule } from '@angular/common';
13
13
 
14
+ /**
15
+ * An multi-provider injection token for providing extra GraphQL fragments that will be spread into cart queries.
16
+ * This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
17
+ * The data will appear in DaffCart#extra_attributes.
18
+ *
19
+ * Fragment structure is platform-specific and this feature should be used with care.
20
+ *
21
+ * This can increase query complexity above the Magento default of 300.
22
+ * Daffodil only guarantees that stock queries don't exceed the limit of 300.
23
+ * Apps using this token should therefore increase the query complexity limit
24
+ * to accommodate the extra complexity contributed by the provided fragments.
25
+ */
26
+ const DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS = new InjectionToken('DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS', { factory: () => [] });
27
+
28
+ /**
29
+ * A multi-provider injection token for providing cart item transform logic in the Magento driver.
30
+ * It is run after the standard transforms and passed both the current transformed Daffodil cart item and the Magento cart item.
31
+ */
32
+ const DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS = new InjectionToken('DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS', { factory: () => [] });
33
+ /**
34
+ * Provides cart item transforms for the Magento cart driver.
35
+ *
36
+ * See {@link DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS}.
37
+ *
38
+ * ```ts
39
+ * providers: [
40
+ * ...daffProvideCartMagentoCartItemTransforms(
41
+ * myCartItemTransform
42
+ * )
43
+ * ]
44
+ * ```
45
+ */
46
+ function daffProvideCartMagentoCartItemTransforms(...transforms) {
47
+ return transforms.map(transform => ({
48
+ provide: DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,
49
+ useValue: transform,
50
+ multi: true,
51
+ }));
52
+ }
53
+
14
54
  /**
15
55
  * Transforms magento addresses into an object usable by daffodil.
16
56
  */
@@ -98,7 +138,7 @@ var MagentoCartItemTypeEnum;
98
138
  */
99
139
  function transformMagentoSimpleCartItem(cartItem) {
100
140
  var _a;
101
- return cartItem ? {
141
+ return {
102
142
  // base
103
143
  type: DaffCartItemInputType.Simple,
104
144
  item_id: cartItem.id,
@@ -125,7 +165,7 @@ function transformMagentoSimpleCartItem(cartItem) {
125
165
  })) || [],
126
166
  // TODO: implement
127
167
  parent_item_id: null,
128
- } : null;
168
+ };
129
169
  }
130
170
 
131
171
  function transformBundleCartItemOption(option) {
@@ -142,7 +182,7 @@ function transformBundleCartItemOption(option) {
142
182
  * @param response the response from a magento cart query.
143
183
  */
144
184
  function transformMagentoBundleCartItem(bundleCartItem) {
145
- return bundleCartItem ? Object.assign(Object.assign({}, transformMagentoSimpleCartItem(bundleCartItem)), { type: DaffCartItemInputType.Composite, options: bundleCartItem.bundle_options.map(transformBundleCartItemOption) }) : null;
185
+ return Object.assign(Object.assign({}, transformMagentoSimpleCartItem(bundleCartItem)), { type: DaffCartItemInputType.Composite, options: bundleCartItem.bundle_options.map(transformBundleCartItemOption) });
146
186
  }
147
187
 
148
188
  function transformConfigurableCartItemAttribute(option) {
@@ -157,24 +197,27 @@ function transformConfigurableCartItemAttribute(option) {
157
197
  * @param response the response from a magento cart query.
158
198
  */
159
199
  function transformMagentoConfigurableCartItem(configurableCartItem) {
160
- return configurableCartItem ? Object.assign(Object.assign({}, transformMagentoSimpleCartItem(configurableCartItem)), { type: DaffCartItemInputType.Configurable, attributes: configurableCartItem.configurable_options.map(transformConfigurableCartItemAttribute) }) : null;
200
+ return Object.assign(Object.assign({}, transformMagentoSimpleCartItem(configurableCartItem)), { type: DaffCartItemInputType.Configurable, attributes: configurableCartItem.configurable_options.map(transformConfigurableCartItemAttribute) });
161
201
  }
162
202
 
163
203
  /**
164
- * Transforms the MagentoCartItem into a DaffCartItem.
165
- *
166
- * @param cartItem a MagentoCartItem
204
+ * The standard transform for a magento cart item.
167
205
  */
168
- function transformMagentoCartItem(cartItem) {
206
+ const daffTransformMagentoCartItem = (cartItem) => {
169
207
  switch (cartItem.__typename) {
170
208
  case MagentoCartItemTypeEnum.Bundle:
171
209
  return transformMagentoBundleCartItem(cartItem);
172
210
  case MagentoCartItemTypeEnum.Configurable:
173
211
  return transformMagentoConfigurableCartItem(cartItem);
212
+ case MagentoCartItemTypeEnum.Simple:
174
213
  default:
175
214
  return transformMagentoSimpleCartItem(cartItem);
176
215
  }
177
- }
216
+ };
217
+ /**
218
+ * Transforms the MagentoCartItem into a DaffCartItem using the provided transforms.
219
+ */
220
+ const transformMagentoCartItem = (daffCartItem, cartItem, transforms = []) => transforms.reduce((item, transform) => transform(item, cartItem), daffCartItem);
178
221
 
179
222
  /**
180
223
  * Transforms magento carts into an object usable by daffodil.
@@ -344,12 +387,13 @@ DaffMagentoShippingAddressTransformer.ctorParameters = () => [
344
387
  * Transforms magento carts into an object usable by daffodil.
345
388
  */
346
389
  class DaffMagentoCartTransformer {
347
- constructor(shippingAddressTransformer, billingAddressTransformer, paymentTransformer, shippingInformationTransformer, shippingRateTransformer) {
390
+ constructor(shippingAddressTransformer, billingAddressTransformer, paymentTransformer, shippingInformationTransformer, shippingRateTransformer, cartItemTransforms) {
348
391
  this.shippingAddressTransformer = shippingAddressTransformer;
349
392
  this.billingAddressTransformer = billingAddressTransformer;
350
393
  this.paymentTransformer = paymentTransformer;
351
394
  this.shippingInformationTransformer = shippingInformationTransformer;
352
395
  this.shippingRateTransformer = shippingRateTransformer;
396
+ this.cartItemTransforms = cartItemTransforms;
353
397
  }
354
398
  transformShippingAddress(cart) {
355
399
  return {
@@ -367,7 +411,8 @@ class DaffMagentoCartTransformer {
367
411
  }
368
412
  transformCartItems(cart) {
369
413
  return {
370
- items: cart.items.map(transformMagentoCartItem),
414
+ // TODO: extract into own transforms
415
+ items: cart.items.filter(item => !!item).map(item => transformMagentoCartItem(daffTransformMagentoCartItem(item), item, this.cartItemTransforms)),
371
416
  };
372
417
  }
373
418
  transformTotals(cart) {
@@ -416,7 +461,7 @@ class DaffMagentoCartTransformer {
416
461
  return cart ? Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ extra_attributes: cart }, this.transformCartItems(cart)), this.transformBillingAddress(cart)), this.transformShippingAddress(cart)), this.transformCoupons(cart)), this.transformPayment(cart)), this.transformTotals(cart)), transformCartTotals(cart)), this.transformShippingInformation(cart)), this.transformShippingMethods(cart)), this.transformPaymentMethods(cart)), { id: cart.id }) : null;
417
462
  }
418
463
  }
419
- /** @nocollapse */ DaffMagentoCartTransformer.ɵprov = ɵɵdefineInjectable({ factory: function DaffMagentoCartTransformer_Factory() { return new DaffMagentoCartTransformer(ɵɵinject(DaffMagentoShippingAddressTransformer), ɵɵinject(DaffMagentoBillingAddressTransformer), ɵɵinject(DaffMagentoCartPaymentTransformer), ɵɵinject(DaffMagentoCartShippingInformationTransformer), ɵɵinject(DaffMagentoCartShippingRateTransformer)); }, token: DaffMagentoCartTransformer, providedIn: "root" });
464
+ /** @nocollapse */ DaffMagentoCartTransformer.ɵprov = ɵɵdefineInjectable({ factory: function DaffMagentoCartTransformer_Factory() { return new DaffMagentoCartTransformer(ɵɵinject(DaffMagentoShippingAddressTransformer), ɵɵinject(DaffMagentoBillingAddressTransformer), ɵɵinject(DaffMagentoCartPaymentTransformer), ɵɵinject(DaffMagentoCartShippingInformationTransformer), ɵɵinject(DaffMagentoCartShippingRateTransformer), ɵɵinject(DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS)); }, token: DaffMagentoCartTransformer, providedIn: "root" });
420
465
  DaffMagentoCartTransformer.decorators = [
421
466
  { type: Injectable, args: [{
422
467
  providedIn: 'root',
@@ -428,7 +473,8 @@ DaffMagentoCartTransformer.ctorParameters = () => [
428
473
  { type: DaffMagentoBillingAddressTransformer },
429
474
  { type: DaffMagentoCartPaymentTransformer },
430
475
  { type: DaffMagentoCartShippingInformationTransformer },
431
- { type: DaffMagentoCartShippingRateTransformer }
476
+ { type: DaffMagentoCartShippingRateTransformer },
477
+ { type: Array, decorators: [{ type: Inject, args: [DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,] }] }
432
478
  ];
433
479
 
434
480
  class DaffMagentoCartAddressInputTransformer {
@@ -549,20 +595,6 @@ DaffMagentoShippingMethodInputTransformer.decorators = [
549
595
  },] }
550
596
  ];
551
597
 
552
- /**
553
- * An multi-provider injection token for providing extra GraphQL fragments that will be spread into cart queries.
554
- * This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
555
- * The data will appear in DaffCart#extra_attributes.
556
- *
557
- * Fragment structure is platform-specific and this feature should be used with care.
558
- *
559
- * This can increase query complexity above the Magento default of 300.
560
- * Daffodil only guarantees that stock queries don't exceed the limit of 300.
561
- * Apps using this token should therefore increase the query complexity limit
562
- * to accommodate the extra complexity contributed by the provided fragments.
563
- */
564
- const DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS = new InjectionToken('DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS', { factory: () => [] });
565
-
566
598
  const moneyFragment = gql `
567
599
  fragment money on Money {
568
600
  value
@@ -1311,17 +1343,22 @@ const DaffCartMagentoErrorMap = {
1311
1343
  };
1312
1344
  const DaffCartMagentoErrorMessageRegexMap = {
1313
1345
  [DaffCartDriverErrorCodes.INVALID_COUPON_CODE]: /The coupon code isn\'t valid/,
1314
- [DaffCartDriverErrorCodes.PRODUCT_OUT_OF_STOCK]: /(The requested qty is not available)|(This product is out of stock)|(Some of the products are out of stock)/,
1346
+ [DaffCartDriverErrorCodes.PRODUCT_OUT_OF_STOCK]: /(The requested qty is not available)|(This product is out of stock)|(Some of the products are out of stock)|(There are no source items with the in stock status)/,
1315
1347
  [DaffCartDriverErrorCodes.ITEM_EXCEEDS_MAX_QTY]: /The requested qty exceeds the maximum qty allowed in shopping cart/,
1316
1348
  [DaffCartDriverErrorCodes.INVALID_EMAIL]: /Invalid email format/,
1317
1349
  };
1318
1350
 
1351
+ /**
1352
+ * Transforms a single GraphQL error.
1353
+ * Optionally accepts a request payload which can be used in certain cases
1354
+ * to add supplemental info to the error.
1355
+ */
1319
1356
  function transformMagentoCartGraphQlError(error, requestPayload) {
1320
1357
  var _a;
1321
1358
  // TODO: readdress this when we move to eslint
1322
1359
  // eslint-disable-next-line
1323
1360
  for (const code in DaffCartMagentoErrorMessageRegexMap) {
1324
- const matchIndex = error.graphQLErrors[0].message.search(DaffCartMagentoErrorMessageRegexMap[code]);
1361
+ const matchIndex = error.message.search(DaffCartMagentoErrorMessageRegexMap[code]);
1325
1362
  if (matchIndex > -1 && DaffCartDriverErrorMap[code]) {
1326
1363
  const errObj = new DaffCartDriverErrorMap[code](error.message);
1327
1364
  if (errObj instanceof DaffInvalidCouponCodeError) {
@@ -1330,13 +1367,17 @@ function transformMagentoCartGraphQlError(error, requestPayload) {
1330
1367
  return errObj;
1331
1368
  }
1332
1369
  }
1333
- return daffTransformMagentoError(error, DaffCartMagentoErrorMap);
1370
+ return daffMagentoTransformGraphQlError(error, DaffCartMagentoErrorMap);
1334
1371
  }
1335
1372
  ;
1373
+ /**
1374
+ * Transforms only the first GraphQL error with the cart magento error transformer,
1375
+ * otherwise falls back to a standard Magento error transform.
1376
+ */
1336
1377
  function transformCartMagentoError(error, requestPayload) {
1337
1378
  var _a;
1338
1379
  if ((_a = error.graphQLErrors) === null || _a === void 0 ? void 0 : _a.length) {
1339
- return transformMagentoCartGraphQlError(error, requestPayload);
1380
+ return transformMagentoCartGraphQlError(error.graphQLErrors[0], requestPayload);
1340
1381
  }
1341
1382
  else {
1342
1383
  return daffTransformMagentoError(error, DaffCartMagentoErrorMap);
@@ -1348,6 +1389,9 @@ const DAFF_MAGENTO_CART_MUTATION_QUEUE = new InjectionToken('DAFF_MAGENTO_CART_M
1348
1389
  factory: () => new DaffQueuedApollo(inject(Apollo)),
1349
1390
  });
1350
1391
 
1392
+ const DAFF_MAGENTO_GET_RECOVERABLE_ERRORS = [
1393
+ DaffProductOutOfStockError,
1394
+ ];
1351
1395
  /**
1352
1396
  * A service for making Magento GraphQL queries for carts.
1353
1397
  *
@@ -1365,7 +1409,17 @@ class DaffMagentoCartService {
1365
1409
  return this.apollo.query({
1366
1410
  query: getCart(this.extraCartFragments),
1367
1411
  variables: { cartId },
1368
- }).pipe(catchError((error) => throwError(transformCartMagentoError(error))), map(result => this.cartTransformer.transform(result.data.cart)));
1412
+ errorPolicy: 'all',
1413
+ }).pipe(map(({ data, errors }) => ({
1414
+ response: data ? this.cartTransformer.transform(data.cart) : undefined,
1415
+ errors: (errors === null || errors === void 0 ? void 0 : errors.map(e => {
1416
+ const error = transformMagentoCartGraphQlError(e);
1417
+ if (DAFF_MAGENTO_GET_RECOVERABLE_ERRORS.filter(klass => error instanceof klass).length > 0) {
1418
+ error.recoverable = true;
1419
+ }
1420
+ return error;
1421
+ })) || [],
1422
+ })));
1369
1423
  }
1370
1424
  create() {
1371
1425
  return this.mutationQueue.mutate({ mutation: createCart }).pipe(map(result => ({ id: result.data.createEmptyCart })));
@@ -1374,7 +1428,7 @@ class DaffMagentoCartService {
1374
1428
  throw new Error('Method is deprecated. Use DaffCartItemServiceInterface#add instead.');
1375
1429
  }
1376
1430
  clear(cartId) {
1377
- return this.cartItemDriver.list(cartId).pipe(switchMap(items => forkJoin(...items.map(item => this.cartItemDriver.delete(cartId, item.id)))), switchMap(() => this.get(cartId)));
1431
+ return this.cartItemDriver.list(cartId).pipe(switchMap(items => forkJoin(...items.map(item => this.cartItemDriver.delete(cartId, item.id)))), switchMap(() => this.get(cartId)), map(({ response }) => response));
1378
1432
  }
1379
1433
  }
1380
1434
  /** @nocollapse */ DaffMagentoCartService.ɵprov = ɵɵdefineInjectable({ factory: function DaffMagentoCartService_Factory() { return new DaffMagentoCartService(ɵɵinject(Apollo), ɵɵinject(DAFF_MAGENTO_CART_MUTATION_QUEUE), ɵɵinject(DaffMagentoCartTransformer), ɵɵinject(DaffCartItemDriver), ɵɵinject(DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS)); }, token: DaffMagentoCartService, providedIn: "root" });
@@ -1416,10 +1470,11 @@ function transformConfigurableCartItem(item) {
1416
1470
  * @inheritdoc
1417
1471
  */
1418
1472
  class DaffMagentoCartItemService {
1419
- constructor(apollo, mutationQueue, extraCartFragments, cartTransformer, cartItemUpdateInputTransformer) {
1473
+ constructor(apollo, mutationQueue, extraCartFragments, cartItemTransforms, cartTransformer, cartItemUpdateInputTransformer) {
1420
1474
  this.apollo = apollo;
1421
1475
  this.mutationQueue = mutationQueue;
1422
1476
  this.extraCartFragments = extraCartFragments;
1477
+ this.cartItemTransforms = cartItemTransforms;
1423
1478
  this.cartTransformer = cartTransformer;
1424
1479
  this.cartItemUpdateInputTransformer = cartItemUpdateInputTransformer;
1425
1480
  }
@@ -1427,7 +1482,7 @@ class DaffMagentoCartItemService {
1427
1482
  return this.apollo.query({
1428
1483
  query: listCartItems(this.extraCartFragments),
1429
1484
  variables: { cartId },
1430
- }).pipe(map(result => result.data.cart.items.map(transformMagentoCartItem)));
1485
+ }).pipe(map(result => result.data.cart.items.filter(item => !!item)), map(items => items.map(item => transformMagentoCartItem(daffTransformMagentoCartItem(item), item, this.cartItemTransforms))));
1431
1486
  }
1432
1487
  get(cartId, itemId) {
1433
1488
  return this.list(cartId).pipe(map(items => items.find(item => item.id === itemId)));
@@ -1479,7 +1534,7 @@ class DaffMagentoCartItemService {
1479
1534
  }).pipe(map(result => this.cartTransformer.transform(result.data.addProductsToCart.cart)));
1480
1535
  }
1481
1536
  }
1482
- /** @nocollapse */ DaffMagentoCartItemService.ɵprov = ɵɵdefineInjectable({ factory: function DaffMagentoCartItemService_Factory() { return new DaffMagentoCartItemService(ɵɵinject(Apollo), ɵɵinject(DAFF_MAGENTO_CART_MUTATION_QUEUE), ɵɵinject(DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS), ɵɵinject(DaffMagentoCartTransformer), ɵɵinject(DaffMagentoCartItemUpdateInputTransformer)); }, token: DaffMagentoCartItemService, providedIn: "root" });
1537
+ /** @nocollapse */ DaffMagentoCartItemService.ɵprov = ɵɵdefineInjectable({ factory: function DaffMagentoCartItemService_Factory() { return new DaffMagentoCartItemService(ɵɵinject(Apollo), ɵɵinject(DAFF_MAGENTO_CART_MUTATION_QUEUE), ɵɵinject(DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS), ɵɵinject(DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS), ɵɵinject(DaffMagentoCartTransformer), ɵɵinject(DaffMagentoCartItemUpdateInputTransformer)); }, token: DaffMagentoCartItemService, providedIn: "root" });
1483
1538
  DaffMagentoCartItemService.decorators = [
1484
1539
  { type: Injectable, args: [{
1485
1540
  providedIn: 'root',
@@ -1490,6 +1545,7 @@ DaffMagentoCartItemService.ctorParameters = () => [
1490
1545
  { type: Apollo },
1491
1546
  { type: DaffQueuedApollo, decorators: [{ type: Inject, args: [DAFF_MAGENTO_CART_MUTATION_QUEUE,] }] },
1492
1547
  { type: Array, decorators: [{ type: Inject, args: [DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS,] }] },
1548
+ { type: Array, decorators: [{ type: Inject, args: [DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,] }] },
1493
1549
  { type: DaffMagentoCartTransformer },
1494
1550
  { type: DaffMagentoCartItemUpdateInputTransformer }
1495
1551
  ];
@@ -1882,9 +1938,13 @@ DaffMagentoCartAddressService.ctorParameters = () => [
1882
1938
  * Transforms magento carts into an object usable by daffodil.
1883
1939
  */
1884
1940
  class DaffMagentoCartCouponResponseTransformer {
1941
+ constructor(cartItemTransforms) {
1942
+ this.cartItemTransforms = cartItemTransforms;
1943
+ }
1885
1944
  transformCartItems(cart) {
1886
1945
  return {
1887
- items: cart.items.map(transformMagentoCartItem),
1946
+ // TODO: extract into own transforms
1947
+ items: cart.items.filter(item => !!item).map(item => transformMagentoCartItem(daffTransformMagentoCartItem(item), item, this.cartItemTransforms)),
1888
1948
  };
1889
1949
  }
1890
1950
  transformTotals(cart) {
@@ -1909,12 +1969,16 @@ class DaffMagentoCartCouponResponseTransformer {
1909
1969
  return cart ? Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this.transformCartItems(cart)), this.transformCoupons(cart)), this.transformTotals(cart)), transformCartTotals(cart)), { id: cart.id }) : null;
1910
1970
  }
1911
1971
  }
1912
- /** @nocollapse */ DaffMagentoCartCouponResponseTransformer.ɵprov = ɵɵdefineInjectable({ factory: function DaffMagentoCartCouponResponseTransformer_Factory() { return new DaffMagentoCartCouponResponseTransformer(); }, token: DaffMagentoCartCouponResponseTransformer, providedIn: "root" });
1972
+ /** @nocollapse */ DaffMagentoCartCouponResponseTransformer.ɵprov = ɵɵdefineInjectable({ factory: function DaffMagentoCartCouponResponseTransformer_Factory() { return new DaffMagentoCartCouponResponseTransformer(ɵɵinject(DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS)); }, token: DaffMagentoCartCouponResponseTransformer, providedIn: "root" });
1913
1973
  DaffMagentoCartCouponResponseTransformer.decorators = [
1914
1974
  { type: Injectable, args: [{
1915
1975
  providedIn: 'root',
1916
1976
  },] }
1917
1977
  ];
1978
+ /** @nocollapse */
1979
+ DaffMagentoCartCouponResponseTransformer.ctorParameters = () => [
1980
+ { type: Array, decorators: [{ type: Inject, args: [DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,] }] }
1981
+ ];
1918
1982
 
1919
1983
  /**
1920
1984
  * A service for making Magento GraphQL queries for carts.
@@ -2083,5 +2147,5 @@ DaffCartMagentoDriverModule.decorators = [
2083
2147
  * Generated bundle index. Do not edit.
2084
2148
  */
2085
2149
 
2086
- export { DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS, DaffCartMagentoDriverModule, DaffMagentoBillingAddressInputTransformer, DaffMagentoBillingAddressTransformer, DaffMagentoCartAddressInputTransformer, DaffMagentoCartAddressTransformer, DaffMagentoCartBillingAddressService, DaffMagentoCartItemService, DaffMagentoCartItemUpdateInputTransformer, DaffMagentoCartPaymentMethodsService, DaffMagentoCartPaymentService, DaffMagentoCartPaymentTransformer, DaffMagentoCartService, DaffMagentoCartShippingAddressService, DaffMagentoCartShippingInformationService, DaffMagentoCartShippingInformationTransformer, DaffMagentoCartShippingMethodsService, DaffMagentoCartShippingRateTransformer, DaffMagentoCartTransformer, DaffMagentoPaymentMethodInputTransformer, DaffMagentoShippingAddressInputTransformer, DaffMagentoShippingAddressTransformer, DaffMagentoShippingMethodInputTransformer, MagentoCartItemTypeEnum, addCartItem, applyCoupon, availablePaymentMethodFragment, availableShippingMethodFragment, cartAddressFragment, cartCouponFragment, cartFragment, cartItemFragment, createCart, getBillingAddress, getCart, getSelectedPaymentMethod, getSelectedShippingMethod, getShippingAddress, listCartCoupons, listCartItems, listPaymentMethods, listShippingMethods, moneyFragment, placeOrder, pricesFragment, removeAllCoupons, removeCartItem, selectedPaymentMethodFragment, selectedShippingMethodFragment, setSelectedPaymentMethod, setSelectedPaymentMethodWithBilling, setSelectedPaymentMethodWithBillingAndEmail, setSelectedShippingMethod, updateAddress, updateAddressWithEmail, updateBillingAddress, updateBillingAddressWithEmail, updateCartItem, updateShippingAddress, updateShippingAddressWithEmail, DAFF_MAGENTO_CART_MUTATION_QUEUE as ɵa, DaffMagentoCartAddressService as ɵb, DaffMagentoCartOrderService as ɵc, DaffMagentoCartCouponService as ɵd, DaffMagentoCartCouponResponseTransformer as ɵe };
2150
+ export { DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS, DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS, DaffCartMagentoDriverModule, DaffMagentoBillingAddressInputTransformer, DaffMagentoBillingAddressTransformer, DaffMagentoCartAddressInputTransformer, DaffMagentoCartAddressTransformer, DaffMagentoCartBillingAddressService, DaffMagentoCartItemService, DaffMagentoCartItemUpdateInputTransformer, DaffMagentoCartPaymentMethodsService, DaffMagentoCartPaymentService, DaffMagentoCartPaymentTransformer, DaffMagentoCartService, DaffMagentoCartShippingAddressService, DaffMagentoCartShippingInformationService, DaffMagentoCartShippingInformationTransformer, DaffMagentoCartShippingMethodsService, DaffMagentoCartShippingRateTransformer, DaffMagentoCartTransformer, DaffMagentoPaymentMethodInputTransformer, DaffMagentoShippingAddressInputTransformer, DaffMagentoShippingAddressTransformer, DaffMagentoShippingMethodInputTransformer, MagentoCartItemTypeEnum, addCartItem, applyCoupon, availablePaymentMethodFragment, availableShippingMethodFragment, cartAddressFragment, cartCouponFragment, cartFragment, cartItemFragment, createCart, daffProvideCartMagentoCartItemTransforms, getBillingAddress, getCart, getSelectedPaymentMethod, getSelectedShippingMethod, getShippingAddress, listCartCoupons, listCartItems, listPaymentMethods, listShippingMethods, moneyFragment, placeOrder, pricesFragment, removeAllCoupons, removeCartItem, selectedPaymentMethodFragment, selectedShippingMethodFragment, setSelectedPaymentMethod, setSelectedPaymentMethodWithBilling, setSelectedPaymentMethodWithBillingAndEmail, setSelectedShippingMethod, updateAddress, updateAddressWithEmail, updateBillingAddress, updateBillingAddressWithEmail, updateCartItem, updateShippingAddress, updateShippingAddressWithEmail, DAFF_MAGENTO_CART_MUTATION_QUEUE as ɵa, DaffMagentoCartAddressService as ɵb, DaffMagentoCartOrderService as ɵc, DaffMagentoCartCouponService as ɵd, DaffMagentoCartCouponResponseTransformer as ɵe };
2087
2151
  //# sourceMappingURL=daffodil-cart-driver-magento.js.map