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/MerchiSDK/entity.js
CHANGED
|
@@ -6,33 +6,106 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.SerialiseMethod = exports.Entity = void 0;
|
|
7
7
|
require("reflect-metadata");
|
|
8
8
|
var _uuid = require("./uuid");
|
|
9
|
-
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); }
|
|
10
|
-
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; } } }; }
|
|
11
|
-
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); }
|
|
12
|
-
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; }
|
|
13
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
|
-
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); } // eslint-disable-next-line no-unused-vars
|
|
18
9
|
// eslint-disable-next-line no-unused-vars
|
|
10
|
+
|
|
19
11
|
// eslint-disable-next-line no-unused-vars
|
|
12
|
+
|
|
20
13
|
// eslint-disable-next-line no-unused-vars
|
|
14
|
+
|
|
21
15
|
// eslint-disable-next-line no-unused-vars
|
|
16
|
+
|
|
22
17
|
// eslint-disable-next-line no-unused-vars
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line no-unused-vars
|
|
20
|
+
|
|
23
21
|
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
|
|
24
23
|
function toUnixTimestamp(date) {
|
|
25
24
|
return parseInt(String(date.getTime() / 1000)).toFixed(0);
|
|
26
25
|
}
|
|
27
|
-
|
|
26
|
+
let SerialiseMethod = exports.SerialiseMethod = /*#__PURE__*/function (SerialiseMethod) {
|
|
28
27
|
SerialiseMethod["TO_DICT"] = "to_dict";
|
|
29
28
|
SerialiseMethod["ONLY_ID"] = "only_id";
|
|
30
29
|
return SerialiseMethod;
|
|
31
30
|
}({});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
class Entity {
|
|
32
|
+
isSingleEntityProperty(info) {
|
|
33
|
+
// the choice of 'Product' below is unimportant -- all Entities should
|
|
34
|
+
// have the same prototype but i don't know how to get instanceof
|
|
35
|
+
// working, so i just compare prototypes directly.
|
|
36
|
+
return info.type.prototype === this.merchi.Product.prototype || info.type.prototype instanceof Entity;
|
|
37
|
+
}
|
|
38
|
+
static property(options) {
|
|
39
|
+
return function (target, propertyKey) {
|
|
40
|
+
if (!options) {
|
|
41
|
+
options = {};
|
|
42
|
+
}
|
|
43
|
+
const arrayType = options.arrayType;
|
|
44
|
+
const jsonName = options.jsonName || propertyKey;
|
|
45
|
+
let properties = Reflect.getMetadata(Entity.propertiesSetKey, target.constructor);
|
|
46
|
+
properties = properties || new Set();
|
|
47
|
+
properties.add(propertyKey);
|
|
48
|
+
Reflect.defineMetadata(Entity.propertiesSetKey, properties, target.constructor);
|
|
49
|
+
Reflect.defineMetadata(Entity.jsonNameKey, jsonName, target, propertyKey);
|
|
50
|
+
Reflect.defineMetadata(Entity.arrayTypeKey, arrayType, target, propertyKey);
|
|
51
|
+
Reflect.defineMetadata(Entity.extraOptionsKey, options, target, propertyKey);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
makePropertiesMap() {
|
|
55
|
+
const map = new Map();
|
|
56
|
+
const self = this;
|
|
57
|
+
const properties = Reflect.getMetadata(Entity.propertiesSetKey, this.constructor);
|
|
58
|
+
properties.forEach(function (attributeName) {
|
|
59
|
+
const jsonName = Reflect.getMetadata(Entity.jsonNameKey, self, attributeName);
|
|
60
|
+
const propertyType = Reflect.getMetadata('design:type', self, attributeName);
|
|
61
|
+
// the array type is needed because 'design:type' breaks down
|
|
62
|
+
// with recursive classes, and also, does not contain the type
|
|
63
|
+
// of an arrays elements, which we need
|
|
64
|
+
const arrayType = Reflect.getMetadata(Entity.arrayTypeKey, self, attributeName);
|
|
65
|
+
const realArrayType = self.getEntityClass(arrayType);
|
|
66
|
+
const options = Reflect.getMetadata(Entity.extraOptionsKey, self, attributeName);
|
|
67
|
+
if (arrayType !== undefined) {
|
|
68
|
+
/* istanbul ignore next */
|
|
69
|
+
if (propertyType !== Object && propertyType !== Array) {
|
|
70
|
+
/* istanbul ignore next */
|
|
71
|
+
throw new Error('array type can only be given for arrays');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
let type;
|
|
75
|
+
if (options.type === undefined) {
|
|
76
|
+
type = propertyType;
|
|
77
|
+
} else {
|
|
78
|
+
type = options.type;
|
|
79
|
+
if (typeof type === 'string') {
|
|
80
|
+
type = self.getEntityClass(type);
|
|
81
|
+
}
|
|
82
|
+
if (type.prototype instanceof Entity) {
|
|
83
|
+
type = self.merchi.setupClass(type);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const normallyEmbeddedByDefault = !(realArrayType || type.prototype instanceof Entity);
|
|
87
|
+
const embeddedByDefault = options.embeddedByDefault !== undefined ? options.embeddedByDefault : normallyEmbeddedByDefault;
|
|
88
|
+
/* istanbul ignore next */
|
|
89
|
+
if (type === Object) {
|
|
90
|
+
/* istanbul ignore next */
|
|
91
|
+
const resource = self.constructor.resourceName;
|
|
92
|
+
const err = 'Bad attribute type ' + `${resource}.${attributeName}: ${type}`;
|
|
93
|
+
throw new Error(err);
|
|
94
|
+
}
|
|
95
|
+
const propertyInfo = {
|
|
96
|
+
property: jsonName,
|
|
97
|
+
attribute: attributeName,
|
|
98
|
+
type: type,
|
|
99
|
+
arrayType: realArrayType,
|
|
100
|
+
embeddedByDefault: embeddedByDefault,
|
|
101
|
+
dirty: true,
|
|
102
|
+
updatingOrder: false
|
|
103
|
+
};
|
|
104
|
+
map.set(jsonName, propertyInfo);
|
|
105
|
+
});
|
|
106
|
+
return map;
|
|
107
|
+
}
|
|
108
|
+
constructor(merchi) {
|
|
36
109
|
// these will be set by the parent Merchi object
|
|
37
110
|
this.merchi = void 0;
|
|
38
111
|
this.isDirty = false;
|
|
@@ -40,9 +113,9 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
40
113
|
this.propertiesMap = void 0;
|
|
41
114
|
this.backObjects = new Set();
|
|
42
115
|
this.key = (0, _uuid.generateUUID)();
|
|
43
|
-
this.getPrimaryKeyValue =
|
|
44
|
-
|
|
45
|
-
|
|
116
|
+
this.getPrimaryKeyValue = () => {
|
|
117
|
+
const name = this.constructor.primaryKey;
|
|
118
|
+
const info = this.propertiesMap.get(name);
|
|
46
119
|
/* istanbul ignore next */
|
|
47
120
|
if (info !== undefined) {
|
|
48
121
|
return info.currentValue;
|
|
@@ -50,77 +123,68 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
50
123
|
/* istanbul ignore next */
|
|
51
124
|
return undefined;
|
|
52
125
|
};
|
|
53
|
-
this.setupProperties =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
126
|
+
this.setupProperties = () => {
|
|
127
|
+
const properties = {};
|
|
128
|
+
const makeSetSingle = info => {
|
|
129
|
+
const get = () => {
|
|
57
130
|
return info.currentValue;
|
|
58
131
|
};
|
|
59
|
-
|
|
132
|
+
const set = newValue => {
|
|
60
133
|
info.currentValue = newValue;
|
|
61
|
-
|
|
62
|
-
|
|
134
|
+
this.addBackObject(newValue);
|
|
135
|
+
this.markDirty(info.property, newValue);
|
|
63
136
|
};
|
|
64
137
|
return {
|
|
65
138
|
get: get,
|
|
66
139
|
set: set
|
|
67
140
|
};
|
|
68
141
|
};
|
|
69
|
-
|
|
70
|
-
|
|
142
|
+
const makeSetScalar = info => {
|
|
143
|
+
const get = () => {
|
|
71
144
|
return info.currentValue;
|
|
72
145
|
};
|
|
73
|
-
|
|
146
|
+
const set = newValue => {
|
|
74
147
|
info.currentValue = newValue;
|
|
75
|
-
|
|
148
|
+
this.markDirty(info.property, newValue);
|
|
76
149
|
};
|
|
77
150
|
return {
|
|
78
151
|
get: get,
|
|
79
152
|
set: set
|
|
80
153
|
};
|
|
81
154
|
};
|
|
82
|
-
|
|
83
|
-
|
|
155
|
+
const makeSetArray = info => {
|
|
156
|
+
const get = () => {
|
|
84
157
|
return info.currentValue;
|
|
85
158
|
};
|
|
86
|
-
|
|
159
|
+
const set = newValue => {
|
|
87
160
|
info.currentValue = newValue;
|
|
88
|
-
|
|
89
|
-
|
|
161
|
+
this.addBackObjectList(newValue);
|
|
162
|
+
this.markDirty(info.property, newValue);
|
|
90
163
|
};
|
|
91
164
|
return {
|
|
92
165
|
get: get,
|
|
93
166
|
set: set
|
|
94
167
|
};
|
|
95
168
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
} else if (info.arrayType) {
|
|
104
|
-
properties[info.attribute] = makeSetArray(info);
|
|
105
|
-
} else {
|
|
106
|
-
properties[info.attribute] = makeSetScalar(info);
|
|
107
|
-
}
|
|
169
|
+
for (const info of this.propertiesMap.values()) {
|
|
170
|
+
if (info.type.prototype instanceof Entity) {
|
|
171
|
+
properties[info.attribute] = makeSetSingle(info);
|
|
172
|
+
} else if (info.arrayType) {
|
|
173
|
+
properties[info.attribute] = makeSetArray(info);
|
|
174
|
+
} else {
|
|
175
|
+
properties[info.attribute] = makeSetScalar(info);
|
|
108
176
|
}
|
|
109
|
-
} catch (err) {
|
|
110
|
-
_iterator.e(err);
|
|
111
|
-
} finally {
|
|
112
|
-
_iterator.f();
|
|
113
177
|
}
|
|
114
|
-
Object.defineProperties(
|
|
178
|
+
Object.defineProperties(this, properties);
|
|
115
179
|
};
|
|
116
|
-
this.save =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
180
|
+
this.save = options => {
|
|
181
|
+
const primaryKey = this.getPrimaryKeyValue();
|
|
182
|
+
const constructor = this.constructor;
|
|
183
|
+
const resourceName = constructor.resourceName;
|
|
184
|
+
const singularName = constructor.singularName;
|
|
185
|
+
const resource = `/${resourceName}/${String(primaryKey)}/`;
|
|
186
|
+
const data = this.toFormData();
|
|
187
|
+
const fetchOptions = {
|
|
124
188
|
method: 'PATCH',
|
|
125
189
|
body: data
|
|
126
190
|
};
|
|
@@ -131,20 +195,21 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
131
195
|
if (!(options && options.withRights)) {
|
|
132
196
|
fetchOptions.query.push(['skip_rights', 'y']);
|
|
133
197
|
}
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
198
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).then(data => {
|
|
199
|
+
this.fromJson(data[singularName]);
|
|
200
|
+
this.cleanDirty();
|
|
201
|
+
return this;
|
|
138
202
|
});
|
|
139
203
|
};
|
|
140
|
-
this.createFactory =
|
|
141
|
-
|
|
142
|
-
resourceName =
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
204
|
+
this.createFactory = _ref => {
|
|
205
|
+
let {
|
|
206
|
+
resourceName = this.constructor.resourceName
|
|
207
|
+
} = _ref;
|
|
208
|
+
return options => {
|
|
209
|
+
const resource = `/${resourceName}/`;
|
|
210
|
+
const data = this.toFormData();
|
|
211
|
+
const singularName = this.constructor.singularName;
|
|
212
|
+
const fetchOptions = {
|
|
148
213
|
method: 'POST',
|
|
149
214
|
body: data
|
|
150
215
|
};
|
|
@@ -155,170 +220,133 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
155
220
|
if (!(options && options.withRights)) {
|
|
156
221
|
fetchOptions.query.push(['skip_rights', 'y']);
|
|
157
222
|
}
|
|
158
|
-
return
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return
|
|
223
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).then(data => {
|
|
224
|
+
this.fromJson(data[singularName]);
|
|
225
|
+
this.cleanDirty();
|
|
226
|
+
return this;
|
|
162
227
|
});
|
|
163
228
|
};
|
|
164
229
|
};
|
|
165
230
|
this.create = this.createFactory({});
|
|
166
|
-
this.getEntityClass =
|
|
231
|
+
this.getEntityClass = name => {
|
|
167
232
|
if (name === undefined) {
|
|
168
233
|
return undefined;
|
|
169
234
|
}
|
|
170
|
-
return
|
|
235
|
+
return this.merchi[name];
|
|
171
236
|
};
|
|
172
|
-
this.cleanDirty =
|
|
237
|
+
this.cleanDirty = () => {
|
|
173
238
|
// remove all dirty records of this entity, makes it untouched
|
|
174
239
|
// entity
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
propertyInfo
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
propertyInfo.currentValue.map(function (v) {
|
|
186
|
-
return v.cleanDirty();
|
|
187
|
-
});
|
|
188
|
-
} else if (_this.isSingleEntityProperty(propertyInfo)) {
|
|
189
|
-
if (propertyInfo.currentValue) {
|
|
190
|
-
propertyInfo.currentValue.cleanDirty();
|
|
191
|
-
}
|
|
240
|
+
this.isDirty = false;
|
|
241
|
+
for (const entry of this.propertiesMap.entries()) {
|
|
242
|
+
const propertyInfo = entry[1];
|
|
243
|
+
propertyInfo.dirty = false;
|
|
244
|
+
if (propertyInfo.currentValue !== undefined) {
|
|
245
|
+
if (propertyInfo.arrayType) {
|
|
246
|
+
propertyInfo.currentValue.map(v => v.cleanDirty());
|
|
247
|
+
} else if (this.isSingleEntityProperty(propertyInfo)) {
|
|
248
|
+
if (propertyInfo.currentValue) {
|
|
249
|
+
propertyInfo.currentValue.cleanDirty();
|
|
192
250
|
}
|
|
193
251
|
}
|
|
194
252
|
}
|
|
195
|
-
} catch (err) {
|
|
196
|
-
_iterator2.e(err);
|
|
197
|
-
} finally {
|
|
198
|
-
_iterator2.f();
|
|
199
253
|
}
|
|
200
254
|
};
|
|
201
|
-
this.fromJson =
|
|
255
|
+
this.fromJson = (json, options) => {
|
|
202
256
|
options = options || {};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
arrayValueStrict = _options$arrayValueSt === void 0 ? true : _options$arrayValueSt;
|
|
257
|
+
const {
|
|
258
|
+
makeDirty = false,
|
|
259
|
+
arrayValueStrict = true
|
|
260
|
+
} = options;
|
|
208
261
|
options = {
|
|
209
|
-
makeDirty
|
|
210
|
-
arrayValueStrict
|
|
262
|
+
makeDirty,
|
|
263
|
+
arrayValueStrict
|
|
211
264
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
var nested = new propertyInfo.arrayType(_this.merchi);
|
|
230
|
-
return nested.fromJson(item, options);
|
|
231
|
-
});
|
|
232
|
-
propertyInfo.currentValue = newValue;
|
|
233
|
-
} else if (_this.isSingleEntityProperty(propertyInfo)) {
|
|
234
|
-
// if property already have a entity as relationship, try to merge
|
|
235
|
-
// with json first, this behavior may need to be configurable in the
|
|
236
|
-
// future.
|
|
237
|
-
if (propertyInfo.currentValue) {
|
|
238
|
-
propertyInfo.currentValue.fromJson(value, options);
|
|
239
|
-
} else {
|
|
240
|
-
var nested = new propertyInfo.type(_this.merchi);
|
|
241
|
-
propertyInfo.currentValue = nested.fromJson(value, options);
|
|
265
|
+
for (const key in json) {
|
|
266
|
+
const value = json[key];
|
|
267
|
+
if (value === undefined) continue;
|
|
268
|
+
const propertyInfo = this.propertiesMap.get(key);
|
|
269
|
+
if (propertyInfo !== undefined) {
|
|
270
|
+
propertyInfo.dirty = makeDirty;
|
|
271
|
+
if (propertyInfo.arrayType) {
|
|
272
|
+
// ignore array value if it is not an array and we did expect it
|
|
273
|
+
if (!arrayValueStrict && !Array.isArray(value)) continue;
|
|
274
|
+
const newValue = value.map((item, index) => {
|
|
275
|
+
const currentValue = propertyInfo.currentValue;
|
|
276
|
+
// if property already have an array of entities as relationship,
|
|
277
|
+
// try to merge with json one by one, this behavior may need to be
|
|
278
|
+
// configurable in the future.
|
|
279
|
+
if (currentValue && currentValue[index]) {
|
|
280
|
+
return currentValue[index].fromJson(item, options);
|
|
242
281
|
}
|
|
282
|
+
const nested = new propertyInfo.arrayType(this.merchi);
|
|
283
|
+
return nested.fromJson(item, options);
|
|
284
|
+
});
|
|
285
|
+
propertyInfo.currentValue = newValue;
|
|
286
|
+
} else if (this.isSingleEntityProperty(propertyInfo)) {
|
|
287
|
+
// if property already have a entity as relationship, try to merge
|
|
288
|
+
// with json first, this behavior may need to be configurable in the
|
|
289
|
+
// future.
|
|
290
|
+
if (propertyInfo.currentValue) {
|
|
291
|
+
propertyInfo.currentValue.fromJson(value, options);
|
|
243
292
|
} else {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
293
|
+
const nested = new propertyInfo.type(this.merchi);
|
|
294
|
+
propertyInfo.currentValue = nested.fromJson(value, options);
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
propertyInfo.currentValue = value;
|
|
298
|
+
if (propertyInfo.type === Date && !!value) {
|
|
299
|
+
propertyInfo.currentValue = new Date(value * 1000);
|
|
248
300
|
}
|
|
249
301
|
}
|
|
250
|
-
}
|
|
251
|
-
_ret;
|
|
252
|
-
for (var key in json) {
|
|
253
|
-
_ret = _loop();
|
|
254
|
-
if (_ret === 0) continue;
|
|
302
|
+
}
|
|
255
303
|
}
|
|
256
|
-
return
|
|
304
|
+
return this;
|
|
257
305
|
};
|
|
258
|
-
this.toJson =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (propertyInfo
|
|
268
|
-
if (propertyInfo.
|
|
269
|
-
|
|
270
|
-
return v.toJson();
|
|
271
|
-
});
|
|
272
|
-
json[propertyName] = array;
|
|
273
|
-
} else if (_this.isSingleEntityProperty(propertyInfo)) {
|
|
274
|
-
if (propertyInfo.currentValue === null) {
|
|
275
|
-
json[propertyName] = null;
|
|
276
|
-
} else {
|
|
277
|
-
json[propertyName] = propertyInfo.currentValue.toJson();
|
|
278
|
-
}
|
|
306
|
+
this.toJson = () => {
|
|
307
|
+
const json = {};
|
|
308
|
+
for (const entry of this.propertiesMap.entries()) {
|
|
309
|
+
const propertyName = entry[0];
|
|
310
|
+
const propertyInfo = entry[1];
|
|
311
|
+
if (propertyInfo.currentValue !== undefined) {
|
|
312
|
+
if (propertyInfo.arrayType) {
|
|
313
|
+
const array = propertyInfo.currentValue.map(v => v.toJson());
|
|
314
|
+
json[propertyName] = array;
|
|
315
|
+
} else if (this.isSingleEntityProperty(propertyInfo)) {
|
|
316
|
+
if (propertyInfo.currentValue === null) {
|
|
317
|
+
json[propertyName] = null;
|
|
279
318
|
} else {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
319
|
+
json[propertyName] = propertyInfo.currentValue.toJson();
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
const value = propertyInfo.currentValue;
|
|
323
|
+
json[propertyName] = value;
|
|
324
|
+
if (propertyInfo.type === Date && !!value) {
|
|
325
|
+
json[propertyName] = value.getTime() / 1000;
|
|
285
326
|
}
|
|
286
327
|
}
|
|
287
328
|
}
|
|
288
|
-
} catch (err) {
|
|
289
|
-
_iterator3.e(err);
|
|
290
|
-
} finally {
|
|
291
|
-
_iterator3.f();
|
|
292
329
|
}
|
|
293
330
|
return json;
|
|
294
331
|
};
|
|
295
|
-
this.forEachProperty =
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
try {
|
|
299
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
300
|
-
var info = _step4.value;
|
|
301
|
-
fn(info);
|
|
302
|
-
}
|
|
303
|
-
} catch (err) {
|
|
304
|
-
_iterator4.e(err);
|
|
305
|
-
} finally {
|
|
306
|
-
_iterator4.f();
|
|
332
|
+
this.forEachProperty = fn => {
|
|
333
|
+
for (const info of this.propertiesMap.values()) {
|
|
334
|
+
fn(info);
|
|
307
335
|
}
|
|
308
336
|
};
|
|
309
|
-
this.toFormData =
|
|
337
|
+
this.toFormData = (options, fileIndex) => {
|
|
310
338
|
if (options === undefined) {
|
|
311
339
|
options = {};
|
|
312
340
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
341
|
+
const result = options.existing || new FormData();
|
|
342
|
+
const prefix = options._prefix || '';
|
|
343
|
+
const excludeOld = options.excludeOld === undefined ? true : options.excludeOld;
|
|
316
344
|
if (fileIndex === undefined) {
|
|
317
345
|
fileIndex = {
|
|
318
346
|
value: 0
|
|
319
347
|
};
|
|
320
348
|
}
|
|
321
|
-
|
|
349
|
+
const appendData = (name, value) => {
|
|
322
350
|
/* istanbul ignore next */
|
|
323
351
|
if (name === undefined || value === undefined) {
|
|
324
352
|
/* istanbul ignore next */
|
|
@@ -329,50 +357,41 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
329
357
|
}
|
|
330
358
|
result.set(name, value);
|
|
331
359
|
};
|
|
332
|
-
if (
|
|
333
|
-
result.set(String(fileIndex.value),
|
|
360
|
+
if (this.fileData !== undefined) {
|
|
361
|
+
result.set(String(fileIndex.value), this.fileData);
|
|
334
362
|
appendData('fileDataIndex', fileIndex.value);
|
|
335
363
|
fileIndex.value++;
|
|
336
364
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
365
|
+
const processArrayProperty = (info, value) => {
|
|
366
|
+
const remoteCount = value.length;
|
|
367
|
+
const initialLength = Array.from(result.entries()).length;
|
|
340
368
|
if (remoteCount === 0 && info.dirty) {
|
|
341
369
|
appendData(info.property + '-count', 0);
|
|
342
370
|
return;
|
|
343
371
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
var item = _step5.value;
|
|
350
|
-
if (item.isDirty) {
|
|
351
|
-
isDirty = true;
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
372
|
+
let isDirty = false;
|
|
373
|
+
for (const item of value) {
|
|
374
|
+
if (item.isDirty) {
|
|
375
|
+
isDirty = true;
|
|
376
|
+
break;
|
|
354
377
|
}
|
|
355
|
-
} catch (err) {
|
|
356
|
-
_iterator5.e(err);
|
|
357
|
-
} finally {
|
|
358
|
-
_iterator5.f();
|
|
359
378
|
}
|
|
360
379
|
isDirty = isDirty || info.dirty;
|
|
361
380
|
if (!isDirty && excludeOld) {
|
|
362
381
|
return;
|
|
363
382
|
}
|
|
364
|
-
for (
|
|
365
|
-
|
|
383
|
+
for (let i = 0; i < remoteCount; ++i) {
|
|
384
|
+
let innerPrefix = info.property + '-' + i;
|
|
366
385
|
if (prefix) {
|
|
367
386
|
innerPrefix = prefix + '-' + innerPrefix;
|
|
368
387
|
}
|
|
369
|
-
value[
|
|
388
|
+
value[i].toFormData({
|
|
370
389
|
existing: result,
|
|
371
390
|
_prefix: innerPrefix,
|
|
372
391
|
excludeOld: excludeOld
|
|
373
392
|
}, fileIndex);
|
|
374
393
|
}
|
|
375
|
-
|
|
394
|
+
const finalLength = Array.from(result.entries()).length;
|
|
376
395
|
if (finalLength - initialLength > 0) {
|
|
377
396
|
appendData(info.property + '-count', remoteCount);
|
|
378
397
|
if (info.updatingOrder) {
|
|
@@ -380,9 +399,9 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
380
399
|
}
|
|
381
400
|
}
|
|
382
401
|
};
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
402
|
+
const processSingleEntityProperty = (info, value) => {
|
|
403
|
+
const primaryKey = this.constructor.primaryKey;
|
|
404
|
+
let innerPrefix = info.property + '-0';
|
|
386
405
|
if (prefix) {
|
|
387
406
|
innerPrefix = prefix + '-' + innerPrefix;
|
|
388
407
|
}
|
|
@@ -396,19 +415,19 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
396
415
|
if (!(info.dirty || value.isDirty) && excludeOld) {
|
|
397
416
|
return;
|
|
398
417
|
}
|
|
399
|
-
|
|
418
|
+
const initialLength = Array.from(result.entries()).length;
|
|
400
419
|
value.toFormData({
|
|
401
420
|
existing: result,
|
|
402
421
|
_prefix: innerPrefix,
|
|
403
422
|
excludeOld: excludeOld
|
|
404
423
|
}, fileIndex);
|
|
405
|
-
|
|
424
|
+
const finalLength = Array.from(result.entries()).length;
|
|
406
425
|
if (finalLength - initialLength > 0) {
|
|
407
426
|
appendData(info.property + '-count', 1);
|
|
408
427
|
}
|
|
409
428
|
};
|
|
410
|
-
|
|
411
|
-
|
|
429
|
+
const processScalarProperty = (info, value) => {
|
|
430
|
+
const primaryKey = this.constructor.primaryKey;
|
|
412
431
|
if (!excludeOld || info.dirty || info.property === primaryKey && value) {
|
|
413
432
|
if (info.type === Date && !!value) {
|
|
414
433
|
value = value.getTime() / 1000;
|
|
@@ -416,87 +435,76 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
416
435
|
appendData(info.property, value);
|
|
417
436
|
}
|
|
418
437
|
};
|
|
419
|
-
|
|
420
|
-
|
|
438
|
+
const processProperty = info => {
|
|
439
|
+
const value = this[info.attribute];
|
|
421
440
|
if (value === undefined) {
|
|
422
441
|
return;
|
|
423
442
|
} else if (info.arrayType) {
|
|
424
443
|
processArrayProperty(info, value);
|
|
425
|
-
} else if (
|
|
444
|
+
} else if (this.isSingleEntityProperty(info)) {
|
|
426
445
|
processSingleEntityProperty(info, value);
|
|
427
446
|
} else {
|
|
428
447
|
processScalarProperty(info, value);
|
|
429
448
|
}
|
|
430
449
|
};
|
|
431
|
-
|
|
450
|
+
this.forEachProperty(processProperty);
|
|
432
451
|
return result;
|
|
433
452
|
};
|
|
434
|
-
this.addBackObject =
|
|
453
|
+
this.addBackObject = remote => {
|
|
435
454
|
if (remote !== undefined) {
|
|
436
|
-
remote.backObjects.add(
|
|
455
|
+
remote.backObjects.add(this);
|
|
437
456
|
}
|
|
438
457
|
};
|
|
439
|
-
this.addBackObjectList =
|
|
458
|
+
this.addBackObjectList = remotes => {
|
|
440
459
|
if (remotes !== undefined) {
|
|
441
|
-
remotes.forEach(
|
|
460
|
+
remotes.forEach(this.addBackObject);
|
|
442
461
|
}
|
|
443
462
|
};
|
|
444
|
-
this.updateOrder =
|
|
445
|
-
|
|
463
|
+
this.updateOrder = property => {
|
|
464
|
+
this.propertiesMap.get(property).updatingOrder = true;
|
|
446
465
|
};
|
|
447
|
-
this.markDirty =
|
|
466
|
+
this.markDirty = (property, newValue) => {
|
|
448
467
|
if (newValue === undefined) {
|
|
449
468
|
return;
|
|
450
469
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
openSet.push(
|
|
470
|
+
this.propertiesMap.get(property).dirty = true;
|
|
471
|
+
const openSet = []; /* Queue (BFS) */
|
|
472
|
+
const closedSet = new Set();
|
|
473
|
+
openSet.push(this);
|
|
455
474
|
while (openSet.length > 0) {
|
|
456
|
-
|
|
475
|
+
const current = openSet.shift();
|
|
457
476
|
if (!closedSet.has(current)) {
|
|
458
477
|
current.isDirty = true;
|
|
459
478
|
closedSet.add(current);
|
|
460
|
-
|
|
461
|
-
_step6;
|
|
462
|
-
try {
|
|
463
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
464
|
-
var child = _step6.value;
|
|
465
|
-
openSet.push(child);
|
|
466
|
-
}
|
|
467
|
-
} catch (err) {
|
|
468
|
-
_iterator6.e(err);
|
|
469
|
-
} finally {
|
|
470
|
-
_iterator6.f();
|
|
471
|
-
}
|
|
479
|
+
for (const child of current.backObjects) openSet.push(child);
|
|
472
480
|
}
|
|
473
481
|
}
|
|
474
482
|
};
|
|
475
|
-
this
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
483
|
+
this.delete = options => {
|
|
484
|
+
const primaryKey = this.getPrimaryKeyValue();
|
|
485
|
+
const resourceName = this.constructor.resourceName;
|
|
486
|
+
const resource = `/${resourceName}/${String(primaryKey)}/`;
|
|
487
|
+
const fetchOptions = {
|
|
480
488
|
method: 'DELETE'
|
|
481
489
|
};
|
|
482
490
|
fetchOptions.query = [];
|
|
483
491
|
if (!(options && options.withRights)) {
|
|
484
492
|
fetchOptions.query.push(['skip_rights', 'y']);
|
|
485
493
|
}
|
|
486
|
-
if (
|
|
487
|
-
fetchOptions.query.push(['session_token',
|
|
494
|
+
if (this.merchi.sessionToken) {
|
|
495
|
+
fetchOptions.query.push(['session_token', this.merchi.sessionToken]);
|
|
488
496
|
}
|
|
489
|
-
return
|
|
490
|
-
return
|
|
497
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions, true).then(() => {
|
|
498
|
+
return this;
|
|
491
499
|
});
|
|
492
500
|
};
|
|
493
|
-
this.recover =
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
501
|
+
this.recover = options => {
|
|
502
|
+
const primaryKey = this.getPrimaryKeyValue();
|
|
503
|
+
const constructor = this.constructor;
|
|
504
|
+
const resourceName = constructor.resourceName;
|
|
505
|
+
const singularName = constructor.singularName;
|
|
506
|
+
const resource = `/unarchive/${resourceName}/${String(primaryKey)}/`;
|
|
507
|
+
const fetchOptions = {
|
|
500
508
|
method: 'POST'
|
|
501
509
|
};
|
|
502
510
|
fetchOptions.query = [];
|
|
@@ -506,9 +514,9 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
506
514
|
if (!(options && options.withRights)) {
|
|
507
515
|
fetchOptions.query.push(['skip_rights', 'y']);
|
|
508
516
|
}
|
|
509
|
-
return
|
|
510
|
-
|
|
511
|
-
return
|
|
517
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).then(data => {
|
|
518
|
+
this.fromJson(data[singularName]);
|
|
519
|
+
return this;
|
|
512
520
|
});
|
|
513
521
|
};
|
|
514
522
|
/* istanbul ignore next */
|
|
@@ -518,370 +526,272 @@ var Entity = exports.Entity = /*#__PURE__*/function () {
|
|
|
518
526
|
this.propertiesMap = this.makePropertiesMap();
|
|
519
527
|
this.setupProperties();
|
|
520
528
|
}
|
|
521
|
-
|
|
522
|
-
key
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
return info.type.prototype === this.merchi.Product.prototype || info.type.prototype instanceof Entity;
|
|
529
|
+
static get(key, options) {
|
|
530
|
+
const resource = `/${this.resourceName}/${String(key)}/`;
|
|
531
|
+
const fetchOptions = {};
|
|
532
|
+
fetchOptions.query = [];
|
|
533
|
+
if (options && options.embed) {
|
|
534
|
+
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
528
535
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
value: function makePropertiesMap() {
|
|
532
|
-
var map = new Map();
|
|
533
|
-
var self = this;
|
|
534
|
-
var properties = Reflect.getMetadata(Entity.propertiesSetKey, this.constructor);
|
|
535
|
-
properties.forEach(function (attributeName) {
|
|
536
|
-
var jsonName = Reflect.getMetadata(Entity.jsonNameKey, self, attributeName);
|
|
537
|
-
var propertyType = Reflect.getMetadata('design:type', self, attributeName);
|
|
538
|
-
// the array type is needed because 'design:type' breaks down
|
|
539
|
-
// with recursive classes, and also, does not contain the type
|
|
540
|
-
// of an arrays elements, which we need
|
|
541
|
-
var arrayType = Reflect.getMetadata(Entity.arrayTypeKey, self, attributeName);
|
|
542
|
-
var realArrayType = self.getEntityClass(arrayType);
|
|
543
|
-
var options = Reflect.getMetadata(Entity.extraOptionsKey, self, attributeName);
|
|
544
|
-
if (arrayType !== undefined) {
|
|
545
|
-
/* istanbul ignore next */
|
|
546
|
-
if (propertyType !== Object && propertyType !== Array) {
|
|
547
|
-
/* istanbul ignore next */
|
|
548
|
-
throw new Error('array type can only be given for arrays');
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
var type;
|
|
552
|
-
if (options.type === undefined) {
|
|
553
|
-
type = propertyType;
|
|
554
|
-
} else {
|
|
555
|
-
type = options.type;
|
|
556
|
-
if (typeof type === 'string') {
|
|
557
|
-
type = self.getEntityClass(type);
|
|
558
|
-
}
|
|
559
|
-
if (type.prototype instanceof Entity) {
|
|
560
|
-
type = self.merchi.setupClass(type);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
var normallyEmbeddedByDefault = !(realArrayType || type.prototype instanceof Entity);
|
|
564
|
-
var embeddedByDefault = options.embeddedByDefault !== undefined ? options.embeddedByDefault : normallyEmbeddedByDefault;
|
|
565
|
-
/* istanbul ignore next */
|
|
566
|
-
if (type === Object) {
|
|
567
|
-
/* istanbul ignore next */
|
|
568
|
-
var resource = self.constructor.resourceName;
|
|
569
|
-
var err = 'Bad attribute type ' + "".concat(resource, ".").concat(attributeName, ": ").concat(type);
|
|
570
|
-
throw new Error(err);
|
|
571
|
-
}
|
|
572
|
-
var propertyInfo = {
|
|
573
|
-
property: jsonName,
|
|
574
|
-
attribute: attributeName,
|
|
575
|
-
type: type,
|
|
576
|
-
arrayType: realArrayType,
|
|
577
|
-
embeddedByDefault: embeddedByDefault,
|
|
578
|
-
dirty: true,
|
|
579
|
-
updatingOrder: false
|
|
580
|
-
};
|
|
581
|
-
map.set(jsonName, propertyInfo);
|
|
582
|
-
});
|
|
583
|
-
return map;
|
|
536
|
+
if (options && options.includeArchived) {
|
|
537
|
+
fetchOptions.query.push(['include_archived', JSON.stringify(options.includeArchived)]);
|
|
584
538
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
value: function property(options) {
|
|
588
|
-
return function (target, propertyKey) {
|
|
589
|
-
if (!options) {
|
|
590
|
-
options = {};
|
|
591
|
-
}
|
|
592
|
-
var arrayType = options.arrayType;
|
|
593
|
-
var jsonName = options.jsonName || propertyKey;
|
|
594
|
-
var properties = Reflect.getMetadata(Entity.propertiesSetKey, target.constructor);
|
|
595
|
-
properties = properties || new Set();
|
|
596
|
-
properties.add(propertyKey);
|
|
597
|
-
Reflect.defineMetadata(Entity.propertiesSetKey, properties, target.constructor);
|
|
598
|
-
Reflect.defineMetadata(Entity.jsonNameKey, jsonName, target, propertyKey);
|
|
599
|
-
Reflect.defineMetadata(Entity.arrayTypeKey, arrayType, target, propertyKey);
|
|
600
|
-
Reflect.defineMetadata(Entity.extraOptionsKey, options, target, propertyKey);
|
|
601
|
-
};
|
|
539
|
+
if (!(options && options.withRights)) {
|
|
540
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
602
541
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
542
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).then(data => {
|
|
543
|
+
const result = new this();
|
|
544
|
+
result.fromJson(data[this.singularName]);
|
|
545
|
+
return result;
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
static list(options) {
|
|
549
|
+
const resource = `/${this.resourceName}/`;
|
|
550
|
+
const fetchOptions = {};
|
|
551
|
+
fetchOptions.query = [];
|
|
552
|
+
if (options) {
|
|
553
|
+
if (options.embed) {
|
|
611
554
|
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
612
555
|
}
|
|
613
|
-
if (options
|
|
614
|
-
fetchOptions.query.push(['
|
|
556
|
+
if (options.offset !== undefined) {
|
|
557
|
+
fetchOptions.query.push(['offset', options.offset.toString()]);
|
|
615
558
|
}
|
|
616
|
-
if (
|
|
617
|
-
fetchOptions.query.push(['
|
|
559
|
+
if (options.limit !== undefined) {
|
|
560
|
+
fetchOptions.query.push(['limit', options.limit.toString()]);
|
|
618
561
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
result.fromJson(data[_this2.singularName]);
|
|
622
|
-
return result;
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
}, {
|
|
626
|
-
key: "list",
|
|
627
|
-
value: function list(options) {
|
|
628
|
-
var _this3 = this;
|
|
629
|
-
var resource = "/".concat(this.resourceName, "/");
|
|
630
|
-
var fetchOptions = {};
|
|
631
|
-
fetchOptions.query = [];
|
|
632
|
-
if (options) {
|
|
633
|
-
if (options.embed) {
|
|
634
|
-
fetchOptions.query.push(['embed', JSON.stringify(options.embed)]);
|
|
635
|
-
}
|
|
636
|
-
if (options.offset !== undefined) {
|
|
637
|
-
fetchOptions.query.push(['offset', options.offset.toString()]);
|
|
638
|
-
}
|
|
639
|
-
if (options.limit !== undefined) {
|
|
640
|
-
fetchOptions.query.push(['limit', options.limit.toString()]);
|
|
641
|
-
}
|
|
642
|
-
if (options.q !== undefined) {
|
|
643
|
-
fetchOptions.query.push(['q', options.q]);
|
|
644
|
-
}
|
|
645
|
-
if (options.sort !== undefined) {
|
|
646
|
-
fetchOptions.query.push(['sort', options.sort]);
|
|
647
|
-
}
|
|
648
|
-
if (options.order !== undefined) {
|
|
649
|
-
fetchOptions.query.push(['order', options.order]);
|
|
650
|
-
}
|
|
651
|
-
if (options.serialiseMethod !== undefined) {
|
|
652
|
-
fetchOptions.query.push(['serialise_method', options.serialiseMethod]);
|
|
653
|
-
}
|
|
654
|
-
if (options.tab !== undefined) {
|
|
655
|
-
fetchOptions.query.push(['tab', options.tab]);
|
|
656
|
-
}
|
|
657
|
-
if (options.as !== undefined) {
|
|
658
|
-
fetchOptions.query.push(['as', options.as]);
|
|
659
|
-
}
|
|
660
|
-
if (options.state !== undefined) {
|
|
661
|
-
fetchOptions.query.push(['state', options.state]);
|
|
662
|
-
}
|
|
663
|
-
if (options.categoryId !== undefined) {
|
|
664
|
-
fetchOptions.query.push(['category_id', options.categoryId.toString()]);
|
|
665
|
-
}
|
|
666
|
-
if (options.platformCategoryId !== undefined) {
|
|
667
|
-
fetchOptions.query.push(['platform_category_id', options.platformCategoryId.toString()]);
|
|
668
|
-
}
|
|
669
|
-
if (options.inDomain !== undefined) {
|
|
670
|
-
fetchOptions.query.push(['in_domain', options.inDomain.toString()]);
|
|
671
|
-
}
|
|
672
|
-
if (options.inDomainName !== undefined) {
|
|
673
|
-
fetchOptions.query.push(['in_domain_name', options.inDomainName.toString()]);
|
|
674
|
-
}
|
|
675
|
-
if (options.inDomainRoles !== undefined) {
|
|
676
|
-
fetchOptions.query.push(['in_domain_roles', JSON.stringify(options.inDomainRoles)]);
|
|
677
|
-
}
|
|
678
|
-
if (options.isPrivate !== undefined) {
|
|
679
|
-
fetchOptions.query.push(['is_private', options.isPrivate.toString()]);
|
|
680
|
-
}
|
|
681
|
-
if (options.asRole !== undefined) {
|
|
682
|
-
fetchOptions.query.push(['as_role', options.asRole.toString()]);
|
|
683
|
-
}
|
|
684
|
-
if (options.groupBuyOnly !== undefined) {
|
|
685
|
-
fetchOptions.query.push(['group_buy_only', options.groupBuyOnly.toString()]);
|
|
686
|
-
}
|
|
687
|
-
if (options.publicOnly !== undefined) {
|
|
688
|
-
fetchOptions.query.push(['public_only', options.publicOnly.toString()]);
|
|
689
|
-
}
|
|
690
|
-
if (options.managedOnly !== undefined) {
|
|
691
|
-
fetchOptions.query.push(['managed_only', options.managedOnly.toString()]);
|
|
692
|
-
}
|
|
693
|
-
if (options.doesNotHaveAdminDomain !== undefined) {
|
|
694
|
-
fetchOptions.query.push(['does_not_have_admin_domain', options.doesNotHaveAdminDomain.toString()]);
|
|
695
|
-
}
|
|
696
|
-
if (options.clientOnly !== undefined) {
|
|
697
|
-
fetchOptions.query.push(['client_only', options.clientOnly.toString()]);
|
|
698
|
-
}
|
|
699
|
-
if (options.teamOnly !== undefined) {
|
|
700
|
-
fetchOptions.query.push(['team_only', options.teamOnly.toString()]);
|
|
701
|
-
}
|
|
702
|
-
if (options.memberOnly !== undefined) {
|
|
703
|
-
fetchOptions.query.push(['member_only', options.memberOnly.toString()]);
|
|
704
|
-
}
|
|
705
|
-
if (options.merchiOnly !== undefined) {
|
|
706
|
-
fetchOptions.query.push(['merchi_only', options.merchiOnly.toString()]);
|
|
707
|
-
}
|
|
708
|
-
if (options.supplierResellOnly !== undefined) {
|
|
709
|
-
fetchOptions.query.push(['supplier_resell_only', options.supplierResellOnly.toString()]);
|
|
710
|
-
}
|
|
711
|
-
if (options.shopifyOnly !== undefined) {
|
|
712
|
-
fetchOptions.query.push(['shopify_only', options.shopifyOnly.toString()]);
|
|
713
|
-
}
|
|
714
|
-
if (options.inbound !== undefined) {
|
|
715
|
-
fetchOptions.query.push(['inbound', options.inbound.toString()]);
|
|
716
|
-
}
|
|
717
|
-
if (options.isMaster !== undefined) {
|
|
718
|
-
fetchOptions.query.push(['is_master', options.isMaster.toString()]);
|
|
719
|
-
}
|
|
720
|
-
if (options.domainRoles !== undefined) {
|
|
721
|
-
fetchOptions.query.push(['domain_roles', options.domainRoles.join(',')]);
|
|
722
|
-
}
|
|
723
|
-
if (options.domainTypes !== undefined) {
|
|
724
|
-
fetchOptions.query.push(['domain_types', options.domainTypes.join(',')]);
|
|
725
|
-
}
|
|
726
|
-
if (options.entityTypes !== undefined) {
|
|
727
|
-
fetchOptions.query.push(['entity_types', options.entityTypes.join(',')]);
|
|
728
|
-
}
|
|
729
|
-
if (options.productTypes !== undefined) {
|
|
730
|
-
fetchOptions.query.push(['product_types', options.productTypes.join(',')]);
|
|
731
|
-
}
|
|
732
|
-
if (options.managedDomainsOnly !== undefined) {
|
|
733
|
-
fetchOptions.query.push(['managed_domains_only', options.managedDomainsOnly.toString()]);
|
|
734
|
-
}
|
|
735
|
-
if (options.businessDomainsOnly !== undefined) {
|
|
736
|
-
fetchOptions.query.push(['business_domains_only', options.businessDomainsOnly.toString()]);
|
|
737
|
-
}
|
|
738
|
-
if (options.dateFrom !== undefined) {
|
|
739
|
-
fetchOptions.query.push(['date_from', toUnixTimestamp(options.dateFrom)]);
|
|
740
|
-
}
|
|
741
|
-
if (options.dateTo !== undefined) {
|
|
742
|
-
fetchOptions.query.push(['date_to', toUnixTimestamp(options.dateTo)]);
|
|
743
|
-
}
|
|
744
|
-
if (options.originalOf !== undefined) {
|
|
745
|
-
fetchOptions.query.push(['original_of', options.originalOf.toString()]);
|
|
746
|
-
}
|
|
747
|
-
if (options.relatedComponent !== undefined) {
|
|
748
|
-
fetchOptions.query.push(['related_component', options.relatedComponent.toString()]);
|
|
749
|
-
}
|
|
750
|
-
if (options.relatedAssignment !== undefined) {
|
|
751
|
-
fetchOptions.query.push(['related_assignment', options.relatedAssignment.toString()]);
|
|
752
|
-
}
|
|
753
|
-
if (options.relatedDraft !== undefined) {
|
|
754
|
-
fetchOptions.query.push(['related_draft', options.relatedDraft.toString()]);
|
|
755
|
-
}
|
|
756
|
-
if (options.relatedJob !== undefined) {
|
|
757
|
-
fetchOptions.query.push(['related_job', options.relatedJob.toString()]);
|
|
758
|
-
}
|
|
759
|
-
if (options.relatedProduct !== undefined) {
|
|
760
|
-
fetchOptions.query.push(['related_product', options.relatedProduct.toString()]);
|
|
761
|
-
}
|
|
762
|
-
if (options.jobNotifiable !== undefined) {
|
|
763
|
-
fetchOptions.query.push(['job_notifiable', options.jobNotifiable.toString()]);
|
|
764
|
-
}
|
|
765
|
-
if (options.notificationType !== undefined) {
|
|
766
|
-
fetchOptions.query.push(['notification_type', options.notificationType.toString()]);
|
|
767
|
-
}
|
|
768
|
-
if (options.notificationRecipient !== undefined) {
|
|
769
|
-
fetchOptions.query.push(['notification_recipient', options.notificationRecipient.toString()]);
|
|
770
|
-
}
|
|
771
|
-
if (options.notificationJob !== undefined) {
|
|
772
|
-
fetchOptions.query.push(['notification_job', options.notificationJob.toString()]);
|
|
773
|
-
}
|
|
774
|
-
if (options.relatedUser !== undefined) {
|
|
775
|
-
fetchOptions.query.push(['related_user', options.relatedUser.toString()]);
|
|
776
|
-
}
|
|
777
|
-
if (options.clientId !== undefined) {
|
|
778
|
-
fetchOptions.query.push(['client_id', options.clientId.toString()]);
|
|
779
|
-
}
|
|
780
|
-
if (options.managerId !== undefined) {
|
|
781
|
-
fetchOptions.query.push(['manager_id', options.managerId.toString()]);
|
|
782
|
-
}
|
|
783
|
-
if (options.masterProduct !== undefined) {
|
|
784
|
-
fetchOptions.query.push(['master_product', options.masterProduct.toString()]);
|
|
785
|
-
}
|
|
786
|
-
if (options.clientCompanyId !== undefined) {
|
|
787
|
-
fetchOptions.query.push(['client_company_id', options.clientCompanyId.toString()]);
|
|
788
|
-
}
|
|
789
|
-
if (options.savedByUser !== undefined) {
|
|
790
|
-
fetchOptions.query.push(['saved_by_user', options.savedByUser.toString()]);
|
|
791
|
-
}
|
|
792
|
-
if (options.receiverId !== undefined) {
|
|
793
|
-
fetchOptions.query.push(['receiver_id', options.receiverId.toString()]);
|
|
794
|
-
}
|
|
795
|
-
if (options.companyCustomerId !== undefined) {
|
|
796
|
-
fetchOptions.query.push(['company_customer_id', options.companyCustomerId.toString()]);
|
|
797
|
-
}
|
|
798
|
-
if (options.companyId !== undefined) {
|
|
799
|
-
fetchOptions.query.push(['company_id', options.companyId.toString()]);
|
|
800
|
-
}
|
|
801
|
-
if (options.companySupplierId !== undefined) {
|
|
802
|
-
fetchOptions.query.push(['company_supplier_id', options.companySupplierId.toString()]);
|
|
803
|
-
}
|
|
804
|
-
if (options.componentId !== undefined) {
|
|
805
|
-
fetchOptions.query.push(['component_id', options.componentId.toString()]);
|
|
806
|
-
}
|
|
807
|
-
if (options.groupBuyForJobId !== undefined) {
|
|
808
|
-
fetchOptions.query.push(['group_buy_for_job_id', options.groupBuyForJobId.toString()]);
|
|
809
|
-
}
|
|
810
|
-
if (options.section !== undefined) {
|
|
811
|
-
fetchOptions.query.push(['section', options.section.toString()]);
|
|
812
|
-
}
|
|
813
|
-
if (options.senderRole !== undefined) {
|
|
814
|
-
fetchOptions.query.push(['sender_role', options.senderRole.toString()]);
|
|
815
|
-
}
|
|
816
|
-
if (options.isOrder) {
|
|
817
|
-
fetchOptions.query.push(['is_order', 'true']);
|
|
818
|
-
}
|
|
819
|
-
if (options.tags !== undefined) {
|
|
820
|
-
fetchOptions.query.push(['tags', options.tags.join(',')]);
|
|
821
|
-
}
|
|
822
|
-
if (options.tagsInternal !== undefined) {
|
|
823
|
-
fetchOptions.query.push(['tags_internal', options.tagsInternal.join(',')]);
|
|
824
|
-
}
|
|
825
|
-
if (options.tagNames !== undefined) {
|
|
826
|
-
fetchOptions.query.push(['tag_names', options.tagNames.join(',')]);
|
|
827
|
-
}
|
|
828
|
-
if (options.exclude !== undefined) {
|
|
829
|
-
fetchOptions.query.push(['exclude', options.exclude.join(',')]);
|
|
830
|
-
}
|
|
831
|
-
if (options.excludeComponents !== undefined) {
|
|
832
|
-
fetchOptions.query.push(['exclude_components', options.excludeComponents.join(',')]);
|
|
833
|
-
}
|
|
834
|
-
if (options.excludeDomains !== undefined) {
|
|
835
|
-
fetchOptions.query.push(['exclude_domains', options.excludeDomains.join(',')]);
|
|
836
|
-
}
|
|
837
|
-
if (options.includeOnly !== undefined) {
|
|
838
|
-
fetchOptions.query.push(['include_only', options.includeOnly.join(',')]);
|
|
839
|
-
}
|
|
840
|
-
if (options.orClientId !== undefined) {
|
|
841
|
-
fetchOptions.query.push(['or_client_id', options.orClientId.toString()]);
|
|
842
|
-
}
|
|
843
|
-
if (options.orClientCompanyId !== undefined) {
|
|
844
|
-
fetchOptions.query.push(['or_client_company_id', options.orClientCompanyId.toString()]);
|
|
845
|
-
}
|
|
562
|
+
if (options.q !== undefined) {
|
|
563
|
+
fetchOptions.query.push(['q', options.q]);
|
|
846
564
|
}
|
|
847
|
-
if (
|
|
848
|
-
fetchOptions.query.push(['
|
|
565
|
+
if (options.sort !== undefined) {
|
|
566
|
+
fetchOptions.query.push(['sort', options.sort]);
|
|
567
|
+
}
|
|
568
|
+
if (options.order !== undefined) {
|
|
569
|
+
fetchOptions.query.push(['order', options.order]);
|
|
570
|
+
}
|
|
571
|
+
if (options.serialiseMethod !== undefined) {
|
|
572
|
+
fetchOptions.query.push(['serialise_method', options.serialiseMethod]);
|
|
573
|
+
}
|
|
574
|
+
if (options.tab !== undefined) {
|
|
575
|
+
fetchOptions.query.push(['tab', options.tab]);
|
|
576
|
+
}
|
|
577
|
+
if (options.as !== undefined) {
|
|
578
|
+
fetchOptions.query.push(['as', options.as]);
|
|
579
|
+
}
|
|
580
|
+
if (options.state !== undefined) {
|
|
581
|
+
fetchOptions.query.push(['state', options.state]);
|
|
582
|
+
}
|
|
583
|
+
if (options.categoryId !== undefined) {
|
|
584
|
+
fetchOptions.query.push(['category_id', options.categoryId.toString()]);
|
|
585
|
+
}
|
|
586
|
+
if (options.platformCategoryId !== undefined) {
|
|
587
|
+
fetchOptions.query.push(['platform_category_id', options.platformCategoryId.toString()]);
|
|
588
|
+
}
|
|
589
|
+
if (options.inDomain !== undefined) {
|
|
590
|
+
fetchOptions.query.push(['in_domain', options.inDomain.toString()]);
|
|
591
|
+
}
|
|
592
|
+
if (options.inDomainName !== undefined) {
|
|
593
|
+
fetchOptions.query.push(['in_domain_name', options.inDomainName.toString()]);
|
|
594
|
+
}
|
|
595
|
+
if (options.inDomainRoles !== undefined) {
|
|
596
|
+
fetchOptions.query.push(['in_domain_roles', JSON.stringify(options.inDomainRoles)]);
|
|
597
|
+
}
|
|
598
|
+
if (options.isPrivate !== undefined) {
|
|
599
|
+
fetchOptions.query.push(['is_private', options.isPrivate.toString()]);
|
|
600
|
+
}
|
|
601
|
+
if (options.asRole !== undefined) {
|
|
602
|
+
fetchOptions.query.push(['as_role', options.asRole.toString()]);
|
|
603
|
+
}
|
|
604
|
+
if (options.groupBuyOnly !== undefined) {
|
|
605
|
+
fetchOptions.query.push(['group_buy_only', options.groupBuyOnly.toString()]);
|
|
606
|
+
}
|
|
607
|
+
if (options.publicOnly !== undefined) {
|
|
608
|
+
fetchOptions.query.push(['public_only', options.publicOnly.toString()]);
|
|
609
|
+
}
|
|
610
|
+
if (options.managedOnly !== undefined) {
|
|
611
|
+
fetchOptions.query.push(['managed_only', options.managedOnly.toString()]);
|
|
612
|
+
}
|
|
613
|
+
if (options.doesNotHaveAdminDomain !== undefined) {
|
|
614
|
+
fetchOptions.query.push(['does_not_have_admin_domain', options.doesNotHaveAdminDomain.toString()]);
|
|
615
|
+
}
|
|
616
|
+
if (options.clientOnly !== undefined) {
|
|
617
|
+
fetchOptions.query.push(['client_only', options.clientOnly.toString()]);
|
|
618
|
+
}
|
|
619
|
+
if (options.teamOnly !== undefined) {
|
|
620
|
+
fetchOptions.query.push(['team_only', options.teamOnly.toString()]);
|
|
621
|
+
}
|
|
622
|
+
if (options.memberOnly !== undefined) {
|
|
623
|
+
fetchOptions.query.push(['member_only', options.memberOnly.toString()]);
|
|
624
|
+
}
|
|
625
|
+
if (options.merchiOnly !== undefined) {
|
|
626
|
+
fetchOptions.query.push(['merchi_only', options.merchiOnly.toString()]);
|
|
627
|
+
}
|
|
628
|
+
if (options.supplierResellOnly !== undefined) {
|
|
629
|
+
fetchOptions.query.push(['supplier_resell_only', options.supplierResellOnly.toString()]);
|
|
630
|
+
}
|
|
631
|
+
if (options.shopifyOnly !== undefined) {
|
|
632
|
+
fetchOptions.query.push(['shopify_only', options.shopifyOnly.toString()]);
|
|
633
|
+
}
|
|
634
|
+
if (options.inbound !== undefined) {
|
|
635
|
+
fetchOptions.query.push(['inbound', options.inbound.toString()]);
|
|
636
|
+
}
|
|
637
|
+
if (options.isMaster !== undefined) {
|
|
638
|
+
fetchOptions.query.push(['is_master', options.isMaster.toString()]);
|
|
639
|
+
}
|
|
640
|
+
if (options.domainRoles !== undefined) {
|
|
641
|
+
fetchOptions.query.push(['domain_roles', options.domainRoles.join(',')]);
|
|
642
|
+
}
|
|
643
|
+
if (options.domainTypes !== undefined) {
|
|
644
|
+
fetchOptions.query.push(['domain_types', options.domainTypes.join(',')]);
|
|
645
|
+
}
|
|
646
|
+
if (options.entityTypes !== undefined) {
|
|
647
|
+
fetchOptions.query.push(['entity_types', options.entityTypes.join(',')]);
|
|
648
|
+
}
|
|
649
|
+
if (options.productTypes !== undefined) {
|
|
650
|
+
fetchOptions.query.push(['product_types', options.productTypes.join(',')]);
|
|
651
|
+
}
|
|
652
|
+
if (options.managedDomainsOnly !== undefined) {
|
|
653
|
+
fetchOptions.query.push(['managed_domains_only', options.managedDomainsOnly.toString()]);
|
|
654
|
+
}
|
|
655
|
+
if (options.businessDomainsOnly !== undefined) {
|
|
656
|
+
fetchOptions.query.push(['business_domains_only', options.businessDomainsOnly.toString()]);
|
|
657
|
+
}
|
|
658
|
+
if (options.dateFrom !== undefined) {
|
|
659
|
+
fetchOptions.query.push(['date_from', toUnixTimestamp(options.dateFrom)]);
|
|
660
|
+
}
|
|
661
|
+
if (options.dateTo !== undefined) {
|
|
662
|
+
fetchOptions.query.push(['date_to', toUnixTimestamp(options.dateTo)]);
|
|
663
|
+
}
|
|
664
|
+
if (options.originalOf !== undefined) {
|
|
665
|
+
fetchOptions.query.push(['original_of', options.originalOf.toString()]);
|
|
666
|
+
}
|
|
667
|
+
if (options.relatedComponent !== undefined) {
|
|
668
|
+
fetchOptions.query.push(['related_component', options.relatedComponent.toString()]);
|
|
669
|
+
}
|
|
670
|
+
if (options.relatedAssignment !== undefined) {
|
|
671
|
+
fetchOptions.query.push(['related_assignment', options.relatedAssignment.toString()]);
|
|
672
|
+
}
|
|
673
|
+
if (options.relatedDraft !== undefined) {
|
|
674
|
+
fetchOptions.query.push(['related_draft', options.relatedDraft.toString()]);
|
|
675
|
+
}
|
|
676
|
+
if (options.relatedJob !== undefined) {
|
|
677
|
+
fetchOptions.query.push(['related_job', options.relatedJob.toString()]);
|
|
678
|
+
}
|
|
679
|
+
if (options.relatedProduct !== undefined) {
|
|
680
|
+
fetchOptions.query.push(['related_product', options.relatedProduct.toString()]);
|
|
681
|
+
}
|
|
682
|
+
if (options.jobNotifiable !== undefined) {
|
|
683
|
+
fetchOptions.query.push(['job_notifiable', options.jobNotifiable.toString()]);
|
|
684
|
+
}
|
|
685
|
+
if (options.notificationType !== undefined) {
|
|
686
|
+
fetchOptions.query.push(['notification_type', options.notificationType.toString()]);
|
|
687
|
+
}
|
|
688
|
+
if (options.notificationRecipient !== undefined) {
|
|
689
|
+
fetchOptions.query.push(['notification_recipient', options.notificationRecipient.toString()]);
|
|
690
|
+
}
|
|
691
|
+
if (options.notificationJob !== undefined) {
|
|
692
|
+
fetchOptions.query.push(['notification_job', options.notificationJob.toString()]);
|
|
693
|
+
}
|
|
694
|
+
if (options.relatedUser !== undefined) {
|
|
695
|
+
fetchOptions.query.push(['related_user', options.relatedUser.toString()]);
|
|
696
|
+
}
|
|
697
|
+
if (options.clientId !== undefined) {
|
|
698
|
+
fetchOptions.query.push(['client_id', options.clientId.toString()]);
|
|
699
|
+
}
|
|
700
|
+
if (options.managerId !== undefined) {
|
|
701
|
+
fetchOptions.query.push(['manager_id', options.managerId.toString()]);
|
|
702
|
+
}
|
|
703
|
+
if (options.masterProduct !== undefined) {
|
|
704
|
+
fetchOptions.query.push(['master_product', options.masterProduct.toString()]);
|
|
705
|
+
}
|
|
706
|
+
if (options.clientCompanyId !== undefined) {
|
|
707
|
+
fetchOptions.query.push(['client_company_id', options.clientCompanyId.toString()]);
|
|
708
|
+
}
|
|
709
|
+
if (options.savedByUser !== undefined) {
|
|
710
|
+
fetchOptions.query.push(['saved_by_user', options.savedByUser.toString()]);
|
|
711
|
+
}
|
|
712
|
+
if (options.receiverId !== undefined) {
|
|
713
|
+
fetchOptions.query.push(['receiver_id', options.receiverId.toString()]);
|
|
714
|
+
}
|
|
715
|
+
if (options.companyCustomerId !== undefined) {
|
|
716
|
+
fetchOptions.query.push(['company_customer_id', options.companyCustomerId.toString()]);
|
|
717
|
+
}
|
|
718
|
+
if (options.companyId !== undefined) {
|
|
719
|
+
fetchOptions.query.push(['company_id', options.companyId.toString()]);
|
|
720
|
+
}
|
|
721
|
+
if (options.companySupplierId !== undefined) {
|
|
722
|
+
fetchOptions.query.push(['company_supplier_id', options.companySupplierId.toString()]);
|
|
723
|
+
}
|
|
724
|
+
if (options.componentId !== undefined) {
|
|
725
|
+
fetchOptions.query.push(['component_id', options.componentId.toString()]);
|
|
726
|
+
}
|
|
727
|
+
if (options.groupBuyForJobId !== undefined) {
|
|
728
|
+
fetchOptions.query.push(['group_buy_for_job_id', options.groupBuyForJobId.toString()]);
|
|
729
|
+
}
|
|
730
|
+
if (options.section !== undefined) {
|
|
731
|
+
fetchOptions.query.push(['section', options.section.toString()]);
|
|
732
|
+
}
|
|
733
|
+
if (options.senderRole !== undefined) {
|
|
734
|
+
fetchOptions.query.push(['sender_role', options.senderRole.toString()]);
|
|
735
|
+
}
|
|
736
|
+
if (options.isOrder) {
|
|
737
|
+
fetchOptions.query.push(['is_order', 'true']);
|
|
738
|
+
}
|
|
739
|
+
if (options.tags !== undefined) {
|
|
740
|
+
fetchOptions.query.push(['tags', options.tags.join(',')]);
|
|
741
|
+
}
|
|
742
|
+
if (options.tagsInternal !== undefined) {
|
|
743
|
+
fetchOptions.query.push(['tags_internal', options.tagsInternal.join(',')]);
|
|
744
|
+
}
|
|
745
|
+
if (options.tagNames !== undefined) {
|
|
746
|
+
fetchOptions.query.push(['tag_names', options.tagNames.join(',')]);
|
|
747
|
+
}
|
|
748
|
+
if (options.exclude !== undefined) {
|
|
749
|
+
fetchOptions.query.push(['exclude', options.exclude.join(',')]);
|
|
750
|
+
}
|
|
751
|
+
if (options.excludeComponents !== undefined) {
|
|
752
|
+
fetchOptions.query.push(['exclude_components', options.excludeComponents.join(',')]);
|
|
753
|
+
}
|
|
754
|
+
if (options.excludeDomains !== undefined) {
|
|
755
|
+
fetchOptions.query.push(['exclude_domains', options.excludeDomains.join(',')]);
|
|
756
|
+
}
|
|
757
|
+
if (options.includeOnly !== undefined) {
|
|
758
|
+
fetchOptions.query.push(['include_only', options.includeOnly.join(',')]);
|
|
759
|
+
}
|
|
760
|
+
if (options.orClientId !== undefined) {
|
|
761
|
+
fetchOptions.query.push(['or_client_id', options.orClientId.toString()]);
|
|
762
|
+
}
|
|
763
|
+
if (options.orClientCompanyId !== undefined) {
|
|
764
|
+
fetchOptions.query.push(['or_client_company_id', options.orClientCompanyId.toString()]);
|
|
849
765
|
}
|
|
850
|
-
return this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
851
|
-
var metadata = {
|
|
852
|
-
canCreate: data.canCreate,
|
|
853
|
-
available: data.available,
|
|
854
|
-
count: data.count,
|
|
855
|
-
limit: data.limit,
|
|
856
|
-
offset: data.offset
|
|
857
|
-
};
|
|
858
|
-
var pluralName = _this3.pluralName;
|
|
859
|
-
var singularName = _this3.singularName;
|
|
860
|
-
var items = data[pluralName];
|
|
861
|
-
var entities = [];
|
|
862
|
-
var _iterator7 = _createForOfIteratorHelper(items),
|
|
863
|
-
_step7;
|
|
864
|
-
try {
|
|
865
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
866
|
-
var item = _step7.value;
|
|
867
|
-
var entity = new _this3();
|
|
868
|
-
entity.fromJson(item[singularName]);
|
|
869
|
-
entities.push(entity);
|
|
870
|
-
}
|
|
871
|
-
} catch (err) {
|
|
872
|
-
_iterator7.e(err);
|
|
873
|
-
} finally {
|
|
874
|
-
_iterator7.f();
|
|
875
|
-
}
|
|
876
|
-
return {
|
|
877
|
-
items: entities,
|
|
878
|
-
metadata: metadata
|
|
879
|
-
};
|
|
880
|
-
});
|
|
881
766
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
}
|
|
767
|
+
if (!(options && options.withRights)) {
|
|
768
|
+
fetchOptions.query.push(['skip_rights', 'y']);
|
|
769
|
+
}
|
|
770
|
+
return this.merchi.authenticatedFetch(resource, fetchOptions).then(data => {
|
|
771
|
+
const metadata = {
|
|
772
|
+
canCreate: data.canCreate,
|
|
773
|
+
available: data.available,
|
|
774
|
+
count: data.count,
|
|
775
|
+
limit: data.limit,
|
|
776
|
+
offset: data.offset
|
|
777
|
+
};
|
|
778
|
+
const pluralName = this.pluralName;
|
|
779
|
+
const singularName = this.singularName;
|
|
780
|
+
const items = data[pluralName];
|
|
781
|
+
const entities = [];
|
|
782
|
+
for (const item of items) {
|
|
783
|
+
const entity = new this();
|
|
784
|
+
entity.fromJson(item[singularName]);
|
|
785
|
+
entities.push(entity);
|
|
786
|
+
}
|
|
787
|
+
return {
|
|
788
|
+
items: entities,
|
|
789
|
+
metadata: metadata
|
|
790
|
+
};
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
exports.Entity = Entity;
|
|
885
795
|
Entity.jsonNameKey = Symbol('jsonName');
|
|
886
796
|
Entity.arrayTypeKey = Symbol('arrayType');
|
|
887
797
|
Entity.extraOptionsKey = Symbol('extraOptions');
|