@shopify/hydrogen 1.3.2 → 1.4.1

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.
Files changed (36) hide show
  1. package/dist/esnext/components/CartProvider/CartActions.client.d.ts +62 -0
  2. package/dist/esnext/components/CartProvider/CartActions.client.js +232 -0
  3. package/dist/esnext/components/CartProvider/CartProviderV2.client.d.ts +49 -0
  4. package/dist/esnext/components/CartProvider/CartProviderV2.client.js +370 -0
  5. package/dist/esnext/components/CartProvider/hooks.client.js +1 -1
  6. package/dist/esnext/components/CartProvider/types.d.ts +165 -0
  7. package/dist/esnext/components/CartProvider/useCartAPIStateMachine.client.d.ts +22 -0
  8. package/dist/esnext/components/CartProvider/useCartAPIStateMachine.client.js +251 -0
  9. package/dist/esnext/entry-client.js +26 -8
  10. package/dist/esnext/experimental.d.ts +1 -0
  11. package/dist/esnext/experimental.js +1 -0
  12. package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +3 -2
  13. package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.js +1 -0
  14. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.client.d.ts +3 -3
  15. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.d.ts +1 -0
  16. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +21 -6
  17. package/dist/esnext/foundation/ShopifyProvider/types.d.ts +5 -2
  18. package/dist/esnext/foundation/useShop/use-shop.d.ts +1 -1
  19. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +1 -0
  20. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +0 -8
  21. package/dist/esnext/hooks/useDelay/useDelay.d.ts +1 -0
  22. package/dist/esnext/hooks/useDelay/useDelay.js +17 -0
  23. package/dist/esnext/hooks/useShopQuery/hooks.js +4 -2
  24. package/dist/esnext/index.d.ts +1 -0
  25. package/dist/esnext/index.js +1 -0
  26. package/dist/esnext/shared-types.d.ts +2 -1
  27. package/dist/esnext/utilities/apiRoutes.js +4 -2
  28. package/dist/esnext/utilities/object.d.ts +1 -1
  29. package/dist/esnext/utilities/storefrontApi.d.ts +4 -2
  30. package/dist/esnext/utilities/storefrontApi.js +31 -6
  31. package/dist/esnext/version.d.ts +1 -1
  32. package/dist/esnext/version.js +1 -1
  33. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +1 -0
  34. package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +0 -8
  35. package/dist/node/shared-types.d.ts +2 -1
  36. package/package.json +3 -1
