rerobe-js-orm 2.9.8 → 3.0.2
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/factories/Order/OrderFromFormState.js +16 -13
- package/lib/form-states/Order/OrderFormState.d.ts +0 -1
- package/lib/form-states/Order/OrderFormState.js +33 -33
- package/lib/helpers/Utilities.d.ts +5 -0
- package/lib/helpers/Utilities.js +18 -0
- package/lib/models/Order.d.ts +3 -0
- package/lib/models/Order.js +12 -0
- package/lib/types/rerobe-order-types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -5,24 +5,24 @@ const Order_1 = require("../../models/Order");
|
|
|
5
5
|
const order_constants_1 = require("../../constants/order-constants");
|
|
6
6
|
class OrderFromFormState extends OrderFactory_1.default {
|
|
7
7
|
createOrder(fs) {
|
|
8
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
9
9
|
const currencyCode = fs.fields.currencyCode.inputValue || 'SEK';
|
|
10
10
|
const customer = fs.fields.customer.selectedValue || {};
|
|
11
11
|
const customerAttr = {
|
|
12
|
-
userId: (customer === null || customer === void 0 ? void 0 : customer.uid) || '',
|
|
13
|
-
customerName:
|
|
12
|
+
userId: (customer === null || customer === void 0 ? void 0 : customer.uid) || (customer === null || customer === void 0 ? void 0 : customer.documentId) || '',
|
|
13
|
+
customerName: `${fs.fields.firstName.inputValue} ${fs.fields.lastName.inputValue}`.trim(),
|
|
14
14
|
email: fs.fields.email.inputValue || '',
|
|
15
15
|
phone: fs.fields.phone.inputValue || '',
|
|
16
|
-
customerUrl: ((
|
|
16
|
+
customerUrl: ((_a = fs.props) === null || _a === void 0 ? void 0 : _a.customerUrl) || '',
|
|
17
17
|
};
|
|
18
18
|
const discountsAttr = {
|
|
19
19
|
appliedDiscount: {
|
|
20
|
-
amount: ((
|
|
21
|
-
value: ((
|
|
22
|
-
title: fs.fields.presentmentData.selectedValue.discountTitlePresentment || ((
|
|
20
|
+
amount: ((_b = fs.fields) === null || _b === void 0 ? void 0 : _b.totalDiscount.inputValue) || 0,
|
|
21
|
+
value: ((_c = fs.fields) === null || _c === void 0 ? void 0 : _c.totalDiscount.inputValue) || 0,
|
|
22
|
+
title: fs.fields.presentmentData.selectedValue.discountTitlePresentment || ((_d = fs.fields) === null || _d === void 0 ? void 0 : _d.discountTitle.inputValue) || '',
|
|
23
23
|
valueType: 'FIXED_AMOUNT',
|
|
24
24
|
},
|
|
25
|
-
discountApplications: ((
|
|
25
|
+
discountApplications: ((_e = fs.props) === null || _e === void 0 ? void 0 : _e.discountApplications) || [],
|
|
26
26
|
creditDiscount: { amount: fs.fields.creditDiscount.inputValue || 0, currencyCode },
|
|
27
27
|
saleDiscount: { amount: fs.fields.saleDiscount.inputValue || 0, currencyCode },
|
|
28
28
|
additionalDiscount: { amount: fs.fields.additionalDiscount.inputValue || 0, currencyCode },
|
|
@@ -38,11 +38,11 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
38
38
|
zip: '',
|
|
39
39
|
};
|
|
40
40
|
const shippingAndLocationAttr = {
|
|
41
|
-
fulfillmentLocations: ((
|
|
41
|
+
fulfillmentLocations: ((_f = fs.fields.shippingInfo.selectedValue) === null || _f === void 0 ? void 0 : _f.productsLocationsMapping) || [],
|
|
42
42
|
shippingAddress: fs.fields.shippingType.selectedValue === order_constants_1.SHIPPING_TYPES.localPickUp
|
|
43
43
|
? initShippingAddress
|
|
44
44
|
: fs.fields.shippingAddress.selectedValue || initShippingAddress,
|
|
45
|
-
shippingDiscountAllocations: ((
|
|
45
|
+
shippingDiscountAllocations: ((_g = fs.props) === null || _g === void 0 ? void 0 : _g.shippingDiscountAllocations) || [],
|
|
46
46
|
shippingLine: fs.fields.shippingLine
|
|
47
47
|
? fs.fields.shippingLine.selectedValue
|
|
48
48
|
: {
|
|
@@ -71,6 +71,9 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
71
71
|
},
|
|
72
72
|
};
|
|
73
73
|
const presentmentTotalPricesAttr = {
|
|
74
|
+
creditDiscountPresentment: fs.fields.presentmentData.selectedValue.creditDiscountPresentment,
|
|
75
|
+
saleDiscountPresentment: fs.fields.presentmentData.selectedValue.saleDiscountPresentment,
|
|
76
|
+
additionalDiscountPresentment: fs.fields.presentmentData.selectedValue.additionalDiscountPresentment,
|
|
74
77
|
subtotalPricePresentment: fs.fields.presentmentData.selectedValue.subtotalPricePresentment,
|
|
75
78
|
totalDiscountPresentment: fs.fields.presentmentData.selectedValue.totalDiscountPresentment,
|
|
76
79
|
totalPricePresentment: fs.fields.presentmentData.selectedValue.totalPricePresentment,
|
|
@@ -90,12 +93,12 @@ class OrderFromFormState extends OrderFactory_1.default {
|
|
|
90
93
|
originalTotalPrice: { amount: fs.fields.originalTotalPrice.inputValue || 0, currencyCode },
|
|
91
94
|
};
|
|
92
95
|
const statusesAttr = {
|
|
93
|
-
state: ((
|
|
96
|
+
state: ((_h = fs.props) === null || _h === void 0 ? void 0 : _h.state) || Order_1.default.ORDER_STATES.draft,
|
|
94
97
|
financialStatus: fs.fields.financialStatus.selectedValue,
|
|
95
98
|
fulfillmentStatus: fs.fields.fulfillmentStatus.selectedValue,
|
|
96
|
-
statusUrl: ((
|
|
99
|
+
statusUrl: ((_j = fs.props) === null || _j === void 0 ? void 0 : _j.statusUrl) || '',
|
|
97
100
|
};
|
|
98
|
-
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((
|
|
101
|
+
const orderAttributes = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, totalPricesAttr), presentmentTotalPricesAttr), discountsAttr), shippingAndLocationAttr), customerAttr), statusesAttr), { id: ((_k = fs.props) === null || _k === void 0 ? void 0 : _k.id) || '', documentId: ((_l = fs.props) === null || _l === void 0 ? void 0 : _l.documentId) || '', name: ((_m = fs.props) === null || _m === void 0 ? void 0 : _m.name) || '', orderNumber: (_o = fs.props) === null || _o === void 0 ? void 0 : _o.orderNumber, ribbnOrderNumber: (_p = fs.props) === null || _p === void 0 ? void 0 : _p.ribbnOrderNumber, merchantId: ((_q = fs.props) === null || _q === void 0 ? void 0 : _q.merchantId) || '', currencyCode: fs.fields.currencyCode.inputValue, lineItems: fs.fields.lineItems.selectedValues || [], fulfillments: ((_r = fs.props) === null || _r === void 0 ? void 0 : _r.fulfillments) || [], refunds: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.refunds) || [], paymentType: fs.fields.paymentType.selectedValue, paymentMethod: fs.fields.paymentMethod.selectedValue || '', paymentDetails: fs.fields.paymentDetails.selectedValue || {}, notes: fs.fields.notes.inputValue || '', tags: fs.fields.tags.selectedValues || [], cancelReason: fs.fields.cancelReason.selectedValue || '', canceledAt: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.canceledAt) || '', processedAt: ((_u = fs.props) === null || _u === void 0 ? void 0 : _u.processedAt) || new Date().toUTCString(), createdAtTimestamp: 0, updatedAtTimestamp: 0 });
|
|
99
102
|
return new Order_1.default(Object.assign({}, orderAttributes));
|
|
100
103
|
}
|
|
101
104
|
}
|
|
@@ -97,24 +97,22 @@ class OrderFormState extends FormState_1.default {
|
|
|
97
97
|
// Update total price
|
|
98
98
|
this.fields.totalPrice.inputValue = Number(Number(this.fields.subtotalPrice.inputValue) - Number(this.fields.totalDiscount.inputValue) + Number(val)).toFixed(2);
|
|
99
99
|
}
|
|
100
|
-
customerChangeHandler(customer) {
|
|
101
|
-
this.fields.customer.selectedValue = customer;
|
|
102
|
-
this.fields.email.inputValue = (customer === null || customer === void 0 ? void 0 : customer.email) || '';
|
|
103
|
-
this.fields.phone.inputValue = (customer === null || customer === void 0 ? void 0 : customer.phone) || '';
|
|
104
|
-
this.fields.firstName.inputValue = (customer === null || customer === void 0 ? void 0 : customer.displayName) || (customer === null || customer === void 0 ? void 0 : customer.firstName) || '';
|
|
105
|
-
this.fields.lastName.inputValue = !(customer === null || customer === void 0 ? void 0 : customer.displayName) && (customer === null || customer === void 0 ? void 0 : customer.lastName) ? customer === null || customer === void 0 ? void 0 : customer.lastName : '';
|
|
106
|
-
}
|
|
107
100
|
fieldFactory(fieldType, fieldKey, fieldOptions) {
|
|
108
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
101
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
109
102
|
let options = fieldOptions || [];
|
|
110
103
|
const hidden = false;
|
|
111
104
|
if (fieldType === 'textInput') {
|
|
112
105
|
let inputValue = this.props[fieldKey] || '';
|
|
113
106
|
if (fieldKey === 'firstName') {
|
|
114
|
-
|
|
107
|
+
const { firstName } = this.utilities.getFirstNameAndLastNameFromDisplayName(this.props.customerName || '');
|
|
108
|
+
inputValue = firstName;
|
|
115
109
|
}
|
|
116
110
|
if (fieldKey === 'lastName') {
|
|
117
|
-
|
|
111
|
+
const { lastName } = this.utilities.getFirstNameAndLastNameFromDisplayName(this.props.customerName || '');
|
|
112
|
+
inputValue = lastName;
|
|
113
|
+
}
|
|
114
|
+
if (fieldKey === 'discountTitle') {
|
|
115
|
+
inputValue = ((_b = (_a = this.props) === null || _a === void 0 ? void 0 : _a.appliedDiscount) === null || _b === void 0 ? void 0 : _b.title) || '';
|
|
118
116
|
}
|
|
119
117
|
if (fieldKey === 'subtotalPrice' ||
|
|
120
118
|
fieldKey === 'totalPrice' ||
|
|
@@ -148,50 +146,52 @@ class OrderFormState extends FormState_1.default {
|
|
|
148
146
|
if (fieldType === 'singleSelect') {
|
|
149
147
|
let selectedValue = this.props[fieldKey] || '';
|
|
150
148
|
if (fieldKey === 'pickupLocation') {
|
|
151
|
-
if (((
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
if (((_c = this.props) === null || _c === void 0 ? void 0 : _c.shippingType) === order_constants_1.SHIPPING_TYPES.localPickUp &&
|
|
150
|
+
((_d = this.props) === null || _d === void 0 ? void 0 : _d.fulfillmentLocations) &&
|
|
151
|
+
((_e = this.props.fulfillmentLocations[0]) === null || _e === void 0 ? void 0 : _e.location)) {
|
|
152
|
+
const location = this.props.fulfillmentLocations[0].location;
|
|
153
|
+
const locationId = location.locationId || location.documentId || '';
|
|
154
|
+
selectedValue = locationId;
|
|
155
|
+
options = [{ label: location.address1 ? this.utilities.getAddressLabel(location) : '', value: locationId }];
|
|
158
156
|
}
|
|
159
|
-
if ((
|
|
160
|
-
options = this.utilities.uniqObjArray(this.opts.pickupLocationOptions, 'value');
|
|
157
|
+
if ((_g = (_f = this.opts) === null || _f === void 0 ? void 0 : _f.pickupLocationOptions) === null || _g === void 0 ? void 0 : _g.length) {
|
|
158
|
+
options = this.utilities.uniqObjArray([...options, ...this.opts.pickupLocationOptions], 'value');
|
|
161
159
|
}
|
|
162
160
|
}
|
|
163
161
|
if (fieldKey === 'shippingInfo') {
|
|
164
162
|
selectedValue = {
|
|
165
|
-
productsLocationsMapping: ((
|
|
163
|
+
productsLocationsMapping: ((_h = this.props) === null || _h === void 0 ? void 0 : _h.fulfillmentLocations) || [],
|
|
166
164
|
description: '',
|
|
167
|
-
price: ((
|
|
165
|
+
price: ((_k = (_j = this.props) === null || _j === void 0 ? void 0 : _j.totalShippingPrice) === null || _k === void 0 ? void 0 : _k.amount) || 0,
|
|
168
166
|
disabled: false,
|
|
169
167
|
};
|
|
170
168
|
}
|
|
171
169
|
if (fieldKey === 'presentmentData') {
|
|
172
170
|
selectedValue = {
|
|
173
|
-
presentmentCurrencyCode: ((
|
|
174
|
-
discountTitlePresentment: ((
|
|
175
|
-
subtotalPricePresentment: ((
|
|
176
|
-
totalDiscountPresentment: ((
|
|
177
|
-
totalShippingPricePresentment: ((
|
|
178
|
-
totalPricePresentment: ((
|
|
179
|
-
totalRefundedPresentment: ((
|
|
180
|
-
totalTaxPresentment: ((
|
|
171
|
+
presentmentCurrencyCode: ((_m = (_l = this.props) === null || _l === void 0 ? void 0 : _l.totalPricePresentment) === null || _m === void 0 ? void 0 : _m.currencyCode) || '',
|
|
172
|
+
discountTitlePresentment: ((_p = (_o = this.props) === null || _o === void 0 ? void 0 : _o.appliedDiscount) === null || _p === void 0 ? void 0 : _p.title) || '',
|
|
173
|
+
subtotalPricePresentment: ((_q = this.props) === null || _q === void 0 ? void 0 : _q.subtotalPricePresentment) || { amount: 0 },
|
|
174
|
+
totalDiscountPresentment: ((_r = this.props) === null || _r === void 0 ? void 0 : _r.totalDiscountPresentment) || { amount: 0 },
|
|
175
|
+
totalShippingPricePresentment: ((_s = this.props) === null || _s === void 0 ? void 0 : _s.totalShippingPricePresentment) || { amount: 0 },
|
|
176
|
+
totalPricePresentment: ((_t = this.props) === null || _t === void 0 ? void 0 : _t.totalPricePresentment) || { amount: 0 },
|
|
177
|
+
totalRefundedPresentment: ((_u = this.props) === null || _u === void 0 ? void 0 : _u.totalRefundedPresentment) || { amount: 0 },
|
|
178
|
+
totalTaxPresentment: ((_v = this.props) === null || _v === void 0 ? void 0 : _v.totalTaxPresentment) || { amount: 0 },
|
|
179
|
+
creditDiscountPresentment: ((_w = this.props) === null || _w === void 0 ? void 0 : _w.creditDiscountPresentment) || { amount: 0 },
|
|
180
|
+
saleDiscountPresentment: ((_x = this.props) === null || _x === void 0 ? void 0 : _x.saleDiscountPresentment) || { amount: 0 },
|
|
181
|
+
additionalDiscountPresentment: ((_y = this.props) === null || _y === void 0 ? void 0 : _y.additionalDiscountPresentment) || { amount: 0 },
|
|
181
182
|
};
|
|
182
183
|
}
|
|
183
|
-
const valid = !!this.props[fieldKey];
|
|
184
|
-
let onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
|
|
185
184
|
if (fieldKey === 'customer') {
|
|
186
185
|
selectedValue = {
|
|
187
186
|
uid: this.props.userId,
|
|
188
187
|
email: this.props.email,
|
|
189
188
|
displayName: this.props.customerName,
|
|
190
189
|
};
|
|
191
|
-
onChangeHandler = (val) => this.customerChangeHandler(val);
|
|
192
190
|
}
|
|
191
|
+
const valid = !!this.props[fieldKey];
|
|
192
|
+
const onChangeHandler = (val) => this.singleSelectChangeHandler(fieldKey, val);
|
|
193
193
|
if (fieldKey === 'shippingType') {
|
|
194
|
-
if ((
|
|
194
|
+
if ((_0 = (_z = this.opts) === null || _z === void 0 ? void 0 : _z.shippingTypeOptions) === null || _0 === void 0 ? void 0 : _0.length) {
|
|
195
195
|
options = this.utilities.uniqObjArray(this.opts.shippingTypeOptions, 'value');
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -16,4 +16,9 @@ export default class Utilities {
|
|
|
16
16
|
sanitizeMillisTimeStamp(t: any): number;
|
|
17
17
|
isProperString(name: any): boolean;
|
|
18
18
|
toProperString(name: any): string;
|
|
19
|
+
getAddressLabel(address: AddressInput): string;
|
|
20
|
+
getFirstNameAndLastNameFromDisplayName(displayName: string): {
|
|
21
|
+
firstName: string;
|
|
22
|
+
lastName: string;
|
|
23
|
+
};
|
|
19
24
|
}
|
package/lib/helpers/Utilities.js
CHANGED
|
@@ -128,5 +128,23 @@ class Utilities {
|
|
|
128
128
|
// Capitalize each word and join the words together
|
|
129
129
|
return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
|
|
130
130
|
}
|
|
131
|
+
getAddressLabel(address) {
|
|
132
|
+
const { address1 = '', address2 = '', zip = '', city = '', province = '', country = '' } = address;
|
|
133
|
+
return [address1, address2, zip, city, province, country].reduce((res, item) => {
|
|
134
|
+
if (item) {
|
|
135
|
+
return (res === null || res === void 0 ? void 0 : res.length) ? `${res}, ${item}` : item;
|
|
136
|
+
}
|
|
137
|
+
return res;
|
|
138
|
+
}, '');
|
|
139
|
+
}
|
|
140
|
+
getFirstNameAndLastNameFromDisplayName(displayName) {
|
|
141
|
+
const res = { firstName: '', lastName: '' };
|
|
142
|
+
const fixedDisplayName = displayName ? displayName.trim() : '';
|
|
143
|
+
if (fixedDisplayName) {
|
|
144
|
+
res.firstName = fixedDisplayName.split(' ')[0];
|
|
145
|
+
res.lastName = fixedDisplayName.split(' ').length > 1 ? fixedDisplayName.split(' ')[1] : '';
|
|
146
|
+
}
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
131
149
|
}
|
|
132
150
|
exports.default = Utilities;
|
package/lib/models/Order.d.ts
CHANGED
|
@@ -94,6 +94,9 @@ export default class Order extends Base {
|
|
|
94
94
|
totalRefundedPresentment: Money;
|
|
95
95
|
totalShippingPricePresentment: Money;
|
|
96
96
|
totalTaxPresentment: Money;
|
|
97
|
+
creditDiscountPresentment: Money;
|
|
98
|
+
saleDiscountPresentment: Money;
|
|
99
|
+
additionalDiscountPresentment: Money;
|
|
97
100
|
createdAtTimestamp: number;
|
|
98
101
|
updatedAtTimestamp: number;
|
|
99
102
|
constructor(props?: any);
|
package/lib/models/Order.js
CHANGED
|
@@ -115,6 +115,15 @@ class Order extends Base_1.default {
|
|
|
115
115
|
this.totalTaxPresentment = (props === null || props === void 0 ? void 0 : props.totalTaxPresentment) || {
|
|
116
116
|
amount: 0,
|
|
117
117
|
};
|
|
118
|
+
this.creditDiscountPresentment = (props === null || props === void 0 ? void 0 : props.creditDiscountPresentment) || {
|
|
119
|
+
amount: 0,
|
|
120
|
+
};
|
|
121
|
+
this.saleDiscountPresentment = (props === null || props === void 0 ? void 0 : props.saleDiscountPresentment) || {
|
|
122
|
+
amount: 0,
|
|
123
|
+
};
|
|
124
|
+
this.additionalDiscountPresentment = (props === null || props === void 0 ? void 0 : props.additionalDiscountPresentment) || {
|
|
125
|
+
amount: 0,
|
|
126
|
+
};
|
|
118
127
|
this.createdAtTimestamp = (props === null || props === void 0 ? void 0 : props.createdAtTimestamp) || 0;
|
|
119
128
|
this.updatedAtTimestamp = (props === null || props === void 0 ? void 0 : props.updatedAtTimestamp) || 0;
|
|
120
129
|
}
|
|
@@ -173,6 +182,9 @@ class Order extends Base_1.default {
|
|
|
173
182
|
totalRefundedPresentment: this.totalRefundedPresentment,
|
|
174
183
|
totalShippingPricePresentment: this.totalShippingPricePresentment,
|
|
175
184
|
totalTaxPresentment: this.totalTaxPresentment,
|
|
185
|
+
creditDiscountPresentment: this.creditDiscountPresentment,
|
|
186
|
+
saleDiscountPresentment: this.saleDiscountPresentment,
|
|
187
|
+
additionalDiscountPresentment: this.additionalDiscountPresentment,
|
|
176
188
|
createdAtTimestamp: this.createdAtTimestamp,
|
|
177
189
|
updatedAtTimestamp: this.updatedAtTimestamp,
|
|
178
190
|
};
|
|
@@ -74,6 +74,9 @@ declare type ReRobeOrderObj = {
|
|
|
74
74
|
totalRefundedPresentment?: Money;
|
|
75
75
|
totalShippingPricePresentment?: Money;
|
|
76
76
|
totalTaxPresentment?: Money;
|
|
77
|
+
creditDiscountPresentment?: Money;
|
|
78
|
+
saleDiscountPresentment?: Money;
|
|
79
|
+
additionalDiscountPresentment?: Money;
|
|
77
80
|
createdAtTimestamp: number;
|
|
78
81
|
updatedAtTimestamp: number;
|
|
79
82
|
};
|
|
@@ -676,6 +679,9 @@ declare type OrderPresentmentData = {
|
|
|
676
679
|
totalPricePresentment: Money;
|
|
677
680
|
totalRefundedPresentment?: Money;
|
|
678
681
|
totalTaxPresentment?: Money;
|
|
682
|
+
creditDiscountPresentment?: Money;
|
|
683
|
+
saleDiscountPresentment?: Money;
|
|
684
|
+
additionalDiscountPresentment?: Money;
|
|
679
685
|
};
|
|
680
686
|
declare type CompleteOrder = ReRobeOrderObj & {
|
|
681
687
|
[key: string]: any;
|