@daffodil/cart 0.39.11 → 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 (57) 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.umd.js +33 -5
  6. package/bundles/daffodil-cart-driver-magento.umd.js.map +1 -1
  7. package/bundles/daffodil-cart-driver-magento.umd.min.js +1 -1
  8. package/bundles/daffodil-cart-driver-magento.umd.min.js.map +1 -1
  9. package/bundles/daffodil-cart-driver-testing.umd.js +4 -1
  10. package/bundles/daffodil-cart-driver-testing.umd.js.map +1 -1
  11. package/bundles/daffodil-cart-driver-testing.umd.min.js +1 -1
  12. package/bundles/daffodil-cart-driver-testing.umd.min.js.map +1 -1
  13. package/bundles/daffodil-cart-driver.umd.js.map +1 -1
  14. package/bundles/daffodil-cart-driver.umd.min.js.map +1 -1
  15. package/bundles/daffodil-cart-state.umd.js +147 -25
  16. package/bundles/daffodil-cart-state.umd.js.map +1 -1
  17. package/bundles/daffodil-cart-state.umd.min.js +1 -1
  18. package/bundles/daffodil-cart-state.umd.min.js.map +1 -1
  19. package/driver/daffodil-cart-driver.metadata.json +1 -1
  20. package/driver/in-memory/daffodil-cart-driver-in-memory.metadata.json +1 -1
  21. package/driver/in-memory/drivers/cart/cart.service.d.ts +3 -2
  22. package/driver/interfaces/cart-service.interface.d.ts +2 -1
  23. package/driver/magento/cart.service.d.ts +2 -1
  24. package/driver/magento/daffodil-cart-driver-magento.metadata.json +1 -1
  25. package/driver/magento/errors/transform.d.ts +13 -1
  26. package/driver/testing/daffodil-cart-driver-testing.metadata.json +1 -1
  27. package/driver/testing/drivers/cart/cart.service.d.ts +2 -1
  28. package/esm2015/driver/in-memory/drivers/cart/cart.service.js +5 -2
  29. package/esm2015/driver/interfaces/cart-service.interface.js +1 -1
  30. package/esm2015/driver/magento/cart.service.js +20 -7
  31. package/esm2015/driver/magento/errors/transform.js +15 -6
  32. package/esm2015/driver/testing/drivers/cart/cart.service.js +5 -2
  33. package/esm2015/state/actions/cart-item.actions.js +30 -1
  34. package/esm2015/state/actions/cart.actions.js +29 -1
  35. package/esm2015/state/effects/cart-item.effects.js +17 -6
  36. package/esm2015/state/effects/cart-resolver.effects.js +23 -10
  37. package/esm2015/state/effects/cart.effects.js +13 -4
  38. package/esm2015/state/reducers/cart/cart.reducer.js +7 -3
  39. package/esm2015/state/reducers/cart-item/cart-item.reducer.js +11 -3
  40. package/esm2015/state/reducers/cart-item-entities/cart-item-entities.reducer.js +4 -1
  41. package/esm2015/state/reducers/errors/error-state-helpers.js +3 -3
  42. package/fesm2015/daffodil-cart-driver-in-memory.js +4 -1
  43. package/fesm2015/daffodil-cart-driver-in-memory.js.map +1 -1
  44. package/fesm2015/daffodil-cart-driver-magento.js +31 -9
  45. package/fesm2015/daffodil-cart-driver-magento.js.map +1 -1
  46. package/fesm2015/daffodil-cart-driver-testing.js +4 -1
  47. package/fesm2015/daffodil-cart-driver-testing.js.map +1 -1
  48. package/fesm2015/daffodil-cart-driver.js.map +1 -1
  49. package/fesm2015/daffodil-cart-state.js +126 -24
  50. package/fesm2015/daffodil-cart-state.js.map +1 -1
  51. package/package.json +5 -5
  52. package/state/actions/cart-item.actions.d.ts +26 -1
  53. package/state/actions/cart.actions.d.ts +31 -5
  54. package/state/daffodil-cart-state.metadata.json +1 -1
  55. package/state/effects/cart-item.effects.d.ts +5 -2
  56. package/state/effects/cart.effects.d.ts +2 -2
  57. package/state/reducers/errors/error-state-helpers.d.ts +1 -1
@@ -1159,12 +1159,17 @@
1159
1159
  _b[i4.DaffCartDriverErrorCodes.INVALID_EMAIL] = /Invalid email format/,
1160
1160
  _b);
1161
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
+ */
1162
1167
  function transformMagentoCartGraphQlError(error, requestPayload) {
1163
1168
  var _a;
1164
1169
  // TODO: readdress this when we move to eslint
1165
1170
  // eslint-disable-next-line
1166
1171
  for (var code in DaffCartMagentoErrorMessageRegexMap) {
1167
- var matchIndex = error.graphQLErrors[0].message.search(DaffCartMagentoErrorMessageRegexMap[code]);
1172
+ var matchIndex = error.message.search(DaffCartMagentoErrorMessageRegexMap[code]);
1168
1173
  if (matchIndex > -1 && i4.DaffCartDriverErrorMap[code]) {
1169
1174
  var errObj = new i4.DaffCartDriverErrorMap[code](error.message);
1170
1175
  if (errObj instanceof i4.DaffInvalidCouponCodeError) {
@@ -1173,13 +1178,17 @@
1173
1178
  return errObj;
1174
1179
  }
1175
1180
  }
1176
- return magento$1.daffTransformMagentoError(error, DaffCartMagentoErrorMap);
1181
+ return magento$1.daffMagentoTransformGraphQlError(error, DaffCartMagentoErrorMap);
1177
1182
  }
1178
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
+ */
1179
1188
  function transformCartMagentoError(error, requestPayload) {
1180
1189
  var _a;
1181
1190
  if ((_a = error.graphQLErrors) === null || _a === void 0 ? void 0 : _a.length) {
1182
- return transformMagentoCartGraphQlError(error, requestPayload);
1191
+ return transformMagentoCartGraphQlError(error.graphQLErrors[0], requestPayload);
1183
1192
  }
1184
1193
  else {
1185
1194
  return magento$1.daffTransformMagentoError(error, DaffCartMagentoErrorMap);
@@ -1191,6 +1200,9 @@
1191
1200
  factory: function () { return new graphql.DaffQueuedApollo(i0.inject(i1.Apollo)); },
1192
1201
  });
1193
1202
 
1203
+ var DAFF_MAGENTO_GET_RECOVERABLE_ERRORS = [
1204
+ i4.DaffProductOutOfStockError,
1205
+ ];
1194
1206
  /**
1195
1207
  * A service for making Magento GraphQL queries for carts.
1196
1208
  *
@@ -1209,7 +1221,20 @@
1209
1221
  return this.apollo.query({
1210
1222
  query: getCart(this.extraCartFragments),
1211
1223
  variables: { cartId: cartId },
1212
- }).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
+ }));
1213
1238
  };
1214
1239
  DaffMagentoCartService.prototype.create = function () {
1215
1240
  return this.mutationQueue.mutate({ mutation: createCart }).pipe(operators.map(function (result) { return ({ id: result.data.createEmptyCart }); }));
@@ -1219,7 +1244,10 @@
1219
1244
  };
1220
1245
  DaffMagentoCartService.prototype.clear = function (cartId) {
1221
1246
  var _this = this;
1222
- 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
+ }));
1223
1251
  };
1224
1252
  return DaffMagentoCartService;
1225
1253
  }());