merchi_cart 0.0.4-c → 0.0.4-e

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 (196) hide show
  1. package/lib/Cart.js +20 -25
  2. package/lib/CartAlert.js +14 -12
  3. package/lib/CartHeader.js +9 -9
  4. package/lib/CartProvider.js +157 -226
  5. package/lib/CartTotals.js +44 -44
  6. package/lib/MerchiSDK/constants/auto_assign_production_on_actions.js +1 -1
  7. package/lib/MerchiSDK/constants/call_to_actions.js +1 -1
  8. package/lib/MerchiSDK/constants/discount_types.js +1 -1
  9. package/lib/MerchiSDK/constants/domain_types.js +1 -1
  10. package/lib/MerchiSDK/constants/errors.js +1 -1
  11. package/lib/MerchiSDK/constants/event_types.js +1 -1
  12. package/lib/MerchiSDK/constants/field_types.js +1 -1
  13. package/lib/MerchiSDK/constants/input_types.js +1 -1
  14. package/lib/MerchiSDK/constants/inventory_statuses.js +1 -1
  15. package/lib/MerchiSDK/constants/invoice_types.js +1 -1
  16. package/lib/MerchiSDK/constants/item_types.js +1 -1
  17. package/lib/MerchiSDK/constants/job/drafting_status.js +1 -1
  18. package/lib/MerchiSDK/constants/job/payment_status.js +1 -1
  19. package/lib/MerchiSDK/constants/job/production_status.js +1 -1
  20. package/lib/MerchiSDK/constants/job/shipment_status.js +1 -1
  21. package/lib/MerchiSDK/constants/job/supply_chain_request_status.js +1 -1
  22. package/lib/MerchiSDK/constants/job_priorities.js +1 -1
  23. package/lib/MerchiSDK/constants/job_status.js +5 -5
  24. package/lib/MerchiSDK/constants/job_types.js +1 -1
  25. package/lib/MerchiSDK/constants/notification_sections.js +1 -1
  26. package/lib/MerchiSDK/constants/notification_types.js +1 -1
  27. package/lib/MerchiSDK/constants/notification_urgencies.js +1 -1
  28. package/lib/MerchiSDK/constants/payment_types.js +1 -1
  29. package/lib/MerchiSDK/constants/platform.js +5 -5
  30. package/lib/MerchiSDK/constants/product_types.js +1 -1
  31. package/lib/MerchiSDK/constants/rights.js +1 -1
  32. package/lib/MerchiSDK/constants/robots_meta_directives.js +1 -1
  33. package/lib/MerchiSDK/constants/roles.js +8 -14
  34. package/lib/MerchiSDK/constants/shipment_companies.js +1 -1
  35. package/lib/MerchiSDK/constants/shipment_services.js +1 -1
  36. package/lib/MerchiSDK/constants/system_roles.js +1 -1
  37. package/lib/MerchiSDK/constants/theme_foundations.js +1 -1
  38. package/lib/MerchiSDK/constants/theme_status.js +1 -1
  39. package/lib/MerchiSDK/constants/user_types.js +1 -1
  40. package/lib/MerchiSDK/constants/white_label_accessibilities.js +1 -1
  41. package/lib/MerchiSDK/cookie.js +3 -3
  42. package/lib/MerchiSDK/entities/address.js +22 -43
  43. package/lib/MerchiSDK/entities/assignment.js +28 -49
  44. package/lib/MerchiSDK/entities/automatic_payment_relationship.js +11 -32
  45. package/lib/MerchiSDK/entities/backup.js +6 -27
  46. package/lib/MerchiSDK/entities/bank.js +17 -38
  47. package/lib/MerchiSDK/entities/cart.js +31 -64
  48. package/lib/MerchiSDK/entities/cart_item.js +30 -51
  49. package/lib/MerchiSDK/entities/cart_shipment_group.js +9 -30
  50. package/lib/MerchiSDK/entities/cart_shipment_quote.js +13 -34
  51. package/lib/MerchiSDK/entities/category.js +14 -35
  52. package/lib/MerchiSDK/entities/company.js +88 -109
  53. package/lib/MerchiSDK/entities/company_invitation.js +13 -34
  54. package/lib/MerchiSDK/entities/component.js +33 -54
  55. package/lib/MerchiSDK/entities/component_tag.js +7 -28
  56. package/lib/MerchiSDK/entities/component_version.js +12 -33
  57. package/lib/MerchiSDK/entities/country_tax.js +21 -45
  58. package/lib/MerchiSDK/entities/discount.js +13 -34
  59. package/lib/MerchiSDK/entities/discount_group.js +11 -32
  60. package/lib/MerchiSDK/entities/domain.js +80 -101
  61. package/lib/MerchiSDK/entities/domain_invitation.js +14 -35
  62. package/lib/MerchiSDK/entities/domain_tag.js +15 -36
  63. package/lib/MerchiSDK/entities/draft.js +32 -65
  64. package/lib/MerchiSDK/entities/draft_comment.js +19 -40
  65. package/lib/MerchiSDK/entities/draft_template.js +15 -36
  66. package/lib/MerchiSDK/entities/email_address.js +10 -31
  67. package/lib/MerchiSDK/entities/email_counter.js +8 -29
  68. package/lib/MerchiSDK/entities/enrolled_domain.js +20 -44
  69. package/lib/MerchiSDK/entities/exchange_rate.js +9 -30
  70. package/lib/MerchiSDK/entities/file.js +59 -80
  71. package/lib/MerchiSDK/entities/internal_tag.js +17 -38
  72. package/lib/MerchiSDK/entities/inventory.js +19 -42
  73. package/lib/MerchiSDK/entities/inventory_unit_variation.js +12 -33
  74. package/lib/MerchiSDK/entities/invoice.js +57 -78
  75. package/lib/MerchiSDK/entities/item.js +18 -39
  76. package/lib/MerchiSDK/entities/job.js +117 -140
  77. package/lib/MerchiSDK/entities/job_comment.js +18 -39
  78. package/lib/MerchiSDK/entities/matching_inventory.js +11 -32
  79. package/lib/MerchiSDK/entities/menu.js +12 -33
  80. package/lib/MerchiSDK/entities/menu_item.js +12 -33
  81. package/lib/MerchiSDK/entities/notification.js +32 -53
  82. package/lib/MerchiSDK/entities/page.js +13 -34
  83. package/lib/MerchiSDK/entities/payment.js +25 -46
  84. package/lib/MerchiSDK/entities/payment_device.js +12 -33
  85. package/lib/MerchiSDK/entities/phone_number.js +14 -35
  86. package/lib/MerchiSDK/entities/product.js +153 -188
  87. package/lib/MerchiSDK/entities/production_comment.js +18 -39
  88. package/lib/MerchiSDK/entities/quote.js +70 -106
  89. package/lib/MerchiSDK/entities/quote_item.js +28 -49
  90. package/lib/MerchiSDK/entities/seo_domain_page.js +13 -34
  91. package/lib/MerchiSDK/entities/session.js +11 -32
  92. package/lib/MerchiSDK/entities/shipment.js +62 -83
  93. package/lib/MerchiSDK/entities/shipment_item.js +7 -28
  94. package/lib/MerchiSDK/entities/shipment_item_fulfillment.js +7 -28
  95. package/lib/MerchiSDK/entities/shipment_method.js +21 -42
  96. package/lib/MerchiSDK/entities/shipment_method_variation.js +15 -36
  97. package/lib/MerchiSDK/entities/short_url.js +14 -35
  98. package/lib/MerchiSDK/entities/subscription_plan.js +26 -47
  99. package/lib/MerchiSDK/entities/supply_domain.js +11 -32
  100. package/lib/MerchiSDK/entities/system_role.js +7 -28
  101. package/lib/MerchiSDK/entities/theme.js +89 -110
  102. package/lib/MerchiSDK/entities/theme_css_setting.js +10 -31
  103. package/lib/MerchiSDK/entities/user.js +151 -213
  104. package/lib/MerchiSDK/entities/user_company.js +11 -32
  105. package/lib/MerchiSDK/entities/variation.js +21 -42
  106. package/lib/MerchiSDK/entities/variation_field.js +61 -94
  107. package/lib/MerchiSDK/entities/variation_fields_option.js +40 -61
  108. package/lib/MerchiSDK/entities/variation_option.js +20 -41
  109. package/lib/MerchiSDK/entities/variations_group.js +15 -36
  110. package/lib/MerchiSDK/entity.js +534 -624
  111. package/lib/MerchiSDK/merchi.js +42 -53
  112. package/lib/MerchiSDK/request.js +47 -75
  113. package/lib/MerchiSDK/test_util.js +6 -10
  114. package/lib/MerchiSDK/toasts.js +12 -13
  115. package/lib/MerchiSDK/util/float.js +7 -19
  116. package/lib/MerchiSDK/util/query_string.js +4 -4
  117. package/lib/MerchiSDK/util/validation.js +2 -3
  118. package/lib/MerchiSDK/uuid.js +2 -2
  119. package/lib/buttons/Button.js +15 -15
  120. package/lib/buttons/ButtonBack.js +22 -25
  121. package/lib/buttons/ButtonClearCart.js +8 -9
  122. package/lib/buttons/ButtonInvoiceDownload.js +26 -61
  123. package/lib/buttons/ButtonNext.js +20 -25
  124. package/lib/buttons/ButtonNextDynamic.js +16 -18
  125. package/lib/buttons/ButtonPay.js +17 -13
  126. package/lib/buttons/ButtonShipmentTabNext.js +12 -13
  127. package/lib/buttons/index.js +13 -13
  128. package/lib/components/Alert.js +14 -12
  129. package/lib/components/CartBody.js +10 -8
  130. package/lib/components/CartClient.js +22 -17
  131. package/lib/components/CartFooter.js +9 -7
  132. package/lib/components/CartItemRow.js +58 -48
  133. package/lib/components/CartPaymentSettingsInvalid.js +3 -4
  134. package/lib/components/CartShipment.js +18 -13
  135. package/lib/components/CartTabContent.js +9 -7
  136. package/lib/components/CartTabPanel.js +15 -13
  137. package/lib/components/CartTableContainer.js +9 -7
  138. package/lib/components/Collapse.js +14 -22
  139. package/lib/components/LoadingTemplate.js +10 -7
  140. package/lib/components/NoCartItems.js +9 -9
  141. package/lib/components/ShipmentGroupCard.js +69 -52
  142. package/lib/components/Table.js +7 -4
  143. package/lib/components/Title.js +11 -9
  144. package/lib/components/containers.js +12 -11
  145. package/lib/components/index.js +30 -31
  146. package/lib/forms/FormNewCustomer.js +48 -76
  147. package/lib/forms/FormReturningCustomer.js +38 -58
  148. package/lib/forms/FormShipmentAddressAndNotes.js +42 -47
  149. package/lib/forms/FormSquarePayment.js +8 -9
  150. package/lib/forms/FormStripePayment.js +8 -9
  151. package/lib/forms/InputAcceptUserTermsAndConditions.js +12 -11
  152. package/lib/forms/InputError.js +11 -9
  153. package/lib/forms/InputSelect.js +34 -36
  154. package/lib/forms/InputText.js +38 -42
  155. package/lib/forms/InputsAddress.js +59 -69
  156. package/lib/index.js +6 -6
  157. package/lib/panels/PanelCartItems.js +14 -17
  158. package/lib/panels/PanelCartShipment.js +10 -13
  159. package/lib/panels/PanelClearCart.js +8 -7
  160. package/lib/panels/PanelClientCheckout.js +18 -17
  161. package/lib/panels/PanelEditCartItem.js +17 -22
  162. package/lib/panels/PanelPaymentSuccess.js +18 -16
  163. package/lib/panels/index.js +13 -13
  164. package/lib/slices/sliceCart.js +53 -56
  165. package/lib/slices/sliceCartAlert.js +11 -15
  166. package/lib/slices/sliceCartItem.js +11 -10
  167. package/lib/slices/sliceCartPayment.js +15 -16
  168. package/lib/slices/sliceCartShipment.js +23 -26
  169. package/lib/slices/sliceFormReturningCustomer.js +7 -7
  170. package/lib/slices/sliceNewCustomerForm.js +6 -6
  171. package/lib/square/SquareCard.js +16 -18
  172. package/lib/square/actions.js +24 -46
  173. package/lib/square/slices/reducersSquare.js +6 -6
  174. package/lib/square/slices/sliceSquareAlerts.js +10 -16
  175. package/lib/square/slices/sliceSquareForm.js +10 -9
  176. package/lib/store.js +359 -565
  177. package/lib/stripe/StripeCardFields.js +43 -44
  178. package/lib/stripe/StripeCardForm.js +51 -109
  179. package/lib/stripe/StripePaymentButtons.js +35 -46
  180. package/lib/stripe/actions.js +75 -196
  181. package/lib/stripe/slices/sliceStripeAlerts.js +10 -16
  182. package/lib/stripe/slices/sliceStripeCardForm.js +6 -6
  183. package/lib/stripe/slices/sliceStripeForm.js +18 -17
  184. package/lib/stripe/utils.js +1 -1
  185. package/lib/tabs/CartNav.js +15 -24
  186. package/lib/tabs/NavTab.js +20 -19
  187. package/lib/utilities/address.js +32 -30
  188. package/lib/utilities/cart.js +33 -50
  189. package/lib/utilities/cookie.js +46 -129
  190. package/lib/utilities/currency.js +29 -25
  191. package/lib/utilities/helpers.js +41 -60
  192. package/lib/utilities/invoice.js +45 -114
  193. package/lib/utilities/product.js +5 -3
  194. package/lib/utilities/user.js +24 -62
  195. package/lib/utilities/variations.js +16 -14
  196. package/package.json +1 -1
