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