@@ -0,0 +1,62 @@
1
+ import { AttributeInput, CartBuyerIdentityInput, CartInput, CartLineInput, CartLineUpdateInput, CountryCode } from '../../storefront-api-types.js';
2
+ import { CartAttributesUpdateMutation } from './graphql/CartAttributesUpdateMutation.js';
3
+ import { CartBuyerIdentityUpdateMutation } from './graphql/CartBuyerIdentityUpdateMutation.js';
4
+ import { CartCreateMutation } from './graphql/CartCreateMutation.js';
5
+ import { CartDiscountCodesUpdateMutation, CartDiscountCodesUpdateMutationVariables } from './graphql/CartDiscountCodesUpdateMutation.js';
6
+ import { CartLineAddMutation } from './graphql/CartLineAddMutation.js';
7
+ import { CartLineRemoveMutation } from './graphql/CartLineRemoveMutation.js';
8
+ import { CartLineUpdateMutation } from './graphql/CartLineUpdateMutation.js';
9
+ import { CartNoteUpdateMutation, CartNoteUpdateMutationVariables } from './graphql/CartNoteUpdateMutation.js';
10
+ import { CartQueryQuery } from './graphql/CartQuery.js';
11
+ /**
12
+ * The `useCartActions` hook returns helper graphql functions for Storefront Cart API
13
+ *
14
+ * See [cart API graphql mutations](https://shopify.dev/api/storefront/2022-07/objects/Cart)
15
+ */
16
+ export declare function useCartActions({ numCartLines, cartFragment, countryCode, }: {
17
+ /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */
18
+ numCartLines?: number;
19
+ /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */
20
+ cartFragment?: string;
21
+ /** The ISO country code for i18n. */
22
+ countryCode?: CountryCode;
23
+ }): {
24
+ cartFetch: (cartId: string) => Promise<{
25
+ data: CartQueryQuery | undefined;
26
+ errors: any;
27
+ }>;
28
+ cartCreate: (cart: CartInput) => Promise<{
29
+ data: CartCreateMutation | undefined;
30
+ errors: any;
31
+ }>;
32
+ cartLineAdd: (cartId: string, lines: CartLineInput[]) => Promise<{
33
+ data: CartLineAddMutation | undefined;
34
+ errors: any;
35
+ }>;
36
+ cartLineUpdate: (cartId: string, lines: CartLineUpdateInput[]) => Promise<{
37
+ data: CartLineUpdateMutation | undefined;
38
+ errors: any;
39
+ }>;
40
+ cartLineRemove: (cartId: string, lines: string[]) => Promise<{
41
+ data: CartLineRemoveMutation | undefined;
42
+ errors: any;
43
+ }>;
44
+ noteUpdate: (cartId: string, note: CartNoteUpdateMutationVariables['note']) => Promise<{
45
+ data: CartNoteUpdateMutation | undefined;
46
+ errors: any;
47
+ }>;
48
+ buyerIdentityUpdate: (cartId: string, buyerIdentity: CartBuyerIdentityInput) => Promise<{
49
+ data: CartBuyerIdentityUpdateMutation | undefined;
50
+ errors: any;
51
+ }>;
52
+ cartAttributesUpdate: (cartId: string, attributes: AttributeInput[]) => Promise<{
53
+ data: CartAttributesUpdateMutation | undefined;
54
+ errors: any;
55
+ }>;
56
+ discountCodesUpdate: (cartId: string, discountCodes: CartDiscountCodesUpdateMutationVariables['discountCodes']) => Promise<{
57
+ data: CartDiscountCodesUpdateMutation | undefined;
58
+ errors: any;
59
+ }>;
60
+ cartFragment: string;
61
+ };
62
+ export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n cost {\n totalAmount {\n amount\n currencyCode\n }\n compareAtAmountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n cost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
@@ -0,0 +1,232 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { CountryCode, } from '../../storefront-api-types.js';
3
+ import { CartAttributesUpdate, CartBuyerIdentityUpdate, CartCreate, CartDiscountCodesUpdate, CartLineAdd, CartLineRemove, CartLineUpdate, CartNoteUpdate, CartQuery, } from './cart-queries.js';
4
+ import { useCartFetch } from './hooks.client.js';
5
+ /**
6
+ * The `useCartActions` hook returns helper graphql functions for Storefront Cart API
7
+ *
8
+ * See [cart API graphql mutations](https://shopify.dev/api/storefront/2022-07/objects/Cart)
9
+ */
10
+ export function useCartActions({ numCartLines, cartFragment = defaultCartFragment, countryCode = CountryCode.Us, }) {
11
+ const fetchCart = useCartFetch();
12
+ const cartFetch = useCallback((cartId) => {
13
+ return fetchCart({
14
+ query: CartQuery(cartFragment),
15
+ variables: {
16
+ id: cartId,
17
+ numCartLines,
18
+ country: countryCode,
19
+ },
20
+ });
21
+ }, [fetchCart, cartFragment, numCartLines, countryCode]);
22
+ const cartCreate = useCallback((cart) => {
23
+ return fetchCart({
24
+ query: CartCreate(cartFragment),
25
+ variables: {
26
+ input: cart,
27
+ numCartLines,
28
+ country: countryCode,
29
+ },
30
+ });
31
+ }, [cartFragment, countryCode, fetchCart, numCartLines]);
32
+ const cartLineAdd = useCallback((cartId, lines) => {
33
+ return fetchCart({
34
+ query: CartLineAdd(cartFragment),
35
+ variables: {
36
+ cartId,
37
+ lines,
38
+ numCartLines,
39
+ country: countryCode,
40
+ },
41
+ });
42
+ }, [cartFragment, countryCode, fetchCart, numCartLines]);
43
+ const cartLineUpdate = useCallback((cartId, lines) => {
44
+ return fetchCart({
45
+ query: CartLineUpdate(cartFragment),
46
+ variables: {
47
+ cartId,
48
+ lines,
49
+ numCartLines,
50
+ country: countryCode,
51
+ },
52
+ });
53
+ }, [cartFragment, countryCode, fetchCart, numCartLines]);
54
+ const cartLineRemove = useCallback((cartId, lines) => {
55
+ return fetchCart({
56
+ query: CartLineRemove(cartFragment),
57
+ variables: {
58
+ cartId,
59
+ lines,
60
+ numCartLines,
61
+ country: countryCode,
62
+ },
63
+ });
64
+ }, [cartFragment, countryCode, fetchCart, numCartLines]);
65
+ const noteUpdate = useCallback((cartId, note) => {
66
+ return fetchCart({
67
+ query: CartNoteUpdate(cartFragment),
68
+ variables: {
69
+ cartId,
70
+ note,
71
+ numCartLines,
72
+ country: countryCode,
73
+ },
74
+ });
75
+ }, [fetchCart, cartFragment, numCartLines, countryCode]);
76
+ const buyerIdentityUpdate = useCallback((cartId, buyerIdentity) => {
77
+ return fetchCart({
78
+ query: CartBuyerIdentityUpdate(cartFragment),
79
+ variables: {
80
+ cartId,
81
+ buyerIdentity,
82
+ numCartLines,
83
+ country: countryCode,
84
+ },
85
+ });
86
+ }, [cartFragment, countryCode, fetchCart, numCartLines]);
87
+ const cartAttributesUpdate = useCallback((cartId, attributes) => {
88
+ return fetchCart({
89
+ query: CartAttributesUpdate(cartFragment),
90
+ variables: {
91
+ cartId,
92
+ attributes,
93
+ numCartLines,
94
+ country: countryCode,
95
+ },
96
+ });
97
+ }, [cartFragment, countryCode, fetchCart, numCartLines]);
98
+ const discountCodesUpdate = useCallback((cartId, discountCodes) => {
99
+ return fetchCart({
100
+ query: CartDiscountCodesUpdate(cartFragment),
101
+ variables: {
102
+ cartId,
103
+ discountCodes,
104
+ numCartLines,
105
+ country: countryCode,
106
+ },
107
+ });
108
+ }, [cartFragment, countryCode, fetchCart, numCartLines]);
109
+ return useMemo(() => ({
110
+ cartFetch,
111
+ cartCreate,
112
+ cartLineAdd,
113
+ cartLineUpdate,
114
+ cartLineRemove,
115
+ noteUpdate,
116
+ buyerIdentityUpdate,
117
+ cartAttributesUpdate,
118
+ discountCodesUpdate,
119
+ cartFragment,
120
+ }), [
121
+ cartFetch,
122
+ cartCreate,
123
+ cartLineAdd,
124
+ cartLineUpdate,
125
+ cartLineRemove,
126
+ noteUpdate,
127
+ buyerIdentityUpdate,
128
+ cartAttributesUpdate,
129
+ discountCodesUpdate,
130
+ cartFragment,
131
+ ]);
132
+ }
133
+ export const defaultCartFragment = `
134
+ fragment CartFragment on Cart {
135
+ id
136
+ checkoutUrl
137
+ totalQuantity
138
+ buyerIdentity {
139
+ countryCode
140
+ customer {
141
+ id
142
+ email
143
+ firstName
144
+ lastName
145
+ displayName
146
+ }
147
+ email
148
+ phone
149
+ }
150
+ lines(first: $numCartLines) {
151
+ edges {
152
+ node {
153
+ id
154
+ quantity
155
+ attributes {
156
+ key
157
+ value
158
+ }
159
+ cost {
160
+ totalAmount {
161
+ amount
162
+ currencyCode
163
+ }
164
+ compareAtAmountPerQuantity {
165
+ amount
166
+ currencyCode
167
+ }
168
+ }
169
+ merchandise {
170
+ ... on ProductVariant {
171
+ id
172
+ availableForSale
173
+ compareAtPriceV2 {
174
+ ...MoneyFragment
175
+ }
176
+ priceV2 {
177
+ ...MoneyFragment
178
+ }
179
+ requiresShipping
180
+ title
181
+ image {
182
+ ...ImageFragment
183
+ }
184
+ product {
185
+ handle
186
+ title
187
+ }
188
+ selectedOptions {
189
+ name
190
+ value
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+ cost {
198
+ subtotalAmount {
199
+ ...MoneyFragment
200
+ }
201
+ totalAmount {
202
+ ...MoneyFragment
203
+ }
204
+ totalDutyAmount {
205
+ ...MoneyFragment
206
+ }
207
+ totalTaxAmount {
208
+ ...MoneyFragment
209
+ }
210
+ }
211
+ note
212
+ attributes {
213
+ key
214
+ value
215
+ }
216
+ discountCodes {
217
+ code
218
+ }
219
+ }
220
+
221
+ fragment MoneyFragment on MoneyV2 {
222
+ currencyCode
223
+ amount
224
+ }
225
+ fragment ImageFragment on Image {
226
+ id
227
+ url
228
+ altText
229
+ width
230
+ height
231
+ }
232
+ `;
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { CartFragmentFragment } from './graphql/CartFragment.js';
3
+ import { CartBuyerIdentityInput, CountryCode } from '../../storefront-api-types.js';
4
+ export declare function CartProviderV2({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, onCreateComplete, onLineAddComplete, onLineRemoveComplete, onLineUpdateComplete, onNoteUpdateComplete, onBuyerIdentityUpdateComplete, onAttributesUpdateComplete, onDiscountCodesUpdateComplete, data, cartFragment, customerAccessToken, countryCode, }: {
5
+ /** Any `ReactNode` elements. */
6
+ children: React.ReactNode;
7
+ /** Maximum number of cart lines to fetch. Defaults to 250 cart lines. */
8
+ numCartLines?: number;
9
+ /** A callback that is invoked when the process to create a cart begins, but before the cart is created in the Storefront API. */
10
+ onCreate?: () => void;
11
+ /** A callback that is invoked when the process to add a line item to the cart begins, but before the line item is added to the Storefront API. */
12
+ onLineAdd?: () => void;
13
+ /** A callback that is invoked when the process to remove a line item to the cart begins, but before the line item is removed from the Storefront API. */
14
+ onLineRemove?: () => void;
15
+ /** A callback that is invoked when the process to update a line item in the cart begins, but before the line item is updated in the Storefront API. */
16
+ onLineUpdate?: () => void;
17
+ /** A callback that is invoked when the process to add or update a note in the cart begins, but before the note is added or updated in the Storefront API. */
18
+ onNoteUpdate?: () => void;
19
+ /** A callback that is invoked when the process to update the buyer identity begins, but before the buyer identity is updated in the Storefront API. */
20
+ onBuyerIdentityUpdate?: () => void;
21
+ /** A callback that is invoked when the process to update the cart attributes begins, but before the attributes are updated in the Storefront API. */
22
+ onAttributesUpdate?: () => void;
23
+ /** A callback that is invoked when the process to update the cart discount codes begins, but before the discount codes are updated in the Storefront API. */
24
+ onDiscountCodesUpdate?: () => void;
25
+ /** A callback that is invoked when the process to create a cart completes */
26
+ onCreateComplete?: () => void;
27
+ /** A callback that is invoked when the process to add a line item to the cart completes */
28
+ onLineAddComplete?: () => void;
29
+ /** A callback that is invoked when the process to remove a line item to the cart completes */
30
+ onLineRemoveComplete?: () => void;
31
+ /** A callback that is invoked when the process to update a line item in the cart completes */
32
+ onLineUpdateComplete?: () => void;
33
+ /** A callback that is invoked when the process to add or update a note in the cart completes */
34
+ onNoteUpdateComplete?: () => void;
35
+ /** A callback that is invoked when the process to update the buyer identity completes */
36
+ onBuyerIdentityUpdateComplete?: () => void;
37
+ /** A callback that is invoked when the process to update the cart attributes completes */
38
+ onAttributesUpdateComplete?: () => void;
39
+ /** A callback that is invoked when the process to update the cart discount codes completes */
40
+ onDiscountCodesUpdateComplete?: () => void;
41
+ /** An object with fields that correspond to the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart). */
42
+ data?: CartFragmentFragment;
43
+ /** A fragment used to query the Storefront API's [Cart object](https://shopify.dev/api/storefront/latest/objects/cart) for all queries and mutations. A default value is used if no argument is provided. */
44
+ cartFragment?: string;
45
+ /** A customer access token that's accessible on the server if there's a customer login. */
46
+ customerAccessToken?: CartBuyerIdentityInput['customerAccessToken'];
47
+ /** The ISO country code for i18n. */
48
+ countryCode?: CountryCode;
49
+ }): JSX.Element;