@@ -10,40 +10,26 @@ exports.phoneOptions = void 0;
10
10
  exports.unpackRecursiveJsonIter = unpackRecursiveJsonIter;
11
11
  var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
12
12
  var _snakeCase = _interopRequireDefault(require("lodash/snakeCase"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
15
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
17
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
18
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
20
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
14
  var TransformationType = /*#__PURE__*/function (TransformationType) {
22
15
  TransformationType["CAMEL"] = "camel";
23
16
  TransformationType["UNDERSCORE"] = "underscore";
24
17
  return TransformationType;
25
18
  }(TransformationType || {});
26
- var functionDict = _defineProperty(_defineProperty({}, TransformationType.CAMEL, _camelCase["default"]), TransformationType.UNDERSCORE, _snakeCase["default"]);
19
+ const functionDict = {
20
+ [TransformationType.CAMEL]: _camelCase.default,
21
+ [TransformationType.UNDERSCORE]: _snakeCase.default
22
+ };
27
23
  function parseJsonKeyNames(jsonObject, standard) {
28
- if (_typeof(jsonObject) === 'object' && jsonObject !== null) {
24
+ if (typeof jsonObject === 'object' && jsonObject !== null) {
29
25
  if (Array.isArray(jsonObject)) {
30
- var _iterator = _createForOfIteratorHelper(jsonObject),
31
- _step;
32
- try {
33
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
34
- var item = _step.value;
35
- parseJsonKeyNames(item, standard);
36
- }
37
- } catch (err) {
38
- _iterator.e(err);
39
- } finally {
40
- _iterator.f();
26
+ for (let item of jsonObject) {
27
+ parseJsonKeyNames(item, standard);
41
28
  }
42
29
  } else {
43
- var oldKeys = Object.keys(jsonObject);
44
- for (var _i = 0, _oldKeys = oldKeys; _i < _oldKeys.length; _i++) {
45
- var old = _oldKeys[_i];
46
- var newKey = functionDict[standard](old);
30
+ const oldKeys = Object.keys(jsonObject);
31
+ for (let old of oldKeys) {
32
+ const newKey = functionDict[standard](old);
47
33
  if (newKey !== old) {
48
34
  jsonObject[newKey] = jsonObject[old];
49
35
  delete jsonObject[old];
@@ -61,12 +47,12 @@ function parseJsonKeyCamel(jsonObject) {
61
47
  }
62
48
  function unpackRecursiveJsonIter(jsonObject, options, fileIndex) {
63
49
  if (!options) options = {};
64
- var result = options.existing || new FormData();
65
- var prefix = options._prefix || '';
50
+ const result = options.existing || new FormData();
51
+ const prefix = options._prefix || '';
66
52
  if (!fileIndex) fileIndex = {
67
53
  value: 0
68
54
  };
69
- var appendData = function appendData(name, value) {
55
+ const appendData = (name, value) => {
70
56
  if (prefix) {
71
57
  name = prefix + '-' + name;
72
58
  }
@@ -74,8 +60,8 @@ function unpackRecursiveJsonIter(jsonObject, options, fileIndex) {
74
60
  result.set(name, value.toString()); // Convert to string since FormData accepts only strings or Blobs.
75
61
  }
76
62
  };
77
- var processSingleEntityProperty = function processSingleEntityProperty(key, value) {
78
- var innerPrefix = key + '-0';
63
+ const processSingleEntityProperty = (key, value) => {
64
+ let innerPrefix = key + '-0';
79
65
  if (prefix) {
80
66
  innerPrefix = prefix + '-' + innerPrefix;
81
67
  }
@@ -85,39 +71,36 @@ function unpackRecursiveJsonIter(jsonObject, options, fileIndex) {
85
71
  }, fileIndex);
86
72
  appendData(key + '-count', '1');
87
73
  };
88
- var _loop = function _loop(_key) {
89
- if ([undefined, '', null].includes(jsonObject[_key]) || _key === 'rights') {
90
- return 1; // continue
74
+ for (const key in jsonObject) {
75
+ if ([undefined, '', null].includes(jsonObject[key]) || key === 'rights') {
76
+ continue;
91
77
  }
92
- if (Array.isArray(jsonObject[_key])) {
93
- jsonObject[_key].forEach(function (item, index) {
94
- if ((_typeof(item) === "object" || Array.isArray(item)) && item !== null) {
95
- var arrayPrefix = prefix ? "".concat(prefix, "-").concat(_key, "-").concat(index) : "".concat(_key, "-").concat(index);
78
+ if (Array.isArray(jsonObject[key])) {
79
+ jsonObject[key].forEach((item, index) => {
80
+ if ((typeof item === "object" || Array.isArray(item)) && item !== null) {
81
+ const arrayPrefix = prefix ? `${prefix}-${key}-${index}` : `${key}-${index}`;
96
82
  unpackRecursiveJsonIter(item, {
97
83
  existing: result,
98
84
  _prefix: arrayPrefix
99
85
  }, fileIndex);
100
86
  } else {
101
- appendData("".concat(_key, "-").concat(index), item);
87
+ appendData(`${key}-${index}`, item);
102
88
  }
103
89
  });
104
- appendData(_key + '-count', jsonObject[_key].length.toString());
105
- } else if (_typeof(jsonObject[_key]) === "object" && jsonObject[_key] !== null) {
106
- processSingleEntityProperty(_key, jsonObject[_key]);
90
+ appendData(key + '-count', jsonObject[key].length.toString());
91
+ } else if (typeof jsonObject[key] === "object" && jsonObject[key] !== null) {
92
+ processSingleEntityProperty(key, jsonObject[key]);
107
93
  } else {
108
- appendData(_key, jsonObject[_key]);
94
+ appendData(key, jsonObject[key]);
109
95
  }
110
- };
111
- for (var _key in jsonObject) {
112
- if (_loop(_key)) continue;
113
96
  }
114
97
  return result;
115
98
  }
116
99
  function encodeMerchiApiData(dataDict) {
117
- var dataJson = parseJsonKeyCamel(dataDict);
100
+ const dataJson = parseJsonKeyCamel(dataDict);
118
101
  return unpackRecursiveJsonIter(dataJson);
119
102
  }
120
- var supportedNumbers = {
103
+ const supportedNumbers = {
121
104
  AU: 'Australia (+61)',
122
105
  AE: 'United Arab Emirates (+971)',
123
106
  BH: 'Bahrain (+973)',
@@ -143,15 +126,13 @@ var supportedNumbers = {
143
126
  US: 'United States (+1)',
144
127
  ZA: 'South Africa (+27)'
145
128
  };
146
- var phoneOptions = exports.phoneOptions = Object.keys(supportedNumbers).map(function (key) {
147
- return {
148
- value: key,
149
- label: supportedNumbers[key]
150
- };
151
- });
129
+ const phoneOptions = exports.phoneOptions = Object.keys(supportedNumbers).map(key => ({
130
+ value: key,
131
+ label: supportedNumbers[key]
132
+ }));
152
133
  function appendStyleSheetText(css, callback) {
153
134
  if (document && document !== undefined) {
154
- var newStyleSheet = document.createElement('style');
135
+ const newStyleSheet = document.createElement('style');
155
136
  newStyleSheet.textContent = css;
156
137
  if (callback) {
157
138
  newStyleSheet.onload = callback;
@@ -159,7 +140,7 @@ function appendStyleSheetText(css, callback) {
159
140
  document.head.appendChild(newStyleSheet);
160
141
  }
161
142
  }
162
- var optionsEmbed = {
143
+ const optionsEmbed = {
163
144
  options: {
164
145
  linkedFile: {},
165
146
  variationCostDiscountGroup: {},
@@ -168,15 +149,15 @@ var optionsEmbed = {
168
149
  variationCostDiscountGroup: {},
169
150
  variationUnitCostDiscountGroup: {}
170
151
  };
171
- var variationsEmbed = {
152
+ const variationsEmbed = {
172
153
  selectedOptions: {},
173
154
  variationField: optionsEmbed,
174
155
  variationFiles: {}
175
156
  };
176
- var variationsGroupsEmbed = {
157
+ const variationsGroupsEmbed = {
177
158
  variations: variationsEmbed
178
159
  };
179
- var productWithImagesEmbed = {
160
+ const productWithImagesEmbed = {
180
161
  domain: {
181
162
  company: {
182
163
  defaultTaxType: {},
@@ -197,13 +178,13 @@ var productWithImagesEmbed = {
197
178
  },
198
179
  taxType: {}
199
180
  };
200
- var cartShipmentQuote = {
181
+ const cartShipmentQuote = {
201
182
  shipmentMethod: {
202
183
  originAddress: {},
203
184
  taxType: {}
204
185
  }
205
186
  };
206
- var cartEmbed = exports.cartEmbed = {
187
+ const cartEmbed = exports.cartEmbed = {
207
188
  cartItems: {
208
189
  product: productWithImagesEmbed,
209
190
  taxType: {},
@@ -1,125 +1,56 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.generatePublicInvoicePdf = generatePublicInvoicePdf;
8
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
11
- var urlToFile = /*#__PURE__*/function () {
12
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, filename, type) {
13
- var res, buf;
14
- return _regeneratorRuntime().wrap(function _callee$(_context) {
15
- while (1) switch (_context.prev = _context.next) {
16
- case 0:
17
- _context.next = 2;
18
- return fetch(url);
19
- case 2:
20
- res = _context.sent;
21
- _context.next = 5;
22
- return res.arrayBuffer();
23
- case 5:
24
- buf = _context.sent;
25
- return _context.abrupt("return", new File([buf], filename, {
26
- type: type
27
- }));
28
- case 7:
29
- case "end":
30
- return _context.stop();
31
- }
32
- }, _callee);
33
- }));
34
- return function urlToFile(_x, _x2, _x3) {
35
- return _ref.apply(this, arguments);
7
+ const urlToFile = async (url, filename, type) => {
8
+ const res = await fetch(url);
9
+ const buf = await res.arrayBuffer();
10
+ return new File([buf], filename, {
11
+ type
12
+ });
13
+ };
14
+ const urlToFilePdf = async (url, filename) => {
15
+ const file = await urlToFile(url, filename, 'application/pdf');
16
+ return file;
17
+ };
18
+ async function generatePublicInvoicePdf(urlApi, invoice, receipt) {
19
+ const id = invoice.id;
20
+ const domain = invoice.domain.emailDomain;
21
+ const queryString = new URLSearchParams({
22
+ invoice_token: invoice.invoiceToken
23
+ }).toString();
24
+ const fetchOptions = {
25
+ method: 'GET',
26
+ mode: 'cors'
36
27
  };
37
- }();
38
- var urlToFilePdf = /*#__PURE__*/function () {
39
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(url, filename) {
40
- var file;
41
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
42
- while (1) switch (_context2.prev = _context2.next) {
43
- case 0:
44
- _context2.next = 2;
45
- return urlToFile(url, filename, 'application/pdf');
46
- case 2:
47
- file = _context2.sent;
48
- return _context2.abrupt("return", file);
49
- case 4:
50
- case "end":
51
- return _context2.stop();
52
- }
53
- }, _callee2);
54
- }));
55
- return function urlToFilePdf(_x4, _x5) {
56
- return _ref2.apply(this, arguments);
57
- };
58
- }();
59
- function generatePublicInvoicePdf(_x6, _x7, _x8) {
60
- return _generatePublicInvoicePdf.apply(this, arguments);
61
- }
62
- function _generatePublicInvoicePdf() {
63
- _generatePublicInvoicePdf = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(urlApi, invoice, receipt) {
64
- var id, domain, queryString, fetchOptions, uri, response, r, pdf, url, doc, anchor;
65
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
66
- while (1) switch (_context3.prev = _context3.next) {
67
- case 0:
68
- id = invoice.id;
69
- domain = invoice.domain.emailDomain;
70
- queryString = new URLSearchParams({
71
- invoice_token: invoice.invoiceToken
72
- }).toString();
73
- fetchOptions = {
74
- method: 'GET',
75
- mode: 'cors'
76
- };
77
- uri = receipt ? '/generate/receipt/pdf/' : '/generate/pdf/';
78
- _context3.prev = 5;
79
- _context3.next = 8;
80
- return fetch("".concat(urlApi, "invoices/").concat(id).concat(uri, "?").concat(queryString), fetchOptions);
81
- case 8:
82
- response = _context3.sent;
83
- if (response.ok) {
84
- _context3.next = 11;
85
- break;
86
- }
87
- throw new Error("Error fetching PDF.");
88
- case 11:
89
- _context3.next = 13;
90
- return response.json();
91
- case 13:
92
- r = _context3.sent;
93
- _context3.next = 16;
94
- return urlToFilePdf("data:application/pdf;base64,".concat(r.pdf), "".concat(domain, "-invoice-").concat(id, ".pdf"));
95
- case 16:
96
- pdf = _context3.sent;
97
- url = URL.createObjectURL(pdf);
98
- doc = document;
99
- anchor = doc.createElement('a');
100
- anchor.href = url;
101
- anchor.download = pdf.name;
28
+ const uri = receipt ? '/generate/receipt/pdf/' : '/generate/pdf/';
29
+ try {
30
+ const response = await fetch(`${urlApi}invoices/${id}${uri}?${queryString}`, fetchOptions);
31
+ if (!response.ok) {
32
+ throw new Error("Error fetching PDF.");
33
+ }
34
+ const r = await response.json();
35
+ const pdf = await urlToFilePdf(`data:application/pdf;base64,${r.pdf}`, `${domain}-invoice-${id}.pdf`);
36
+ const url = URL.createObjectURL(pdf);
37
+ const doc = document;
38
+ const anchor = doc.createElement('a');
39
+ anchor.href = url;
40
+ anchor.download = pdf.name;
102
41
 
103
- // Append to the DOM
104
- doc.body.appendChild(anchor);
42
+ // Append to the DOM
43
+ doc.body.appendChild(anchor);
105
44
 
106
- // Trigger `click` event
107
- anchor.click();
45
+ // Trigger `click` event
46
+ anchor.click();
108
47
 
109
- // Remove element from DOM
110
- doc.body.removeChild(anchor);
111
- return _context3.abrupt("return", {
112
- success: true
113
- });
114
- case 28:
115
- _context3.prev = 28;
116
- _context3.t0 = _context3["catch"](5);
117
- throw _context3.t0;
118
- case 31:
119
- case "end":
120
- return _context3.stop();
121
- }
122
- }, _callee3, null, [[5, 28]]);
123
- }));
124
- return _generatePublicInvoicePdf.apply(this, arguments);
48
+ // Remove element from DOM
49
+ doc.body.removeChild(anchor);
50
+ return {
51
+ success: true
52
+ };
53
+ } catch (e) {
54
+ throw e;
55
+ }
125
56
  }
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.productFeatureImageUrl = productFeatureImageUrl;
7
7
  var _productNotFound = _interopRequireDefault(require("../assets/product-not-found.png"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  function productFeatureImageUrl(product) {
10
- var featureImage = product.featureImage;
11
- return featureImage && featureImage.viewUrl ? featureImage.viewUrl : _productNotFound["default"].src;
10
+ const {
11
+ featureImage
12
+ } = product;
13
+ return featureImage && featureImage.viewUrl ? featureImage.viewUrl : _productNotFound.default.src;
12
14
  }
@@ -10,77 +10,39 @@ exports.primaryPhone = primaryPhone;
10
10
  exports.tryReturningCustomerEmail = tryReturningCustomerEmail;
11
11
  var _merchi = require("../MerchiSDK/merchi");
12
12
  var _helpers = require("./helpers");
13
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
14
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
15
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
16
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
17
- var merchi = new _merchi.Merchi();
13
+ const merchi = new _merchi.Merchi();
18
14
  function makeUser(userJson, makeDirty) {
19
- var user = new merchi.User();
15
+ const user = new merchi.User();
20
16
  return user.fromJson(userJson, {
21
- makeDirty: makeDirty
17
+ makeDirty
22
18
  });
23
19
  }
24
20
  function primaryEmail(user) {
25
- var _user$emailAddresses = user.emailAddresses,
26
- emailAddresses = _user$emailAddresses === void 0 ? [] : _user$emailAddresses;
21
+ const {
22
+ emailAddresses = []
23
+ } = user;
27
24
  return emailAddresses[0] ? emailAddresses[0].emailAddress : '';
28
25
  }
29
26
  function primaryPhone(user) {
30
- var _user$phoneNumbers = user.phoneNumbers,
31
- phoneNumbers = _user$phoneNumbers === void 0 ? [] : _user$phoneNumbers;
27
+ const {
28
+ phoneNumbers = []
29
+ } = user;
32
30
  return phoneNumbers[0] ? phoneNumbers[0].internationalFormatNumber : '';
33
31
  }
34
- function tryReturningCustomerEmail(_x, _x2) {
35
- return _tryReturningCustomerEmail.apply(this, arguments);
32
+ async function tryReturningCustomerEmail(urlApi, emailAddress) {
33
+ const queryString = new URLSearchParams({
34
+ email_address: emailAddress
35
+ }).toString();
36
+ const fetchOptions = {
37
+ method: 'POST'
38
+ };
39
+ return await fetch(`${urlApi}user-check-email/?${queryString}`, fetchOptions);
36
40
  }
37
- function _tryReturningCustomerEmail() {
38
- _tryReturningCustomerEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(urlApi, emailAddress) {
39
- var queryString, fetchOptions;
40
- return _regeneratorRuntime().wrap(function _callee$(_context) {
41
- while (1) switch (_context.prev = _context.next) {
42
- case 0:
43
- queryString = new URLSearchParams({
44
- email_address: emailAddress
45
- }).toString();
46
- fetchOptions = {
47
- method: 'POST'
48
- };
49
- _context.next = 4;
50
- return fetch("".concat(urlApi, "user-check-email/?").concat(queryString), fetchOptions);
51
- case 4:
52
- return _context.abrupt("return", _context.sent);
53
- case 5:
54
- case "end":
55
- return _context.stop();
56
- }
57
- }, _callee);
58
- }));
59
- return _tryReturningCustomerEmail.apply(this, arguments);
60
- }
61
- function createNewCustomer(_x3, _x4) {
62
- return _createNewCustomer.apply(this, arguments);
63
- }
64
- function _createNewCustomer() {
65
- _createNewCustomer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(urlApi, customerJson) {
66
- var formData, fetchOptions;
67
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
68
- while (1) switch (_context2.prev = _context2.next) {
69
- case 0:
70
- formData = (0, _helpers.encodeMerchiApiData)(customerJson);
71
- fetchOptions = {
72
- method: 'POST',
73
- body: formData
74
- };
75
- _context2.next = 4;
76
- return fetch("".concat(urlApi, "public_user_create/"), fetchOptions);
77
- case 4:
78
- return _context2.abrupt("return", _context2.sent);
79
- case 5:
80
- case "end":
81
- return _context2.stop();
82
- }
83
- }, _callee2);
84
- }));
85
- return _createNewCustomer.apply(this, arguments);
41
+ async function createNewCustomer(urlApi, customerJson) {
42
+ const formData = (0, _helpers.encodeMerchiApiData)(customerJson);
43
+ const fetchOptions = {
44
+ method: 'POST',
45
+ body: formData
46
+ };
47
+ return await fetch(`${urlApi}public_user_create/`, fetchOptions);
86
48
  }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.FieldType = void 0;
7
7
  exports.isSelectable = isSelectable;
8
8
  exports.valueString = valueString;
9
- var FieldType = exports.FieldType = /*#__PURE__*/function (FieldType) {
9
+ let FieldType = exports.FieldType = /*#__PURE__*/function (FieldType) {
10
10
  FieldType[FieldType["TEXT_INPUT"] = 1] = "TEXT_INPUT";
11
11
  FieldType[FieldType["SELECT"] = 2] = "SELECT";
12
12
  FieldType[FieldType["FILE_UPLOAD"] = 3] = "FILE_UPLOAD";
@@ -24,17 +24,17 @@ function isSelectable(fieldType) {
24
24
  return [FieldType.SELECT, FieldType.CHECKBOX, FieldType.RADIO, FieldType.IMAGE_SELECT, FieldType.COLOUR_SELECT].includes(fieldType);
25
25
  }
26
26
  function concatinatedSelectedOptionValues(variation) {
27
- var selectableOptions = variation.selectableOptions,
28
- value = variation.value;
29
- var optionIds = value ? value.split(',') : [];
30
- var optionIdsLength = optionIds.length - 1;
31
- var option;
32
- var i = 0;
33
- var val = '';
27
+ const {
28
+ selectableOptions,
29
+ value
30
+ } = variation;
31
+ const optionIds = value ? value.split(',') : [];
32
+ const optionIdsLength = optionIds.length - 1;
33
+ let option;
34
+ let i = 0;
35
+ let val = '';
34
36
  for (i; i < optionIds.length; i++) {
35
- option = selectableOptions.find(function (o) {
36
- return String(o.optionId) === String(optionIds[i]);
37
- });
37
+ option = selectableOptions.find(o => String(o.optionId) === String(optionIds[i]));
38
38
  val += option ? option.value : '';
39
39
  if (optionIdsLength > i) {
40
40
  val += ', ';
@@ -43,9 +43,11 @@ function concatinatedSelectedOptionValues(variation) {
43
43
  return val;
44
44
  }
45
45
  function valueString(variation) {
46
- var field = variation.variationField,
47
- variationFiles = variation.variationFiles,
48
- value = variation.value;
46
+ const {
47
+ variationField: field,
48
+ variationFiles,
49
+ value
50
+ } = variation;
49
51
  if (isSelectable(field.fieldType)) {
50
52
  return concatinatedSelectedOptionValues(variation);
51
53
  } else if (field.fieldType === FieldType.FILE_UPLOAD && variationFiles) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "merchi_cart",
3
- "version": "0.0.4c",
3
+ "version": "0.0.4e",
4
4
  "description": "Merchi's cart",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.tsx",