@faststore/api 2.2.0-alpha.1 → 2.2.0-alpha.10
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 +86 -103
- 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 +86 -103
- 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/dist/platforms/vtex/utils/sanitizeHtml.d.ts +17 -0
- package/package.json +7 -5
- 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/enhanceSku.ts +11 -1
- package/src/platforms/vtex/utils/sanitizeHtml.ts +21 -0
- package/src/platforms/vtex/utils/shouldUpdateShippingData.ts +49 -102
|
@@ -6,6 +6,7 @@ var schema = require('@graphql-tools/schema');
|
|
|
6
6
|
var fetch = _interopDefault(require('isomorphic-unfetch'));
|
|
7
7
|
var DataLoader = _interopDefault(require('dataloader'));
|
|
8
8
|
var pLimit = _interopDefault(require('p-limit'));
|
|
9
|
+
var sanitizeHtmlLib = _interopDefault(require('sanitize-html'));
|
|
9
10
|
var deepEquals = _interopDefault(require('fast-deep-equal'));
|
|
10
11
|
var crypto = _interopDefault(require('crypto'));
|
|
11
12
|
var graphql = require('graphql');
|
|
@@ -22,7 +23,7 @@ var api = require('@opentelemetry/api');
|
|
|
22
23
|
var apiLogs = require('@opentelemetry/api-logs');
|
|
23
24
|
|
|
24
25
|
var name = "@faststore/api";
|
|
25
|
-
var version = "2.2.0-alpha.
|
|
26
|
+
var version = "2.2.0-alpha.6";
|
|
26
27
|
var license = "MIT";
|
|
27
28
|
var main = "dist/index.js";
|
|
28
29
|
var typings = "dist/index.d.ts";
|
|
@@ -54,15 +55,17 @@ var dependencies = {
|
|
|
54
55
|
dataloader: "^2.1.0",
|
|
55
56
|
"fast-deep-equal": "^3.1.3",
|
|
56
57
|
"isomorphic-unfetch": "^3.1.0",
|
|
57
|
-
"p-limit": "^3.1.0"
|
|
58
|
+
"p-limit": "^3.1.0",
|
|
59
|
+
"sanitize-html": "^2.11.0"
|
|
58
60
|
};
|
|
59
61
|
var devDependencies = {
|
|
60
62
|
"@envelop/core": "^2.6.0",
|
|
61
|
-
"@faststore/eslint-config": "^2.2.0-alpha.
|
|
62
|
-
"@faststore/shared": "^2.2.0-alpha.
|
|
63
|
+
"@faststore/eslint-config": "^2.2.0-alpha.1",
|
|
64
|
+
"@faststore/shared": "^2.2.0-alpha.1",
|
|
63
65
|
"@graphql-codegen/cli": "2.2.0",
|
|
64
66
|
"@graphql-codegen/typescript": "2.2.2",
|
|
65
67
|
"@types/express": "^4.17.16",
|
|
68
|
+
"@types/sanitize-html": "^2.9.1",
|
|
66
69
|
concurrently: "^6.2.1",
|
|
67
70
|
eslint: "7.32.0",
|
|
68
71
|
express: "^4.17.3",
|
|
@@ -205,7 +208,14 @@ const VtexCommerce = ({
|
|
|
205
208
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
206
209
|
sc: salesChannel
|
|
207
210
|
});
|
|
208
|
-
|
|
211
|
+
const requestInit = ctx.headers ? {
|
|
212
|
+
...BASE_INIT,
|
|
213
|
+
headers: {
|
|
214
|
+
'content-type': 'application/json',
|
|
215
|
+
cookie: ctx.headers.cookie
|
|
216
|
+
}
|
|
217
|
+
} : BASE_INIT;
|
|
218
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, requestInit);
|
|
209
219
|
},
|
|
210
220
|
updateOrderFormItems: ({
|
|
211
221
|
id,
|
|
@@ -218,14 +228,25 @@ const VtexCommerce = ({
|
|
|
218
228
|
allowOutdatedData,
|
|
219
229
|
sc: salesChannel
|
|
220
230
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
orderItems,
|
|
225
|
-
noSplitItem: !shouldSplitItem
|
|
226
|
-
}),
|
|
227
|
-
method: 'PATCH'
|
|
231
|
+
const items = JSON.stringify({
|
|
232
|
+
orderItems,
|
|
233
|
+
noSplitItem: !shouldSplitItem
|
|
228
234
|
});
|
|
235
|
+
const requestInit = ctx.headers ? {
|
|
236
|
+
headers: {
|
|
237
|
+
'content-type': 'application/json',
|
|
238
|
+
cookie: ctx.headers.cookie
|
|
239
|
+
},
|
|
240
|
+
body: items,
|
|
241
|
+
method: 'PATCH'
|
|
242
|
+
} : {
|
|
243
|
+
headers: {
|
|
244
|
+
'content-type': 'application/json'
|
|
245
|
+
},
|
|
246
|
+
body: items,
|
|
247
|
+
method: 'PATCH'
|
|
248
|
+
};
|
|
249
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/items?${params}`, requestInit);
|
|
229
250
|
},
|
|
230
251
|
setCustomData: ({
|
|
231
252
|
id,
|
|
@@ -497,9 +518,32 @@ const getSimulationLoader = (_, clients) => {
|
|
|
497
518
|
});
|
|
498
519
|
};
|
|
499
520
|
|
|
521
|
+
/**
|
|
522
|
+
* For now, we're using sanitize-html's default set
|
|
523
|
+
* of allowed tags and attributes, which don't even include img elements
|
|
524
|
+
*
|
|
525
|
+
* It is known many client depends on pontentially vulnerable tags, such as script tags
|
|
526
|
+
* We chose to be restrictive at first, and document those restrictions later.
|
|
527
|
+
*
|
|
528
|
+
* When expanding the set of allowed tags and attributes, please consider performance, privacy and security.
|
|
529
|
+
*
|
|
530
|
+
* This possibily breaks compatibility with Portal and Store Framework,
|
|
531
|
+
* which both allows an enormous amount of tags and attributes
|
|
532
|
+
*
|
|
533
|
+
* This was a thoughtful decision that can be reviewed in the future given
|
|
534
|
+
* research was made to back up those changes.
|
|
535
|
+
*/
|
|
536
|
+
const sanitizeHtml = (dirty, options) => sanitizeHtmlLib(dirty, options);
|
|
537
|
+
|
|
538
|
+
function sanitizeProduct(product) {
|
|
539
|
+
return {
|
|
540
|
+
...product,
|
|
541
|
+
description: product.description ? sanitizeHtml(product.description) : product.description
|
|
542
|
+
};
|
|
543
|
+
}
|
|
500
544
|
const enhanceSku = (item, product) => ({
|
|
501
545
|
...item,
|
|
502
|
-
isVariantOf: product
|
|
546
|
+
isVariantOf: sanitizeProduct(product)
|
|
503
547
|
});
|
|
504
548
|
|
|
505
549
|
class FastStoreError extends Error {
|
|
@@ -1002,55 +1046,31 @@ function getPropertyId(item) {
|
|
|
1002
1046
|
}
|
|
1003
1047
|
|
|
1004
1048
|
const shouldUpdateShippingData = (orderForm, session) => {
|
|
1005
|
-
var _orderForm$shippingDa;
|
|
1049
|
+
var _orderForm$shippingDa, _orderForm$shippingDa2;
|
|
1006
1050
|
if (!hasSessionPostalCodeOrGeoCoordinates(session)) {
|
|
1007
1051
|
return {
|
|
1008
1052
|
updateShipping: false,
|
|
1009
1053
|
addressChanged: false
|
|
1010
1054
|
};
|
|
1011
1055
|
}
|
|
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)) {
|
|
1056
|
+
if (!hasItems(orderForm)) {
|
|
1020
1057
|
return {
|
|
1021
|
-
updateShipping:
|
|
1022
|
-
addressChanged:
|
|
1058
|
+
updateShipping: false,
|
|
1059
|
+
addressChanged: false
|
|
1023
1060
|
};
|
|
1024
1061
|
}
|
|
1025
|
-
|
|
1062
|
+
const [selectedAddress] = (_orderForm$shippingDa = orderForm == null ? void 0 : (_orderForm$shippingDa2 = orderForm.shippingData) == null ? void 0 : _orderForm$shippingDa2.selectedAddresses) != null ? _orderForm$shippingDa : [];
|
|
1063
|
+
if (checkPostalCode(selectedAddress, session.postalCode) || checkGeoCoordinates(selectedAddress, session.geoCoordinates) || checkAddressType(selectedAddress, session.addressType)) {
|
|
1026
1064
|
return {
|
|
1027
1065
|
updateShipping: true,
|
|
1028
1066
|
addressChanged: true
|
|
1029
1067
|
};
|
|
1030
1068
|
}
|
|
1031
|
-
if (!hasItems(orderForm)) {
|
|
1032
|
-
return {
|
|
1033
|
-
updateShipping: false,
|
|
1034
|
-
addressChanged: false
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
1069
|
// The logisticsInfo will always exist if there´s at least one item inside the cart
|
|
1038
1070
|
const {
|
|
1039
1071
|
logisticsInfo
|
|
1040
1072
|
} = 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)) {
|
|
1073
|
+
if (shouldUpdateDeliveryInfo(logisticsInfo, session)) {
|
|
1054
1074
|
return {
|
|
1055
1075
|
updateShipping: true,
|
|
1056
1076
|
addressChanged: false
|
|
@@ -1063,15 +1083,16 @@ const shouldUpdateShippingData = (orderForm, session) => {
|
|
|
1063
1083
|
};
|
|
1064
1084
|
// Validate if theres any postal Code or GeoCoordinates set at the session
|
|
1065
1085
|
const hasSessionPostalCodeOrGeoCoordinates = session => {
|
|
1066
|
-
|
|
1086
|
+
var _session$geoCoordinat, _session$geoCoordinat2;
|
|
1087
|
+
return !!session.postalCode || ((_session$geoCoordinat = session.geoCoordinates) == null ? void 0 : _session$geoCoordinat.latitude) && ((_session$geoCoordinat2 = session.geoCoordinates) == null ? void 0 : _session$geoCoordinat2.longitude);
|
|
1067
1088
|
};
|
|
1068
1089
|
// Validate if theres a difference between the session postal code and orderForm postal code
|
|
1069
1090
|
const checkPostalCode = (address, postalCode) => {
|
|
1070
1091
|
return typeof postalCode === 'string' && (address == null ? void 0 : address.postalCode) !== postalCode;
|
|
1071
1092
|
};
|
|
1072
1093
|
// 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))
|
|
1094
|
+
const checkGeoCoordinates = (address, geoCoordinates) => {
|
|
1095
|
+
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
1096
|
};
|
|
1076
1097
|
const checkAddressType = (address, addressType) => {
|
|
1077
1098
|
return typeof addressType === 'string' && (address == null ? void 0 : address.addressType) !== addressType;
|
|
@@ -1080,67 +1101,29 @@ const checkAddressType = (address, addressType) => {
|
|
|
1080
1101
|
const hasItems = orderForm => {
|
|
1081
1102
|
return orderForm.items.length !== 0;
|
|
1082
1103
|
};
|
|
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
|
-
}
|
|
1104
|
+
const shouldUpdateDeliveryInfo = (logisticsInfo, session) => {
|
|
1105
|
+
var _session$deliveryMode, _session$deliveryMode2, _session$deliveryMode3;
|
|
1106
|
+
const deliveryChannel = session == null ? void 0 : (_session$deliveryMode = session.deliveryMode) == null ? void 0 : _session$deliveryMode.deliveryChannel;
|
|
1107
|
+
const deliveryMethod = session == null ? void 0 : (_session$deliveryMode2 = session.deliveryMode) == null ? void 0 : _session$deliveryMode2.deliveryMethod;
|
|
1130
1108
|
const {
|
|
1131
1109
|
startDate,
|
|
1132
1110
|
endDate
|
|
1133
|
-
} = session.deliveryMode.deliveryWindow;
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1111
|
+
} = (session == null ? void 0 : (_session$deliveryMode3 = session.deliveryMode) == null ? void 0 : _session$deliveryMode3.deliveryWindow) || {};
|
|
1112
|
+
return logisticsInfo.some(({
|
|
1113
|
+
selectedDeliveryChannel,
|
|
1114
|
+
selectedSla,
|
|
1115
|
+
slas
|
|
1116
|
+
}) => {
|
|
1117
|
+
const checkDeliveryChannel = deliveryChannel && selectedDeliveryChannel !== deliveryChannel;
|
|
1118
|
+
const checkDeliveryMethod = deliveryMethod && selectedSla !== deliveryMethod;
|
|
1119
|
+
return slas == null ? void 0 : slas.some(sla => {
|
|
1120
|
+
var _sla$deliveryWindow, _sla$deliveryWindow2, _sla$availableDeliver;
|
|
1121
|
+
if (checkDeliveryChannel && sla.deliveryChannel === deliveryChannel || checkDeliveryMethod && sla.id === deliveryMethod) {
|
|
1139
1122
|
return true;
|
|
1140
1123
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1124
|
+
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));
|
|
1125
|
+
});
|
|
1126
|
+
});
|
|
1144
1127
|
};
|
|
1145
1128
|
|
|
1146
1129
|
const getAddressOrderForm = (orderForm, session, addressChanged) => {
|