@faststore/api 2.0.156-alpha.0 → 2.0.157-alpha.0
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 +29 -16
- 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 +29 -16
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +4 -2
- package/dist/platforms/vtex/clients/commerce/types/IncrementedAddress.d.ts +16 -0
- package/dist/platforms/vtex/clients/index.d.ts +2 -1
- package/dist/platforms/vtex/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/platforms/vtex/clients/commerce/index.ts +33 -12
- package/src/platforms/vtex/clients/commerce/types/IncrementedAddress.ts +17 -0
- package/src/platforms/vtex/index.ts +11 -10
- package/src/platforms/vtex/resolvers/validateCart.ts +19 -6
|
@@ -13,7 +13,7 @@ var language = require('graphql/language');
|
|
|
13
13
|
var utils = require('@graphql-tools/utils');
|
|
14
14
|
|
|
15
15
|
var name = "@faststore/api";
|
|
16
|
-
var version = "2.0.
|
|
16
|
+
var version = "2.0.156-alpha.0";
|
|
17
17
|
var license = "MIT";
|
|
18
18
|
var main = "dist/index.js";
|
|
19
19
|
var typings = "dist/index.d.ts";
|
|
@@ -113,7 +113,8 @@ const BASE_INIT = {
|
|
|
113
113
|
};
|
|
114
114
|
const VtexCommerce = ({
|
|
115
115
|
account,
|
|
116
|
-
environment
|
|
116
|
+
environment,
|
|
117
|
+
incrementAddress
|
|
117
118
|
}, ctx) => {
|
|
118
119
|
const base = `https://${account}.${environment}.com.br`;
|
|
119
120
|
return {
|
|
@@ -154,25 +155,33 @@ const VtexCommerce = ({
|
|
|
154
155
|
body: JSON.stringify(args)
|
|
155
156
|
});
|
|
156
157
|
},
|
|
158
|
+
incrementAddress: (country, postalCode) => {
|
|
159
|
+
return incrementAddress ? fetchAPI(`${base}/api/checkout/pub/postal-code/${country}/${postalCode}`, {
|
|
160
|
+
method: 'GET',
|
|
161
|
+
headers: {
|
|
162
|
+
'content-type': 'application/json'
|
|
163
|
+
}
|
|
164
|
+
}) : Promise.resolve(undefined);
|
|
165
|
+
},
|
|
157
166
|
shippingData: ({
|
|
158
167
|
id,
|
|
159
168
|
body
|
|
160
|
-
}) => {
|
|
169
|
+
}, incrementedAddress) => {
|
|
161
170
|
var _body$selectedAddress;
|
|
162
171
|
const mappedBody = {
|
|
163
172
|
"selectedAddresses": body == null ? void 0 : (_body$selectedAddress = body.selectedAddresses) == null ? void 0 : _body$selectedAddress.map(address => ({
|
|
164
173
|
"addressType": address.addressType || null,
|
|
165
174
|
"receiverName": address.receiverName || null,
|
|
166
|
-
"postalCode": address.postalCode || null,
|
|
167
|
-
"city":
|
|
168
|
-
"state":
|
|
169
|
-
"country": address.country || null,
|
|
170
|
-
"street":
|
|
171
|
-
"number":
|
|
172
|
-
"neighborhood":
|
|
173
|
-
"complement":
|
|
174
|
-
"reference":
|
|
175
|
-
"geoCoordinates": address.geoCoordinates || []
|
|
175
|
+
"postalCode": address.postalCode || (incrementedAddress == null ? void 0 : incrementedAddress.postalCode) || null,
|
|
176
|
+
"city": (incrementedAddress == null ? void 0 : incrementedAddress.city) || null,
|
|
177
|
+
"state": (incrementedAddress == null ? void 0 : incrementedAddress.state) || null,
|
|
178
|
+
"country": address.country || (incrementedAddress == null ? void 0 : incrementedAddress.country) || null,
|
|
179
|
+
"street": (incrementedAddress == null ? void 0 : incrementedAddress.street) || null,
|
|
180
|
+
"number": (incrementedAddress == null ? void 0 : incrementedAddress.number) || null,
|
|
181
|
+
"neighborhood": (incrementedAddress == null ? void 0 : incrementedAddress.neighborhood) || null,
|
|
182
|
+
"complement": (incrementedAddress == null ? void 0 : incrementedAddress.complement) || null,
|
|
183
|
+
"reference": (incrementedAddress == null ? void 0 : incrementedAddress.reference) || null,
|
|
184
|
+
"geoCoordinates": address.geoCoordinates || (incrementedAddress == null ? void 0 : incrementedAddress.geoCoordinates) || []
|
|
176
185
|
}))
|
|
177
186
|
};
|
|
178
187
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, {
|
|
@@ -1155,7 +1164,7 @@ const getOrderForm = async (id, session, {
|
|
|
1155
1164
|
commerce
|
|
1156
1165
|
}
|
|
1157
1166
|
}) => {
|
|
1158
|
-
var _orderForm$shippingDa, _orderForm$shippingDa2;
|
|
1167
|
+
var _orderForm$shippingDa, _orderForm$shippingDa2, _session$geoCoordinat, _orderForm$shippingDa3, _orderForm$shippingDa4, _orderForm$shippingDa5, _orderForm$shippingDa6;
|
|
1159
1168
|
const orderForm = await commerce.checkout.orderForm({
|
|
1160
1169
|
id
|
|
1161
1170
|
});
|
|
@@ -1167,14 +1176,18 @@ const getOrderForm = async (id, session, {
|
|
|
1167
1176
|
if (!session) {
|
|
1168
1177
|
return orderForm;
|
|
1169
1178
|
}
|
|
1170
|
-
const shouldUpdateShippingData = typeof session.postalCode === 'string' && ((_orderForm$shippingDa = orderForm.shippingData) == null ? void 0 : (_orderForm$shippingDa2 = _orderForm$shippingDa.address) == null ? void 0 : _orderForm$shippingDa2.postalCode)
|
|
1179
|
+
const shouldUpdateShippingData = typeof session.postalCode === 'string' && ((_orderForm$shippingDa = orderForm.shippingData) == null ? void 0 : (_orderForm$shippingDa2 = _orderForm$shippingDa.address) == null ? void 0 : _orderForm$shippingDa2.postalCode) !== session.postalCode || typeof session.geoCoordinates === 'object' && typeof ((_session$geoCoordinat = session.geoCoordinates) == null ? void 0 : _session$geoCoordinat.latitude) === 'number' && typeof session.geoCoordinates.longitude === 'number' && (((_orderForm$shippingDa3 = orderForm.shippingData) == null ? void 0 : (_orderForm$shippingDa4 = _orderForm$shippingDa3.address) == null ? void 0 : _orderForm$shippingDa4.geoCoordinates[0]) !== session.geoCoordinates.longitude || ((_orderForm$shippingDa5 = orderForm.shippingData) == null ? void 0 : (_orderForm$shippingDa6 = _orderForm$shippingDa5.address) == null ? void 0 : _orderForm$shippingDa6.geoCoordinates[1]) !== session.geoCoordinates.latitude);
|
|
1171
1180
|
if (shouldUpdateShippingData) {
|
|
1181
|
+
let incrementedAddress;
|
|
1182
|
+
if (session.postalCode) {
|
|
1183
|
+
incrementedAddress = await commerce.checkout.incrementAddress(session.country, session.postalCode);
|
|
1184
|
+
}
|
|
1172
1185
|
return commerce.checkout.shippingData({
|
|
1173
1186
|
id: orderForm.orderFormId,
|
|
1174
1187
|
body: {
|
|
1175
1188
|
selectedAddresses: [session]
|
|
1176
1189
|
}
|
|
1177
|
-
});
|
|
1190
|
+
}, incrementedAddress);
|
|
1178
1191
|
}
|
|
1179
1192
|
return orderForm;
|
|
1180
1193
|
};
|