@faststore/api 2.1.99 → 2.1.102
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/dist/api.cjs.development.js +58 -101
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +58 -101
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/platforms/vtex/clients/commerce/types/OrderForm.d.ts +17 -17
- package/dist/platforms/vtex/index.d.ts +2 -2
- package/dist/platforms/vtex/resolvers/mutation.d.ts +2 -2
- package/dist/platforms/vtex/resolvers/validateCart.d.ts +2 -2
- package/package.json +4 -4
- package/src/platforms/vtex/clients/commerce/index.ts +33 -10
- package/src/platforms/vtex/clients/commerce/types/OrderForm.ts +17 -17
- package/src/platforms/vtex/index.ts +1 -1
- package/src/platforms/vtex/resolvers/validateCart.ts +0 -1
- package/src/platforms/vtex/utils/shouldUpdateShippingData.ts +49 -102
package/dist/api.esm.js
CHANGED
|
@@ -18,7 +18,7 @@ import { trace, context, SpanKind } from '@opentelemetry/api';
|
|
|
18
18
|
import { SeverityNumber } from '@opentelemetry/api-logs';
|
|
19
19
|
|
|
20
20
|
var name = "@faststore/api";
|
|
21
|
-
var version = "2.1.
|
|
21
|
+
var version = "2.1.99";
|
|
22
22
|
var license = "MIT";
|
|
23
23
|
var main = "dist/index.js";
|
|
24
24
|
var typings = "dist/index.d.ts";
|
|
@@ -54,8 +54,8 @@ var dependencies = {
|
|
|
54
54
|
};
|
|
55
55
|
var devDependencies = {
|
|
56
56
|
"@envelop/core": "^2.6.0",
|
|
57
|
-
"@faststore/eslint-config": "^2.1.
|
|
58
|
-
"@faststore/shared": "^2.1.
|
|
57
|
+
"@faststore/eslint-config": "^2.1.99",
|
|
58
|
+
"@faststore/shared": "^2.1.99",
|
|
59
59
|
"@graphql-codegen/cli": "2.2.0",
|
|
60
60
|
"@graphql-codegen/typescript": "2.2.2",
|
|
61
61
|
"@types/express": "^4.17.16",
|
|
@@ -201,7 +201,14 @@ const VtexCommerce = ({
|
|
|
201
201
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
202
202
|
sc: salesChannel
|
|
203
203
|
});
|
|
204
|
-
|
|
204
|
+
const requestInit = ctx.headers ? {
|
|
205
|
+
...BASE_INIT,
|
|
206
|
+
headers: {
|
|
207
|
+
'content-type': 'application/json',
|
|
208
|
+
cookie: ctx.headers.cookie
|
|
209
|
+
}
|
|
210
|
+
} : BASE_INIT;
|
|
211
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, requestInit);
|
|
205
212
|
},
|
|
206
213
|
updateOrderFormItems: ({
|
|
207
214
|
id,
|
|
@@ -214,14 +221,25 @@ const VtexCommerce = ({
|
|
|
214
221
|
allowOutdatedData,
|
|
215
222
|
sc: salesChannel
|
|
216
223
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
orderItems,
|
|
221
|
-
noSplitItem: !shouldSplitItem
|
|
222
|
-
}),
|
|
223
|
-
method: 'PATCH'
|
|
224
|
+
const items = JSON.stringify({
|
|
225
|
+
orderItems,
|
|
226
|
+
noSplitItem: !shouldSplitItem
|
|
224
227
|
});
|
|
228
|
+
const requestInit = ctx.headers ? {
|
|
229
|
+
headers: {
|
|
230
|
+
'content-type': 'application/json',
|
|
231
|
+
cookie: ctx.headers.cookie
|
|
232
|
+
},
|
|
233
|
+
body: items,
|
|
234
|
+
method: 'PATCH'
|
|
235
|
+
} : {
|
|
236
|
+
headers: {
|
|
237
|
+
'content-type': 'application/json'
|
|
238
|
+
},
|
|
239
|
+
body: items,
|
|
240
|
+
method: 'PATCH'
|
|
241
|
+
};
|
|
242
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/items?${params}`, requestInit);
|
|
225
243
|
},
|
|
226
244
|
setCustomData: ({
|
|
227
245
|
id,
|
|
@@ -998,55 +1016,31 @@ function getPropertyId(item) {
|
|
|
998
1016
|
}
|
|
999
1017
|
|
|
1000
1018
|
const shouldUpdateShippingData = (orderForm, session) => {
|
|
1001
|
-
var _orderForm$shippingDa;
|
|
1019
|
+
var _orderForm$shippingDa, _orderForm$shippingDa2;
|
|
1002
1020
|
if (!hasSessionPostalCodeOrGeoCoordinates(session)) {
|
|
1003
1021
|
return {
|
|
1004
1022
|
updateShipping: false,
|
|
1005
1023
|
addressChanged: false
|
|
1006
1024
|
};
|
|
1007
1025
|
}
|
|
1008
|
-
|
|
1009
|
-
if (checkPostalCode(selectedAddress, session.postalCode)) {
|
|
1010
|
-
return {
|
|
1011
|
-
updateShipping: true,
|
|
1012
|
-
addressChanged: true
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
if (checkGeoCoordinates(selectedAddress, session.geoCoordinates, session.postalCode)) {
|
|
1026
|
+
if (!hasItems(orderForm)) {
|
|
1016
1027
|
return {
|
|
1017
|
-
updateShipping:
|
|
1018
|
-
addressChanged:
|
|
1028
|
+
updateShipping: false,
|
|
1029
|
+
addressChanged: false
|
|
1019
1030
|
};
|
|
1020
1031
|
}
|
|
1021
|
-
|
|
1032
|
+
const [selectedAddress] = (_orderForm$shippingDa = orderForm == null ? void 0 : (_orderForm$shippingDa2 = orderForm.shippingData) == null ? void 0 : _orderForm$shippingDa2.selectedAddresses) != null ? _orderForm$shippingDa : [];
|
|
1033
|
+
if (checkPostalCode(selectedAddress, session.postalCode) || checkGeoCoordinates(selectedAddress, session.geoCoordinates) || checkAddressType(selectedAddress, session.addressType)) {
|
|
1022
1034
|
return {
|
|
1023
1035
|
updateShipping: true,
|
|
1024
1036
|
addressChanged: true
|
|
1025
1037
|
};
|
|
1026
1038
|
}
|
|
1027
|
-
if (!hasItems(orderForm)) {
|
|
1028
|
-
return {
|
|
1029
|
-
updateShipping: false,
|
|
1030
|
-
addressChanged: false
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
1033
1039
|
// The logisticsInfo will always exist if there´s at least one item inside the cart
|
|
1034
1040
|
const {
|
|
1035
1041
|
logisticsInfo
|
|
1036
1042
|
} = orderForm.shippingData;
|
|
1037
|
-
if (
|
|
1038
|
-
return {
|
|
1039
|
-
updateShipping: true,
|
|
1040
|
-
addressChanged: false
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
if (shouldUpdateDeliveryMethod(logisticsInfo, session)) {
|
|
1044
|
-
return {
|
|
1045
|
-
updateShipping: true,
|
|
1046
|
-
addressChanged: false
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
if (shouldUpdateDeliveryWindow(logisticsInfo, session)) {
|
|
1043
|
+
if (shouldUpdateDeliveryInfo(logisticsInfo, session)) {
|
|
1050
1044
|
return {
|
|
1051
1045
|
updateShipping: true,
|
|
1052
1046
|
addressChanged: false
|
|
@@ -1059,15 +1053,16 @@ const shouldUpdateShippingData = (orderForm, session) => {
|
|
|
1059
1053
|
};
|
|
1060
1054
|
// Validate if theres any postal Code or GeoCoordinates set at the session
|
|
1061
1055
|
const hasSessionPostalCodeOrGeoCoordinates = session => {
|
|
1062
|
-
|
|
1056
|
+
var _session$geoCoordinat, _session$geoCoordinat2;
|
|
1057
|
+
return !!session.postalCode || ((_session$geoCoordinat = session.geoCoordinates) == null ? void 0 : _session$geoCoordinat.latitude) && ((_session$geoCoordinat2 = session.geoCoordinates) == null ? void 0 : _session$geoCoordinat2.longitude);
|
|
1063
1058
|
};
|
|
1064
1059
|
// Validate if theres a difference between the session postal code and orderForm postal code
|
|
1065
1060
|
const checkPostalCode = (address, postalCode) => {
|
|
1066
1061
|
return typeof postalCode === 'string' && (address == null ? void 0 : address.postalCode) !== postalCode;
|
|
1067
1062
|
};
|
|
1068
1063
|
// Validate if theres a difference between the session geoCoords and orderForm geoCoords
|
|
1069
|
-
const checkGeoCoordinates = (address, geoCoordinates
|
|
1070
|
-
return typeof (geoCoordinates == null ? void 0 : geoCoordinates.latitude) === 'number' && typeof (geoCoordinates == null ? void 0 : geoCoordinates.longitude) === 'number' && ((address == null ? void 0 : address.geoCoordinates[0]) !== (geoCoordinates == null ? void 0 : geoCoordinates.longitude) || (address == null ? void 0 : address.geoCoordinates[1]) !== (geoCoordinates == null ? void 0 : geoCoordinates.latitude))
|
|
1064
|
+
const checkGeoCoordinates = (address, geoCoordinates) => {
|
|
1065
|
+
return typeof (geoCoordinates == null ? void 0 : geoCoordinates.latitude) === 'number' && typeof (geoCoordinates == null ? void 0 : geoCoordinates.longitude) === 'number' && ((address == null ? void 0 : address.geoCoordinates[0]) !== (geoCoordinates == null ? void 0 : geoCoordinates.longitude) || (address == null ? void 0 : address.geoCoordinates[1]) !== (geoCoordinates == null ? void 0 : geoCoordinates.latitude));
|
|
1071
1066
|
};
|
|
1072
1067
|
const checkAddressType = (address, addressType) => {
|
|
1073
1068
|
return typeof addressType === 'string' && (address == null ? void 0 : address.addressType) !== addressType;
|
|
@@ -1076,67 +1071,29 @@ const checkAddressType = (address, addressType) => {
|
|
|
1076
1071
|
const hasItems = orderForm => {
|
|
1077
1072
|
return orderForm.items.length !== 0;
|
|
1078
1073
|
};
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
if (!(session != null && (_session$deliveryMode = session.deliveryMode) != null && _session$deliveryMode.deliveryChannel)) {
|
|
1084
|
-
return false;
|
|
1085
|
-
}
|
|
1086
|
-
const {
|
|
1087
|
-
deliveryChannel
|
|
1088
|
-
} = session.deliveryMode;
|
|
1089
|
-
for (const item of logisticsInfo) {
|
|
1090
|
-
if (item.selectedDeliveryChannel !== deliveryChannel) {
|
|
1091
|
-
const matchingSla = item.slas.find(sla => sla.deliveryChannel === deliveryChannel);
|
|
1092
|
-
if (matchingSla) {
|
|
1093
|
-
return true;
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
return false;
|
|
1098
|
-
};
|
|
1099
|
-
// Validate if the deliveryMethod from the session is different from the selectedSLA
|
|
1100
|
-
// and if so needs to validate if the deliveryMethod for the session is available inside the slas for the item
|
|
1101
|
-
const shouldUpdateDeliveryMethod = (logisticsInfo, session) => {
|
|
1102
|
-
var _session$deliveryMode2;
|
|
1103
|
-
if (!(session != null && (_session$deliveryMode2 = session.deliveryMode) != null && _session$deliveryMode2.deliveryMethod)) {
|
|
1104
|
-
return false;
|
|
1105
|
-
}
|
|
1106
|
-
const {
|
|
1107
|
-
deliveryMethod
|
|
1108
|
-
} = session.deliveryMode;
|
|
1109
|
-
for (const item of logisticsInfo) {
|
|
1110
|
-
if (item.selectedSla !== deliveryMethod) {
|
|
1111
|
-
const matchingSla = item.slas.find(sla => sla.id === deliveryMethod);
|
|
1112
|
-
if (matchingSla) {
|
|
1113
|
-
return true;
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
return false;
|
|
1118
|
-
};
|
|
1119
|
-
// Validate if the deliveryWindow from the session is different from the deliveryWindow of the SLA
|
|
1120
|
-
// and if so needs to validate if the deliveryWindow for the session is available inside the availableDeliveryWindows for the item
|
|
1121
|
-
const shouldUpdateDeliveryWindow = (logisticsInfo, session) => {
|
|
1122
|
-
var _session$deliveryMode3, _session$deliveryMode4, _session$deliveryMode5, _session$deliveryMode6;
|
|
1123
|
-
if (!(session != null && (_session$deliveryMode3 = session.deliveryMode) != null && (_session$deliveryMode4 = _session$deliveryMode3.deliveryWindow) != null && _session$deliveryMode4.startDate) || !(session != null && (_session$deliveryMode5 = session.deliveryMode) != null && (_session$deliveryMode6 = _session$deliveryMode5.deliveryWindow) != null && _session$deliveryMode6.endDate)) {
|
|
1124
|
-
return false;
|
|
1125
|
-
}
|
|
1074
|
+
const shouldUpdateDeliveryInfo = (logisticsInfo, session) => {
|
|
1075
|
+
var _session$deliveryMode, _session$deliveryMode2, _session$deliveryMode3;
|
|
1076
|
+
const deliveryChannel = session == null ? void 0 : (_session$deliveryMode = session.deliveryMode) == null ? void 0 : _session$deliveryMode.deliveryChannel;
|
|
1077
|
+
const deliveryMethod = session == null ? void 0 : (_session$deliveryMode2 = session.deliveryMode) == null ? void 0 : _session$deliveryMode2.deliveryMethod;
|
|
1126
1078
|
const {
|
|
1127
1079
|
startDate,
|
|
1128
1080
|
endDate
|
|
1129
|
-
} = session.deliveryMode.deliveryWindow;
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1081
|
+
} = (session == null ? void 0 : (_session$deliveryMode3 = session.deliveryMode) == null ? void 0 : _session$deliveryMode3.deliveryWindow) || {};
|
|
1082
|
+
return logisticsInfo.some(({
|
|
1083
|
+
selectedDeliveryChannel,
|
|
1084
|
+
selectedSla,
|
|
1085
|
+
slas
|
|
1086
|
+
}) => {
|
|
1087
|
+
const checkDeliveryChannel = deliveryChannel && selectedDeliveryChannel !== deliveryChannel;
|
|
1088
|
+
const checkDeliveryMethod = deliveryMethod && selectedSla !== deliveryMethod;
|
|
1089
|
+
return slas == null ? void 0 : slas.some(sla => {
|
|
1090
|
+
var _sla$deliveryWindow, _sla$deliveryWindow2, _sla$availableDeliver;
|
|
1091
|
+
if (checkDeliveryChannel && sla.deliveryChannel === deliveryChannel || checkDeliveryMethod && sla.id === deliveryMethod) {
|
|
1135
1092
|
return true;
|
|
1136
1093
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1094
|
+
return startDate && endDate && sla.deliveryChannel === deliveryChannel && sla.id === deliveryMethod && (!(sla != null && sla.deliveryWindow) || (sla == null ? void 0 : (_sla$deliveryWindow = sla.deliveryWindow) == null ? void 0 : _sla$deliveryWindow.startDateUtc) !== startDate || (sla == null ? void 0 : (_sla$deliveryWindow2 = sla.deliveryWindow) == null ? void 0 : _sla$deliveryWindow2.endDateUtc) !== endDate) && ((_sla$availableDeliver = sla.availableDeliveryWindows) == null ? void 0 : _sla$availableDeliver.some(window => (window == null ? void 0 : window.startDateUtc) === startDate && (window == null ? void 0 : window.endDateUtc) === endDate));
|
|
1095
|
+
});
|
|
1096
|
+
});
|
|
1140
1097
|
};
|
|
1141
1098
|
|
|
1142
1099
|
const getAddressOrderForm = (orderForm, session, addressChanged) => {
|