@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
@@ -4,6 +4,50 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.daffodil = global.daffodil || {}, global.daffodil.cart = global.daffodil.cart || {}, global.daffodil.cart.driver = global.daffodil.cart.driver || {}, global.daffodil.cart.driver.magento = {}), global.ng.core, global.daffodil.cart, global.magento, global.core, global.i1, global.graphql, global.rxjs, global.rxjs.operators, global.daffodil.cart.driver, global.magento$1, global.driver, global.ng.common));
5
5
  }(this, (function (exports, i0, cart, magento, core, i1, graphql, rxjs, operators, i4, magento$1, driver, common) { 'use strict';
6
6
 
7
+ /**
8
+ * An multi-provider injection token for providing extra GraphQL fragments that will be spread into cart queries.
9
+ * This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
10
+ * The data will appear in DaffCart#extra_attributes.
11
+ *
12
+ * Fragment structure is platform-specific and this feature should be used with care.
13
+ *
14
+ * This can increase query complexity above the Magento default of 300.
15
+ * Daffodil only guarantees that stock queries don't exceed the limit of 300.
16
+ * Apps using this token should therefore increase the query complexity limit
17
+ * to accommodate the extra complexity contributed by the provided fragments.
18
+ */
19
+ var DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS = new i0.InjectionToken('DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS', { factory: function () { return []; } });
20
+
21
+ /**
22
+ * A multi-provider injection token for providing cart item transform logic in the Magento driver.
23
+ * It is run after the standard transforms and passed both the current transformed Daffodil cart item and the Magento cart item.
24
+ */
25
+ var DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS = new i0.InjectionToken('DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS', { factory: function () { return []; } });
26
+ /**
27
+ * Provides cart item transforms for the Magento cart driver.
28
+ *
29
+ * See {@link DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS}.
30
+ *
31
+ * ```ts
32
+ * providers: [
33
+ * ...daffProvideCartMagentoCartItemTransforms(
34
+ * myCartItemTransform
35
+ * )
36
+ * ]
37
+ * ```
38
+ */
39
+ function daffProvideCartMagentoCartItemTransforms() {
40
+ var transforms = [];
41
+ for (var _i = 0; _i < arguments.length; _i++) {
42
+ transforms[_i] = arguments[_i];
43
+ }
44
+ return transforms.map(function (transform) { return ({
45
+ provide: DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,
46
+ useValue: transform,
47
+ multi: true,
48
+ }); });
49
+ }
50
+
7
51
  /**
8
52
  * Transforms magento addresses into an object usable by daffodil.
9
53
  */
@@ -94,7 +138,7 @@
94
138
  */
95
139
  function transformMagentoSimpleCartItem(cartItem) {
96
140
  var _a;
97
- return cartItem ? {
141
+ return {
98
142
  // base
99
143
  type: cart.DaffCartItemInputType.Simple,
100
144
  item_id: cartItem.id,
@@ -121,7 +165,7 @@
121
165
  })) || [],
122
166
  // TODO: implement
123
167
  parent_item_id: null,
124
- } : null;
168
+ };
125
169
  }
126
170
 
