@faststore/api 1.11.4 → 1.11.7
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/CHANGELOG.md +9 -0
- package/dist/__generated__/schema.d.ts +1 -0
- package/dist/api.cjs.development.js +38 -6
- 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 +38 -6
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/platforms/vtex/clients/commerce/index.d.ts +4 -0
- package/dist/platforms/vtex/clients/index.d.ts +4 -0
- package/dist/platforms/vtex/index.d.ts +1 -3
- package/dist/platforms/vtex/resolvers/mutation.d.ts +1 -3
- package/dist/platforms/vtex/resolvers/validateCart.d.ts +2 -4
- package/package.json +2 -2
- package/src/__generated__/schema.ts +3 -0
- package/src/platforms/vtex/clients/commerce/index.ts +11 -0
- package/src/platforms/vtex/resolvers/validateCart.ts +31 -10
- package/src/typeDefs/mutation.graphql +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.11.7](https://github.com/vtex/faststore/compare/v1.11.6...v1.11.7) (2022-08-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Cart with session info ([#1444](https://github.com/vtex/faststore/issues/1444)) ([e36ad6f](https://github.com/vtex/faststore/commit/e36ad6f6e1af1a03c0dd47c4263e96bc9d0b7b8d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
## [1.11.4](https://github.com/vtex/faststore/compare/v1.11.3...v1.11.4) (2022-08-15)
|
|
7
16
|
|
|
8
17
|
|
|
@@ -199,6 +199,7 @@ export declare type MutationSubscribeToNewsletterArgs = {
|
|
|
199
199
|
};
|
|
200
200
|
export declare type MutationValidateCartArgs = {
|
|
201
201
|
cart: IStoreCart;
|
|
202
|
+
session?: Maybe<IStoreSession>;
|
|
202
203
|
};
|
|
203
204
|
export declare type MutationValidateSessionArgs = {
|
|
204
205
|
search: Scalars['String'];
|
|
@@ -71,6 +71,14 @@ const VtexCommerce = ({
|
|
|
71
71
|
body: JSON.stringify(args)
|
|
72
72
|
});
|
|
73
73
|
},
|
|
74
|
+
shippingData: ({
|
|
75
|
+
id,
|
|
76
|
+
body
|
|
77
|
+
}) => {
|
|
78
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, { ...BASE_INIT,
|
|
79
|
+
body: JSON.stringify(body)
|
|
80
|
+
});
|
|
81
|
+
},
|
|
74
82
|
orderForm: ({
|
|
75
83
|
id,
|
|
76
84
|
refreshOutdatedData = true,
|
|
@@ -1074,6 +1082,31 @@ const isOrderFormStale = form => {
|
|
|
1074
1082
|
|
|
1075
1083
|
const newEtag = getOrderFormEtag(form);
|
|
1076
1084
|
return newEtag !== oldEtag;
|
|
1085
|
+
}; // Returns the regionalized orderForm
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
const getOrderForm = async (id, session, {
|
|
1089
|
+
clients: {
|
|
1090
|
+
commerce
|
|
1091
|
+
}
|
|
1092
|
+
}) => {
|
|
1093
|
+
var _orderForm$shippingDa, _orderForm$shippingDa2;
|
|
1094
|
+
|
|
1095
|
+
const orderForm = await commerce.checkout.orderForm({
|
|
1096
|
+
id
|
|
1097
|
+
});
|
|
1098
|
+
const shouldUpdateShippingData = ((_orderForm$shippingDa = orderForm.shippingData) == null ? void 0 : (_orderForm$shippingDa2 = _orderForm$shippingDa.address) == null ? void 0 : _orderForm$shippingDa2.postalCode) != (session == null ? void 0 : session.postalCode);
|
|
1099
|
+
|
|
1100
|
+
if (shouldUpdateShippingData) {
|
|
1101
|
+
return commerce.checkout.shippingData({
|
|
1102
|
+
id: orderForm.orderFormId,
|
|
1103
|
+
body: {
|
|
1104
|
+
selectedAddresses: [session]
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
return orderForm;
|
|
1077
1110
|
};
|
|
1078
1111
|
/**
|
|
1079
1112
|
* This resolver implements the optimistic cart behavior. The main idea in here
|
|
@@ -1093,7 +1126,8 @@ const isOrderFormStale = form => {
|
|
|
1093
1126
|
const validateCart = async (_, {
|
|
1094
1127
|
cart: {
|
|
1095
1128
|
order
|
|
1096
|
-
}
|
|
1129
|
+
},
|
|
1130
|
+
session
|
|
1097
1131
|
}, ctx) => {
|
|
1098
1132
|
const {
|
|
1099
1133
|
enableOrderFormSync
|
|
@@ -1111,9 +1145,7 @@ const validateCart = async (_, {
|
|
|
1111
1145
|
}
|
|
1112
1146
|
} = ctx; // Step1: Get OrderForm from VTEX Commerce
|
|
1113
1147
|
|
|
1114
|
-
const orderForm = await
|
|
1115
|
-
id: orderNumber
|
|
1116
|
-
}); // Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
1148
|
+
const orderForm = await getOrderForm(orderNumber, session, ctx); // Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
1117
1149
|
// If so, this means the user interacted with this cart elsewhere and expects
|
|
1118
1150
|
// to see this new cart state instead of what's stored on the user's browser.
|
|
1119
1151
|
|
|
@@ -2181,8 +2213,8 @@ var doc$6 = {"kind":"Document","definitions":[{"kind":"UnionTypeDefinition","nam
|
|
|
2181
2213
|
var doc$7 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Image.","block":true},"name":{"kind":"Name","value":"StoreImage"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Image URL.","block":true},"name":{"kind":"Name","value":"url"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Alias for the image.","block":true},"name":{"kind":"Name","value":"alternateName"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","description":{"kind":"StringValue","value":"Image input.","block":true},"name":{"kind":"Name","value":"IStoreImage"},"directives":[],"fields":[{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Image input URL.","block":true},"name":{"kind":"Name","value":"url"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Alias for the input image.","block":true},"name":{"kind":"Name","value":"alternateName"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]}],"loc":{"start":0,"end":291}};
|
|
2182
2214
|
doc$7.loc.source = {"body":"\"\"\"\nImage.\n\"\"\"\ntype StoreImage {\n \"\"\"\n Image URL.\n \"\"\"\n url: String!\n \"\"\"\n Alias for the image.\n \"\"\"\n alternateName: String!\n}\n\n\"\"\"\nImage input.\n\"\"\"\ninput IStoreImage {\n \"\"\"\n Image input URL.\n \"\"\"\n url: String!\n \"\"\"\n Alias for the input image.\n \"\"\"\n alternateName: String!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
2183
2215
|
|
|
2184
|
-
var doc$8 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"Mutation"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.","block":true},"name":{"kind":"Name","value":"validateCart"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"cart"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreCart"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCart"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Updates a web session with the specified values.","block":true},"name":{"kind":"Name","value":"validateSession"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"session"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreSession"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"search"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreSession"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Subscribes a new person to the newsletter list.","block":true},"name":{"kind":"Name","value":"subscribeToNewsletter"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"data"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IPersonNewsletter"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"PersonNewsletter"}},"directives":[]}]}],"loc":{"start":0,"end":
|
|
2185
|
-
doc$8.loc.source = {"body":"type Mutation {\n \"\"\"\n Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.\n \"\"\"\n validateCart(cart: IStoreCart
|
|
2216
|
+
var doc$8 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","name":{"kind":"Name","value":"Mutation"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.","block":true},"name":{"kind":"Name","value":"validateCart"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"cart"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreCart"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"session"},"type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreSession"}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreCart"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Updates a web session with the specified values.","block":true},"name":{"kind":"Name","value":"validateSession"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"session"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreSession"}}},"directives":[]},{"kind":"InputValueDefinition","name":{"kind":"Name","value":"search"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreSession"}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Subscribes a new person to the newsletter list.","block":true},"name":{"kind":"Name","value":"subscribeToNewsletter"},"arguments":[{"kind":"InputValueDefinition","name":{"kind":"Name","value":"data"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IPersonNewsletter"}}},"directives":[]}],"type":{"kind":"NamedType","name":{"kind":"Name","value":"PersonNewsletter"}},"directives":[]}]}],"loc":{"start":0,"end":570}};
|
|
2217
|
+
doc$8.loc.source = {"body":"type Mutation {\n \"\"\"\n Checks for changes between the cart presented in the UI and the cart stored in the ecommerce platform. If changes are detected, it returns the cart stored on the platform. Otherwise, it returns `null`.\n \"\"\"\n validateCart(cart: IStoreCart!, session: IStoreSession): StoreCart\n \"\"\"\n Updates a web session with the specified values.\n \"\"\"\n validateSession(session: IStoreSession!, search: String!): StoreSession\n \"\"\"\n Subscribes a new person to the newsletter list.\n \"\"\"\n subscribeToNewsletter(data: IPersonNewsletter!): PersonNewsletter\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|
|
2186
2218
|
|
|
2187
2219
|
var doc$9 = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Offer information.","block":true},"name":{"kind":"Name","value":"StoreOffer"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.","block":true},"name":{"kind":"Name","value":"listPrice"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.","block":true},"name":{"kind":"Name","value":"sellingPrice"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"ISO code of the currency used for the offer prices.","block":true},"name":{"kind":"Name","value":"priceCurrency"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Also known as spot price.","block":true},"name":{"kind":"Name","value":"price"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.","block":true},"name":{"kind":"Name","value":"priceValidUntil"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Offer item condition.","block":true},"name":{"kind":"Name","value":"itemCondition"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Offer item availability.","block":true},"name":{"kind":"Name","value":"availability"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Seller responsible for the offer.","block":true},"name":{"kind":"Name","value":"seller"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreOrganization"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Information on the item being offered.","block":true},"name":{"kind":"Name","value":"itemOffered"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"StoreProduct"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Number of items offered.","block":true},"name":{"kind":"Name","value":"quantity"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","description":{"kind":"StringValue","value":"Offer input.","block":true},"name":{"kind":"Name","value":"IStoreOffer"},"directives":[],"fields":[{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Also known as spot price.","block":true},"name":{"kind":"Name","value":"price"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.","block":true},"name":{"kind":"Name","value":"listPrice"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Float"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Seller responsible for the offer.","block":true},"name":{"kind":"Name","value":"seller"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreOrganization"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Information on the item being offered.","block":true},"name":{"kind":"Name","value":"itemOffered"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"IStoreProduct"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Number of items offered.","block":true},"name":{"kind":"Name","value":"quantity"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},"directives":[]}]}],"loc":{"start":0,"end":1501}};
|
|
2188
2220
|
doc$9.loc.source = {"body":"\"\"\"\nOffer information.\n\"\"\"\ntype StoreOffer {\n \"\"\"\n This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.\n \"\"\"\n listPrice: Float!\n \"\"\"\n Computed price before applying coupons, taxes or benefits. This may change before it reaches the shelf.\n \"\"\"\n sellingPrice: Float!\n \"\"\"\n ISO code of the currency used for the offer prices.\n \"\"\"\n priceCurrency: String!\n \"\"\"\n Also known as spot price.\n \"\"\"\n price: Float!\n \"\"\"\n Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time.\n \"\"\"\n priceValidUntil: String!\n \"\"\"\n Offer item condition.\n \"\"\"\n itemCondition: String!\n \"\"\"\n Offer item availability.\n \"\"\"\n availability: String!\n \"\"\"\n Seller responsible for the offer.\n \"\"\"\n seller: StoreOrganization!\n \"\"\"\n Information on the item being offered.\n \"\"\"\n itemOffered: StoreProduct!\n \"\"\"\n Number of items offered.\n \"\"\"\n quantity: Int!\n}\n\n\"\"\"\nOffer input.\n\"\"\"\ninput IStoreOffer {\n \"\"\"\n Also known as spot price.\n \"\"\"\n price: Float!\n \"\"\"\n This is displayed as the \"from\" price in the context of promotions' price comparison. This may change before it reaches the shelf.\n \"\"\"\n listPrice: Float!\n \"\"\"\n Seller responsible for the offer.\n \"\"\"\n seller: IStoreOrganization!\n \"\"\"\n Information on the item being offered.\n \"\"\"\n itemOffered: IStoreProduct!\n \"\"\"\n Number of items offered.\n \"\"\"\n quantity: Int!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
|