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.
- package/lib/Cart.js +20 -25
- package/lib/CartAlert.js +14 -12
- package/lib/CartHeader.js +9 -9
- package/lib/CartProvider.js +157 -226
- package/lib/CartTotals.js +44 -44
- package/lib/MerchiSDK/constants/auto_assign_production_on_actions.js +1 -1
- package/lib/MerchiSDK/constants/call_to_actions.js +1 -1
- package/lib/MerchiSDK/constants/discount_types.js +1 -1
- package/lib/MerchiSDK/constants/domain_types.js +1 -1
- package/lib/MerchiSDK/constants/errors.js +1 -1
- package/lib/MerchiSDK/constants/event_types.js +1 -1
- package/lib/MerchiSDK/constants/field_types.js +1 -1
- package/lib/MerchiSDK/constants/input_types.js +1 -1
- package/lib/MerchiSDK/constants/inventory_statuses.js +1 -1
- package/lib/MerchiSDK/constants/invoice_types.js +1 -1
- package/lib/MerchiSDK/constants/item_types.js +1 -1
- package/lib/MerchiSDK/constants/job/drafting_status.js +1 -1
- package/lib/MerchiSDK/constants/job/payment_status.js +1 -1
- package/lib/MerchiSDK/constants/job/production_status.js +1 -1
- package/lib/MerchiSDK/constants/job/shipment_status.js +1 -1
- package/lib/MerchiSDK/constants/job/supply_chain_request_status.js +1 -1
- package/lib/MerchiSDK/constants/job_priorities.js +1 -1
- package/lib/MerchiSDK/constants/job_status.js +5 -5
- package/lib/MerchiSDK/constants/job_types.js +1 -1
- package/lib/MerchiSDK/constants/notification_sections.js +1 -1
- package/lib/MerchiSDK/constants/notification_types.js +1 -1
- package/lib/MerchiSDK/constants/notification_urgencies.js +1 -1
- package/lib/MerchiSDK/constants/payment_types.js +1 -1
- package/lib/MerchiSDK/constants/platform.js +5 -5
- package/lib/MerchiSDK/constants/product_types.js +1 -1
- package/lib/MerchiSDK/constants/rights.js +1 -1
- package/lib/MerchiSDK/constants/robots_meta_directives.js +1 -1
- package/lib/MerchiSDK/constants/roles.js +8 -14
- package/lib/MerchiSDK/constants/shipment_companies.js +1 -1
- package/lib/MerchiSDK/constants/shipment_services.js +1 -1
- package/lib/MerchiSDK/constants/system_roles.js +1 -1
- package/lib/MerchiSDK/constants/theme_foundations.js +1 -1
- package/lib/MerchiSDK/constants/theme_status.js +1 -1
- package/lib/MerchiSDK/constants/user_types.js +1 -1
- package/lib/MerchiSDK/constants/white_label_accessibilities.js +1 -1
- package/lib/MerchiSDK/cookie.js +3 -3
- package/lib/MerchiSDK/entities/address.js +22 -43
- package/lib/MerchiSDK/entities/assignment.js +28 -49
- package/lib/MerchiSDK/entities/automatic_payment_relationship.js +11 -32
- package/lib/MerchiSDK/entities/backup.js +6 -27
- package/lib/MerchiSDK/entities/bank.js +17 -38
- package/lib/MerchiSDK/entities/cart.js +31 -64
- package/lib/MerchiSDK/entities/cart_item.js +30 -51
- package/lib/MerchiSDK/entities/cart_shipment_group.js +9 -30
- package/lib/MerchiSDK/entities/cart_shipment_quote.js +13 -34
- package/lib/MerchiSDK/entities/category.js +14 -35
- package/lib/MerchiSDK/entities/company.js +88 -109
- package/lib/MerchiSDK/entities/company_invitation.js +13 -34
- package/lib/MerchiSDK/entities/component.js +33 -54
- package/lib/MerchiSDK/entities/component_tag.js +7 -28
- package/lib/MerchiSDK/entities/component_version.js +12 -33
- package/lib/MerchiSDK/entities/country_tax.js +21 -45
- package/lib/MerchiSDK/entities/discount.js +13 -34
- package/lib/MerchiSDK/entities/discount_group.js +11 -32
- package/lib/MerchiSDK/entities/domain.js +80 -101
- package/lib/MerchiSDK/entities/domain_invitation.js +14 -35
- package/lib/MerchiSDK/entities/domain_tag.js +15 -36
- package/lib/MerchiSDK/entities/draft.js +32 -65
- package/lib/MerchiSDK/entities/draft_comment.js +19 -40
- package/lib/MerchiSDK/entities/draft_template.js +15 -36
- package/lib/MerchiSDK/entities/email_address.js +10 -31
- package/lib/MerchiSDK/entities/email_counter.js +8 -29
- package/lib/MerchiSDK/entities/enrolled_domain.js +20 -44
- package/lib/MerchiSDK/entities/exchange_rate.js +9 -30
- package/lib/MerchiSDK/entities/file.js +59 -80
- package/lib/MerchiSDK/entities/internal_tag.js +17 -38
- package/lib/MerchiSDK/entities/inventory.js +19 -42
- package/lib/MerchiSDK/entities/inventory_unit_variation.js +12 -33
- package/lib/MerchiSDK/entities/invoice.js +57 -78
- package/lib/MerchiSDK/entities/item.js +18 -39
- package/lib/MerchiSDK/entities/job.js +117 -140
- package/lib/MerchiSDK/entities/job_comment.js +18 -39
- package/lib/MerchiSDK/entities/matching_inventory.js +11 -32
- package/lib/MerchiSDK/entities/menu.js +12 -33
- package/lib/MerchiSDK/entities/menu_item.js +12 -33
- package/lib/MerchiSDK/entities/notification.js +32 -53
- package/lib/MerchiSDK/entities/page.js +13 -34
- package/lib/MerchiSDK/entities/payment.js +25 -46
- package/lib/MerchiSDK/entities/payment_device.js +12 -33
- package/lib/MerchiSDK/entities/phone_number.js +14 -35
- package/lib/MerchiSDK/entities/product.js +153 -188
- package/lib/MerchiSDK/entities/production_comment.js +18 -39
- package/lib/MerchiSDK/entities/quote.js +70 -106
- package/lib/MerchiSDK/entities/quote_item.js +28 -49
- package/lib/MerchiSDK/entities/seo_domain_page.js +13 -34
- package/lib/MerchiSDK/entities/session.js +11 -32
- package/lib/MerchiSDK/entities/shipment.js +62 -83
- package/lib/MerchiSDK/entities/shipment_item.js +7 -28
- package/lib/MerchiSDK/entities/shipment_item_fulfillment.js +7 -28
- package/lib/MerchiSDK/entities/shipment_method.js +21 -42
- package/lib/MerchiSDK/entities/shipment_method_variation.js +15 -36
- package/lib/MerchiSDK/entities/short_url.js +14 -35
- package/lib/MerchiSDK/entities/subscription_plan.js +26 -47
- package/lib/MerchiSDK/entities/supply_domain.js +11 -32
- package/lib/MerchiSDK/entities/system_role.js +7 -28
- package/lib/MerchiSDK/entities/theme.js +89 -110
- package/lib/MerchiSDK/entities/theme_css_setting.js +10 -31
- package/lib/MerchiSDK/entities/user.js +151 -213
- package/lib/MerchiSDK/entities/user_company.js +11 -32
- package/lib/MerchiSDK/entities/variation.js +21 -42
- package/lib/MerchiSDK/entities/variation_field.js +61 -94
- package/lib/MerchiSDK/entities/variation_fields_option.js +40 -61
- package/lib/MerchiSDK/entities/variation_option.js +20 -41
- package/lib/MerchiSDK/entities/variations_group.js +15 -36
- package/lib/MerchiSDK/entity.js +534 -624
- package/lib/MerchiSDK/merchi.js +42 -53
- package/lib/MerchiSDK/request.js +47 -75
- package/lib/MerchiSDK/test_util.js +6 -10
- package/lib/MerchiSDK/toasts.js +12 -13
- package/lib/MerchiSDK/util/float.js +7 -19
- package/lib/MerchiSDK/util/query_string.js +4 -4
- package/lib/MerchiSDK/util/validation.js +2 -3
- package/lib/MerchiSDK/uuid.js +2 -2
- package/lib/buttons/Button.js +15 -15
- package/lib/buttons/ButtonBack.js +22 -25
- package/lib/buttons/ButtonClearCart.js +8 -9
- package/lib/buttons/ButtonInvoiceDownload.js +26 -61
- package/lib/buttons/ButtonNext.js +20 -25
- package/lib/buttons/ButtonNextDynamic.js +16 -18
- package/lib/buttons/ButtonPay.js +17 -13
- package/lib/buttons/ButtonShipmentTabNext.js +12 -13
- package/lib/buttons/index.js +13 -13
- package/lib/components/Alert.js +14 -12
- package/lib/components/CartBody.js +10 -8
- package/lib/components/CartClient.js +22 -17
- package/lib/components/CartFooter.js +9 -7
- package/lib/components/CartItemRow.js +58 -48
- package/lib/components/CartPaymentSettingsInvalid.js +3 -4
- package/lib/components/CartShipment.js +18 -13
- package/lib/components/CartTabContent.js +9 -7
- package/lib/components/CartTabPanel.js +15 -13
- package/lib/components/CartTableContainer.js +9 -7
- package/lib/components/Collapse.js +14 -22
- package/lib/components/LoadingTemplate.js +10 -7
- package/lib/components/NoCartItems.js +9 -9
- package/lib/components/ShipmentGroupCard.js +69 -52
- package/lib/components/Table.js +7 -4
- package/lib/components/Title.js +11 -9
- package/lib/components/containers.js +12 -11
- package/lib/components/index.js +30 -31
- package/lib/forms/FormNewCustomer.js +48 -76
- package/lib/forms/FormReturningCustomer.js +38 -58
- package/lib/forms/FormShipmentAddressAndNotes.js +42 -47
- package/lib/forms/FormSquarePayment.js +8 -9
- package/lib/forms/FormStripePayment.js +8 -9
- package/lib/forms/InputAcceptUserTermsAndConditions.js +12 -11
- package/lib/forms/InputError.js +11 -9
- package/lib/forms/InputSelect.js +34 -36
- package/lib/forms/InputText.js +38 -42
- package/lib/forms/InputsAddress.js +59 -69
- package/lib/index.js +6 -6
- package/lib/panels/PanelCartItems.js +14 -17
- package/lib/panels/PanelCartShipment.js +10 -13
- package/lib/panels/PanelClearCart.js +8 -7
- package/lib/panels/PanelClientCheckout.js +18 -17
- package/lib/panels/PanelEditCartItem.js +17 -22
- package/lib/panels/PanelPaymentSuccess.js +18 -16
- package/lib/panels/index.js +13 -13
- package/lib/slices/sliceCart.js +53 -56
- package/lib/slices/sliceCartAlert.js +11 -15
- package/lib/slices/sliceCartItem.js +11 -10
- package/lib/slices/sliceCartPayment.js +15 -16
- package/lib/slices/sliceCartShipment.js +23 -26
- package/lib/slices/sliceFormReturningCustomer.js +7 -7
- package/lib/slices/sliceNewCustomerForm.js +6 -6
- package/lib/square/SquareCard.js +16 -18
- package/lib/square/actions.js +24 -46
- package/lib/square/slices/reducersSquare.js +6 -6
- package/lib/square/slices/sliceSquareAlerts.js +10 -16
- package/lib/square/slices/sliceSquareForm.js +10 -9
- package/lib/store.js +359 -565
- package/lib/stripe/StripeCardFields.js +43 -44
- package/lib/stripe/StripeCardForm.js +51 -109
- package/lib/stripe/StripePaymentButtons.js +35 -46
- package/lib/stripe/actions.js +75 -196
- package/lib/stripe/slices/sliceStripeAlerts.js +10 -16
- package/lib/stripe/slices/sliceStripeCardForm.js +6 -6
- package/lib/stripe/slices/sliceStripeForm.js +18 -17
- package/lib/stripe/utils.js +1 -1
- package/lib/tabs/CartNav.js +15 -24
- package/lib/tabs/NavTab.js +20 -19
- package/lib/utilities/address.js +32 -30
- package/lib/utilities/cart.js +33 -50
- package/lib/utilities/cookie.js +46 -129
- package/lib/utilities/currency.js +29 -25
- package/lib/utilities/helpers.js +41 -60
- package/lib/utilities/invoice.js +45 -114
- package/lib/utilities/product.js +5 -3
- package/lib/utilities/user.js +24 -62
- package/lib/utilities/variations.js +16 -14
- package/package.json +1 -1
package/lib/utilities/helpers.js
CHANGED
|
@@ -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 : {
|
|
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
|
-
|
|
19
|
+
const functionDict = {
|
|
20
|
+
[TransformationType.CAMEL]: _camelCase.default,
|
|
21
|
+
[TransformationType.UNDERSCORE]: _snakeCase.default
|
|
22
|
+
};
|
|
27
23
|
function parseJsonKeyNames(jsonObject, standard) {
|
|
28
|
-
if (
|
|
24
|
+
if (typeof jsonObject === 'object' && jsonObject !== null) {
|
|
29
25
|
if (Array.isArray(jsonObject)) {
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
44
|
-
for (
|
|
45
|
-
|
|
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
|
-
|
|
65
|
-
|
|
50
|
+
const result = options.existing || new FormData();
|
|
51
|
+
const prefix = options._prefix || '';
|
|
66
52
|
if (!fileIndex) fileIndex = {
|
|
67
53
|
value: 0
|
|
68
54
|
};
|
|
69
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
89
|
-
if ([undefined, '', null].includes(jsonObject[
|
|
90
|
-
|
|
74
|
+
for (const key in jsonObject) {
|
|
75
|
+
if ([undefined, '', null].includes(jsonObject[key]) || key === 'rights') {
|
|
76
|
+
continue;
|
|
91
77
|
}
|
|
92
|
-
if (Array.isArray(jsonObject[
|
|
93
|
-
jsonObject[
|
|
94
|
-
if ((
|
|
95
|
-
|
|
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(
|
|
87
|
+
appendData(`${key}-${index}`, item);
|
|
102
88
|
}
|
|
103
89
|
});
|
|
104
|
-
appendData(
|
|
105
|
-
} else if (
|
|
106
|
-
processSingleEntityProperty(
|
|
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(
|
|
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
|
-
|
|
100
|
+
const dataJson = parseJsonKeyCamel(dataDict);
|
|
118
101
|
return unpackRecursiveJsonIter(dataJson);
|
|
119
102
|
}
|
|
120
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
152
|
+
const variationsEmbed = {
|
|
172
153
|
selectedOptions: {},
|
|
173
154
|
variationField: optionsEmbed,
|
|
174
155
|
variationFiles: {}
|
|
175
156
|
};
|
|
176
|
-
|
|
157
|
+
const variationsGroupsEmbed = {
|
|
177
158
|
variations: variationsEmbed
|
|
178
159
|
};
|
|
179
|
-
|
|
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
|
-
|
|
181
|
+
const cartShipmentQuote = {
|
|
201
182
|
shipmentMethod: {
|
|
202
183
|
originAddress: {},
|
|
203
184
|
taxType: {}
|
|
204
185
|
}
|
|
205
186
|
};
|
|
206
|
-
|
|
187
|
+
const cartEmbed = exports.cartEmbed = {
|
|
207
188
|
cartItems: {
|
|
208
189
|
product: productWithImagesEmbed,
|
|
209
190
|
taxType: {},
|
package/lib/utilities/invoice.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
104
|
-
|
|
42
|
+
// Append to the DOM
|
|
43
|
+
doc.body.appendChild(anchor);
|
|
105
44
|
|
|
106
|
-
|
|
107
|
-
|
|
45
|
+
// Trigger `click` event
|
|
46
|
+
anchor.click();
|
|
108
47
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
}
|
package/lib/utilities/product.js
CHANGED
|
@@ -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 : {
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
9
|
function productFeatureImageUrl(product) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const {
|
|
11
|
+
featureImage
|
|
12
|
+
} = product;
|
|
13
|
+
return featureImage && featureImage.viewUrl ? featureImage.viewUrl : _productNotFound.default.src;
|
|
12
14
|
}
|
package/lib/utilities/user.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
15
|
+
const user = new merchi.User();
|
|
20
16
|
return user.fromJson(userJson, {
|
|
21
|
-
makeDirty
|
|
17
|
+
makeDirty
|
|
22
18
|
});
|
|
23
19
|
}
|
|
24
20
|
function primaryEmail(user) {
|
|
25
|
-
|
|
26
|
-
emailAddresses =
|
|
21
|
+
const {
|
|
22
|
+
emailAddresses = []
|
|
23
|
+
} = user;
|
|
27
24
|
return emailAddresses[0] ? emailAddresses[0].emailAddress : '';
|
|
28
25
|
}
|
|
29
26
|
function primaryPhone(user) {
|
|
30
|
-
|
|
31
|
-
phoneNumbers =
|
|
27
|
+
const {
|
|
28
|
+
phoneNumbers = []
|
|
29
|
+
} = user;
|
|
32
30
|
return phoneNumbers[0] ? phoneNumbers[0].internationalFormatNumber : '';
|
|
33
31
|
}
|
|
34
|
-
function tryReturningCustomerEmail(
|
|
35
|
-
|
|
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
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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(
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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) {
|