127
171
  function transformBundleCartItemOption(option) {
@@ -138,7 +182,7 @@
138
182
  * @param response the response from a magento cart query.
139
183
  */
140
184
  function transformMagentoBundleCartItem(bundleCartItem) {
141
- return bundleCartItem ? Object.assign(Object.assign({}, transformMagentoSimpleCartItem(bundleCartItem)), { type: cart.DaffCartItemInputType.Composite, options: bundleCartItem.bundle_options.map(transformBundleCartItemOption) }) : null;
185
+ return Object.assign(Object.assign({}, transformMagentoSimpleCartItem(bundleCartItem)), { type: cart.DaffCartItemInputType.Composite, options: bundleCartItem.bundle_options.map(transformBundleCartItemOption) });
142
186
  }
143
187
 
144
188
  function transformConfigurableCartItemAttribute(option) {
@@ -153,24 +197,30 @@
153
197
  * @param response the response from a magento cart query.
154
198
  */
155
199
  function transformMagentoConfigurableCartItem(configurableCartItem) {
156
- return configurableCartItem ? Object.assign(Object.assign({}, transformMagentoSimpleCartItem(configurableCartItem)), { type: cart.DaffCartItemInputType.Configurable, attributes: configurableCartItem.configurable_options.map(transformConfigurableCartItemAttribute) }) : null;
200
+ return Object.assign(Object.assign({}, transformMagentoSimpleCartItem(configurableCartItem)), { type: cart.DaffCartItemInputType.Configurable, attributes: configurableCartItem.configurable_options.map(transformConfigurableCartItemAttribute) });
157
201
  }
158
202
 
159
203
  /**
160
- * Transforms the MagentoCartItem into a DaffCartItem.
161
- *
162
- * @param cartItem a MagentoCartItem
204
+ * The standard transform for a magento cart item.
163
205
  */
164
- function transformMagentoCartItem(cartItem) {
206
+ var daffTransformMagentoCartItem = function (cartItem) {
165
207
  switch (cartItem.__typename) {
166
208
  case exports.MagentoCartItemTypeEnum.Bundle:
167
209
  return transformMagentoBundleCartItem(cartItem);
168
210
  case exports.MagentoCartItemTypeEnum.Configurable:
169
211
  return transformMagentoConfigurableCartItem(cartItem);
212
+ case exports.MagentoCartItemTypeEnum.Simple:
170
213
  default:
171
214
  return transformMagentoSimpleCartItem(cartItem);
172
215
  }
173
- }
216
+ };
217
+ /**
218
+ * Transforms the MagentoCartItem into a DaffCartItem using the provided transforms.
219
+ */
220
+ var transformMagentoCartItem = function (daffCartItem, cartItem, transforms) {
221
+ if (transforms === void 0) { transforms = []; }
222
+ return transforms.reduce(function (item, transform) { return transform(item, cartItem); }, daffCartItem);
223
+ };
174
224
 
175
225
  /**
176
226
  * Transforms magento carts into an object usable by daffodil.
@@ -667,12 +717,13 @@
667
717
  * Transforms magento carts into an object usable by daffodil.
668
718
  */
669
719
  var DaffMagentoCartTransformer = /** @class */ (function () {
670
- function DaffMagentoCartTransformer(shippingAddressTransformer, billingAddressTransformer, paymentTransformer, shippingInformationTransformer, shippingRateTransformer) {
720
+ function DaffMagentoCartTransformer(shippingAddressTransformer, billingAddressTransformer, paymentTransformer, shippingInformationTransformer, shippingRateTransformer, cartItemTransforms) {
671
721
  this.shippingAddressTransformer = shippingAddressTransformer;
672
722
  this.billingAddressTransformer = billingAddressTransformer;
673
723
  this.paymentTransformer = paymentTransformer;
674
724
  this.shippingInformationTransformer = shippingInformationTransformer;
675
725
  this.shippingRateTransformer = shippingRateTransformer;
726
+ this.cartItemTransforms = cartItemTransforms;
676
727
  }
677
728
  DaffMagentoCartTransformer.prototype.transformShippingAddress = function (cart) {
678
729
  return {
@@ -689,8 +740,10 @@
689
740
  };
690
741
  };
691
742
  DaffMagentoCartTransformer.prototype.transformCartItems = function (cart) {
743
+ var _this = this;
692
744
  return {
693
- items: cart.items.map(transformMagentoCartItem),
745
+ // TODO: extract into own transforms
746
+ items: cart.items.filter(function (item) { return !!item; }).map(function (item) { return transformMagentoCartItem(daffTransformMagentoCartItem(item), item, _this.cartItemTransforms); }),
694
747
  };
695
748
  };
696
749
  DaffMagentoCartTransformer.prototype.transformTotals = function (cart) {
@@ -742,7 +795,7 @@
742
795
  };
743
796
  return DaffMagentoCartTransformer;
744
797
  }());
745
- /** @nocollapse */ DaffMagentoCartTransformer.ɵprov = i0.ɵɵdefineInjectable({ factory: function DaffMagentoCartTransformer_Factory() { return new DaffMagentoCartTransformer(i0.ɵɵinject(DaffMagentoShippingAddressTransformer), i0.ɵɵinject(DaffMagentoBillingAddressTransformer), i0.ɵɵinject(DaffMagentoCartPaymentTransformer), i0.ɵɵinject(DaffMagentoCartShippingInformationTransformer), i0.ɵɵinject(DaffMagentoCartShippingRateTransformer)); }, token: DaffMagentoCartTransformer, providedIn: "root" });
798
+ /** @nocollapse */ DaffMagentoCartTransformer.ɵprov = i0.ɵɵdefineInjectable({ factory: function DaffMagentoCartTransformer_Factory() { return new DaffMagentoCartTransformer(i0.ɵɵinject(DaffMagentoShippingAddressTransformer), i0.ɵɵinject(DaffMagentoBillingAddressTransformer), i0.ɵɵinject(DaffMagentoCartPaymentTransformer), i0.ɵɵinject(DaffMagentoCartShippingInformationTransformer), i0.ɵɵinject(DaffMagentoCartShippingRateTransformer), i0.ɵɵinject(DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS)); }, token: DaffMagentoCartTransformer, providedIn: "root" });
746
799
  DaffMagentoCartTransformer.decorators = [
747
800
  { type: i0.Injectable, args: [{
748
801
  providedIn: 'root',
@@ -754,7 +807,8 @@
754
807
  { type: DaffMagentoBillingAddressTransformer },
755
808
  { type: DaffMagentoCartPaymentTransformer },
756
809
  { type: DaffMagentoCartShippingInformationTransformer },
757
- { type: DaffMagentoCartShippingRateTransformer }
810
+ { type: DaffMagentoCartShippingRateTransformer },
811
+ { type: Array, decorators: [{ type: i0.Inject, args: [DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,] }] }
758
812
  ]; };
759
813
 
760
814
  var DaffMagentoCartAddressInputTransformer = /** @class */ (function () {
@@ -889,20 +943,6 @@
889
943
  },] }
890
944
  ];
891
945
 
892
- /**
893
- * An multi-provider injection token for providing extra GraphQL fragments that will be spread into cart queries.
894
- * This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
895
- * The data will appear in DaffCart#extra_attributes.
896
- *
897
- * Fragment structure is platform-specific and this feature should be used with care.
898
- *
899
- * This can increase query complexity above the Magento default of 300.
900
- * Daffodil only guarantees that stock queries don't exceed the limit of 300.
901
- * Apps using this token should therefore increase the query complexity limit
902
- * to accommodate the extra complexity contributed by the provided fragments.
903
- */
904
- var DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS = new i0.InjectionToken('DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS', { factory: function () { return []; } });
905
-
906
946
  var moneyFragment = i1.gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n fragment money on Money {\n value\n currency\n }\n"], ["\n fragment money on Money {\n value\n currency\n }\n"])));
907
947
  var templateObject_1;
908
948
 
@@ -1114,17 +1154,22 @@
1114
1154
  _a);
1115
1155
  var DaffCartMagentoErrorMessageRegexMap = (_b = {},
1116
1156
  _b[i4.DaffCartDriverErrorCodes.INVALID_COUPON_CODE] = /The coupon code isn\'t valid/,
1117
- _b[i4.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)/,
1157
+ _b[i4.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)/,
1118
1158
  _b[i4.DaffCartDriverErrorCodes.ITEM_EXCEEDS_MAX_QTY] = /The requested qty exceeds the maximum qty allowed in shopping cart/,
1119
1159
  _b[i4.DaffCartDriverErrorCodes.INVALID_EMAIL] = /Invalid email format/,
1120
1160
  _b);
1121
1161
 
1162
+ /**
1163
+ * Transforms a single GraphQL error.
1164
+ * Optionally accepts a request payload which can be used in certain cases
1165
+ * to add supplemental info to the error.
1166
+ */
1122
1167
  function transformMagentoCartGraphQlError(error, requestPayload) {
1123
1168
  var _a;
1124
1169
  // TODO: readdress this when we move to eslint
1125
1170
  // eslint-disable-next-line
1126
1171
  for (var code in DaffCartMagentoErrorMessageRegexMap) {
1127
- var matchIndex = error.graphQLErrors[0].message.search(DaffCartMagentoErrorMessageRegexMap[code]);
1172
+ var matchIndex = error.message.search(DaffCartMagentoErrorMessageRegexMap[code]);
1128
1173
  if (matchIndex > -1 && i4.DaffCartDriverErrorMap[code]) {
1129
1174
  var errObj = new i4.DaffCartDriverErrorMap[code](error.message);
1130
1175
  if (errObj instanceof i4.DaffInvalidCouponCodeError) {
@@ -1133,13 +1178,17 @@
1133
1178
  return errObj;
1134
1179
  }
1135
1180
  }
1136
- return magento$1.daffTransformMagentoError(error, DaffCartMagentoErrorMap);
1181
+ return magento$1.daffMagentoTransformGraphQlError(error, DaffCartMagentoErrorMap);
1137
1182
  }
1138
1183
  ;
1184
+ /**
1185
+ * Transforms only the first GraphQL error with the cart magento error transformer,
1186
+ * otherwise falls back to a standard Magento error transform.
1187
+ */
1139
1188
  function transformCartMagentoError(error, requestPayload) {
1140
1189
  var _a;
1141
1190
  if ((_a = error.graphQLErrors) === null || _a === void 0 ? void 0 : _a.length) {
1142
- return transformMagentoCartGraphQlError(error, requestPayload);
1191
+ return transformMagentoCartGraphQlError(error.graphQLErrors[0], requestPayload);
1143
1192
  }
1144
1193
  else {
1145
1194
  return magento$1.daffTransformMagentoError(error, DaffCartMagentoErrorMap);
@@ -1151,6 +1200,9 @@
1151
1200
  factory: function () { return new graphql.DaffQueuedApollo(i0.inject(i1.Apollo)); },
1152
1201
  });
1153
1202
 
1203
+ var DAFF_MAGENTO_GET_RECOVERABLE_ERRORS = [
1204
+ i4.DaffProductOutOfStockError,
1205
+ ];
1154
1206
  /**
1155
1207
  * A service for making Magento GraphQL queries for carts.
1156
1208
  *
@@ -1169,7 +1221,20 @@
1169
1221
  return this.apollo.query({
1170
1222
  query: getCart(this.extraCartFragments),
1171
1223
  variables: { cartId: cartId },
1172
- }).pipe(operators.catchError(function (error) { return rxjs.throwError(transformCartMagentoError(error)); }), operators.map(function (result) { return _this.cartTransformer.transform(result.data.cart); }));
1224
+ errorPolicy: 'all',
1225
+ }).pipe(operators.map(function (_a) {
1226
+ var data = _a.data, errors = _a.errors;
1227
+ return ({
1228
+ response: data ? _this.cartTransformer.transform(data.cart) : undefined,
1229
+ errors: (errors === null || errors === void 0 ? void 0 : errors.map(function (e) {
1230
+ var error = transformMagentoCartGraphQlError(e);
1231
+ if (DAFF_MAGENTO_GET_RECOVERABLE_ERRORS.filter(function (klass) { return error instanceof klass; }).length > 0) {
1232
+ error.recoverable = true;
1233
+ }
1234
+ return error;
1235
+ })) || [],
1236
+ });
1237
+ }));
1173
1238
  };
1174
1239
  DaffMagentoCartService.prototype.create = function () {
1175
1240
  return this.mutationQueue.mutate({ mutation: createCart }).pipe(operators.map(function (result) { return ({ id: result.data.createEmptyCart }); }));
@@ -1179,7 +1244,10 @@
1179
1244
  };
1180
1245
  DaffMagentoCartService.prototype.clear = function (cartId) {
1181
1246
  var _this = this;
1182
- return this.cartItemDriver.list(cartId).pipe(operators.switchMap(function (items) { return rxjs.forkJoin.apply(void 0, __spread(items.map(function (item) { return _this.cartItemDriver.delete(cartId, item.id); }))); }), operators.switchMap(function () { return _this.get(cartId); }));
1247
+ return this.cartItemDriver.list(cartId).pipe(operators.switchMap(function (items) { return rxjs.forkJoin.apply(void 0, __spread(items.map(function (item) { return _this.cartItemDriver.delete(cartId, item.id); }))); }), operators.switchMap(function () { return _this.get(cartId); }), operators.map(function (_a) {
1248
+ var response = _a.response;
1249
+ return response;
1250
+ }));
1183
1251
  };
1184
1252
  return DaffMagentoCartService;
1185
1253
  }());
@@ -1222,18 +1290,20 @@
1222
1290
  * @inheritdoc
1223
1291
  */
1224
1292
  var DaffMagentoCartItemService = /** @class */ (function () {
1225
- function DaffMagentoCartItemService(apollo, mutationQueue, extraCartFragments, cartTransformer, cartItemUpdateInputTransformer) {
1293
+ function DaffMagentoCartItemService(apollo, mutationQueue, extraCartFragments, cartItemTransforms, cartTransformer, cartItemUpdateInputTransformer) {
1226
1294
  this.apollo = apollo;
1227
1295
  this.mutationQueue = mutationQueue;
1228
1296
  this.extraCartFragments = extraCartFragments;
1297
+ this.cartItemTransforms = cartItemTransforms;
1229
1298
  this.cartTransformer = cartTransformer;
1230
1299
  this.cartItemUpdateInputTransformer = cartItemUpdateInputTransformer;
1231
1300
  }
1232
1301
  DaffMagentoCartItemService.prototype.list = function (cartId) {
1302
+ var _this = this;
1233
1303
  return this.apollo.query({
1234
1304
  query: listCartItems(this.extraCartFragments),
1235
1305
  variables: { cartId: cartId },
1236
- }).pipe(operators.map(function (result) { return result.data.cart.items.map(transformMagentoCartItem); }));
1306
+ }).pipe(operators.map(function (result) { return result.data.cart.items.filter(function (item) { return !!item; }); }), operators.map(function (items) { return items.map(function (item) { return transformMagentoCartItem(daffTransformMagentoCartItem(item), item, _this.cartItemTransforms); }); }));
1237
1307
  };
1238
1308
  DaffMagentoCartItemService.prototype.get = function (cartId, itemId) {
1239
1309
  return this.list(cartId).pipe(operators.map(function (items) { return items.find(function (item) { return item.id === itemId; }); }));
@@ -1289,7 +1359,7 @@
1289
1359
  };
1290
1360
  return DaffMagentoCartItemService;
1291
1361
  }());
1292
- /** @nocollapse */ DaffMagentoCartItemService.ɵprov = i0.ɵɵdefineInjectable({ factory: function DaffMagentoCartItemService_Factory() { return new DaffMagentoCartItemService(i0.ɵɵinject(i1.Apollo), i0.ɵɵinject(DAFF_MAGENTO_CART_MUTATION_QUEUE), i0.ɵɵinject(DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS), i0.ɵɵinject(DaffMagentoCartTransformer), i0.ɵɵinject(DaffMagentoCartItemUpdateInputTransformer)); }, token: DaffMagentoCartItemService, providedIn: "root" });
1362
+ /** @nocollapse */ DaffMagentoCartItemService.ɵprov = i0.ɵɵdefineInjectable({ factory: function DaffMagentoCartItemService_Factory() { return new DaffMagentoCartItemService(i0.ɵɵinject(i1.Apollo), i0.ɵɵinject(DAFF_MAGENTO_CART_MUTATION_QUEUE), i0.ɵɵinject(DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS), i0.ɵɵinject(DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS), i0.ɵɵinject(DaffMagentoCartTransformer), i0.ɵɵinject(DaffMagentoCartItemUpdateInputTransformer)); }, token: DaffMagentoCartItemService, providedIn: "root" });
1293
1363
  DaffMagentoCartItemService.decorators = [
1294
1364
  { type: i0.Injectable, args: [{
1295
1365
  providedIn: 'root',
@@ -1300,6 +1370,7 @@
1300
1370
  { type: i1.Apollo },
1301
1371
  { type: graphql.DaffQueuedApollo, decorators: [{ type: i0.Inject, args: [DAFF_MAGENTO_CART_MUTATION_QUEUE,] }] },
1302
1372
  { type: Array, decorators: [{ type: i0.Inject, args: [DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS,] }] },
1373
+ { type: Array, decorators: [{ type: i0.Inject, args: [DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,] }] },
1303
1374
  { type: DaffMagentoCartTransformer },
1304
1375
  { type: DaffMagentoCartItemUpdateInputTransformer }
1305
1376
  ]; };
@@ -1717,11 +1788,14 @@
1717
1788
  * Transforms magento carts into an object usable by daffodil.
1718
1789
  */
1719
1790
  var DaffMagentoCartCouponResponseTransformer = /** @class */ (function () {
1720
- function DaffMagentoCartCouponResponseTransformer() {
1791
+ function DaffMagentoCartCouponResponseTransformer(cartItemTransforms) {
1792
+ this.cartItemTransforms = cartItemTransforms;
1721
1793
  }
1722
1794
  DaffMagentoCartCouponResponseTransformer.prototype.transformCartItems = function (cart) {
1795
+ var _this = this;
1723
1796
  return {
1724
- items: cart.items.map(transformMagentoCartItem),
1797
+ // TODO: extract into own transforms
1798
+ items: cart.items.filter(function (item) { return !!item; }).map(function (item) { return transformMagentoCartItem(daffTransformMagentoCartItem(item), item, _this.cartItemTransforms); }),
1725
1799
  };
1726
1800
  };
1727
1801
  DaffMagentoCartCouponResponseTransformer.prototype.transformTotals = function (cart) {
@@ -1747,12 +1821,16 @@
1747
1821
  };
1748
1822
  return DaffMagentoCartCouponResponseTransformer;
1749
1823
  }());
1750
- /** @nocollapse */ DaffMagentoCartCouponResponseTransformer.ɵprov = i0.ɵɵdefineInjectable({ factory: function DaffMagentoCartCouponResponseTransformer_Factory() { return new DaffMagentoCartCouponResponseTransformer(); }, token: DaffMagentoCartCouponResponseTransformer, providedIn: "root" });
1824
+ /** @nocollapse */ DaffMagentoCartCouponResponseTransformer.ɵprov = i0.ɵɵdefineInjectable({ factory: function DaffMagentoCartCouponResponseTransformer_Factory() { return new DaffMagentoCartCouponResponseTransformer(i0.ɵɵinject(DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS)); }, token: DaffMagentoCartCouponResponseTransformer, providedIn: "root" });
1751
1825
  DaffMagentoCartCouponResponseTransformer.decorators = [
1752
1826
  { type: i0.Injectable, args: [{
1753
1827
  providedIn: 'root',
1754
1828
  },] }
1755
1829
  ];
1830
+ /** @nocollapse */
1831
+ DaffMagentoCartCouponResponseTransformer.ctorParameters = function () { return [
1832
+ { type: Array, decorators: [{ type: i0.Inject, args: [DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS,] }] }
1833
+ ]; };
1756
1834
 
1757
1835
  /**
1758
1836
  * A service for making Magento GraphQL queries for carts.
@@ -1928,6 +2006,7 @@
1928
2006
  * Generated bundle index. Do not edit.
1929
2007
  */
1930
2008
 
2009
+ exports.DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS = DAFF_CART_MAGENTO_CART_ITEM_TRANSFORMS;
1931
2010
  exports.DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS = DAFF_CART_MAGENTO_EXTRA_CART_FRAGMENTS;
1932
2011
  exports.DaffCartMagentoDriverModule = DaffCartMagentoDriverModule;
1933
2012
  exports.DaffMagentoBillingAddressInputTransformer = DaffMagentoBillingAddressInputTransformer;
@@ -1960,6 +2039,7 @@
1960
2039
  exports.cartFragment = cartFragment;
1961
2040
  exports.cartItemFragment = cartItemFragment;
1962
2041
  exports.createCart = createCart;
2042
+ exports.daffProvideCartMagentoCartItemTransforms = daffProvideCartMagentoCartItemTransforms;
1963
2043
  exports.getBillingAddress = getBillingAddress;
1964
2044
  exports.getCart = getCart;
1965
2045
  exports.getSelectedPaymentMethod = getSelectedPaymentMethod;